private const byte CFU_UNDERLINEHAIRLINE = 0x0000000A; /* (*) displayed as ordinary underline */ #endregion #endregion #region ++ Constructeurs ++ public WebViewerEx() { _liensVersHelpActifs = true; _navigationEnCour = false; Navigating += new WebBrowserNavigatingEventHandler(Navigation); Navigated += new WebBrowserNavigatedEventHandler(WebViewerEx_Navigated); }
/// <summary> /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed. /// <example> /// webbrowsernavigatingeventhandler.BeginInvoke(sender, e, callback); /// </example> /// </summary> public static IAsyncResult BeginInvoke(this WebBrowserNavigatingEventHandler webbrowsernavigatingeventhandler, Object sender, WebBrowserNavigatingEventArgs e, AsyncCallback callback) { if (webbrowsernavigatingeventhandler == null) { throw new ArgumentNullException("webbrowsernavigatingeventhandler"); } return(webbrowsernavigatingeventhandler.BeginInvoke(sender, e, callback, null)); }
protected virtual void OnNavigating(WebBrowserNavigatingEventArgs e) { WebBrowserNavigatingEventHandler handler = (WebBrowserNavigatingEventHandler)this.Events[NavigatingEventKey]; if (handler != null) { handler(this, e); } }
protected virtual void OnNavigating(WebBrowserNavigatingEventArgs e) { WebBrowserNavigatingEventHandler navigatingEventHandler = (WebBrowserNavigatingEventHandler)this.Events[RadWebBrowserItem.NavigatingEventKey]; if (navigatingEventHandler == null) { return; } navigatingEventHandler((object)this, e); }
/// <summary> /// 异步执行 /// </summary> /// <param name="options"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public Task <BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default) { var tcs = new TaskCompletionSource <BrowserResult>(); WebBrowserNavigatingEventHandler handler = (sender, e) => { if (e.Url.AbsoluteUri.StartsWith(options.EndUrl)) { tcs.SetResult(new BrowserResult { ResultType = BrowserResultType.Success, Response = e.Url.ToString() }); } }; webBrowser.Navigating += handler; webBrowser.Navigate(options.StartUrl); return(tcs.Task.ContinueWith((result) => { webBrowser.Navigating -= handler; return result.Result; })); }
private void InitializeComponent() { // pop Twitter's OAuth authentication web page here var f = this; var cursor = f.Cursor; f.Cursor = System.Windows.Forms.Cursors.WaitCursor; string authzUrlStub = TwitPicSettings.URL_AUTHORIZE .Substring(0, TwitPicSettings.URL_AUTHORIZE.LastIndexOf('?')); Tracing.Trace("authzUrlStub = '{0}'", authzUrlStub); // event handlers WebBrowserDocumentCompletedEventHandler docCompleted = (sender, e) => { Tracing.Trace("web1.completed, url = '{0}'", web1.Url.ToString()); var url2 = web1.Url.ToString(); // It's possible there will be multiple pages in the flow. if (url2.StartsWith(TwitPicSettings.URL_AUTHORIZE)) { // The login page has been displayed completely f.Cursor = cursor; return; } if (url2 == authzUrlStub) { // the user has clicked the "allow" or "deny" button if (web1.DocumentText.Contains("you've denied")) { // deny Tracing.Trace("Access denied."); web1.Visible = false; _oauth["token"] = ""; // forget the request token _oauth["token_secret"] = ""; // forget the secret f.DialogResult = DialogResult.Cancel; f.Close(); // The caller is responsible for popping a // notification - like a MessageBox saying "you // need to authorize Cropper in order to // upload". } if (web1.DocumentText.Contains("You've successfully granted access")) { var divMarker = "<div id=\"oauth_pin\">"; var index = web1.DocumentText.LastIndexOf(divMarker) + divMarker.Length; var snip = web1.DocumentText.Substring(index); var pin = RE.Regex.Replace(snip, "(?s)[^0-9]*([0-9]+).*", "$1").Trim(); Tracing.Trace("Approval. PIN: '{0}'", pin); web1.Visible = false; // all done with the web UI GetAccessToken(pin); } } }; WebBrowserNavigatingEventHandler navigating = (sender, e) => { Tracing.Trace("web1.navigating, url = '{0}'", web1.Url.ToString()); f.Cursor = System.Windows.Forms.Cursors.WaitCursor; f.Update(); }; // The embedded browser can navigate through HTTP 302 // redirects, download images, and so on. The display will // initially be blank while it is waiting for downloads and // redirects. Also, after the user clicks "Login", there's a // delay. In those cases we want the wait cursor. Only turn // it off if the status text is "Done." EventHandler statusChanged = (sender, e) => { var t = web1.StatusText; if (t == "Done") { f.Cursor = cursor; } else if (!String.IsNullOrEmpty(t)) { Tracing.Trace("web1.status = '{0}'", t); f.Cursor = System.Windows.Forms.Cursors.WaitCursor; } }; web1 = new System.Windows.Forms.WebBrowser(); btnCancel = new System.Windows.Forms.Button(); lblInstructions = new System.Windows.Forms.Label(); // // web1 // web1.Location = new System.Drawing.Point(4, 86); web1.Name = "web1"; web1.DocumentCompleted += docCompleted; web1.Navigating += navigating; web1.StatusTextChanged += statusChanged; web1.Dock = DockStyle.Fill; // // lblInstructions // lblInstructions.Text = _instructions1; lblInstructions.ForeColor = System.Drawing.Color.Red; lblInstructions.AutoSize = true; lblInstructions.Visible = false; lblInstructions.Size = new System.Drawing.Size(576, 46); lblInstructions.Location = new System.Drawing.Point(4, 6); // // btnCancel // btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; btnCancel.Location = new System.Drawing.Point(368, 94); btnCancel.Name = "btnCancel"; btnCancel.Size = new System.Drawing.Size(68, 23); btnCancel.TabIndex = 71; btnCancel.Visible = false; btnCancel.Text = "&Close"; btnCancel.UseVisualStyleBackColor = true; // // Form // f.Controls.Add(web1); f.Controls.Add(lblInstructions); f.Controls.Add(btnCancel); f.Name = "Authorize"; f.Text = "Authorize the Cropper Plugin for TwitPic"; // size to accommodate the twitter confirmation dialog f.MinimumSize = new System.Drawing.Size(820, 474); f.MaximumSize = new System.Drawing.Size(820, 474); }
private void AuthorizeApp() { string url = String.Format(FacebookSettings.AUTHORIZE_URL_FORMAT, FacebookSettings.APP_ID); // create and display a new form var f = new System.Windows.Forms.Form(); var web1 = new System.Windows.Forms.WebBrowser(); f.SuspendLayout(); var cursor = f.Cursor; f.Cursor = System.Windows.Forms.Cursors.WaitCursor; // event handlers WebBrowserDocumentCompletedEventHandler docCompleted = (sender, e) => { Tracing.Trace("web1.completed, url = '{0}'", web1.Url.ToString()); var url2 = web1.Url.ToString(); // It's possible there will be multiple pages in the flow. // We want to respond only to the "login_success" page. Don't // be confused by the name: login_success does not mean "access // granted." if (url2.StartsWith("http://www.facebook.com/connect/login_success.html#") || url2.StartsWith("http://www.facebook.com/connect/login_success.html?")) { web1.Visible = false; var token = RE.Regex.Replace(url2, ".+login_success.html#access_token=([^&]+).+", "$1"); PluginSettings.AccessToken = token; // If token is null or empty, then The user has declined access. // Otherwise, then the user has granted access. // Either way, we want to close the form and return. f.Close(); } }; WebBrowserNavigatingEventHandler navigating = (sender, e) => { Tracing.Trace("web1.navigating, url = '{0}'", web1.Url.ToString()); f.Cursor = System.Windows.Forms.Cursors.WaitCursor; f.Update(); }; // The embedded browser can navigate through HTTP 302 // redirects, download images, and so on. The display will // initially be blank while it is waiting for downloads and // redirects. Also, after the user clicks "Login", there's a // delay. In those cases we want the wait cursor. Only turn // it off if the status text is "Done." EventHandler statusChanged = (sender, e) => { var t = web1.StatusText; if (t == "Done") { f.Cursor = cursor; } else if (!String.IsNullOrEmpty(t)) { Tracing.Trace("web1.status = '{0}'", t); f.Cursor = System.Windows.Forms.Cursors.WaitCursor; } }; // // web1 // web1.Location = new System.Drawing.Point(4, 166); web1.Name = "web1"; web1.DocumentCompleted += docCompleted; web1.Navigating += navigating; web1.StatusTextChanged += statusChanged; web1.Dock = DockStyle.Fill; f.Name = "embeddedBrowserForm"; f.Text = "Please approve the Cropper Plugin for Facebook"; f.Icon = global::Cropper.SendToFacebook.Properties.Resources.icon; f.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); f.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; f.ClientSize = new System.Drawing.Size(460, 320); f.Controls.Add(web1); f.ResumeLayout(false); web1.Url = new Uri(url); f.ShowDialog(); // this will wait for form exit }
public ExtendWebBrowser() : base() { Navigating += new WebBrowserNavigatingEventHandler(event_Navigating); }