private const int OpenLoadScript = (int)CefSharp.CefMenuCommand.UserFirst + 6; //加载脚本

        public void OnBeforeContextMenu(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model)
        {
            if (BeforeContextMenu != null)
            {
                BeforeContextMenu(this, new BeforeContextMenuEvenArgs(parameters, model));
            }
            model.AddSeparator();
            if (parameters.MediaType == CefSharp.ContextMenuMediaType.Image)
            {
                model.AddItem((CefSharp.CefMenuCommand)CopyImage, "复制图片(&I)");
            }
            if ((CefSharp.ContextMenuType)(parameters.TypeFlags & CefSharp.ContextMenuType.Link) == CefSharp.ContextMenuType.Link)
            {
                if (!string.IsNullOrWhiteSpace(parameters.LinkUrl) && !parameters.LinkUrl.StartsWith("about:black"))
                {
                    model.AddItem((CefSharp.CefMenuCommand)OpenLink, "打开链接(&L)");

                    model.AddItem((CefSharp.CefMenuCommand)OpenLinkSource, "打开链接源码(&S)");

                    model.AddItem((CefSharp.CefMenuCommand)CopyLink, "复制链接(&C)");
                }
            }
            model.AddItem((CefSharp.CefMenuCommand)OpenDevTool, "开发者工具 F12");
            model.AddItem((CefSharp.CefMenuCommand)OpenLoadScript, "加载脚本 F6");
        }
        public bool OnContextMenuCommand(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.CefMenuCommand commandId, CefSharp.CefEventFlags eventFlags)
        {
            switch (commandId)
            {
            case CefSharp.CefMenuCommand.ViewSource:
                if (ViewSource != null)
                {
                    ViewSource(this, new EventArgs());
                }
                return(true);

            case (CefSharp.CefMenuCommand)OpenLink:
            case (CefSharp.CefMenuCommand)OpenLinkSource:
            {
                if (OpenLinkOrSource != null)
                {
                    OpenLinkOrSource(this, new OpenLinkOrSourceArgs(parameters.LinkUrl, commandId == (CefSharp.CefMenuCommand)OpenLinkSource));
                }
            }
                return(true);

            case (CefSharp.CefMenuCommand)CopyImage:
            {
                if (CopyImageToClipboard != null)
                {
                    CopyImageToClipboard(this, new CopyImageEventArgs(parameters.SourceUrl));
                }
            }
                return(true);

            case (CefSharp.CefMenuCommand)OpenDevTool:
            {
                if (ShowDevTool != null)
                {
                    ShowDevTool(this, new EventArgs());
                }
            }
                return(true);

            case (CefSharp.CefMenuCommand)CopyLink:
            {
                Clipboard.SetText(parameters.LinkUrl);
            }
                return(true);

            case (CefSharp.CefMenuCommand)OpenLoadScript:
            {
                if (LoadScript != null)
                {
                    LoadScript(this, new EventArgs());
                }
            }
                return(true);

            default:
                break;
            }
            return(false);
        }
Exemple #3
0
 public bool DoClose(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser)
 {
     if (browser.IsDisposed || browser.IsPopup)
     {
         return(false);
     }
     return(true);
 }
Exemple #4
0
 public NewWindowEventArgs(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, CefSharp.IFrame frame, string targetUrl, string targetFrameName, CefSharp.WindowOpenDisposition targetDisposition, CefSharp.IWindowInfo windowInfo)
 {
     this.chromiumWebBrowser = chromiumWebBrowser;
     this.browser            = browser;
     this.frame             = frame;
     this.targetUrl         = targetUrl;
     this.targetFrameName   = targetFrameName;
     this.targetDisposition = targetDisposition;
     this.windowInfo        = windowInfo;
 }
 public bool OnJSDialog(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, string originUrl, CefSharp.CefJsDialogType dialogType, string messageText, string defaultPromptText, CefSharp.IJsDialogCallback callback, ref bool suppressMessage)
 {
     if (JsDialog != null)
     {
         var args = new JsDialogEventArgs(dialogType, messageText, defaultPromptText, callback, suppressMessage);
         JsDialog(this, args);
         suppressMessage = args.suppressMessage;
         return(args.result);
     }
     return(false);
 }
Exemple #6
0
        /// <summary>
        /// Handles forward and backward
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void navigate_tofo(object sender, RoutedEventArgs e)
        {
            CefSharp.IBrowser wbrowser = getActiveTabBrowser().GetBrowser();

            if (sender == nav_back && wbrowser.CanGoBack)
            {
                wbrowser.GoBack();
            }
            else if (sender == nav_for && wbrowser.CanGoForward)
            {
                wbrowser.GoForward();
            }
        }
Exemple #7
0
 public void OnDownloadUpdated(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, CefSharp.DownloadItem downloadItem, CefSharp.IDownloadItemCallback callback)
 {
     if (downloadItem.IsCancelled || downloadItem.IsComplete || !downloadItem.IsInProgress || !downloadItem.IsValid)
     {
         Console.WriteLine("OnDownloadUpdated downloadItem.Id=" + downloadItem.Id + ",downloadItem.OriginalUrl=" + downloadItem.OriginalUrl);
         DownloadManager.Update(downloadItem);
         DownloadManager.Remove(downloadItem.Id);
     }
     else
     {
         lastDownloadItem = downloadItem;
     }
 }
Exemple #8
0
 public void OnBeforeDownload(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, CefSharp.DownloadItem downloadItem, CefSharp.IBeforeDownloadCallback callback)
 {
     if (!callback.IsDisposed)
     {
         using (callback)
         {
             var find = DownloadManager.Find(downloadItem.OriginalUrl);
             if (find != null)
             {
                 find.Id = downloadItem.Id;
                 Console.WriteLine("OnBeforeDownload downloadItem.Id=" + downloadItem.Id + ",downloadItem.OriginalUrl=" + downloadItem.OriginalUrl);
                 find.downloadItem = downloadItem;
                 callback.Continue(find.localPathFile, false);
             }
         }
     }
 }
Exemple #9
0
        public bool OnBeforePopup(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, CefSharp.IFrame frame, string targetUrl, string targetFrameName, CefSharp.WindowOpenDisposition targetDisposition, bool userGesture, CefSharp.IPopupFeatures popupFeatures, CefSharp.IWindowInfo windowInfo, CefSharp.IBrowserSettings browserSettings, ref bool noJavascriptAccess, out CefSharp.IWebBrowser newBrowser)
        {
            newBrowser = null;
            if (BeforePopupEvent == null)
            {
                return(false);
            }
            NewWindowEventArgs e = new NewWindowEventArgs(chromiumWebBrowser, browser, frame, targetUrl, targetFrameName, targetDisposition, windowInfo);

            BeforePopupEvent(this, e);
            if (e.newBrowser == null)
            {
                return(false);
            }
            //newBrowser = e.newBrowser;
            return(true);
        }
Exemple #10
0
 bool CefSharp.IContextMenuHandler.OnContextMenuCommand(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.CefMenuCommand commandId, CefSharp.CefEventFlags eventFlags)
 {
     return(false);
 }
Exemple #11
0
 public virtual void OnAfterBrowserCreated(CefSharp.IBrowser browser)
 {
 }
 public bool OnContextMenuCommand(IWebBrowser browserControl, CefSharp.IBrowser browser, IFrame frame, IContextMenuParams parameters,
                                  CefMenuCommand commandId, CefEventFlags eventFlags)
 {
     return(false);
 }
 public void OnBeforeContextMenu(IWebBrowser browserControl, CefSharp.IBrowser browser, IFrame frame, IContextMenuParams parameters,
                                 IMenuModel model)
 {
     model.Clear();
 }
 public void OnContextMenuDismissed(IWebBrowser browserControl, CefSharp.IBrowser browser, IFrame frame)
 {
 }
Exemple #15
0
 protected override bool OnResourceResponse(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IRequest request, CefSharp.IResponse response)
 {
     return(base.OnResourceResponse(chromiumWebBrowser, browser, frame, request, response));
 }
 void CefSharp.IContextMenuHandler.OnBeforeContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model)
 {
     model.Clear();
 }
Exemple #17
0
 public void OnDraggableRegionsChanged(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, System.Collections.Generic.IList <CefSharp.DraggableRegion> regions)
 {
 }
 void CefSharp.IContextMenuHandler.OnContextMenuDismissed(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame)
 {
     //throw new NotImplementedException();
 }
Exemple #19
0
 protected override CefSharp.CefReturnValue OnBeforeResourceLoad(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IRequest request, CefSharp.IRequestCallback callback)
 {
     return(CefSharp.CefReturnValue.Continue);
 }
 public void OnResetDialogState(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser)
 {
 }
Exemple #21
0
 protected override CefSharp.IResponseFilter GetResourceResponseFilter(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IRequest request, CefSharp.IResponse response)
 {
     return(null);
 }
 public void OnDialogClosed(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser)
 {
 }
 public bool OnBeforeUnloadDialog(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, string messageText, bool isReload, CefSharp.IJsDialogCallback callback)
 {
     return(true);
 }
Exemple #24
0
 void CefSharp.IContextMenuHandler.OnContextMenuDismissed(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame)
 {
 }
Exemple #25
0
        void CefSharp.IContextMenuHandler.OnBeforeContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model)
        {
            var flag = parameters.TypeFlags;

            if ((flag & CefSharp.ContextMenuType.Editable) == CefSharp.ContextMenuType.Editable)
            {
            }
            else if ((flag & CefSharp.ContextMenuType.Selection) == CefSharp.ContextMenuType.Selection)
            {
            }
            else
            {
                //model.Clear();
            }
        }
Exemple #26
0
 public void OnBeforeClose(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser)
 {
     //throw new NotImplementedException();
 }
 bool CefSharp.IContextMenuHandler.OnContextMenuCommand(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.CefMenuCommand commandId, CefSharp.CefEventFlags eventFlags)
 {
     //throw new NotImplementedException();
     return(false);
 }
Exemple #28
0
 public CefSharp.IResourceRequestHandler GetResourceRequestHandler(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
 {
     if (request.ResourceType == CefSharp.ResourceType.Image)
     {
         return(new CefResourceRequestHandler());
     }
     return(null);
 }
 bool CefSharp.IContextMenuHandler.RunContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model, CefSharp.IRunContextMenuCallback callback)
 {
     return(false);
 }
Exemple #30
0
 public void OnAfterCreated(CefSharp.IWebBrowser chromiumWebBrowser, CefSharp.IBrowser browser)
 {
     //throw new NotImplementedException();
 }