void ICefWebBrowserInternal.OnBeforePopup(BeforePopupEventArgs e)
        {
            try
            {
                var beforePopup = BeforePopup;
                if (!_disablePopups && beforePopup != null)
                {
                    // If no initial size specified, default to the parent window's size
                    if (e.WindowInfo.Width <= 0 && ActualWidth != double.NaN)
                    {
                        e.WindowInfo.Width = (int)ActualWidth;
                    }
                    if (e.WindowInfo.Height <= 0 && ActualHeight != double.NaN)
                    {
                        e.WindowInfo.Height = (int)ActualHeight;
                    }

                    beforePopup(this, e);

                    if (!e.Cancel && e.NeedCustomPopupWindow)
                    {
                        var name = e.TargetFrameName;

                        // The following code must be executed on the UI thread of the browser process
                        DispatchIfRequired(() =>
                        {
                            var newBrowser = CreatePopupBrowser(Identifier, _router);
                            if (newBrowser != null)
                            {
                                newBrowser.Source      = e.TargetUrl;
                                newBrowser._currentUrl = e.TargetUrl;
                                newBrowser.Width       = e.WindowInfo.Width;
                                newBrowser.Height      = e.WindowInfo.Height;
                                newBrowser._name       = name;
                                // Force the creation of the control handle
                                newBrowser.CreateControl();

                                e.WindowInfo.SetAsChild(newBrowser.ParentHandle, new CefRectangle(0, 0, e.WindowInfo.Width, e.WindowInfo.Height));

                                // Set the client to new browser's client so that the OnAfterBrowserCreated (and other notifications) go to that control
                                e.Client = newBrowser._client;
                            }
                            ;
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                e.Cancel = true;
                Logger.Error("Error in OnBeforePopup : {0}. Popup will not be allowed.", ex);
            }
            finally
            {
                if (!e.Cancel && _disablePopups)
                {
                    e.Cancel = true;
                }
            }
        }
 private void OnRootBrowserBeforePopup(object sender, BeforePopupEventArgs eventArgs)
 {
     // FIXME: Depending on the ordering of an enum seems a bit dodgy to me.
     if (Application.State <= ApplicationState.Running)
     {
         eventArgs.NeedCustomPopupWindow = true;
         eventArgs.Cancel = false;
     }
 }
Ejemplo n.º 3
0
        internal void OnBeforePopup(BeforePopupEventArgs e)
        {
            BeforePopup?.Invoke(this, e);

            if (!e.Handled)
            {
                LoadURL(e.TargetUrl);
                e.Handled = true;
            }
        }
Ejemplo n.º 4
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)
        {
            var eventArgs = new BeforePopupEventArgs(frame, targetUrl, targetFrameName, popupFeatures, windowInfo, client, settings,
                                                     noJavascriptAccess);

            m_browser.InvokeAsyncIfPossible(() => m_browser.OnBeforePopup(eventArgs));

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

            return(eventArgs.Handled);
        }
        public void BeforeApplicationWindowPopup(BeforePopupEventArgs eventArgs)
        {
            if (eventArgs == null)
            {
                Logger.Error("Unable to apply settings to popup window. EventArgs is null");
                return;
            }

            // Create pending request based on details supplied to window.open
            var options = new CreateWindowOptions {
                Id = eventArgs.TargetFrameName
            };

            if (eventArgs.PopupFeatures != null)
            {
                options.OuterBounds = new BoundsSpecification
                {
                    Left   = eventArgs.PopupFeatures.X.HasValue ? eventArgs.PopupFeatures.X.Value : double.NaN,
                    Top    = eventArgs.PopupFeatures.Y.HasValue ? eventArgs.PopupFeatures.Y.Value : double.NaN,
                    Height = eventArgs.PopupFeatures.Height.HasValue ? eventArgs.PopupFeatures.Height.Value : double.NaN,
                    Width  = eventArgs.PopupFeatures.Width.HasValue ? eventArgs.PopupFeatures.Width.Value : double.NaN
                };

                options.InitialState = "normal";
                if (eventArgs.PopupFeatures.Fullscreen)
                {
                    options.InitialState = "fullscreen";
                }

                options.Resizable = eventArgs.PopupFeatures.Resizable;
                options.Frame     = new FrameOptions {
                    Type = Application.Package.Manifest.DefaultFrameType
                };
                options.AlwaysOnTop = false;
                options.Focused     = true;
                options.Hidden      = false;
            }
            var request = new CreateWindowRequest(eventArgs.TargetUrl, options, null, eventArgs.TargetFrameName);

            lock (_pendingWindowCreations)
            {
                _pendingWindowCreations.Add(request);
            }
            eventArgs.NeedCustomPopupWindow = true;
            eventArgs.Cancel = false;
        }
Ejemplo n.º 6
0
 public virtual void OnBeforePopup(BeforePopupEventArgs eventArgs)
 {
     this.BeforePopup?.Invoke(this, eventArgs);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// The on before popup.
 /// </summary>
 /// <param name="eventArgs">
 /// The event args.
 /// </param>
 public void OnBeforePopup(BeforePopupEventArgs eventArgs)
 {
     BeforePopup?.Invoke(this, eventArgs);
 }