private void WebView2NavigationStarting(object sender, Wrapper.NavigationStartingEventArgs e) { bool cancel = e.Cancel; bool isRedirected = e.IsRedirected; bool isUserInitiated = e.IsUserInitiated; WebView2HttpRequestHeaderCollection requestHeaders = e.HttpHeaderCollection; string uri = e.Uri; string message = "{ \"kind\": \"event\", \"name\": \"NavigationStarting\", \"args\": {"; message += "\"cancel\": " + BoolToString(cancel) + ", " + "\"isRedirected\": " + BoolToString(isRedirected) + ", " + "\"isUserInitiated\": " + BoolToString(isUserInitiated) + ", " + "\"requestHeaders\": " + RequestHeadersToJsonString(requestHeaders) + ", " + "\"uri\": " + EncodeQuote(uri) + " " + "}" + WebViewPropertiesToJsonString(_eventSourceWebView2) + "}"; PostEventMessage(message); }
private void _webView2_NavigationStarting(object sender, Wrapper.NavigationStartingEventArgs e) { string navigationTargetUri = e.Uri; if (_sampleUri == navigationTargetUri) { //! [AddRemoteObject] // _remoteObject = new RemoteObjectSampleNet(); string progId = "RemoteComObjectImpl.1"; Type comType = Type.GetTypeFromProgID(progId, true); //Guid clsId = new Guid("19C0E72A-9D34-4F10-A92E-1119F53D1645"); //Type comType = Type.GetTypeFromCLSID(clsId, true); _remoteObject = Activator.CreateInstance(comType); // VARIANT remoteObjectAsVariant = { }; // m_remoteObject.query_to<IDispatch>(&remoteObjectAsVariant.pdispVal); // remoteObjectAsVariant.vt = VT_DISPATCH; // We can call AddRemoteObject multiple times in a row without // calling RemoveRemoteObject first. This will replace the previous object // with the new object. In our case this is the same object and everything // is fine. _webView2.AddRemoteObject("sample", ref _remoteObject); // remoteObjectAsVariant.pdispVal->Release(); //! [AddRemoteObject] } else { // We can call RemoveRemoteObject multiple times in a row without // calling AddRemoteObject first. This will produce an error result // so we ignore the failure. _webView2.RemoveRemoteObject("sample"); // When we navigate elsewhere we're off of the sample // scenario page and so should remove the scenario. _parent.DeleteComponent(this); } }
/// <summary> /// Register a handler for the NavigationStarting event. /// This handler just enables the Cancel button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WebView2NavigationStarting(object sender, Wrapper.NavigationStartingEventArgs e) { _toolbar.CanCancel = true; }