Example #1
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);
        }
Example #2
0
        public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
        {
            int id = (int)commandId;

            if (id == ShowDevTools)
            {
                browser.ShowDevTools();
            }
            if (id == CloseDevTools)
            {
                browser.CloseDevTools();
            }
            if (id == SaveImageAs)
            {
                browser.GetHost().StartDownload(parameters.SourceUrl);
            }
            if (id == SaveLinkAs)
            {
                browser.GetHost().StartDownload(parameters.LinkUrl);
            }
            if (id == OpenLinkInNewTab)
            {
                ChromiumWebBrowser newBrowser = myForm.AddNewBrowserTab(parameters.LinkUrl, false, browser.MainFrame.Url);
            }
            if (id == CopyLinkAddress)
            {
                Clipboard.SetText(parameters.LinkUrl);
            }
            if (id == CloseTab)
            {
                myForm.InvokeOnParent(delegate() {
                    myForm.CloseActiveTab();
                });
            }
            if (id == RefreshTab)
            {
                myForm.InvokeOnParent(delegate() {
                    myForm.RefreshActiveTab();
                });
            }

            return(false);
        }
Example #3
0
 public void addNewBrowserTab(string url, bool focusNewTab = true)
 {
     myForm.AddNewBrowserTab(url, focusNewTab);
 }
Example #4
0
        public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
        {
            int id = (int)commandId;

            if (id == ShowDevTools)
            {
                browser.ShowDevTools();
            }
            if (id == CloseDevTools)
            {
                browser.CloseDevTools();
            }
            if (id == SaveImageAs)
            {
                browser.GetHost().StartDownload(parameters.SourceUrl);
            }
            if (id == SaveLinkAs)
            {
                browser.GetHost().StartDownload(parameters.LinkUrl);
            }
            if (id == OpenLinkInNewTab)
            {
                ChromiumWebBrowser newBrowser = myForm.AddNewBrowserTab(parameters.LinkUrl, false, browser.MainFrame.Url);
            }
            if (id == CopyLinkAddress)
            {
                Clipboard.SetText(parameters.LinkUrl);
            }
            if (id == CloseTab)
            {
                myForm.InvokeOnParent(delegate() {
                    myForm.CloseActiveTab();
                });
            }
            if (id == RefreshTab)
            {
                myForm.InvokeOnParent(delegate() {
                    myForm.RefreshActiveTab();
                });
            }
            if (id == SaveAsPdf)
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "PDF Files | *.pdf";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    //string path = Path.GetFileName(sfd.FileName);
                    browser.PrintToPdfAsync(sfd.FileName, new PdfPrintSettings()
                    {
                        SelectionOnly      = false,
                        BackgroundsEnabled = true
                    });
                }
            }
            if (id == Print)
            {
                browser.Print();
            }

            return(false);
        }