private object DeserializeJournaledObject(MemoryStream inputStream)
        {
            object result = null;
            int    num    = inputStream.ReadByte();

            if (num >= 0)
            {
                byte b = (byte)num;
                if (b != 1)
                {
                    if (b == 2)
                    {
                        try
                        {
                            new SecurityPermission(SecurityPermissionFlag.SerializationFormatter).Demand();
                            BinaryFormatter binaryFormatter = new BinaryFormatter();
                            return(binaryFormatter.Deserialize(inputStream));
                        }
                        catch (SecurityException)
                        {
                            return(null);
                        }
                    }
                    throw new FormatException();
                }
                result = ApplicationProxyInternal.ReadInt32(inputStream);
            }
            return(result);
        }
        private object _GetSaveHistoryBytesDelegate(object arg)
        {
            bool flag = (bool)arg;

            ApplicationProxyInternal.SaveHistoryReturnInfo saveHistoryReturnInfo = new ApplicationProxyInternal.SaveHistoryReturnInfo();
            if (this._serviceProvider == null)
            {
                return(null);
            }
            if (Application.IsApplicationObjectShuttingDown)
            {
                return(null);
            }
            Invariant.Assert(this._rbw.Value != null, "BrowserJournalingError: _rbw should not be null");
            Journal journal = this._rbw.Value.Journal;

            Invariant.Assert(journal != null, "BrowserJournalingError: Could not get internal journal for the window");
            JournalEntry journalEntry;

            if (flag)
            {
                NavigationService navigationService = this._rbw.Value.NavigationService;
                try
                {
                    navigationService.RequestCustomContentStateOnAppShutdown();
                }
                catch (Exception ex)
                {
                    if (CriticalExceptions.IsCriticalException(ex))
                    {
                        throw;
                    }
                }
                journal.PruneKeepAliveEntries();
                journalEntry = navigationService.MakeJournalEntry(JournalReason.NewContentNavigation);
                if (journalEntry != null && !journalEntry.IsAlive())
                {
                    if (journalEntry.JEGroupState.JournalDataStreams != null)
                    {
                        journalEntry.JEGroupState.JournalDataStreams.PrepareForSerialization();
                    }
                    journal.UpdateCurrentEntry(journalEntry);
                }
                else
                {
                    journalEntry = journal.GetGoBackEntry();
                }
            }
            else
            {
                journalEntry = journal.CurrentEntry;
            }
            if (journalEntry != null)
            {
                saveHistoryReturnInfo.title   = journalEntry.Name;
                saveHistoryReturnInfo.entryId = journalEntry.Id;
            }
            else
            {
                saveHistoryReturnInfo.title = this._rbw.Value.Title;
            }
            saveHistoryReturnInfo.uri = BindUriHelper.UriToString(this.Uri);
            MemoryStream memoryStream = new MemoryStream();

            memoryStream.Seek(0L, SeekOrigin.Begin);
            if (flag)
            {
                ApplicationProxyInternal.BrowserJournal browserJournal = new ApplicationProxyInternal.BrowserJournal(journal, BindUriHelper.BaseUri);
                new SecurityPermission(SecurityPermissionFlag.SerializationFormatter).Assert();
                try
                {
                    memoryStream.WriteByte(2);
                    BinaryFormatter binaryFormatter = new BinaryFormatter();
                    binaryFormatter.Serialize(memoryStream, browserJournal);
                    goto IL_1A6;
                }
                catch (Exception ex2)
                {
                    if (CriticalExceptions.IsCriticalException(ex2))
                    {
                        throw;
                    }
                    Invariant.Assert(false, "Failed to serialize the navigation journal: " + ex2);
                    goto IL_1A6;
                }
                finally
                {
                    CodeAccessPermission.RevertAll();
                }
            }
            memoryStream.WriteByte(1);
            ApplicationProxyInternal.WriteInt32(memoryStream, saveHistoryReturnInfo.entryId);
IL_1A6:
            saveHistoryReturnInfo.saveByteArray = memoryStream.ToArray();
            ((IDisposable)memoryStream).Dispose();
            return(saveHistoryReturnInfo);
        }
Пример #3
0
        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;
        } 
Пример #4
0
        internal void RunApplication(ApplicationRunner runner)
        {
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordHosting | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose, EventTrace.Event.WpfHost_DocObjHostRunApplicationStart);
 
            // Run the App in the new AppDomain and ask the AppDomainManager
            // to save it. 
            PresentationAppDomainManager.SaveAppDomain = true; 

            EnableErrorPage(); 

            runner();
            Invariant.Assert(PresentationAppDomainManager.NewAppDomain != null);
 
            if (ApplicationProxyInternal.Current == null)
            { 
                Debug.Fail("Unexpected reentrant PostShutdown?"); 
                return;
            } 

            // Create an ApplicationProxyInternal in the new domain.
            PresentationAppDomainManager appDomainMgrProxy =
                        PresentationAppDomainManager.NewAppDomain.DomainManager as PresentationAppDomainManager; 

            // And replace _appProxyInternal. 
            Invariant.Assert(ApplicationProxyInternal.Current == _appProxyInternal, 
                "AppProxyInternal has shut down unexpectedly.");
            _appProxyInternal = appDomainMgrProxy.CreateApplicationProxyInternal(); 

            PresentationAppDomainManager.SaveAppDomain = false;

            // Run the app. 
            ApplicationProxyInternal.InitData initData = _initData.Value;
            initData.HandleHistoryLoad = true; 
            _appProxyInternal.Run(initData); 
            _initData.Value = null; // free objects
 
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordHosting | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose, EventTrace.Event.WpfHost_DocObjHostRunApplicationEnd);
        }
Пример #5
0
        internal void RunApplication(ApplicationRunner runner)
        {
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordHosting | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose, EventTrace.Event.WpfHost_DocObjHostRunApplicationStart);

            // Run the App in the new AppDomain and ask the AppDomainManager
            // to save it.
            PresentationAppDomainManager.SaveAppDomain = true;

            EnableErrorPage();

            if (runner())
            {
                Invariant.Assert(PresentationAppDomainManager.NewAppDomain != null, "Failed to start the application in a new AppDomain");

                Invariant.Assert(ApplicationProxyInternal.Current != null, "Unexpected reentrant PostShutdown?");

                // Create an ApplicationProxyInternal in the new domain.
                PresentationAppDomainManager appDomainMgrProxy =
                            PresentationAppDomainManager.NewAppDomain.DomainManager as PresentationAppDomainManager;

                // And replace _appProxyInternal.
                Invariant.Assert(ApplicationProxyInternal.Current == _appProxyInternal,
                    "AppProxyInternal has shut down unexpectedly.");
                _appProxyInternal = appDomainMgrProxy.CreateApplicationProxyInternal();

                PresentationAppDomainManager.SaveAppDomain = false;

                // Run the app.
                ApplicationProxyInternal.InitData initData = _initData.Value;
                initData.HandleHistoryLoad = true;
                _appProxyInternal.Run(initData);
                _initData.Value = null; // free objects
            }
            else
            {
                // Cached application activation failed
                // we will give the app launcher a chance to retry with Uri activation
                PresentationAppDomainManager.SaveAppDomain = false;
            }

            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordHosting | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose, EventTrace.Event.WpfHost_DocObjHostRunApplicationEnd);
        }