protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
 {
     bool res = false;
     if (!string.IsNullOrEmpty(targetUrl))
     {
         if (webBrowser.selfRequest != null)
         {
             CefRequest req = CefRequest.Create();
             req.FirstPartyForCookies = webBrowser.selfRequest.FirstPartyForCookies;
             req.Options = webBrowser.selfRequest.Options;
             /*CefPostData postData = CefPostData.Create();
             CefPostDataElement element = CefPostDataElement.Create();
             int index = targetUrl.IndexOf("?");
             string url = targetUrl.Substring(0, index);
             string data = targetUrl.Substring(index + 1);
             byte[] bytes = Encoding.UTF8.GetBytes(data);
             element.SetToBytes(bytes);
             postData.Add(element);
             */
             System.Collections.Specialized.NameValueCollection h = new System.Collections.Specialized.NameValueCollection();
             h.Add("Content-Type", "application/x-www-form-urlencoded");
             req.Set(targetUrl, webBrowser.selfRequest.Method, null, webBrowser.selfRequest.GetHeaderMap());
             webBrowser.selfRequest = req;
         }
         //webBrowser.selfRequest.Set(targetUrl, webBrowser.selfRequest.Method, webBrowser.selfRequest.PostData, webBrowser.selfRequest.GetHeaderMap());
         res = webBrowser.OnNewWindow(targetUrl);
         if (res)
             return res;
     }
     res = base.OnBeforePopup(browser, frame, targetUrl, targetFrameName, popupFeatures, windowInfo, ref client, settings, ref noJavascriptAccess);
     return res;
 }
 protected override void OnAddressChange(CefBrowser browser, CefFrame frame, string url)
 {
     if (frame.IsMain)
     {
         webBrowser.OnUrlChange(url);
     }
 }
        protected override void OnLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode)
        {
            base.OnLoadEnd(browser, frame, httpStatusCode);
            webBrowser.OnLoadEnd();
            if (frame.IsMain)
            {
                //browser.SendProcessMessage(CefProcessId.Renderer, CefProcessMessage.Create("VisitorDocument"));
                webBrowser.OnDocumentCompleted();
            }

        }
 protected override bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags)
 {
     foreach (CommandItem commItem in commandItems)
     {
         if (commItem.id == commandId)
         {
             commItem.item.PerformClick();
             break;
         }
     }
     return base.OnContextMenuCommand(browser, frame, state, commandId, eventFlags);
 }
 protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
 {
     if (!webBrowser.menuVisible)
         model.Clear();
     int commandId = 1001;
     if (webBrowser.ContextMenu != null)
     {
         foreach (MenuItem item in webBrowser.ContextMenu.MenuItems)
         {
             if (item.Text == "-")
                 model.AddSeparator();
             else
                 model.AddItem(commandId, item.Text);
             CommandItem commandItem = new CommandItem();
             commandItem.id = commandId;
             commandItem.item = item;
             commandItems.Add(commandItem);
             commandId++;
         }
     }
     
     base.OnBeforeContextMenu(browser, frame, state, model);
     
 }
 protected override bool OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request)
 {
     return base.OnBeforeResourceLoad(browser, frame, request);
 }
 /// <summary>
 /// Called for global uncaught exceptions in a frame. Execution of this
 /// callback is disabled by default. To enable set
 /// CefSettings.uncaught_exception_stack_size &gt; 0.
 /// </summary>
 protected virtual void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
 }
 /// <summary>
 /// Called on the IO thread before a resource is loaded. To allow the resource
 /// to load normally return NULL. To specify a handler for the resource return
 /// a CefResourceHandler object. The |request| object should not be modified in
 /// this callback.
 /// </summary>
 protected virtual CefResourceHandler GetResourceHandler(CefBrowser browser, CefFrame frame, CefRequest request)
 {
     return null;
 }
Beispiel #9
0
 /// <summary>
 /// Called when the resource load for a navigation fails or is canceled.
 /// |errorCode| is the error code number, |errorText| is the error text and
 /// |failedUrl| is the URL that failed to load. See net\base\net_error_list.h
 /// for complete descriptions of the error codes.
 /// </summary>
 protected virtual void OnLoadError(CefBrowser browser, CefFrame frame, CefErrorCode errorCode, string errorText, string failedUrl)
 {
 }
 /// <summary>
 /// Called on the IO thread when a resource load is redirected. The |old_url|
 /// parameter will contain the old URL. The |new_url| parameter will contain
 /// the new URL and can be changed if desired.
 /// </summary>
 protected virtual void OnResourceRedirect(CefBrowser browser, CefFrame frame, string oldUrl, ref string newUrl)
 {
 }
 /// <summary>
 /// Called on the UI thread before browser navigation. Return true to cancel
 /// the navigation or false to allow the navigation to proceed. The |request|
 /// object cannot be modified in this callback.
 /// CefLoadHandler::OnLoadingStateChange will be called twice in all cases.
 /// If the navigation is allowed CefLoadHandler::OnLoadStart and
 /// CefLoadHandler::OnLoadEnd will be called. If the navigation is canceled
 /// CefLoadHandler::OnLoadError will be called with an |errorCode| value of
 /// ERR_ABORTED.
 /// </summary>
 protected virtual bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool isRedirect)
 {
     return false;
 }
Beispiel #12
0
 /// <summary>
 /// Called when the context menu is dismissed irregardless of whether the menu
 /// was empty or a command was selected.
 /// </summary>
 protected virtual void OnContextMenuDismissed(CefBrowser browser, CefFrame frame)
 {
 }
 /// <summary>
 /// Called to execute a command selected from the context menu. Return true if
 /// the command was handled or false for the default implementation. See
 /// cef_menu_id_t for the command ids that have default implementations. All
 /// user-defined command ids should be between MENU_ID_USER_FIRST and
 /// MENU_ID_USER_LAST. |params| will have the same values as what was passed to
 /// OnBeforeContextMenu(). Do not keep a reference to |params| outside of this
 /// callback.
 /// </summary>
 protected virtual bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags)
 {
     return false;
 }
Beispiel #14
0
 /// <summary>
 /// Called before a context menu is displayed. |params| provides information
 /// about the context menu state. |model| initially contains the default
 /// context menu. The |model| can be cleared to show no context menu or
 /// modified to show a custom menu. Do not keep references to |params| or
 /// |model| outside of this callback.
 /// </summary>
 protected virtual void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
 {
 }
Beispiel #15
0
 /// <summary>
 /// Called to execute a command selected from the context menu. Return true if
 /// the command was handled or false for the default implementation. See
 /// cef_menu_id_t for the command ids that have default implementations. All
 /// user-defined command ids should be between MENU_ID_USER_FIRST and
 /// MENU_ID_USER_LAST. |params| will have the same values as what was passed to
 /// OnBeforeContextMenu(). Do not keep a reference to |params| outside of this
 /// callback.
 /// </summary>
 protected virtual bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags)
 {
     return(false);
 }
 /// <summary>
 /// Called when a frame's address has changed.
 /// </summary>
 protected virtual void OnAddressChange(CefBrowser browser, CefFrame frame, string url)
 {
 }
 protected override CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request)
 {
     return new RequestResourceHandler();
 }
Beispiel #18
0
 /// <summary>
 /// Called when the browser begins loading a frame. The |frame| value will
 /// never be empty -- call the IsMain() method to check if this frame is the
 /// main frame. Multiple frames may be loading at the same time. Sub-frames may
 /// start or continue loading after the main frame load has ended. This method
 /// may not be called for a particular frame if the load request for that frame
 /// fails. For notification of overall browser load status use
 /// OnLoadingStateChange instead.
 /// </summary>
 protected virtual void OnLoadStart(CefBrowser browser, CefFrame frame)
 {
 }
 /// <summary>
 /// Called when the browser begins loading a frame. The |frame| value will
 /// never be empty -- call the IsMain() method to check if this frame is the
 /// main frame. Multiple frames may be loading at the same time. Sub-frames may
 /// start or continue loading after the main frame load has ended. This method
 /// may not be called for a particular frame if the load request for that frame
 /// fails. For notification of overall browser load status use
 /// OnLoadingStateChange instead.
 /// </summary>
 protected virtual void OnLoadStart(CefBrowser browser, CefFrame frame)
 {
 }
Beispiel #20
0
 /// <summary>
 /// Returns the frame for this context. This method will return an empty
 /// reference for WebWorker contexts.
 /// </summary>
 public CefFrame GetFrame()
 {
     return(CefFrame.FromNativeOrNull(
                cef_v8context_t.get_frame(_self)
                ));
 }
 /// <summary>
 /// Called immediately before the V8 context for a frame is released. No
 /// references to the context should be kept after this method is called.
 /// </summary>
 protected virtual void OnContextReleased(CefBrowser browser, CefFrame frame, CefV8Context context)
 {
 }
 /// <summary>
 /// Return a new resource handler instance to handle the request or an empty
 /// reference to allow default handling of the request. |browser| and |frame|
 /// will be the browser window and frame respectively that originated the
 /// request or NULL if the request did not originate from a browser window
 /// (for example, if the request came from CefURLRequest). The |request| object
 /// passed to this method will not contain cookie data.
 /// </summary>
 protected abstract CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request);
 /// <summary>
 /// Called when the context menu is dismissed irregardless of whether the menu
 /// was empty or a command was selected.
 /// </summary>
 protected virtual void OnContextMenuDismissed(CefBrowser browser, CefFrame frame)
 {
 }
 protected override bool OnBeforeNavigation(CefBrowser browser, CefFrame frame, CefRequest request, CefNavigationType navigation_type, bool isRedirect)
 {
     return base.OnBeforeNavigation(browser, frame, request, navigation_type, isRedirect);
 }
 /// <summary>
 /// Called on the IO thread when the browser needs credentials from the user.
 /// |isProxy| indicates whether the host is a proxy server. |host| contains the
 /// hostname and |port| contains the port number. Return true to continue the
 /// request and call CefAuthCallback::Continue() when the authentication
 /// information is available. Return false to cancel the request.
 /// </summary>
 protected virtual bool GetAuthCredentials(CefBrowser browser, CefFrame frame, bool isProxy, string host, int port, string realm, string scheme, CefAuthCallback callback)
 {
     return false;
 }
 /// <summary>
 /// Called when a new node in the the browser gets focus. The |node| value may
 /// be empty if no specific node has gained focus. The node object passed to
 /// this method represents a snapshot of the DOM at the time this method is
 /// executed. DOM objects are only valid for the scope of this method. Do not
 /// keep references to or attempt to access any DOM objects outside the scope
 /// of this method.
 /// </summary>
 protected virtual void OnFocusedNodeChanged(CefBrowser browser, CefFrame frame, CefDomNode node)
 {
 }
 /// <summary>
 /// Called on the IO thread before a resource request is loaded. The |request|
 /// object may be modified. To cancel the request return true otherwise return
 /// false.
 /// </summary>
 protected virtual bool OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request)
 {
     return false;
 }
 /// <summary>
 /// Return a new resource handler instance to handle the request or an empty
 /// reference to allow default handling of the request. |browser| and |frame|
 /// will be the browser window and frame respectively that originated the
 /// request or NULL if the request did not originate from a browser window
 /// (for example, if the request came from CefURLRequest). The |request| object
 /// passed to this method will not contain cookie data.
 /// </summary>
 protected abstract CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request);
        protected override void OnContextCreated(CefBrowser browser, CefFrame frame, CefV8Context context)
        {
            /*缓存数据库*/
            string extensionCode =
                    "var cachedb;" +
                    "if(!cachedb)" +
                    "	cachedb={};" +
                    "(function() {" +
                    " cachedb.Connect = function(dbName) {" +
                    "	native function Connect(dbName);" +
                    "	return Connect(dbName);" +
                    " };" +

                    " cachedb.Execute = function(commandText) {" +
                    "	native function Execute(commandText);" +
                    "	return Execute(commandText);" +
                    " };" +

                    " cachedb.Query = function(commandText) {" +
                    "	native function Query(commandText);" +
                    "	return Query(commandText);" +
                    " };" +

                    " cachedb.Close = function() {" +
                    "	native function Close();" +
                    "	return Close();" +
                    " };"+

					"})();";
            CefV8Handler ExtendsionHandler = new CwbJsExtendHandler(browser);
            CefRuntime.RegisterExtension("v8/cachedb", extensionCode, ExtendsionHandler);

            /*屏幕分辨率设置*/
            int w = webBrowser.screenWidth;
            int h = webBrowser.screenHeight;
            if (w > 0 && h > 0)
		    {
			    string jscode =
				     "Object.defineProperty(window.screen, 'height', {" +
				     "    get: function() {"+
				      "        return "+h+";"+
				      "    }"+
				      "});"+
				     "Object.defineProperty(window.screen, 'width', {"+
				     "    get: function() {"+
				     "        return "+w+";"+
				     "    }"+
				     "});";
			    frame.ExecuteJavaScript(jscode,frame.Url,0);
		    }
            /*注册执行C#方法*/
            CefV8Value globalValue = context.GetGlobal();
            CefV8Handler callHandler = new CwbJsExtendHandler(browser);
            CefV8Value callMethod = CefV8Value.CreateFunction("CallCSharpMethod", callHandler);
            globalValue.SetValue("CallCSharpMethod", callMethod, CefV8PropertyAttribute.None);
            base.OnContextCreated(browser, frame, context);
            
        }
Beispiel #30
0
 /// <summary>
 /// Called when the browser is done loading a frame. The |frame| value will
 /// never be empty -- call the IsMain() method to check if this frame is the
 /// main frame. Multiple frames may be loading at the same time. Sub-frames may
 /// start or continue loading after the main frame load has ended. This method
 /// will always be called for all frames irrespective of whether the request
 /// completes successfully.
 /// </summary>
 protected virtual void OnLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode)
 {
 }
 protected override void OnLoadStart(CefBrowser browser, CefFrame frame)
 {
     base.OnLoadStart(browser, frame);
     webBrowser.OnLoadStart();
 }
Beispiel #32
0
 /// <summary>
 /// Called before browser navigation. Return true to cancel the navigation or
 /// false to allow the navigation to proceed. The |request| object cannot be
 /// modified in this callback.
 /// </summary>
 protected virtual bool OnBeforeNavigation(CefBrowser browser, CefFrame frame, CefRequest request, CefNavigationType navigation_type, bool isRedirect)
 {
     return(false);
 }
 protected override void OnLoadError(CefBrowser browser, CefFrame frame, CefErrorCode errorCode, string errorText, string failedUrl)
 {
     base.OnLoadError(browser, frame, errorCode, errorText, failedUrl);
     if (errorCode == CefErrorCode.Aborted) return;
     webBrowser.OnLoadError(errorCode, errorText, failedUrl);
 }
Beispiel #34
0
 /// <summary>
 /// Called immediately before the V8 context for a frame is released. No
 /// references to the context should be kept after this method is called.
 /// </summary>
 protected virtual void OnContextReleased(CefBrowser browser, CefFrame frame, CefV8Context context)
 {
 }
 protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool isRedirect)
 {
     webBrowser.selfRequest = request;
     return base.OnBeforeBrowse(browser, frame, request, isRedirect);
 }
Beispiel #36
0
 /// <summary>
 /// Called for global uncaught exceptions in a frame. Execution of this
 /// callback is disabled by default. To enable set
 /// CefSettings.uncaught_exception_stack_size &gt; 0.
 /// </summary>
 protected virtual void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
 }
 /// <summary>
 /// 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.
 /// </summary>
 protected virtual bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
 {
     return false;
 }
Beispiel #38
0
 /// <summary>
 /// Called when a new node in the the browser gets focus. The |node| value may
 /// be empty if no specific node has gained focus. The node object passed to
 /// this method represents a snapshot of the DOM at the time this method is
 /// executed. DOM objects are only valid for the scope of this method. Do not
 /// keep references to or attempt to access any DOM objects outside the scope
 /// of this method.
 /// </summary>
 protected virtual void OnFocusedNodeChanged(CefBrowser browser, CefFrame frame, CefDomNode node)
 {
 }
 /// <summary>
 /// Called when the resource load for a navigation fails or is canceled.
 /// |errorCode| is the error code number, |errorText| is the error text and
 /// |failedUrl| is the URL that failed to load. See net\base\net_error_list.h
 /// for complete descriptions of the error codes.
 /// </summary>
 protected virtual void OnLoadError(CefBrowser browser, CefFrame frame, CefErrorCode errorCode, string errorText, string failedUrl)
 {
 }
 /// <summary>
 /// Called before a context menu is displayed. |params| provides information
 /// about the context menu state. |model| initially contains the default
 /// context menu. The |model| can be cleared to show no context menu or
 /// modified to show a custom menu. Do not keep references to |params| or
 /// |model| outside of this callback.
 /// </summary>
 protected virtual void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
 {
 }
 /// <summary>
 /// Called when the browser is done loading a frame. The |frame| value will
 /// never be empty -- call the IsMain() method to check if this frame is the
 /// main frame. Multiple frames may be loading at the same time. Sub-frames may
 /// start or continue loading after the main frame load has ended. This method
 /// will always be called for all frames irrespective of whether the request
 /// completes successfully.
 /// </summary>
 protected virtual void OnLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode)
 {
 }
 /// <summary>
 /// Called before browser navigation. Return true to cancel the navigation or
 /// false to allow the navigation to proceed. The |request| object cannot be
 /// modified in this callback.
 /// </summary>
 protected virtual bool OnBeforeNavigation(CefBrowser browser, CefFrame frame, CefRequest request, CefNavigationType navigation_type, bool isRedirect)
 {
     return false;
 }