private object _LoadHistoryStreamDelegate(object arg)
        {
            ApplicationProxyInternal.LoadHistoryStreamInfo loadHistoryStreamInfo = (ApplicationProxyInternal.LoadHistoryStreamInfo)arg;
            if (this.IsShutdown())
            {
                return(null);
            }
            loadHistoryStreamInfo.loadStream.Seek(0L, SeekOrigin.Begin);
            object obj = this.DeserializeJournaledObject(loadHistoryStreamInfo.loadStream);

            if (loadHistoryStreamInfo.firstLoadFromHistory)
            {
                if (!(obj is ApplicationProxyInternal.BrowserJournal))
                {
                    return(null);
                }
                ApplicationProxyInternal.BrowserJournal browserJournal = (ApplicationProxyInternal.BrowserJournal)obj;
                Journal      journal      = browserJournal.Journal;
                JournalEntry journalEntry = journal.CurrentEntry;
                if (journalEntry == null)
                {
                    journalEntry = journal.GetGoBackEntry();
                }
                NavigationService navigationService = this._rbw.Value.NavigationService;
                this._rbw.Value.SetJournalForBrowserInterop(journal);
                if (BindUriHelper.BaseUri == null)
                {
                    BindUriHelper.BaseUri = browserJournal.BaseUri;
                }
                if (journalEntry != null)
                {
                    Application.Current.Startup += this.OnStartup;
                    this._rbw.Value.JournalNavigationScope.NavigateToEntry(journalEntry);
                }
            }
            else
            {
                if (!(obj is int))
                {
                    return(null);
                }
                Journal journal = this._rbw.Value.Journal;
                int     index   = journal.FindIndexForEntryWithId((int)obj);
                if (!this._rbw.Value.JournalNavigationScope.NavigateToEntry(index))
                {
                    throw new OperationCanceledException();
                }
            }
            return(null);
        }
        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);
        }