public void NavigateComplete2(object pDisp, ref object url) { UnsafeNativeMethods.IWebBrowser2 webBrowser = (UnsafeNativeMethods.IWebBrowser2)pDisp; if (this._parent.AxIWebBrowser2 == webBrowser) { if (this._parent.DocumentStream != null) { Invariant.Assert(this._parent.NavigatingToAboutBlank && string.Compare((string)url, "about:blank", StringComparison.OrdinalIgnoreCase) == 0); try { UnsafeNativeMethods.IHTMLDocument nativeHTMLDocument = this._parent.NativeHTMLDocument; if (nativeHTMLDocument != null) { UnsafeNativeMethods.IPersistStreamInit persistStreamInit = nativeHTMLDocument as UnsafeNativeMethods.IPersistStreamInit; System.Runtime.InteropServices.ComTypes.IStream pstm = new ManagedIStream(this._parent.DocumentStream); persistStreamInit.Load(pstm); } return; } finally { this._parent.DocumentStream = null; } } string text = (string)url; if (this._parent.NavigatingToAboutBlank) { Invariant.Assert(string.Compare(text, "about:blank", StringComparison.OrdinalIgnoreCase) == 0); text = null; } Uri uri = string.IsNullOrEmpty(text) ? null : new Uri(text); NavigationEventArgs e = new NavigationEventArgs(uri, null, null, null, null, true); this._parent.OnNavigated(e); } }
public void NavigateComplete2(object pDisp, ref object url) { Debug.Assert(url == null || url is string, "invalid url type"); // Events only fired for top level navigation. UnsafeNativeMethods.IWebBrowser2 axIWebBrowser2 = (UnsafeNativeMethods.IWebBrowser2)pDisp; if (_parent.AxIWebBrowser2 == axIWebBrowser2) { // If we are loading from stream. if (_parent.DocumentStream != null) { Invariant.Assert(_parent.NavigatingToAboutBlank && (String.Compare((string)url, WebBrowser.AboutBlankUriString, StringComparison.OrdinalIgnoreCase) == 0)); try { UnsafeNativeMethods.IHTMLDocument nativeHTMLDocument = _parent.NativeHTMLDocument; if (nativeHTMLDocument != null) { UnsafeNativeMethods.IPersistStreamInit psi = nativeHTMLDocument as UnsafeNativeMethods.IPersistStreamInit; Debug.Assert(psi != null, "The Document does not implement IPersistStreamInit"); System.Runtime.InteropServices.ComTypes.IStream iStream = new MS.Internal.IO.Packaging.ManagedIStream(_parent.DocumentStream); psi.Load(iStream); } } finally { _parent.DocumentStream = null; } } else { string urlString = (string)url; // When source set to null or navigating to stream/string, we navigate to "about:blank" // internally. Make sure we pass null in the event args. if (_parent.NavigatingToAboutBlank) { Invariant.Assert(String.Compare(urlString, WebBrowser.AboutBlankUriString, StringComparison.OrdinalIgnoreCase) == 0); urlString = null; } Uri source = (String.IsNullOrEmpty(urlString) ? null : new Uri(urlString)); NavigationEventArgs e = new NavigationEventArgs(source, null, null, null, null, true); _parent.OnNavigated(e); } } }
private void ReleaseAxControl() { // This line is like a bit of magic... // sometimes, we crash with it on, // sometimes, with it off... // Lately, I have decided to leave it on... // (oh, yes, and the crashes seemed to disappear...) //cpr: ComLib.Release(instance); this.NoComponentChangeEvents++; ContainerControl f = ContainingControl; if (f != null) { f.VisibleChanged -= this.onContainerVisibleChanged; } try { if (instance != null) { Marshal.FinalReleaseComObject(instance); instance = null; iOleInPlaceObject = null; iOleObject = null; iOleControl = null; iOleInPlaceActiveObject = null; iOleInPlaceActiveObjectExternal = null; iPerPropertyBrowsing = null; iCategorizeProperties = null; iPersistStream = null; iPersistStreamInit = null; iPersistStorage = null; } axState[checkedIppb] = false; axState[checkedCP] = false; axState[disposed] = true; freezeCount = 0; axState[sinkAttached] = false; wndprocAddr = IntPtr.Zero; SetOcState(OC_PASSIVE); } finally { this.NoComponentChangeEvents--; } }
private void DepersistControl() { Freeze(true); if (ocxState == null) { // must init new: // if (instance is UnsafeNativeMethods.IPersistStreamInit) { iPersistStreamInit = (UnsafeNativeMethods.IPersistStreamInit) instance; try { storageType = STG_STREAMINIT; iPersistStreamInit.InitNew(); } catch (Exception e1) { Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "Exception thrown trying to IPersistStreamInit.InitNew(). Is this good?" + e1.ToString()); } return; } if (instance is UnsafeNativeMethods.IPersistStream) { storageType = STG_STREAM; iPersistStream = (UnsafeNativeMethods.IPersistStream) instance; return; } if (instance is UnsafeNativeMethods.IPersistStorage) { storageType = STG_STORAGE; ocxState = new State(this); iPersistStorage = (UnsafeNativeMethods.IPersistStorage) instance; try { iPersistStorage.InitNew(ocxState.GetStorage()); } catch (Exception e2) { Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "Exception thrown trying to IPersistStorage.InitNew(). Is this good?" + e2.ToString()); } return; } if (instance is UnsafeNativeMethods.IPersistPropertyBag) { Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, this + " supports IPersistPropertyBag."); iPersistPropBag = (UnsafeNativeMethods.IPersistPropertyBag) instance; try { iPersistPropBag.InitNew(); } catch (Exception e1) { Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "Exception thrown trying to IPersistPropertyBag.InitNew(). Is this good?" + e1.ToString()); } } Debug.Fail("no implemented persitance interfaces on object"); throw new InvalidOperationException(SR.GetString(SR.UnableToInitComponent)); } // Otherwise, we have state to deperist from: switch (ocxState.Type) { case STG_STREAM: try { iPersistStream = (UnsafeNativeMethods.IPersistStream) instance; DepersistFromIStream(ocxState.GetStream()); } catch (Exception e) { Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "Exception thrown trying to IPersistStream.DepersistFromIStream(). Is this good?" + e.ToString()); } break; case STG_STREAMINIT: if (instance is UnsafeNativeMethods.IPersistStreamInit) { try { iPersistStreamInit = (UnsafeNativeMethods.IPersistStreamInit) instance; DepersistFromIStreamInit(ocxState.GetStream()); } catch (Exception e) { Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "Exception thrown trying to IPersistStreamInit.DepersistFromIStreamInit(). Is this good?" + e.ToString()); } GetControlEnabled(); } else { ocxState.Type = STG_STREAM; DepersistControl(); return; } break; case STG_STORAGE: try { iPersistStorage = (UnsafeNativeMethods.IPersistStorage) instance; DepersistFromIStorage(ocxState.GetStorage()); } catch (Exception e) { Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "Exception thrown trying to IPersistStorage.DepersistFromIStorage(). Is this good?" + e.ToString()); } break; default: Debug.Fail("unknown storage type."); throw new InvalidOperationException(SR.GetString(SR.UnableToInitComponent)); } if (ocxState.GetPropBag() != null) { try { iPersistPropBag = (UnsafeNativeMethods.IPersistPropertyBag)instance; DepersistFromIPropertyBag(ocxState.GetPropBag()); } catch (Exception e) { Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "Exception thrown trying to IPersistPropertyBag.DepersistFromIPropertyBag(). Is this good?" + e.ToString()); } } }