예제 #1
0
        /// <summary>
        /// Enables requests to certain schemes (http, https and scchrom) to be exchanged and manipulated.
        /// Also adds the scchrom scheme to provide scchrom internal stuff like the editors help content.
        /// </summary>
        private void setupSchemes()
        {
            var    whitelist       = new List <RequestIdentifier>();
            string whitelistString = Arguments.GetArgument("request-whitelist", "").Trim();

            if (!string.IsNullOrWhiteSpace(whitelistString))
            {
                string[] whitelistEntries = whitelistString.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                foreach (string entry in whitelistEntries)
                {
                    whitelist.Add(new RequestIdentifier(entry));
                }
            }

            List <Tuple <RequestIdentifier, string> > response_exchanges_utf8 = null;
            var exchangeResponseHandler = Tools.Arguments.GetStackedArguments("exchange-response-utf8");

            if (exchangeResponseHandler != null)
            {
                response_exchanges_utf8 = new List <Tuple <RequestIdentifier, string> >();
                foreach (var rrh in exchangeResponseHandler)
                {
                    var filter = new RequestIdentifier(rrh.Key);
                    response_exchanges_utf8.Add(new Tuple <RequestIdentifier, string>(filter, rrh.Value));
                }
            }

            List <Tuple <RequestIdentifier, string> > js_Rewrites = null;
            var js_rewriteHandler = Tools.Arguments.GetStackedArguments("exchange-response-utf8_script");

            if (js_rewriteHandler != null)
            {
                js_Rewrites = new List <Tuple <RequestIdentifier, string> >();
                foreach (var rrh in js_rewriteHandler)
                {
                    var filter = new RequestIdentifier(rrh.Key);
                    js_Rewrites.Add(new Tuple <RequestIdentifier, string>(filter, rrh.Value));
                }
            }


            var resourceSchemehandler = new Handler.SchemeHandlerFactory(whitelist, response_exchanges_utf8, js_Rewrites);

            // remove old schemes and ...
            Cef.ClearSchemeHandlerFactories();

            // ... register all new schemes
            var globalRequestContext = Cef.GetGlobalRequestContext();

            globalRequestContext.RegisterSchemeHandlerFactory("http", "", resourceSchemehandler);
            globalRequestContext.RegisterSchemeHandlerFactory("https", "", resourceSchemehandler);
            globalRequestContext.RegisterSchemeHandlerFactory("scchrom", "", resourceSchemehandler);
        }
예제 #2
0
        private void init_event_onResponse()
        {
            var manipulateResponseHandler_once = Arguments.GetStackedArguments("on-response");

            if (manipulateResponseHandler_once == null)
            {
                return;
            }
            foreach (var brh in manipulateResponseHandler_once)
            {
                string urlPattern = brh.Key;

                string parameterName = "on-response";
                if (!string.IsNullOrWhiteSpace(urlPattern))
                {
                    parameterName += "<" + urlPattern + ">";
                }

                // no pattern? Only execute once
                bool executeOnlyOnce = false;

                RequestIdentifier ri = null;
                if (urlPattern == null || urlPattern == "")
                {
                    executeOnlyOnce = true;
                    urlPattern      = "*";
                    Logger.Log("Added on-response handler for pattern " + urlPattern, Logger.LogLevel.debug);
                }
                else
                {
                    Logger.Log("Added on-response handler for pattern " + urlPattern, Logger.LogLevel.debug);
                }

                ri = new RequestIdentifier(urlPattern);
                var or_m = new OutputResponse_Manipulate(brh.Value, null, parameterName, executeOnlyOnce);


                ((CustomResourceRequestHandlerFactory)browser.ResourceRequestHandlerFactory).AddRessourceRequestHandler(
                    new Tuple <RequestIdentifier, IResourceRequestHandler>(
                        ri,
                        or_m
                        ));
            }
        }
예제 #3
0
        private void init_parameter_cookie()
        {
            var cookies = Tools.Arguments.GetStackedArguments("cookies");

            if (cookies != null)
            {
                EventHandler setCookies = null;
                setCookies = (e, v) => {
                    if (!browser.IsBrowserInitialized)
                    {
                        return;
                    }

                    browser.IsBrowserInitializedChanged -= setCookies;

                    foreach (string cookieUrl in cookies.Keys)
                    {
                        RequestIdentifier ri       = new RequestIdentifier(cookieUrl);
                        string            contents = cookies[cookieUrl];
                        if (!contents.Contains("\t"))
                        {
                            try {
                                if (File.Exists(contents))
                                {
                                    foreach (var c in Tools.Common.ParseCookieFile(contents))
                                    {
                                        if (browser.GetCookieManager().SetCookie(cookieUrl, c))
                                        {
                                            Logger.Log("Added cookie for url " + cookieUrl + " and path " + c.Path, Logger.LogLevel.debug);
                                        }
                                        else
                                        {
                                            Logger.Log("Failed to add cookie for url " + cookieUrl + " and path " + c.Path, Logger.LogLevel.error);
                                        }
                                    }
                                }
                            } catch (Exception ex) {
                                Logger.Log("Error while trying to read from cookie file: " + contents, Logger.LogLevel.error);
                                Logger.Log("Error was: " + ex.Message, Logger.LogLevel.error);
                                Application.Exit();
                            }
                        }
                        else
                        {
                            try {
                                var lines = contents.Split(Environment.NewLine.ToCharArray());
                                foreach (var c in Tools.Common.ParseCookieLines(new List <string>(lines)))
                                {
                                    if (browser.GetCookieManager().SetCookie(cookieUrl, c))
                                    {
                                        Logger.Log("Added cookie for url " + cookieUrl + " and path " + c.Path, Logger.LogLevel.debug);
                                    }
                                    else
                                    {
                                        Logger.Log("Failed to add cookie for url " + cookieUrl + " and path " + c.Path, Logger.LogLevel.error);
                                    }
                                }
                            } catch (Exception ex) {
                                Logger.Log("Error while trying add cookeis for url: " + cookieUrl, Logger.LogLevel.error);
                                Logger.Log("Error was: " + ex.Message, Logger.LogLevel.error);
                                Application.Exit();
                            }
                        }
                    }
                };

                browser.IsBrowserInitializedChanged += setCookies;
            }
        }