コード例 #1
0
        // Shutdown the App.
        // Note: The "post" in the method name is legacy. Now all of Application's shutdown work is complete
        // when this method returns. In particular, the managed Dispatcher is shut down.
        internal void PostShutdown()
        {
            Cleanup();
            _proxyInstance = null;

            Application app = Application.Current;

            if (app != null)
            {
                XappLauncherApp launcherApp = app as XappLauncherApp;
                if (launcherApp != null)
                {
                    launcherApp.AbortActivation();
                    Debug.Assert(Application.IsShuttingDown);
                }
                else
                {
                    //this calls into the internal helper and is hardcoded for a clean
                    // shutdown
                    app.CriticalShutdown(0);

                    // The Application.Exit event is raised in a Dispatcher callback at Normal priority.
                    // Blocking on this callback here ensures that the event will be raised before we've
                    // disconnected from the browser. An XBAP may want, in particular, to write a cookie.
                    app.Dispatcher.Invoke(DispatcherPriority.Normal,
                                          new DispatcherOperationCallback(delegate(object unused) { return(null); }), null);
                }
            }
        }
コード例 #2
0
        internal void PostShutdown()
        {
            this.Cleanup();
            ApplicationProxyInternal._proxyInstance = null;
            Application application = Application.Current;

            if (application != null)
            {
                XappLauncherApp xappLauncherApp = application as XappLauncherApp;
                if (xappLauncherApp != null)
                {
                    xappLauncherApp.AbortActivation();
                    return;
                }
                application.CriticalShutdown(0);
                application.Dispatcher.Invoke(DispatcherPriority.Normal, new DispatcherOperationCallback((object unused) => null), null);
            }
        }
コード例 #3
0
ファイル: DocobjHost.cs プロジェクト: sjyanxin/WPFSource
        int IBrowserHostServices.Run(
            String path,
            String fragment, 
            MimeType mime,
            String debugSecurityZoneURL, 
            String applicationId, 
            object streamContainer,
            object ucomLoadIStream, 
            HostingFlags hostingFlags,
            INativeProgressPage nativeProgressPage,
            string progressAssemblyName,
            string progressClassName, 
            string errorAssemblyName,
            string errorClassName, 
            IHostBrowser hostBrowser 
            )
        { 
            Invariant.Assert(String.IsNullOrEmpty(path) == false,  "path string should not be null or empty when Run method is called.");
            Invariant.Assert(mime != MimeType.Unknown, "Unknown mime type");

            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordHosting | EventTrace.Keyword.KeywordPerf, EventTrace.Event.WpfHost_IBHSRunStart, "\""+path+"\"", "\""+applicationId+"\""); 

            int exitCode = 0; 
 
            try
            { 
                ApplicationProxyInternal.InitData initData = _initData.Value;
                initData.HostBrowser = hostBrowser;
                initData.Fragment = fragment;
                initData.UcomLoadIStream = ucomLoadIStream; 
                initData.HandleHistoryLoad = true;
                initData.MimeType.Value = mime; 
 
                // Dev10 821573 - Installing .NET 4.0 adds two parts to the user agent string, i.e.
                // .NET4.0C and .NET4.0E, potentially causing the user agent string to overflow its 
                // documented maximum length of MAX_PATH. While the right place to fix this is in
                // HostBrowserIE::GetUserAgentString in PresentationHostProxy, shared components
                // turn out hard to patch after the fact, so we do a spot-fix here in case we're
                // running in IE. 
                string userAgent = null;
                MS.Internal.Interop.HRESULT hr = hostBrowser.GetUserAgentString(out userAgent); // get it only once for both AppDomains 
                if (hr == MS.Internal.Interop.HRESULT.E_OUTOFMEMORY && (hostingFlags & HostingFlags.hfHostedInIEorWebOC) != 0) 
                {
                    userAgent = MS.Win32.UnsafeNativeMethods.ObtainUserAgentString(); 
                    hr = MS.Internal.Interop.HRESULT.S_OK;
                }
                hr.ThrowIfFailed();
 
                initData.UserAgentString = userAgent;
                initData.HostingFlags = hostingFlags; 
 
                Uri activationUri = new UriBuilder(path).Uri;
                initData.ActivationUri.Value = activationUri; 
                PresentationAppDomainManager.ActivationUri = activationUri;

                // We do this here so that it will be set correctly when our deployment application
                // launches. This matters because if it isn't set when the app ctor is run, then 
                // we will call Dispatcher.Run synchronously, which will make the browser
                // unresponsive. 
                BrowserInteropHelper.SetBrowserHosted(true); 

                if ((hostingFlags & HostingFlags.hfInDebugMode) != 0) 
                {
                    _browserCallbackServices.ChangeDownloadState(false); // stop waving the flag
                    _browserCallbackServices.UpdateProgress(-1, 0); // make the progress bar go away
                    EnableErrorPage(); 
                    _appProxyInternal = new ApplicationLauncherXappDebug(path, debugSecurityZoneURL).Initialize();
                } 
                else 
                {
                    switch (mime) 
                    {
                        case MimeType.Document:

                            _appProxyInternal = CreateAppDomainForXpsDocument(); 
                            if (_appProxyInternal == null)
                            { 
                                exitCode = -1; 
                            }
                            else 
                            {
                                if (streamContainer != null)
                                {
                                    IntPtr punk = Marshal.GetIUnknownForObject(streamContainer); 
                                    _appProxyInternal.StreamContainer = punk;
                                    Marshal.Release(punk); 
                                } 
                            }
                            // Free objects (after the _appProxyInternal.Run(initData) call below). 
                            // For the other MIME types, this is done in RunApplication().
                            _initData.Value = null;
                            break;
 
                        case MimeType.Markup:
                            _appProxyInternal = CreateAppDomainForLooseXaml(activationUri); 
                            _initData.Value = null; // Not needed anymore. 
                            break;
 
                        case MimeType.Application:
                            // This is a browser hosted express app scenario.
                            // Setup XappLauncherApp with default values, and instantiate
                            // ApplicationProxyInternal for this AppDomain. 
                            XappLauncherApp application = new XappLauncherApp(activationUri, applicationId,
                                _browserCallbackServices, new ApplicationRunnerCallback(RunApplication), 
                                nativeProgressPage, 
                                progressAssemblyName, progressClassName, errorAssemblyName, errorClassName);
 
                            // No need to handle history for progress app.  Remember
                            // it for the real app.
                            initData.HandleHistoryLoad = false;
 
                            _appProxyInternal = new ApplicationProxyInternal();
                            break; 
 
                        default:
                            exitCode = -1; 
                            break;
                    }
                }
                if (exitCode != -1) 
                {
                    if (mime == MimeType.Document || mime == MimeType.Markup) 
                    { 
                        //[[....], 7/27/07]
                        // Unfortunately, XPSViewer relies on the unhandled exception page to report bad XAML. 
                        // Ideally, only exceptions from the XamlReader should be caught and shown this way,
                        // in order not to hide platform bugs. But it's more than one place where XAML is
                        // loaded from the XPS package, and in more than one way. A little too much to change
                        // in SP1. 
                        // For loose XAML viewing, most exceptions likely to occur from this point on should be
                        // due to bad XAML. 
                        EnableErrorPage(); 
                    }
 
                    //[[....], 01/06/08]
                    // This mitigates TFS Dev10 451830 by showing an actionable message instead of crashing
                    // deep inside the Input code where MSCTF gets loaded and fails to do so. More info on the
                    // conditions leading to this bug and how we detect those can be found in the method used 
                    // for the check below and in the TFS bug database.
                    // See KB article http://support.microsoft.com/kb/954494 (linked in the displayed message). 
                    if (IsAffectedByCtfIssue()) 
                    {
                        exitCode = -1; 
                        _browserCallbackServices.ProcessUnhandledException(
                            String.Format(
                                CultureInfo.CurrentCulture,
                                SR.Get(SRID.AffectedByMsCtfIssue), 
                                "http://support.microsoft.com/kb/954494"
                            ) 
                        ); 
                    }
                    else 
                    {
                        exitCode = _appProxyInternal.Run(initData);
                    }
                } 
            }
            catch (Exception ex) 
            { 
                exitCode = -1;
                // The exception is re-thrown here, but it will get translated to an HRESULT by 
                // COM Interop. That's why ProcessUnhandledException() is called directly.
                // In most cases it runs a modal loop around the error page and never returns.
                _browserCallbackServices.ProcessUnhandledException(ex.ToString());
                throw; 
            }
            catch 
            { 
                // This catches non-CLS compliant exceptions.
                // Not having this clause triggers an FxCop violation. 
                exitCode = -1;
                _browserCallbackServices.ProcessUnhandledException(SR.Get(SRID.NonClsActivationException));
                throw;
            } 
            finally
            { 
                Cleanup(exitCode); 
            }
 
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordHosting | EventTrace.Keyword.KeywordPerf, EventTrace.Event.WpfHost_IBHSRunEnd, exitCode);

            return exitCode;
        }