Exemplo n.º 1
0
        protected override void OnContextCreated(CefBrowser browser, CefFrame frame, CefV8Context context)
        {
            if (frame.IsMain)
            {
                LogManager.CefLog("-> Setting main context!");

                Browser father = CefUtil.GetBrowserFromCef(browser);
                if (father != null)
                {
                    if (!CefUtil.DISABLE_CEF)
                    {
                        father._mainContext = context;
                    }
                    LogManager.CefLog("-> Main context set!");
                }
            }

            CefV8Value global = context.GetGlobal();

            CefV8Value func = CefV8Value.CreateFunction("resourceCall", new V8Bridge(browser));

            global.SetValue("resourceCall", func);

            CefV8Value func2 = CefV8Value.CreateFunction("resourceEval", new V8Bridge(browser));

            global.SetValue("resourceEval", func2);

            base.OnContextCreated(browser, frame, context);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        protected override CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request)
        {
            Browser father = null;

            //LogManager.CefLog("-> Entering request w/ schemeName " + schemeName);

            try
            {
                father = CefUtil.GetBrowserFromCef(browser);

                if (father == null || father._localMode)
                {
                    LogManager.CefLog("-> [Local mode] Uri: " + request.Url);
                    var uri           = new Uri(request.Url);
                    var path          = Main.GTANInstallDir + "resources\\";
                    var requestedFile = path + uri.Host + uri.LocalPath.Replace("/", "\\");

                    LogManager.CefLog("-> Loading: " + requestedFile);

                    if (File.Exists(requestedFile))
                    {
                        return(SecureCefResourceHandler.FromFilePath(requestedFile,
                                                                     MimeType.GetMimeType(Path.GetExtension(requestedFile))));
                    }
                    LogManager.CefLog("-> Error: File does not exist!");
                    browser.StopLoad();
                    return(SecureCefResourceHandler.FromString("404", ".txt"));
                }
            }
            catch (Exception ex)
            {
                LogManager.CefLog(ex, "CEF SCHEME HANDLING");
                browser?.StopLoad();
                return(SecureCefResourceHandler.FromString("error", ".txt"));
            }

            return(null);
        }
Exemplo n.º 4
0
        protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
        {
            Browser father = null;

            LogManager.CefLog("-> Entering JS Execute. Func: " + name + " arg len: " + arguments.Length);

            father = CefUtil.GetBrowserFromCef(_browser);

            if (father == null)
            {
                LogManager.SimpleLog("cef", "NO FATHER FOUND FOR BROWSER " + _browser.Identifier);
                returnValue = CefV8Value.CreateNull();
                exception   = "NO FATHER WAS FOUND.";
                return(false);
            }
            if (!CefUtil.DISABLE_CEF)
            {
                LogManager.CefLog("-> Father was found!");
                try
                {
                    switch (name)
                    {
                    case "resourceCall":
                    {
                        LogManager.CefLog("-> Entering resourceCall...");

                        List <object> args = new List <object>();

                        for (int i = 1; i < arguments.Length; i++)
                        {
                            args.Add(arguments[i].GetValue());
                        }

                        LogManager.CefLog("-> Executing callback...");

                        object output = father._callback.call(arguments[0].GetStringValue(), args.ToArray());

                        LogManager.CefLog("-> Callback executed!");

                        returnValue = V8Helper.CreateValue(output);
                        exception   = null;
                        return(true);
                    }

                    case "resourceEval":
                    {
                        LogManager.CefLog("-> Entering resource eval");
                        object output = father._callback.eval(arguments[0].GetStringValue());
                        LogManager.CefLog("-> callback executed!");

                        returnValue = V8Helper.CreateValue(output);
                        exception   = null;
                        return(true);
                    }
                    }
                }
                catch (Exception ex)
                {
                    LogManager.CefLog(ex, "EXECUTE JS FUNCTION");
                }
            }
            returnValue = CefV8Value.CreateNull();
            exception   = "";
            return(false);
        }