Beispiel #1
0
        public ICefValue Serialize(object source, Stack <object> seen, ObjectSerializer objectSerializer)
        {
            if (!CanHandle(source?.GetType()))
            {
                throw new InvalidOperationException();
            }

            using (var value = CefDictionaryValue.Create())
                using (var dict = CefDictionaryValue.Create())
                {
                    value.SetString(ObjectSerializer.TypeIdPropertyName, ObjectSerializer.DictionaryTypeId);

                    foreach (DictionaryEntry dictionaryEntry in (IDictionary)source)
                    {
                        var cefValue = objectSerializer.Serialize(dictionaryEntry.Value, seen);
                        dict.SetValue(dictionaryEntry.Key.ToString(), cefValue);
                    }
                    value.SetDictionary(ObjectSerializer.ValuePropertyName, dict);

                    var result = CefValue.Create();
                    result.SetDictionary(value);

                    return(result);
                }
        }
Beispiel #2
0
        public CefValue Serialize(object source, HashSet <object> seen, ObjectSerializer objectSerializer)
        {
            if (!CanHandle(source?.GetType()))
            {
                throw new InvalidOperationException();
            }

            var actualSource = (PropertyDescriptor)source;
            var result       = CefValue.Create();

            using (var resultDict = CefDictionaryValue.Create())
                using (var value = CefDictionaryValue.Create())
                {
                    resultDict.SetString(ObjectSerializer.TypeIdPropertyName, PropertyDescriptor.TypeId);

                    value.SetInt64(nameof(actualSource.Id), actualSource.Id);
                    value.SetString(nameof(PropertyDescriptor.Name), actualSource.Name);
                    value.SetValue(nameof(PropertyDescriptor.Value),
                                   objectSerializer.Serialize(actualSource.Value, new HashSet <object>()));

                    resultDict.SetDictionary(ObjectSerializer.ValuePropertyName, value);
                    result.SetDictionary(resultDict);
                }

            return(result);
        }
Beispiel #3
0
        public JSValue(CefDictionaryValue value)
        {
            if (value == null)
            {
                return;
            }

            var result = new Dictionary <String, Object>();
            var keys   = value.GetKeys();

            for (var i = 0; i < value.Count; i++)
            {
                try
                {
                    switch (value.GetKeyType(keys[i]))
                    {
                    case CefValueType.List:
                        result.Add(keys[i], new JSValue(value.GetList(keys[i])).Value);
                        break;

                    case CefValueType.Binary:
                        result.Add(keys[i], new JSValue(value.GetBinary(keys[i])).Value);
                        break;

                    case CefValueType.String:
                        result.Add(keys[i], value.GetString(keys[i]));
                        break;

                    case CefValueType.Double:
                        result.Add(keys[i], value.GetDouble(keys[i]));
                        break;

                    case CefValueType.Int:
                        result.Add(keys[i], value.GetInt(keys[i]));
                        break;

                    case CefValueType.Bool:
                        result.Add(keys[i], value.GetBool(keys[i]));
                        break;

                    case CefValueType.Dictionary:
                        result.Add(keys[i], new JSValue(value.GetDictionary(keys[i])).Value);
                        break;

                    default:
                        result.Add(keys[i], null);
                        break;
                    }
                }
                catch (ArgumentException)
                {
                }
            }

            this.Value = result;
        }
Beispiel #4
0
        public CefDictionaryValue AsCefDictionaryValue()
        {
            var result = CefDictionaryValue.Create();

            if (this.Value is IDictionary)
            {
                var v = (IDictionary)this.Value;

                Debug.Assert(v.Keys.Count == v.Values.Count);

                var vKeys   = new String[v.Keys.Count];
                var vValues = new Object[v.Values.Count];

                v.Keys.CopyTo(vKeys, 0);
                v.Values.CopyTo(vValues, 0);

                for (var i = 0; i < vKeys.Length; i++)
                {
                    if (vValues[i] is Byte[])
                    {
                        result.SetBinary(vKeys[i], new JSValue(vValues[i]).AsCefBinaryValue());
                    }
                    else if (vValues[i] is Boolean)
                    {
                        result.SetBool(vKeys[i], (Boolean)vValues[i]);
                    }
                    else if (vValues[i] is IDictionary)
                    {
                        result.SetDictionary(vKeys[i], new JSValue(vValues[i]).AsCefDictionaryValue());
                    }
                    else if (vValues[i] is Single || vValues[i] is Double || vValues[i] is Decimal || vValues[i] is UInt32 || vValues[i] is UInt64 || vValues[i] is Int64)
                    {
                        result.SetDouble(vKeys[i], (Double)vValues[i]);
                    }
                    else if (vValues[i] is Byte || vValues[i] is SByte || vValues[i] is UInt16 || vValues[i] is Int16 || vValues[i] is Int32)
                    {
                        result.SetInt(vKeys[i], (Int32)vValues[i]);
                    }
                    else if (vValues[i] is IList)
                    {
                        result.SetList(vKeys[i], new JSValue(vValues[i]).AsCefListValue());
                    }
                    else if (vValues[i] is String)
                    {
                        result.SetString(vKeys[i], (String)vValues[i]);
                    }
                    else
                    {
                        result.SetNull(vKeys[i]);
                    }
                }
            }

            return(result);
        }
Beispiel #5
0
        static XElement ToXElement(string name, CefDictionaryValue value)
        {
            var result = new XElement(name);
            var keys   = value.GetKeys();

            foreach (var key in keys)
            {
                var type = value.GetValueType(key);
                switch (type)
                {
                case CefValueType.Invalid:
                    break;

                case CefValueType.Null:
                    result.SetAttributeValue(key, null);
                    break;

                case CefValueType.Bool:
                    result.SetAttributeValue(key, value.GetBool(key));
                    break;

                case CefValueType.Int:
                    result.SetAttributeValue(key, value.GetInt(key));
                    break;

                case CefValueType.Double:
                    result.SetAttributeValue(key, value.GetDouble(key));
                    break;

                case CefValueType.String:
                    result.SetAttributeValue(key, value.GetString(key));
                    break;

                case CefValueType.Binary:
                    break;

                case CefValueType.Dictionary:
                    result.Add(ToXElement(key, value.GetDictionary(key)));
                    break;

                case CefValueType.List:
                    result.Add(ToXElement(key, value.GetList(key)));
                    break;

                default:
                    break;
                }
            }
            return(result);
        }
Beispiel #6
0
        public ICefValue Serialize(object obj, Stack <object> seen, ObjectSerializer objectSerializer)
        {
            var type = obj?.GetType();

            if (!CanHandle(type))
            {
                throw new InvalidOperationException();
            }

            if (type == typeof(string))
            {
                var result = CefValue.Create();
                result.SetString((string)obj);

                return(result);
            }

            using (var value = CefDictionaryValue.Create())
                using (var dict = CefDictionaryValue.Create())
                {
                    value.SetString(ObjectSerializer.TypeIdPropertyName, GetTypeId(type));
                    var properties   = type.GetProperties();
                    var shouldFilter = type.GetCustomAttribute <DataContractAttribute>() != null;

                    foreach (var propertyDesc in properties
                             .Where(p => p.GetIndexParameters().Length <= 0)
                             .Select(p => new { Property = p, DataMember = p.GetCustomAttribute <DataMemberAttribute>() })
                             .Where(p => p.DataMember != null || !shouldFilter))
                    {
                        var propertyValue = propertyDesc.Property.GetValue(obj);
                        var name          = propertyDesc.DataMember?.Name ?? propertyDesc.Property.Name;

                        var cefValue = objectSerializer.Serialize(propertyValue, seen);
                        dict.SetValue(name, cefValue);
                    }

                    value.SetDictionary(ObjectSerializer.ValuePropertyName, dict);

                    var result = CefValue.Create();
                    result.SetDictionary(value);

                    return(result);
                }
        }
Beispiel #7
0
            static CefDictionaryValue ToDictionaryValue(CefV8Value value, CompositeDisposable disposable)
            {
                var result = CefDictionaryValue.Create();

                foreach (var key in value.GetKeys())
                {
                    var val = value.GetValue(key);
                    if (val.IsBool)
                    {
                        result.SetBool(key, val.GetBoolValue());
                    }
                    else if (val.IsInt)
                    {
                        result.SetInt(key, val.GetIntValue());
                    }
                    else if (val.IsDouble)
                    {
                        result.SetDouble(key, val.GetDoubleValue());
                    }
                    else if (val.IsString)
                    {
                        result.SetString(key, val.GetStringValue());
                    }
                    else if (val.IsNull)
                    {
                        result.SetNull(key);
                    }
                    else if (val.IsArray)
                    {
                        result.SetList(key, ToListValue(val, disposable));
                    }
                    else if (val.IsObject)
                    {
                        result.SetDictionary(key, ToDictionaryValue(val, disposable));
                    }
                }
                disposable.Add(result);
                return(result);
            }
 public void OnBrowserCreated(CefBrowser browser, CefDictionaryValue extraInfo)
 {
     _application.OnBrowserCreated(browser, extraInfo);
 }
Beispiel #9
0
 protected internal unsafe override void OnBrowserCreated(CefBrowser browser, CefDictionaryValue extraInfo)
 {
     _implementation.OnBrowserCreated(browser, extraInfo);
 }
 /// <summary>
 /// Execute a method call over the DevTools protocol. This is a more structured
 /// version of SendDevToolsMessage. |message_id| is an incremental number that
 /// uniquely identifies the message (pass 0 to have the next number assigned
 /// automatically based on previous values). |method| is the method name.
 /// |params| are the method parameters, which may be empty. See the DevTools
 /// protocol documentation (linked above) for details of supported methods and
 /// the expected |params| dictionary contents. This method will return the
 /// assigned message ID if called on the UI thread and the message was
 /// successfully submitted for validation, otherwise 0. See the
 /// SendDevToolsMessage documentation for additional usage information.
 /// </summary>
 public int ExecuteDevToolsMethod(int messageId, string method, CefDictionaryValue parameters)
 {
     return(BrowserHost == null ? 0 : BrowserHost.ExecuteDevToolsMethod(messageId, method, parameters));
 }
Beispiel #11
0
 public override void OnBrowserCreated(CefBrowser browser, CefDictionaryValue extraInfo)
 {
     _implementation.OnBrowserCreated(browser, extraInfo);
 }
Beispiel #12
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));
 }
Beispiel #13
0
 public static void SetTime(this CefDictionaryValue @this, string index, DateTime value)
 {
     SetTime(_ => @this.SetBinary(index, _), value);
 }
Beispiel #14
0
 public static bool IsType(this CefDictionaryValue @this, string index, CefTypes type)
 {
     return(IsType(() => @this.GetValue(index), type));
 }
Beispiel #15
0
 public static void SetInt64(this CefDictionaryValue @this, string index, long value)
 {
     SetInt64(_ => @this.SetBinary(index, _), value);
 }
 private static ICefDictionaryValue CreateDictionary()
 {
     return(new CefDictionaryValueImpl(CefDictionaryValue.Create()));
 }
Beispiel #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 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);
        }
Beispiel #18
0
 public static DateTime GetTime(this CefDictionaryValue @this, string index)
 {
     return(GetTime(() => @this.GetValue(index)));
 }
Beispiel #19
0
 public static long GetInt64(this CefDictionaryValue @this, string index)
 {
     return(GetInt64(() => @this.GetValue(index)));
 }
Beispiel #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 CefDictionaryValue extraInfo, ref bool noJavascriptAccess)
        {
            var e = new BeforePopupEventArgs(frame, targetUrl, targetFrameName, userGesture, popupFeatures, windowInfo, client, settings, noJavascriptAccess);

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


            if (e.Handled == false)
            {
                if (popupFeatures.X.HasValue)
                {
                    windowInfo.X = popupFeatures.X.Value;
                }


                if (popupFeatures.Y.HasValue)
                {
                    windowInfo.Y = popupFeatures.Y.Value;
                }

                if (popupFeatures.Width.HasValue)
                {
                    windowInfo.Width = popupFeatures.Width.Value;
                }
                else
                {
                    windowInfo.Width = _owner.Width;
                }

                if (popupFeatures.Height.HasValue)
                {
                    windowInfo.Height = popupFeatures.Height.Value;
                }
                else
                {
                    windowInfo.Height = _owner.Height;
                }



                windowInfo.SetAsPopup(IntPtr.Zero, $"正在加载 - {_owner.Title}");

                client = new PopupBrowserClient(_owner);
            }


            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 CefDictionaryValue extraInfo, ref bool noJavascriptAccess)
        {
            _browser.InvokeAsyncIfPossible(() => _browser.OnBeforePopup(new BeforePopupEventArgs(frame, targetUrl, targetFrameName)));

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

            if (isUrlExternal.HasValue && isUrlExternal.Value)
            {
                RegisteredExternalUrl.Launch(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 (UrlHelper.IsChromeInternalUrl(targetUrl))
                {
                    return(false);
                }

                if (Uri.IsWellFormedUriString(targetUrl, UriKind.RelativeOrAbsolute))
                {
                    var uri = new Uri(targetUrl);
                    if (!uri.IsAbsoluteUri)
                    {
                        // turning relative urls into full path to avoid that someone runs custom command lines
                        targetUrl = new Uri(new Uri(frame.Url), uri).AbsoluteUri;
                    }
                }
                else
                {
                    return(false); // if the url is not well formed let's use the browser to handle the things
                }

                try {
                    var popupOpening = OwnerWebView.PopupOpening;
                    if (popupOpening != null)
                    {
                        popupOpening(targetUrl);
                    }
                    else
                    {
                        UrlHelper.OpenInExternalBrowser(targetUrl);
                    }
                } catch {
                    // if we can't handle the command line let's continue the normal request with the popup
                    // with this, will not blow in the users face
                    return(false);
                }

                return(true);
            }
        /// <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);
        }
Beispiel #24
0
        protected virtual void OnCreateBrowser()
        {
            if (this.Opener != null)
            {
                return;
            }

            if (GetState(State.Creating) || GetState(State.Created))
            {
                throw new InvalidOperationException();
            }

            SetState(State.Creating, true);

            Dictionary <InitialPropertyKeys, object> propertyBag = InitialPropertyBag;

            InitialPropertyBag = null;

            var wpfwindow = System.Windows.Window.GetWindow(this);

            if (wpfwindow == null)
            {
                throw new InvalidOperationException("Window not found!");
            }

            using (var windowInfo = new CefWindowInfo())
            {
                windowInfo.SetAsWindowless(new WindowInteropHelper(wpfwindow).Handle);

                string             initialUrl      = null;
                CefDictionaryValue extraInfo       = null;
                CefRequestContext  requestContext  = null;
                CefBrowserSettings browserSettings = null;
                if (propertyBag != null)
                {
                    object value;
                    if (propertyBag.TryGetValue(InitialPropertyKeys.Url, out value))
                    {
                        initialUrl = value as string;
                    }
                    if (propertyBag.TryGetValue(InitialPropertyKeys.BrowserSettings, out value))
                    {
                        browserSettings = value as CefBrowserSettings;
                    }
                    if (propertyBag.TryGetValue(InitialPropertyKeys.RequestContext, out value))
                    {
                        requestContext = value as CefRequestContext;
                    }
                    if (propertyBag.TryGetValue(InitialPropertyKeys.ExtraInfo, out value))
                    {
                        extraInfo = value as CefDictionaryValue;
                    }
                }

                if (initialUrl == null)
                {
                    initialUrl = "about:blank";
                }
                if (browserSettings == null)
                {
                    browserSettings = DefaultBrowserSettings;
                }

                if (!CefApi.CreateBrowser(windowInfo, ViewGlue.Client, initialUrl, browserSettings, extraInfo, requestContext))
                {
                    throw new InvalidOperationException("Failed to create browser instance.");
                }
            }
        }
Beispiel #25
0
 internal void OnReceiveData(CefFrame frame, CefDictionaryValue data)
 {
     FReceivedData = ToXElement("data", data);
 }
Beispiel #26
0
        public CefValue Serialize(object source, HashSet <object> seen, ObjectSerializer objectSerializer)
        {
            if (!CanHandle(source?.GetType()))
            {
                throw new InvalidOperationException();
            }

            long frameId = 0;

            using (var context = CefV8Context.GetCurrentContext())
            {
                frameId = context.GetFrame().Identifier;
            }
            var result = CefValue.Create();

            result.SetNull();

            var value = (CefV8Value)source;

            if (value.IsString)
            {
                result.SetString(value.GetStringValue());
            }
            else if (value.IsBool)
            {
                result.SetBool(value.GetBoolValue());
            }
            else if (value.IsDouble)
            {
                result.SetDouble(value.GetDoubleValue());
            }
            else if (value.IsInt)
            {
                result.SetInt(value.GetIntValue());
            }
            else if (value.IsUInt)
            {
                result.SetDouble(value.GetUIntValue());
            }
            else if (value.IsDate)
            {
                result.SetTime(value.GetDateValue());
            }
            else if (value.IsArray)
            {
                using (var list = CefListValue.Create())
                {
                    list.SetSize(value.GetArrayLength());
                    for (var i = 0; i < value.GetArrayLength(); i++)
                    {
                        list.SetValue(i, objectSerializer.Serialize(value.GetValue(i), seen));
                    }
                    result.SetList(list);
                }
            }
            else if (value.IsFunction)
            {
                var callback = new Callback(value, promiseService, objectSerializer);
                var id       = callbackRegistry.Save(frameId, callback);

                using (var list = CefDictionaryValue.Create())
                    using (var actualValue = CefDictionaryValue.Create())
                    {
                        list.SetString(ObjectSerializer.TypeIdPropertyName, CallbackDescriptor.TypeId);

                        actualValue.SetInt64(nameof(CallbackDescriptor.FunctionId), id);

                        list.SetDictionary(ObjectSerializer.ValuePropertyName, actualValue);
                        result.SetDictionary(list);
                    }
            }
            else if (value.IsObject)
            {
                using (var dict = CefDictionaryValue.Create())
                    using (var actualValue = CefDictionaryValue.Create())
                    {
                        dict.SetString(ObjectSerializer.TypeIdPropertyName, ObjectSerializer.DictionaryTypeId);
                        if (value.TryGetKeys(out var keys))
                        {
                            foreach (var key in keys)
                            {
                                actualValue.SetValue(key, objectSerializer.Serialize(value.GetValue(key), seen));
                            }
                        }

                        dict.SetDictionary(ObjectSerializer.ValuePropertyName, actualValue);
                        result.SetDictionary(dict);
                    }
            }


            return(result);
        }
 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);
 }
Beispiel #28
0
        protected virtual void OnCreateBrowser()
        {
            if (this.Opener != null)
            {
                return;
            }

            if (GetState(State.Creating) || GetState(State.Created))
            {
                throw new InvalidOperationException();
            }

            SetState(State.Creating, true);

            Dictionary <InitialPropertyKeys, object> propertyBag = InitialPropertyBag;

            InitialPropertyBag = null;

            var avaloniaWindow = this.GetVisualRoot() as Window;

            if (avaloniaWindow is null)
            {
                throw new InvalidOperationException("Window not found!");
            }

            using (var windowInfo = new CefWindowInfo())
            {
                IPlatformHandle platformHandle = avaloniaWindow.PlatformImpl.Handle;
                if (platformHandle is IMacOSTopLevelPlatformHandle macOSHandle)
                {
                    windowInfo.SetAsWindowless(macOSHandle.GetNSWindowRetained());
                }
                else
                {
                    windowInfo.SetAsWindowless(platformHandle.Handle);
                }

                string             initialUrl      = null;
                CefDictionaryValue extraInfo       = null;
                CefRequestContext  requestContext  = null;
                CefBrowserSettings browserSettings = null;
                if (propertyBag != null)
                {
                    object value;
                    if (propertyBag.TryGetValue(InitialPropertyKeys.Url, out value))
                    {
                        initialUrl = value as string;
                    }
                    if (propertyBag.TryGetValue(InitialPropertyKeys.BrowserSettings, out value))
                    {
                        browserSettings = value as CefBrowserSettings;
                    }
                    if (propertyBag.TryGetValue(InitialPropertyKeys.RequestContext, out value))
                    {
                        requestContext = value as CefRequestContext;
                    }
                    if (propertyBag.TryGetValue(InitialPropertyKeys.ExtraInfo, out value))
                    {
                        extraInfo = value as CefDictionaryValue;
                    }
                }

                if (initialUrl == null)
                {
                    initialUrl = "about:blank";
                }
                if (browserSettings == null)
                {
                    browserSettings = DefaultBrowserSettings;
                }

                if (!CefApi.CreateBrowser(windowInfo, ViewGlue.Client, initialUrl, browserSettings, extraInfo, requestContext))
                {
                    throw new InvalidOperationException("Failed to create browser instance.");
                }
            }
        }
    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);
    }
 protected override void OnBrowserCreated(CefBrowser browser, CefDictionaryValue extraInfo)
 {
     base.OnBrowserCreated(browser, extraInfo);
 }