Esempio n. 1
0
        internal void CreateBrowser(IntPtr hostHandle, IntPtr winXID)
        {
            if (_client == null)
            {
                _client = CreateClient();
            }
            if (_settings == null)
            {
                _settings = new CefBrowserSettings();
            }

            _settings.DefaultEncoding             = "UTF-8";
            _settings.FileAccessFromFileUrls      = CefState.Enabled;
            _settings.UniversalAccessFromFileUrls = CefState.Enabled;
            _settings.WebSecurity = CefState.Disabled;

            HostHandle = hostHandle;
            var windowInfo = CefWindowInfo.Create();

            windowInfo.SetAsChild(winXID, new CefRectangle(0, 0, _config.WindowOptions.Size.Width, _config.WindowOptions.Size.Height));

            Address  = _config.StartUrl;
            StartUrl = _config.StartUrl;
            CefBrowserHost.CreateBrowser(windowInfo, _client, _settings, StartUrl);
        }
 protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName,
                                       CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures,
                                       CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref CefDictionaryValue extraInfo,
                                       ref bool noJavascriptAccess)
 {
     frame.LoadUrl(targetUrl);
     return(true);
 }
 public CefBeforePopupEventArgs(CefBrowser parentBrowser, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, string url, ref CefClient client, CefBrowserSettings settings)
 {
     this.parentBrowser = parentBrowser;
     this.popupFeatures = popupFeatures;
     this.windowInfo = windowInfo;
     this.url = url;
     this.client = client;
     this.settings = settings;
 }
Esempio n. 4
0
 public CefBeforePopupEventArgs(CefBrowser parentBrowser, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, string url, ref CefClient client, CefBrowserSettings settings)
 {
     this.parentBrowser = parentBrowser;
     this.popupFeatures = popupFeatures;
     this.windowInfo    = windowInfo;
     this.url           = url;
     this.client        = client;
     this.settings      = settings;
 }
Esempio n. 5
0
        public void Create(CefWindowInfo windowInfo)
        {
            if (_client == null)
            {
                _client = new WebClient(this);
            }

            CefBrowserHost.CreateBrowser(windowInfo, _client, _settings, StartUrl);
        }
Esempio n. 6
0
        public void Create(CefWindowInfo windowInfo)
        {
            if (_client == null)
            {
                _client = new WebClient(this);
            }

            CefBrowserHost.CreateBrowser(windowInfo, _client, _settings, StartUrl);
        }
Esempio n. 7
0
        protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl,
                                              string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo,
                                              ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
        {
            var e = new BeforePopupEventArgs(targetUrl, targetFrameName,
                                             popupFeatures, windowInfo, client, noJavascriptAccess);

            _core.OnBeforePopup(e);
            client             = e.Client;
            noJavascriptAccess = e.NoJavascriptAccess;
            return(e.Cancel);
        }
Esempio n. 8
0
		protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
		{
			var e = new BeforePopupEventArgs(frame, targetUrl, targetFrameName, popupFeatures, windowInfo, client, settings,
								 noJavascriptAccess);

			_core.InvokeIfRequired(() => _core.OnBeforePopup(e));

			client = e.Client;
			noJavascriptAccess = e.NoJavascriptAccess;

			return e.Handled;
		}
        protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName,
                                              CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo,
                                              ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
        {
            var e = new BeforePopupEventArgs(frame, targetUrl, targetFrameName, popupFeatures, windowInfo, client, settings, noJavascriptAccess);

            this.owner.OnBeforePopup(e);

            client             = e.Client;
            noJavascriptAccess = e.NoJavascriptAccess;

            return(e.Handled);
        }
Esempio n. 10
0
            protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName,
                                                  CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures,
                                                  CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
            {
                //settings.WebSecurity = CefState.Disabled;
                windowInfo.SetAsWindowless(IntPtr.Zero, false);
                var newBrowser = new Browser(false);

                client = newBrowser.CefClient;

                WaitForBrowser(newBrowser);

                return(false);
            }
Esempio n. 11
0
        public void Create(CefWindowInfo windowInfo)
        {
            if (_client == null)
            {
                _client = new WebClient(this);
                ((WebClient)_client).OnProcessMessage += (a, b) =>
                {
                    if (OnProcessMessage != null)
                    {
                        return(OnProcessMessage(a, b));
                    }
                    return(false);
                };
            }

            CefBrowserHost.CreateBrowser(windowInfo, _client, _settings, StartUrl);
        }
Esempio n. 12
0
 public BeforePopupEventArgs(
     string targetUrl,
     string targetFrameName,
     CefPopupFeatures popupFeatures,
     CefWindowInfo windowInfo,
     CefClient client,
     bool noJavascriptAccess)
 {
     TargetUrl             = string.IsNullOrEmpty(targetUrl) ? "about:blank" : targetUrl;
     TargetFrameName       = string.IsNullOrEmpty(targetFrameName) ? Guid.NewGuid().ToString() : targetFrameName;
     PopupFeatures         = popupFeatures;
     WindowInfo            = windowInfo;
     Client                = client;
     NoJavascriptAccess    = noJavascriptAccess;
     NeedCustomPopupWindow = false;
     Cancel                = false;
 }
Esempio n. 13
0
		public BeforePopupEventArgs(
			CefFrame frame,
			string targetUrl,
			string targetFrameName,
			CefPopupFeatures popupFeatures,
			CefWindowInfo windowInfo,
			CefClient client,
			CefBrowserSettings settings,
			bool noJavascriptAccess)
		{
			Frame = frame;
			TargetUrl = targetUrl;
			TargetFrameName = targetFrameName;
			PopupFeatures = popupFeatures;
			WindowInfo = windowInfo;
			Client = client;
			Settings = settings;
			NoJavascriptAccess = noJavascriptAccess;
		}
Esempio n. 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BeforePopupEventArgs"/> class.
 /// </summary>
 /// <param name="frame">
 /// The frame.
 /// </param>
 /// <param name="targetUrl">
 /// The target url.
 /// </param>
 /// <param name="targetFrameName">
 /// The target frame name.
 /// </param>
 /// <param name="popupFeatures">
 /// The popup features.
 /// </param>
 /// <param name="windowInfo">
 /// The window info.
 /// </param>
 /// <param name="client">
 /// The client.
 /// </param>
 /// <param name="settings">
 /// The settings.
 /// </param>
 /// <param name="noJavascriptAccess">
 /// The no javascript access.
 /// </param>
 public BeforePopupEventArgs(
     CefFrame frame,
     string targetUrl,
     string targetFrameName,
     CefPopupFeatures popupFeatures,
     CefWindowInfo windowInfo,
     CefClient client,
     CefBrowserSettings settings,
     bool noJavascriptAccess)
 {
     this.Frame              = frame;
     this.TargetUrl          = targetUrl;
     this.TargetFrameName    = targetFrameName;
     this.PopupFeatures      = popupFeatures;
     this.WindowInfo         = windowInfo;
     this.Client             = client;
     this.Settings           = settings;
     this.NoJavascriptAccess = noJavascriptAccess;
 }
Esempio n. 15
0
 internal BeforePopupEventArgs(
     CefFrame frame,
     string targetUrl,
     string targetFrameName,
     bool userGesture,
     CefPopupFeatures popupFeatures,
     CefWindowInfo windowInfo,
     CefClient client,
     CefBrowserSettings settings,
     bool noJavascriptAccess)
 {
     Frame              = frame;
     TargetUrl          = targetUrl;
     TargetFrameName    = targetFrameName;
     UserGesture        = userGesture;
     PopupFeatures      = popupFeatures;
     WindowInfo         = windowInfo;
     Client             = client;
     Settings           = settings;
     NoJavascriptAccess = noJavascriptAccess;
 }
        private void CreateBrowser()
        {
            CefWindowInfo windowInfo = CefWindowInfo.Create();

            windowInfo.SetAsChild(Handle, new CefRectangle {
                X = 0, Y = 0, Width = Width, Height = Height
            });
            if (client == null)
            {
                client = new ClientBrowser(this);
            }
            var settings = new CefBrowserSettings()
            {
            };

            settings.AcceleratedCompositing = CefState.Enabled;
            settings.ApplicationCache       = CefState.Enabled;
            settings.AuthorAndUserStyles    = CefState.Enabled;
            settings.CaretBrowsing          = CefState.Enabled;
            settings.Databases = CefState.Enabled;
            settings.FileAccessFromFileUrls     = CefState.Enabled;
            settings.ImageLoading               = CefState.Enabled;
            settings.ImageShrinkStandaloneToFit = CefState.Enabled;
            settings.Java       = CefState.Enabled;
            settings.JavaScript = CefState.Enabled;;
            settings.JavaScriptAccessClipboard = CefState.Enabled;
            settings.JavaScriptCloseWindows    = CefState.Enabled;
            settings.JavaScriptDomPaste        = CefState.Enabled;;
            settings.JavaScriptOpenWindows     = CefState.Enabled;
            settings.LocalStorage   = CefState.Enabled;;
            settings.Plugins        = CefState.Enabled;;
            settings.RemoteFonts    = CefState.Enabled;
            settings.TabToLinks     = CefState.Enabled;;
            settings.TextAreaResize = CefState.Enabled;
            settings.UniversalAccessFromFileUrls = CefState.Enabled;
            settings.WebGL       = CefState.Enabled;
            settings.WebSecurity = CefState.Enabled;

            CefBrowserHost.CreateBrowser(windowInfo, client, settings, browserSettings.DefaultUrl);
        }
Esempio n. 17
0
 protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl,
                                       string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture,
                                       CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings,
                                       ref bool noJavascriptAccess)
 {
     // Block a new popup window.
     // Instead just redirect the popup target to the current browser.
     browser.GetMainFrame().LoadUrl(targetUrl);
     return(true);
 }
Esempio n. 18
0
        protected override bool OnBeforePopup(CefBrowser parentBrowser, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, string url, ref CefClient client, CefBrowserSettings settings)
        {
            #if DIAGNOSTICS
            Cef.Logger.Trace(LogTarget.CefLifeSpanHandler, "OnBeforePopup");
            #endif

            /*
             #if DEBUG
             *  string message = string.Format(
             *      "LifeSpanHandler:OnBeforePopup\n"
             + "               URL: {0}\n"
             + "                 X: {1}\n"
             + "                 Y: {2}\n"
             + "             Width: {3}\n"
             + "            Height: {4}\n"
             + "    MenuBarVisible: {5}\n"
             + "  StatusBarVisible: {6}\n"
             + "    ToolBarVisible: {7}\n"
             + "LocationBarVisible: {8}\n"
             + " ScrollbarsVisible: {9}\n"
             + "         Resizable: {10}\n"
             + "        Fullscreen: {11}\n"
             + "            Dialog: {12}\n",
             +      url,
             +      popupFeatures.X.HasValue ? popupFeatures.X.ToString() : "not set",
             +      popupFeatures.Y.HasValue ? popupFeatures.Y.ToString() : "not set",
             +      popupFeatures.Width.HasValue ? popupFeatures.Width.ToString() : "not set",
             +      popupFeatures.Height.HasValue ? popupFeatures.Height.ToString() : "not set",
             +      popupFeatures.MenuBarVisible,
             +      popupFeatures.StatusBarVisible,
             +      popupFeatures.ToolBarVisible,
             +      popupFeatures.LocationBarVisible,
             +      popupFeatures.ScrollbarsVisible,
             +      popupFeatures.Resizable,
             +      popupFeatures.Fullscreen,
             +      popupFeatures.Dialog
             +      );
             #endif
             */

            this.context.OnBeforePopup(parentBrowser, popupFeatures, windowInfo, url, ref client, settings);

            // TODO: create webview here
            // TODO: do not inherit browser settings for devtools
            client = CefWebClientFactory.Default.Create(new CefWebBrowserCore(null, this.context.Settings, url));

            // TODO: create new browsercontext for popup windows

            return(false);
        }
        /// <summary>
        /// The on before popup.
        /// </summary>
        /// <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="client">
        /// The client.
        /// </param>
        /// <param name="settings">
        /// The settings.
        /// </param>
        /// <param name="noJavascriptAccess">
        /// The no javascript access.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
        {
            var eventArgs = new BeforePopupEventArgs(
                frame,
                targetUrl,
                targetFrameName,
                popupFeatures,
                windowInfo,
                client,
                settings,
                noJavascriptAccess);

            this.mBrowser.InvokeAsyncIfPossible(() => this.mBrowser.OnBeforePopup(eventArgs));

            client             = eventArgs.Client;
            noJavascriptAccess = eventArgs.NoJavascriptAccess;

            return(eventArgs.Handled);

            // return base.OnBeforePopup(browser, frame, targetUrl, targetFrameName, targetDisposition, userGesture, popupFeatures, windowInfo, ref client, settings, ref noJavascriptAccess);
        }
Esempio n. 20
0
        protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
        {
            Browser father = CefUtil.GetBrowserFromCef(browser);

            father.GoToPage(targetUrl);
            return(true);
        }
Esempio n. 21
0
 /// <summary>
 /// Open developer tools (DevTools) in its own browser. The DevTools browser
 /// will remain associated with this browser. If the DevTools browser is
 /// already open then it will be focused, in which case the |windowInfo|,
 /// |client| and |settings| parameters will be ignored. If |inspect_element_at|
 /// is non-empty then the element at the specified (x,y) location will be
 /// inspected. The |windowInfo| parameter will be ignored if this browser is
 /// wrapped in a CefBrowserView.
 /// </summary>
 public void ShowDevTools(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings browserSettings, CefPoint inspectElementAt)
 {
     BrowserHost?.ShowDevTools(windowInfo, client, browserSettings, inspectElementAt);
 }
Esempio n. 22
0
 protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
 {
     FRenderer.LoadUrl(targetUrl);
     return(true);
 }
        protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref CefDictionaryValue extraInfo, ref bool noJavascriptAccess)
        {
            _browser.InvokeAsyncIfPossible(() => _browser.OnBeforePopup(new BeforePopupEventArgs(frame, targetUrl, targetFrameName)));

            var isUrlExternal = _config?.UrlSchemes?.IsUrlRegisteredExternalBrowserScheme(targetUrl);

            if (isUrlExternal.HasValue && isUrlExternal.Value)
            {
                BrowserLauncher.Open(_config.Platform, targetUrl);
                return(true);
            }

            var isUrlCommand = _config?.UrlSchemes?.IsUrlRegisteredCommandScheme(targetUrl);

            if (isUrlCommand.HasValue && isUrlCommand.Value)
            {
                _commandTaskRunner.RunAsync(targetUrl);
                return(true);
            }

            return(false);
        }
    protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref CefDictionaryValue extraInfo, ref bool noJavascriptAccess)
    {
        if (_browser is not null)
        {
            _browser.InvokeAsyncIfPossible(() => _browser.OnBeforePopup(new BeforePopupEventArgs(frame, targetUrl, targetFrameName)));
        }

        if (_config is not null)
        {
            var isUrlExternal = _config.UrlSchemes?.IsUrlRegisteredExternalBrowserScheme(targetUrl);
            if (isUrlExternal.HasValue && isUrlExternal.Value)
            {
                BrowserLauncher.Open(_config.Platform, targetUrl);
                return(true);
            }
        }

        // Sample: http://chromely.com/democontroller/showdevtools
        // Expected to execute controller route action without return value
        var route = _routeProvider.GetRoute(targetUrl);

        if (route is not null && !route.HasReturnValue)
        {
            _requestHandler.Execute(targetUrl);
            return(true);
        }

        return(false);
    }
Esempio n. 25
0
        protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref CefDictionaryValue extraInfo, ref bool noJavascriptAccess)
        {
            //  return base.OnBeforePopup(browser, frame, targetUrl, targetFrameName, targetDisposition, userGesture, popupFeatures, windowInfo, ref client, settings, ref extraInfo, ref noJavascriptAccess);

            var e = new BeforePopupEventArgs(frame, targetUrl, targetFrameName, popupFeatures, windowInfo, client, settings, noJavascriptAccess);

            client             = e.Client;
            noJavascriptAccess = e.NoJavascriptAccess;
            _core.x            = windowInfo.X;
            _core.y            = windowInfo.Y;
            _core._width       = windowInfo.Width;
            _core._height      = windowInfo.Height;
            _core.InvokeIfRequired(() => _core.OnBeforePopup(e));
            return(e.Handled);
        }
        /// <summary>
        /// 弹出窗口事件
        /// </summary>
        /// <param name="browser"></param>
        /// <param name="frame"></param>
        /// <param name="targetUrl"></param>
        /// <param name="targetFrameName"></param>
        /// <param name="targetDisposition"></param>
        /// <param name="userGesture"></param>
        /// <param name="popupFeatures"></param>
        /// <param name="windowInfo"></param>
        /// <param name="client"></param>
        /// <param name="settings"></param>
        /// <param name="noJavascriptAccess"></param>
        /// <returns></returns>
        protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
        {
            //无窗口模式 禁止打开弹窗
            return(true);
            //var e = new BeforePopupEventArgs(frame, targetUrl, targetFrameName, popupFeatures, windowInfo, client, settings,
            //                     noJavascriptAccess);

            /////*_core.InvokeIfRequired(() => _core.OnBeforePopup(e));*/

            ////client = e.Client;
            ////noJavascriptAccess = e.NoJavascriptAccess;
            ////无窗口模式 禁止打开弹窗
            ////直接在当前页面进行跳转
            //e.Frame.Browser.GetMainFrame().LoadUrl(e.TargetUrl);

            //e.Handled = true;
            //return e.Handled;
        }
Esempio n. 27
0
        /// <summary>
        /// The on before popup.
        /// </summary>
        /// <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="client">
        /// The client.
        /// </param>
        /// <param name="settings">
        /// The settings.
        /// </param>
        /// <param name="noJavascriptAccess">
        /// The no javascript access.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
        {
            var isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(targetUrl);

            if (isUrlExternal)
            {
                RegisteredExternalUrl.Launch(targetUrl);
            }

            return(true);
        }
Esempio n. 28
0
 public void OnBeforePopup(CefBrowser parentBrowser, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, string url, ref CefClient client, CefBrowserSettings settings)
 {
     var handler = this.BeforePopup;
     if (handler != null)
     {
         handler(this.owner, new CefBeforePopupEventArgs(parentBrowser, popupFeatures, windowInfo, url, ref client, settings));
     }
 }
Esempio n. 29
0
        protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
        {
            var e = new BeforePopupEventArgs(frame, targetUrl, targetFrameName, popupFeatures, windowInfo, client, settings,
                                             noJavascriptAccess);

            _core.InvokeIfRequired(() => _core.OnBeforePopup(e));

            client             = e.Client;
            noJavascriptAccess = e.NoJavascriptAccess;
            //if (FileHelper1.read("//config//chromeconfig.txt")[0] == "true") {
            e.Handled = true;
            //}
            return(e.Handled);
            //  return true;//强制不弹出
        }
Esempio n. 30
0
 public override bool OnBeforeBrowser(CefExtension extension, CefBrowser browser, CefBrowser activeBrowser, int index, string url, bool active, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings)
 {
     return(_implementation.OnBeforeBrowser(extension, browser, activeBrowser, index, url, active, windowInfo, ref client, settings));
 }
        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);
        }
Esempio n. 32
0
 protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref CefDictionaryValue extraInfo, ref int noJavascriptAccess)
 {
     switch (targetDisposition)
     {
     case CefWindowOpenDisposition.NewForegroundTab:
     case CefWindowOpenDisposition.NewBackgroundTab:
     case CefWindowOpenDisposition.NewPopup:
     case CefWindowOpenDisposition.NewWindow:
         if (webView.OpenInBrowser)
         {
             BrowserOpen(targetUrl);
         }
         else
         {
             // 禁止创建新窗口,仅在当前窗口跳转
             browser.MainFrame.LoadUrl(targetUrl);
         }
         return(true);
     }
     return(base.OnBeforePopup(browser, frame, targetUrl, targetFrameName, targetDisposition, userGesture, popupFeatures, windowInfo, ref client, settings, ref extraInfo, ref noJavascriptAccess));
 }
        protected override bool OnBeforePopup(CefBrowser parentBrowser, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, string url, ref CefClient client, CefBrowserSettings settings)
        {
            #if DIAGNOSTICS
            Cef.Logger.Trace(LogTarget.CefLifeSpanHandler, "OnBeforePopup");
            #endif

            /*
                #if DEBUG
                string message = string.Format(
                    "LifeSpanHandler:OnBeforePopup\n"
                    + "               URL: {0}\n"
                    + "                 X: {1}\n"
                    + "                 Y: {2}\n"
                    + "             Width: {3}\n"
                    + "            Height: {4}\n"
                    + "    MenuBarVisible: {5}\n"
                    + "  StatusBarVisible: {6}\n"
                    + "    ToolBarVisible: {7}\n"
                    + "LocationBarVisible: {8}\n"
                    + " ScrollbarsVisible: {9}\n"
                    + "         Resizable: {10}\n"
                    + "        Fullscreen: {11}\n"
                    + "            Dialog: {12}\n",
                    url,
                    popupFeatures.X.HasValue ? popupFeatures.X.ToString() : "not set",
                    popupFeatures.Y.HasValue ? popupFeatures.Y.ToString() : "not set",
                    popupFeatures.Width.HasValue ? popupFeatures.Width.ToString() : "not set",
                    popupFeatures.Height.HasValue ? popupFeatures.Height.ToString() : "not set",
                    popupFeatures.MenuBarVisible,
                    popupFeatures.StatusBarVisible,
                    popupFeatures.ToolBarVisible,
                    popupFeatures.LocationBarVisible,
                    popupFeatures.ScrollbarsVisible,
                    popupFeatures.Resizable,
                    popupFeatures.Fullscreen,
                    popupFeatures.Dialog
                    );
                #endif
                */

            this.context.OnBeforePopup(parentBrowser, popupFeatures, windowInfo, url, ref client, settings);

            // TODO: create webview here
            // TODO: do not inherit browser settings for devtools
            client = CefWebClientFactory.Default.Create(new CefWebBrowserCore(null, this.context.Settings, url));

            // TODO: create new browsercontext for popup windows

            return false;
        }
        /// <summary>
        /// Called on the UI thread before a new popup browser is created. To allow creation of the popup
        /// browser optionally modify <paramref name="windowInfo"/>, <paramref name="client"/>,
        /// <paramref name="settings"/> and <paramref name="noJavascriptAccess"/> and return false.
        /// To cancel creation of the popup browser return true. Popup browser creation will be canceled
        /// if the parent browser is destroyed before the popup browser creation completes (indicated by a
        /// call to <see cref="OnAfterCreated"/> for the popup browser).
        /// </summary>
        /// <param name="browser">A value represent the source browser of the popup request.</param>
        /// <param name="frame">A value represent the source frame of the popup request.</param>
        /// <param name="targetUrl">
        /// A value indicate where the popup browser should navigate and may be empty if not specified
        /// with the request.
        /// </param>
        /// <param name="targetFrameName">
        /// A value indicate where the popup browser should navigate and may be empty if not specified
        /// with the request.
        /// </param>
        /// <param name="targetDisposition">
        /// A value indicates where the user intended to open the popup (e.g. current tab, new tab, etc).
        /// </param>
        /// <param name="userGesture">
        /// A 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).
        /// </param>
        /// <param name="popupFeatures">Additional information about the requested popup window.</param>
        /// <param name="windowInfo">The window information.</param>
        /// <param name="client"></param>
        /// <param name="settings">The browser settings, defaults to source browsers.</param>
        /// <param name="extraInfo">
        /// Provides an opportunity to specify extra information specific to the created popup browser that
        /// will be passed to <see cref="CefNetApplication.OnBrowserCreated"/> in the render process.
        /// </param>
        /// <param name="noJavascriptAccess">
        /// If the value is set to false the new browser will not be scriptable and may not be hosted in
        /// the same renderer process as the source browser.
        /// </param>
        /// <returns></returns>
        internal protected virtual bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition,
                                                      bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref CefDictionaryValue extraInfo, ref int noJavascriptAccess)
        {
#if DEBUG
            if (!BrowserObject.IsSame(browser))
            {
                throw new InvalidOperationException();
            }
#endif
            var ea = new CreateWindowEventArgs(frame, targetUrl, targetFrameName, targetDisposition, userGesture, popupFeatures, windowInfo, null, settings, extraInfo, noJavascriptAccess != 0);
            WebView.RaiseCefCreateWindow(ea);
            extraInfo          = ea.ExtraInfo;
            noJavascriptAccess = ea.NoJavaScriptAccess ? 1 : 0;
            client             = ea.Client;
            if (!ea.Cancel)
            {
                (client as CefClientGlue)?.NotifyPopupBrowserCreating();
            }
            return(ea.Cancel);
        }
Esempio n. 35
0
        /// <summary>
        /// The on before popup.
        /// </summary>
        /// <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="client">
        /// The client.
        /// </param>
        /// <param name="settings">
        /// The settings.
        /// </param>
        /// <param name="noJavascriptAccess">
        /// The no javascript access.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
        {
            var isUrlExternal = _config?.UrlSchemes?.IsUrlRegisteredExternalScheme(targetUrl);

            if (isUrlExternal.HasValue && isUrlExternal.Value)
            {
                RegisteredExternalUrl.Launch(targetUrl);
            }

            var isUrlCommand = _config?.UrlSchemes?.IsUrlRegisteredCommandScheme(targetUrl);

            if (isUrlCommand.HasValue && isUrlCommand.Value)
            {
                _commandTaskRunner.RunAsync(targetUrl);
            }

            return(true);
        }
Esempio n. 36
0
 public override bool OnBeforeBackgroundBrowser(CefExtension extension, string url, ref CefClient client, CefBrowserSettings settings)
 {
     return(_implementation.OnBeforeBackgroundBrowser(extension, url, ref client, settings));
 }