コード例 #1
0
 bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
 {
     newBrowser = null;
     //browserControl.Load(targetUrl);
     OpenInNewTab?.Invoke(this, new NewTabEventArgs(targetUrl)); //this breaks when there are multiple window.open calls from JS.
     return true;
 }
コード例 #2
0
        public bool OnBeforePopup(IWebBrowser rpBrowserControl, IBlinkBrowser rpBrowser, IFrame rpFrame, string rpTargetUrl, string rpTargetFrameName, WindowOpenDisposition rpTargetDisposition, bool rpUserGesture, IPopupFeatures rpPopupFeatures, IWindowInfo rpWindowInfo, IBrowserSettings rpBrowserSettings, ref bool rrpNoJavascriptAccess, out IWebBrowser ropNewBrowser)
        {
            rpBrowserControl.Load(rpTargetUrl);

            ropNewBrowser = rpBrowserControl;
            return true;
        }
コード例 #3
0
        protected override bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
        {
            if(openNewTab == null)
            {
                return false;
            }

            var control = (Control)browserControl;

            control.InvokeOnUiThreadIfRequired(delegate ()
            {
                openNewTab(targetUrl, null);
            });

            return true;
        }
コード例 #4
0
ファイル: LifespanHandler.cs プロジェクト: jex518/CefSharp
        bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IWindowInfo windowInfo, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            ChromiumWebBrowser chromiumBrowser = null;

            var windowX = (windowInfo.X == int.MinValue) ? double.NaN : windowInfo.X;
            var windowY = (windowInfo.Y == int.MinValue) ? double.NaN : windowInfo.Y;
            var windowWidth = (windowInfo.Width == int.MinValue) ? double.NaN : windowInfo.Width;
            var windowHeight = (windowInfo.Height == int.MinValue) ? double.NaN : windowInfo.Height;

            chromiumWebBrowser.Dispatcher.Invoke(() =>
            {
                var owner = Window.GetWindow(chromiumWebBrowser);
                chromiumBrowser = new ChromiumWebBrowser
                {
                    Address = targetUrl,
                };

                var popup = new Window
                {
                    Left = windowX,
                    Top = windowY,
                    Width = windowWidth,
                    Height = windowHeight,
                    Content = chromiumBrowser,
                    Owner = owner,
                    Title = targetFrameName
                };

                popup.Closed += (o, e) =>
                {
                    var w = o as Window;
                    if (w != null && w.Content is IWebBrowser)
                    {
                        (w.Content as IWebBrowser).Dispose();
                        w.Content = null;
                    }
                };

                chromiumBrowser.LifeSpanHandler = this;
            });

            newBrowser = chromiumBrowser;

            return false;
        }
コード例 #5
0
ファイル: LifeSpanHandler.cs プロジェクト: bartwe/CefSharp
        bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            //Default behaviour
            newBrowser = null;

            return false; //Return true to cancel the popup creation

            //EXPERIMENTAL: Demonstrates using a new instance of ChromiumWebBrowser to host the popup.
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            ChromiumWebBrowser chromiumBrowser = null;

            var windowX = windowInfo.X;
            var windowY = windowInfo.Y;
            var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width;
            var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height;

            chromiumWebBrowser.Invoke(new Action(() =>
            {
                var owner = chromiumWebBrowser.FindForm();
                chromiumBrowser = new ChromiumWebBrowser(targetUrl)
                {
                    LifeSpanHandler = this
                };
                chromiumBrowser.SetAsPopup();

                var popup = new Form
                {
                    Left = windowX,
                    Top = windowY,
                    Width = windowWidth,
                    Height = windowHeight,
                    Text = targetFrameName
                };

                owner.AddOwnedForm(popup);

                popup.Controls.Add(new Label { Text = "CefSharp Custom Popup" });
                popup.Controls.Add(chromiumBrowser);

                popup.Show();
            }));

            newBrowser = chromiumBrowser;

            return false;
        }
コード例 #6
0
ファイル: LifeSpanHandler.cs プロジェクト: gleox/CefSharp
		bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IWindowInfo windowInfo, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
		{
			var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

			ChromiumWebBrowser chromiumBrowser = null;

			var windowX = windowInfo.X;
			var windowY = windowInfo.Y;
			var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width;
			var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height;

			chromiumWebBrowser.Invoke(new Action(() =>
			{
				var owner = chromiumWebBrowser.FindForm();
				chromiumBrowser = new ChromiumWebBrowser(targetUrl)
				{
					LifeSpanHandler = this
				};
				chromiumBrowser.SetAsPopup();

				var popup = new Form
				{
					Left = windowX,
					Top = windowY,
					Width = windowWidth,
					Height = windowHeight,
					Text = targetFrameName
				};

				owner.AddOwnedForm(popup);

				popup.Controls.Add(new Label { Text = "CefSharp Custom Popup" });
				popup.Controls.Add(chromiumBrowser);

				popup.Show();
			}));

			newBrowser = chromiumBrowser;

			return false;
		}
コード例 #7
0
        public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IWindowInfo windowInfo, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            newBrowser = null;

            Dispatcher.BeginInvoke((Action)(() =>
            {
                ApplicationCommands.New.Execute(new OpenTabCommandParameters(targetUrl, "New tab", "#FFF9F9F9"), this);
            }));

            return true;
        }
コード例 #8
0
 /// <summary>
 /// Called on the UI thread before OnBeforeBrowse in certain limited cases
 /// where navigating a new or different browser might be desirable. This
 /// includes user-initiated navigation that might open in a special way (e.g.
 /// links clicked via middle-click or ctrl + left-click) and certain types of
 /// cross-origin navigation initiated from the renderer process (e.g.
 /// navigating the top-level frame to/from a file URL).
 /// </summary>
 /// <param name="browserControl">the ChromiumWebBrowser control</param>
 /// <param name="browser">the browser object</param>
 /// <param name="frame">The frame object</param>
 /// <param name="targetUrl">target url</param>
 /// <param name="targetDisposition">The value indicates where the user intended to navigate the browser based
 /// on standard Chromium behaviors (e.g. current tab, new tab, etc). </param>
 /// <param name="userGesture">The value will be true if the browser navigated via explicit user gesture
 /// (e.g. clicking a link) or false if it navigated automatically (e.g. via the DomContentLoaded event).</param>
 /// <returns>Return true to cancel the navigation or false to allow the navigation
 /// to proceed in the source browser's top-level frame.</returns>
 public virtual bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl,
                                      WindowOpenDisposition targetDisposition, bool userGesture)
 {
     return(false);
 }
コード例 #9
0
 public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
 { newBrowser = null; return true; }
コード例 #10
0
ファイル: LifeSpanHandler.cs プロジェクト: masixian/CefSharp
        /// <inheritdoc/>
        /// <remarks>
        /// NOTE: DevTools popups DO NOT trigger OnBeforePopup.
        /// </remarks>
        protected override bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            newBrowser = null;

            PopupCreation userAction = onBeforePopupCreated?.Invoke(chromiumWebBrowser, browser, frame, targetUrl, targetFrameName, targetDisposition, userGesture, browserSettings) ?? PopupCreation.Continue;

            //Cancel popup creation
            if (userAction == PopupCreation.Cancel)
            {
                return(true);
            }

            if (userAction == PopupCreation.ContinueWithJavascriptDisabled)
            {
                noJavascriptAccess = true;
            }

            //No action so we'll go with the default behaviour.
            if (onPopupCreated == null)
            {
                return(false);
            }

            var webBrowser = (ChromiumWebBrowser)chromiumWebBrowser;

            //Load and Display Handlers are used to trigger the relevant events.
            //If they are already assigned we'll leave the user preference in place
            if (webBrowser.LoadHandler == null)
            {
                webBrowser.LoadHandler = new LoadHandler();
            }
            if (webBrowser.DisplayHandler == null)
            {
                webBrowser.DisplayHandler = new DisplayHandler();
            }

            //We need to execute sync here so IWindowInfo.SetAsChild is called before we return false;
            webBrowser.InvokeSyncOnUiThreadIfRequired(new Action(() =>
            {
                ChromiumHostControl control = chromiumHostControlCreatedDelegate?.Invoke();

                if (control == null)
                {
                    control = new ChromiumHostControl
                    {
                        Dock = DockStyle.Fill
                    };
                }
                control.CreateControl();

                onPopupCreated?.Invoke(control, targetUrl);

                var rect = control.ClientRectangle;

                var windowBounds = new CefSharp.Structs.Rect(rect.X, rect.Y, rect.Width, rect.Height);

                windowInfo.SetAsChild(control.Handle, windowBounds);
            }));

            return(false);
        }
コード例 #11
0
 bool IRequestHandler.OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
 {
     return OnOpenUrlFromTab(browserControl, browser, frame, targetUrl, targetDisposition, userGesture);
 }
コード例 #12
0
ファイル: TabWindow.cs プロジェクト: Valinwolf/Sibor
            public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
            {
                TabWindow newTab = null;

                _tab.ParentTabs.Invoke(new Action(() =>
                {
                    _tab.ParentTabs.AddNewTab();
                    newTab = _tab.ParentTabs.SelectedTab.Content as TabWindow;

                    bool newTabLoaded = false;

                    if (!newTab.WebBrowser.IsBrowserInitialized)
                    {
                        newTab.WebBrowser.IsBrowserInitializedChanged += (_, __) =>
                        {
                            newTab.WebBrowser.LoadingStateChanged += (___, e) =>
                            {
                                if (!newTabLoaded)
                                {
                                    if (!e.IsLoading)
                                    {
                                        newTabLoaded = true;
                                        newTab.WebBrowser.Load(targetUrl);
                                    }
                                }
                            };
                        };
                    }

                    else
                    {
                        newTab.WebBrowser.LoadingStateChanged += (_, e) =>
                        {
                            if (!newTabLoaded)
                            {
                                if (!e.IsLoading)
                                {
                                    newTabLoaded = true;
                                    newTab.WebBrowser.Load(targetUrl);
                                }
                            }
                        };
                    }
                }));

                newBrowser = null;
                return(true);
            }
コード例 #13
0
        //
        // Summary:
        //     Called before a popup window is created.
        //
        // Parameters:
        //   browserControl:
        //     The CefSharp.IWebBrowser control this request is for.
        //
        //   browser:
        //     The browser instance that launched this popup.
        //
        //   frame:
        //     The HTML frame that launched this popup.
        //
        //   targetUrl:
        //     The URL of the popup content. (This may be empty/null)
        //
        //   targetFrameName:
        //     The name of the popup. (This may be empty/null)
        //
        //   targetDisposition:
        //     The value indicates where the user intended to open the popup (e.g. current
        //     tab, new tab, etc)
        //
        //   userGesture:
        //     The value will be true if the popup was opened via explicit user gesture
        //     (e.g. clicking a link) or false if the popup opened automatically (e.g. via
        //     the DomContentLoaded event).
        //
        //   popupFeatures:
        //     structure contains additional information about the requested popup window
        //
        //   windowInfo:
        //     window information
        //
        //   browserSettings:
        //     browser settings, defaults to source browsers
        //
        //   noJavascriptAccess:
        //     value indicates whether the new browser window should be scriptable and in
        //     the same process as the source browser.
        //
        //   newBrowser:
        //     EXPERIMENTAL - A newly created browser that will host the popup
        //
        // Returns:
        //     To cancel creation of the popup window return true otherwise return false.
        //
        // Remarks:
        //     CEF documentation: Called on the IO thread before a new popup window is created.
        //     The |browser| and |frame| parameters represent the source of the popup request.
        //     The |target_url| and |target_frame_name| values may be empty if none were
        //     specified with the request. The |popupFeatures| structure contains information
        //     about the requested popup window. To allow creation of the popup window optionally
        //     modify |windowInfo|, |client|, |settings| and |no_javascript_access| and
        //     return false. To cancel creation of the popup window return true. The |client|
        //     and |settings| values will default to the source browser's values. The |no_javascript_access|
        //     value indicates whether the new browser window should be scriptable and in
        //     the same process as the source browser.
        public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            // open popup in new tab!
            newBrowser = myForm.AddNewBrowserTab(targetUrl);

            return(true);
        }
コード例 #14
0
        bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            //Set newBrowser to null unless your attempting to host the popup in a new instance of ChromiumWebBrowser
            //This option is typically used in WPF. This example demos using IWindowInfo.SetAsChild
            //Older branches likely still have an example of this method if you choose to go down that path.
            newBrowser = null;

            //Use IWindowInfo.SetAsChild to specify the parent handle
            //NOTE: user PopupAsChildHelper to handle with Form move and Control resize
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            chromiumWebBrowser.Invoke(new Action(() =>
            {
                if (chromiumWebBrowser.FindForm() is BrowserForm owner)
                {
                    var control = new Control
                    {
                        Dock = DockStyle.Fill
                    };
                    control.CreateControl();

                    owner.AddTab(control, targetUrl);

                    var rect = control.ClientRectangle;

                    windowInfo.SetAsChild(control.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom);
                }
            }));

            return(false);
        }
コード例 #15
0
        /// <summary>
        /// The on before popup.
        /// </summary>
        /// <param name="browserControl">
        /// The browser control.
        /// </param>
        /// <param name="browser">
        /// The browser.
        /// </param>
        /// <param name="frame">
        /// The frame.
        /// </param>
        /// <param name="targetUrl">
        /// The target url.
        /// </param>
        /// <param name="targetFrameName">
        /// The target frame name.
        /// </param>
        /// <param name="targetDisposition">
        /// The target disposition.
        /// </param>
        /// <param name="userGesture">
        /// The user gesture.
        /// </param>
        /// <param name="popupFeatures">
        /// The popup features.
        /// </param>
        /// <param name="windowInfo">
        /// The window info.
        /// </param>
        /// <param name="browserSettings">
        /// The browser settings.
        /// </param>
        /// <param name="noJavascriptAccess">
        /// The no javascript access.
        /// </param>
        /// <param name="newBrowser">
        /// The new browser.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            newBrowser = null;

            var isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(targetUrl);

            if (isUrlExternal)
            {
                System.Diagnostics.Process.Start(targetUrl);
            }

            var isUrlCommand = UrlSchemeProvider.IsUrlRegisteredCommand(targetUrl);

            if (isUrlCommand)
            {
                CommandTaskRunner.RunAsync(targetUrl);
            }

            return(true);
        }
コード例 #16
0
        public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            var chromiumWebBrowser = (MyChromiumWebBrowser)browserControl;

            chromiumWebBrowser.Invoke(new Action(() =>
            {
                NewWindowEventArgs e = new NewWindowEventArgs(windowInfo, targetUrl);
                chromiumWebBrowser.OnNewWindow(e);
            }));
            newBrowser = null;
            return(true);
        }
コード例 #17
0
ファイル: RequestEventHandler.cs プロジェクト: qwe900/ArkBot
        protected override bool OnOpenUrlFromTab(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
        {
            var args = new OnOpenUrlFromTabEventArgs(chromiumWebBrowser, browser, frame, targetUrl, targetDisposition, userGesture);

            OnOpenUrlFromTabEvent?.Invoke(this, args);

            return(args.CancelNavigation);
        }
コード例 #18
0
        protected override bool OnOpenUrlFromTab(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
        {
            if (openNewTab == null)
            {
                return(false);
            }

            var control = (Control)chromiumWebBrowser;

            control.InvokeOnUiThreadIfRequired(delegate()
            {
                openNewTab(targetUrl, null);
            });

            return(true);
        }
コード例 #19
0
 bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
 {
     newBrowser = null;
     //browserControl.Load(targetUrl);
     OpenInNewTab?.Invoke(this, new NewTabEventArgs(targetUrl));
     return(true);
 }
コード例 #20
0
 bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
 {
     browser.MainFrame.LoadUrl(targetUrl);
     newBrowser = null;
     return(true);
 }
コード例 #21
0
        bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IWindowInfo windowInfo, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            ChromiumWebBrowser chromiumBrowser = null;

            var windowX      = (windowInfo.X == int.MinValue) ? double.NaN : windowInfo.X;
            var windowY      = (windowInfo.Y == int.MinValue) ? double.NaN : windowInfo.Y;
            var windowWidth  = (windowInfo.Width == int.MinValue) ? double.NaN : windowInfo.Width;
            var windowHeight = (windowInfo.Height == int.MinValue) ? double.NaN : windowInfo.Height;

            chromiumWebBrowser.Dispatcher.Invoke(() =>
            {
                var owner       = Window.GetWindow(chromiumWebBrowser);
                chromiumBrowser = new ChromiumWebBrowser
                {
                    Address = targetUrl,
                };

                var popup = new Window
                {
                    Left    = windowX,
                    Top     = windowY,
                    Width   = windowWidth,
                    Height  = windowHeight,
                    Content = chromiumBrowser,
                    Owner   = owner,
                    Title   = targetFrameName
                };

                popup.Closed += (o, e) =>
                {
                    var w = o as Window;
                    if (w != null && w.Content is IWebBrowser)
                    {
                        (w.Content as IWebBrowser).Dispose();
                        w.Content = null;
                    }
                };

                chromiumBrowser.LifeSpanHandler = this;
            });

            newBrowser = chromiumBrowser;

            return(false);
        }
コード例 #22
0
        //public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName,
        //    WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo,
        //    IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser) {

        //ExtChromiumBrowser webBrowser = chromiumWebBrowser as ExtChromiumBrowser;


        //Action action = new Action(() => {
        //    if (webBrowser.FindForm() is BrowserForm owner) {
        //        NewWindowEventArgs e = new NewWindowEventArgs(windowInfo, targetUrl);
        //        webBrowser.OnNewWindow(e);
        //    }
        //});
        //webBrowser.Invoke(action);
        //newBrowser = null;
        //return true;
        //}

        public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IWindowInfo windowInfo, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            ExtChromiumBrowser webBrowser = browserControl as ExtChromiumBrowser;


            Action action = new Action(() => {
                if (webBrowser.FindForm() is BrowserForm owner)
                {
                    NewWindowEventArgs e = new NewWindowEventArgs(windowInfo, targetUrl);
                    webBrowser.OnNewWindow(e);
                }
            });

            webBrowser.Invoke(action);
            newBrowser = null;
            return(true);
        }
コード例 #23
0
 public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
 {
     newBrowser = null;
     if (chromiumWebBrowser != null)
     {
         chromiumWebBrowser.RequestHandler  = new UA_RequestHandler();
         chromiumWebBrowser.LifeSpanHandler = new CustomLifeSpanHandler();
     }
     return(false);
 }
コード例 #24
0
ファイル: ViewerViewModel.cs プロジェクト: johnhk/SyncTrayzor
 bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IWindowInfo windowInfo, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
 {
     this.processStartProvider.StartDetached(targetUrl);
     newBrowser = null;
     return true;
 }
コード例 #25
0
        public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IWindowInfo windowInfo, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            newBrowser = null;

            Dispatcher.BeginInvoke((Action)(() =>
            {
                ApplicationCommands.New.Execute(new OpenTabCommandParameters(targetUrl, "New tab", "#FFF9F9F9"), this);
            }));

            return(true);
        }
コード例 #26
0
ファイル: LifespanHandler.cs プロジェクト: zhizlm/CefSharp
        bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            newBrowser = null;

            return(false);

            //NOTE: This is experimental
            //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //ChromiumWebBrowser chromiumBrowser = null;

            //var windowX = (windowInfo.X == int.MinValue) ? double.NaN : windowInfo.X;
            //var windowY = (windowInfo.Y == int.MinValue) ? double.NaN : windowInfo.Y;
            //var windowWidth = (windowInfo.Width == int.MinValue) ? double.NaN : windowInfo.Width;
            //var windowHeight = (windowInfo.Height == int.MinValue) ? double.NaN : windowInfo.Height;

            //chromiumWebBrowser.Dispatcher.Invoke(() =>
            //{
            //	var owner = Window.GetWindow(chromiumWebBrowser);
            //	chromiumBrowser = new ChromiumWebBrowser
            //	{
            //		Address = targetUrl,
            //	};

            //	chromiumBrowser.SetAsPopup();
            //	chromiumBrowser.LifeSpanHandler = this;

            //	var popup = new Window
            //	{
            //		Left = windowX,
            //		Top = windowY,
            //		Width = windowWidth,
            //		Height = windowHeight,
            //		Content = chromiumBrowser,
            //		Owner = owner,
            //		Title = targetFrameName
            //	};

            //	var windowInteropHelper = new WindowInteropHelper(popup);
            //	//Create the handle Window handle (In WPF there's only one handle per window, not per control)
            //	var handle = windowInteropHelper.EnsureHandle();

            //	//The parentHandle value will be used to identify monitor info and to act as the parent window for dialogs,
            //	//context menus, etc. If parentHandle is not provided then the main screen monitor will be used and some
            //	//functionality that requires a parent window may not function correctly.
            //	windowInfo.SetAsWindowless(handle, true);

            //	popup.Closed += (o, e) =>
            //	{
            //		var w = o as Window;
            //		if (w != null && w.Content is IWebBrowser)
            //		{
            //			(w.Content as IWebBrowser).Dispose();
            //			w.Content = null;
            //		}
            //	};
            //});

            //newBrowser = chromiumBrowser;

            //return false;
        }
コード例 #27
0
        public OnOpenUrlFromTabEventArgs(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
            : base(chromiumWebBrowser, browser)
        {
            Frame             = frame;
            TargetUrl         = targetUrl;
            TargetDisposition = targetDisposition;
            UserGesture       = userGesture;

            CancelNavigation = false; // default
        }
コード例 #28
0
 /// <summary>
 /// Called on the UI thread before OnBeforeBrowse in certain limited cases where navigating a new or different browser might be
 /// desirable. This includes user-initiated navigation that might open in a special way (e.g. links clicked via middle-click or
 /// ctrl + left-click) and certain types of cross-origin navigation initiated from the renderer process (e.g. navigating the top-
 /// level frame to/from a file URL).
 /// </summary>
 /// <param name="chromiumWebBrowser">the ChromiumWebBrowser control.</param>
 /// <param name="browser">the browser object.</param>
 /// <param name="frame">The frame object.</param>
 /// <param name="targetUrl">target url.</param>
 /// <param name="targetDisposition">The value indicates where the user intended to navigate the browser based on standard
 /// Chromium behaviors (e.g. current tab, new tab, etc).</param>
 /// <param name="userGesture">The value will be true if the browser navigated via explicit user gesture (e.g. clicking a link) or
 /// false if it navigated automatically (e.g. via the DomContentLoaded event).</param>
 /// <returns>
 /// Return true to cancel the navigation or false to allow the navigation to proceed in the source browser's top-level frame.
 /// </returns>
 protected virtual bool OnOpenUrlFromTab(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl,
     WindowOpenDisposition targetDisposition, bool userGesture)
 {
     return false;
 }
コード例 #29
0
        bool IRequestHandler.OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
        {
            var args = new OnOpenUrlFromTabEventArgs(browserControl, browser, frame, targetUrl, targetDisposition, userGesture);

            ExecuteEventHandler <OnOpenUrlFromTabEventArgs>(OnOpenUrlFromTabEvent, args);
            return(args.CancelNavigation);
        }
コード例 #30
0
 public bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture) =>
 true;
コード例 #31
0
 public bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
 {
     throw new NotImplementedException();
 }
コード例 #32
0
 public static LifeSpanHandlerLogic.TargetDisposition ConvertTargetDisposition(WindowOpenDisposition targetDisposition)
 {
     return(targetDisposition switch {
         WindowOpenDisposition.NewBackgroundTab => NewBackgroundTab,
         WindowOpenDisposition.NewForegroundTab => NewForegroundTab,
         WindowOpenDisposition.NewPopup => NewPopup,
         WindowOpenDisposition.NewWindow => NewWindow,
         _ => Other
     });
コード例 #33
0
        bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            //Set newBrowser to null unless your attempting to host the popup in a new instance of ChromiumWebBrowser
            newBrowser = null;

            //Use IWindowInfo.SetAsChild to specify the parent handle
            //NOTE: user PopupAsChildHelper to handle with Form move and Control resize
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            chromiumWebBrowser.Invoke(new Action(() =>
            {
                var owner = chromiumWebBrowser.FindForm() as BrowserForm;

                if (owner != null)
                {
                    var control  = new Control();
                    control.Dock = DockStyle.Fill;
                    control.CreateControl();

                    owner.AddTab(control, targetUrl);

                    var rect = control.ClientRectangle;

                    windowInfo.SetAsChild(control.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom);
                }
            }));

            return(false);
        }
コード例 #34
0
 protected virtual bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame,
     string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture) {
     return false;
 }
コード例 #35
0
ファイル: LifespanHandler.cs プロジェクト: Antonyo/CefSharp
        bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            newBrowser = null;

            return false;

            //NOTE: This is experimental
            //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //ChromiumWebBrowser chromiumBrowser = null;

            //var windowX = (windowInfo.X == int.MinValue) ? double.NaN : windowInfo.X;
            //var windowY = (windowInfo.Y == int.MinValue) ? double.NaN : windowInfo.Y;
            //var windowWidth = (windowInfo.Width == int.MinValue) ? double.NaN : windowInfo.Width;
            //var windowHeight = (windowInfo.Height == int.MinValue) ? double.NaN : windowInfo.Height;

            //chromiumWebBrowser.Dispatcher.Invoke(() =>
            //{
            //	var owner = Window.GetWindow(chromiumWebBrowser);
            //	chromiumBrowser = new ChromiumWebBrowser
            //	{
            //		Address = targetUrl,
            //	};

            //	chromiumBrowser.SetAsPopup();
            //	chromiumBrowser.LifeSpanHandler = this;

            //	var popup = new Window
            //	{
            //		Left = windowX,
            //		Top = windowY,
            //		Width = windowWidth,
            //		Height = windowHeight,
            //		Content = chromiumBrowser,
            //		Owner = owner,
            //		Title = targetFrameName
            //	};

            //	var windowInteropHelper = new WindowInteropHelper(popup);
            //	//Create the handle Window handle (In WPF there's only one handle per window, not per control)
            //	var handle = windowInteropHelper.EnsureHandle();

            //	//The parentHandle value will be used to identify monitor info and to act as the parent window for dialogs,
            //	//context menus, etc. If parentHandle is not provided then the main screen monitor will be used and some
            //	//functionality that requires a parent window may not function correctly.
            //	windowInfo.SetAsWindowless(handle, true);

            //	popup.Closed += (o, e) =>
            //	{
            //		var w = o as Window;
            //		if (w != null && w.Content is IWebBrowser)
            //		{
            //			(w.Content as IWebBrowser).Dispose();
            //			w.Content = null;
            //		}
            //	};
            //});

            //newBrowser = chromiumBrowser;

            //return false;
        }
コード例 #36
0
 protected override bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
 {
     newBrowser = null;
     return(Logic.OnBeforePopup(targetUrl, ConvertTargetDisposition(targetDisposition)));
 }
コード例 #37
0
ファイル: LifeSpanHandler.cs プロジェクト: zxz1989/CefSharp
        bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            //Set newBrowser to null unless your attempting to host the popup in a new instance of ChromiumWebBrowser
            newBrowser = null;

            return(false); //Return true to cancel the popup creation

            //EXPERIMENTAL OPTION #1: Demonstrates using a new instance of ChromiumWebBrowser to host the popup.
            //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //ChromiumWebBrowser chromiumBrowser = null;

            //var windowX = windowInfo.X;
            //var windowY = windowInfo.Y;
            //var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width;
            //var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height;

            //chromiumWebBrowser.Invoke(new Action(() =>
            //{
            //    var owner = chromiumWebBrowser.FindForm();
            //    chromiumBrowser = new ChromiumWebBrowser(targetUrl)
            //    {
            //        LifeSpanHandler = this
            //    };

            //    //NOTE: This is important and must be called before the handle is created
            //    chromiumBrowser.SetAsPopup();

            //    //Ask nicely for the control to create it's underlying handle as we'll need to
            //    //pass it to IWindowInfo.SetAsChild
            //    chromiumBrowser.CreateControl();

            //    var popup = new Form
            //    {
            //        Left = windowX,
            //        Top = windowY,
            //        Width = windowWidth,
            //        Height = windowHeight,
            //        Text = targetFrameName
            //    };

            //    owner.AddOwnedForm(popup);

            //    popup.Controls.Add(new Label { Text = "CefSharp Custom Popup" });
            //    popup.Controls.Add(chromiumBrowser);

            //    popup.Show();

            //    var rect = chromiumBrowser.ClientRectangle;

            //    //This is key, need to tell the Browser which handle will it's parent
            //    //You maybe able to pass in 0 values for left, top, right and bottom though it's safest to provide them
            //    windowInfo.SetAsChild(chromiumBrowser.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom);
            //}));

            //newBrowser = chromiumBrowser;

            //return false;

            //EXPERIMENTAL OPTION #2: Use IWindowInfo.SetAsChild to specify the parent handle
            //NOTE: Window resize not yet handled - it should be possible to get the
            // IBrowserHost from the newly created IBrowser instance that represents the popup
            // Then subscribe to window resize notifications and call NotifyMoveOrResizeStarted
            //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //var windowX = windowInfo.X;
            //var windowY = windowInfo.Y;
            //var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width;
            //var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height;

            //chromiumWebBrowser.Invoke(new Action(() =>
            //{
            //    var owner = chromiumWebBrowser.FindForm();

            //    var popup = new Form
            //    {
            //        Left = windowX,
            //        Top = windowY,
            //        Width = windowWidth,
            //        Height = windowHeight,
            //        Text = targetFrameName
            //    };

            //    popup.CreateControl();

            //    owner.AddOwnedForm(popup);

            //    var control = new Control();
            //    control.Dock = DockStyle.Fill;
            //    control.CreateControl();

            //    popup.Controls.Add(control);

            //    popup.Show();

            //    var rect = control.ClientRectangle;

            //    windowInfo.SetAsChild(control.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom);
            //}));
        }
コード例 #38
0
 /// <summary>
 /// The OnOpenUrlFromTab.
 /// </summary>
 /// <param name="chromiumWebBrowser">The chromiumWebBrowser<see cref="IWebBrowser"/>.</param>
 /// <param name="browser">The browser<see cref="IBrowser"/>.</param>
 /// <param name="frame">The frame<see cref="IFrame"/>.</param>
 /// <param name="targetUrl">The targetUrl<see cref="string"/>.</param>
 /// <param name="targetDisposition">The targetDisposition<see cref="WindowOpenDisposition"/>.</param>
 /// <param name="userGesture">The userGesture<see cref="bool"/>.</param>
 /// <returns>The <see cref="bool"/>.</returns>
 protected override bool OnOpenUrlFromTab(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
 {
     this.OpenUrlFromTabAction?.Invoke(targetUrl);
     return(true);
 }
コード例 #39
0
 public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
 {
     //使用源窗口打开链接,取消创建新窗口
     newBrowser = null;
     //var chromiumWebBrowser = (ChromiumWebBrowser)chromiumWebBrowser;
     chromiumWebBrowser.Load(targetUrl);
     return(true);
 }
コード例 #40
0
 public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
 {
     newBrowser = null;
     PopupRequest?.Invoke(targetUrl);
     return(true);
 }
コード例 #41
0
ファイル: LifeSpanHandler.cs プロジェクト: Antonyo/CefSharp
        bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            //Default behaviour
            newBrowser = null;

            return false; //Return true to cancel the popup creation

            //EXPERIMENTAL OPTION #1: Demonstrates using a new instance of ChromiumWebBrowser to host the popup.
            //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //ChromiumWebBrowser chromiumBrowser = null;

            //var windowX = windowInfo.X;
            //var windowY = windowInfo.Y;
            //var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width;
            //var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height;

            //chromiumWebBrowser.Invoke(new Action(() =>
            //{
            //    var owner = chromiumWebBrowser.FindForm();
            //    chromiumBrowser = new ChromiumWebBrowser(targetUrl)
            //    {
            //        LifeSpanHandler = this
            //    };

            //    //NOTE: This is important and must be called before the handle is created
            //    chromiumBrowser.SetAsPopup();

            //    //Ask nicely for the control to create it's underlying handle as we'll need to
            //    //pass it to IWindowInfo.SetAsChild
            //    chromiumBrowser.CreateControl();

            //    var popup = new Form
            //    {
            //        Left = windowX,
            //        Top = windowY,
            //        Width = windowWidth,
            //        Height = windowHeight,
            //        Text = targetFrameName
            //    };

            //    owner.AddOwnedForm(popup);

            //    popup.Controls.Add(new Label { Text = "CefSharp Custom Popup" });
            //    popup.Controls.Add(chromiumBrowser);

            //    popup.Show();

            //    var rect = chromiumBrowser.ClientRectangle;

            //    //This is key, need to tell the Browser which handle will it's parent
            //    //You maybe able to pass in 0 values for left, top, right and bottom though it's safest to provide them
            //    windowInfo.SetAsChild(chromiumBrowser.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom);
            //}));

            //newBrowser = chromiumBrowser;

            //return false;

            //EXPERIMENTAL OPTION #2: Use IWindowInfo.SetAsChild to specify the parent handle
            //NOTE: Window resize not yet handled - it should be possible to get the
            // IBrowserHost from the newly created IBrowser instance that represents the popup
            // Then subscribe to window resize notifications and call NotifyMoveOrResizeStarted
            //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //var windowX = windowInfo.X;
            //var windowY = windowInfo.Y;
            //var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width;
            //var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height;

            //chromiumWebBrowser.Invoke(new Action(() =>
            //{
            //    var owner = chromiumWebBrowser.FindForm();

            //    var popup = new Form
            //    {
            //        Left = windowX,
            //        Top = windowY,
            //        Width = windowWidth,
            //        Height = windowHeight,
            //        Text = targetFrameName
            //    };

            //    popup.CreateControl();

            //    owner.AddOwnedForm(popup);

            //    var control = new Control();
            //    control.Dock = DockStyle.Fill;
            //    control.CreateControl();

            //    popup.Controls.Add(control);

            //    popup.Show();

            //    var rect = control.ClientRectangle;

            //    windowInfo.SetAsChild(control.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom);
            //}));
        }
コード例 #42
0
 protected override bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
 {
     return(LifeSpanHandler.HandleLinkClick(browserControl, targetDisposition, targetUrl));
 }
コード例 #43
0
 bool IRequestHandler.OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame,
     string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture) {
     return OnOpenUrlFromTab(browserControl, browser, frame, targetUrl, targetDisposition, userGesture);
 }
コード例 #44
0
        public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl,
            string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IWindowInfo windowInfo,
            ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            newBrowser = null;

            Dispatcher.BeginInvoke(
                (Action)
                    (() =>
                    {
                        try
                        {
                            ApplicationCommands.New.Execute(
                                new OpenTabCommandParameters(targetUrl, "New tab", "#FFF9F9F9"), this);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Open popup in new tab error: " + ex.Message + " " + ex.Data);
                        }
                    }));

            return true;
        }