public WebBrowser(BrowserType browserType, IVariableRetriever v)
 {
     _browserType = browserType;
     _browser = BrowserFactory.CreateBrowser(browserType);
     _variableRetriver = v;
     initializeUserSettingsPropertiesList();
 }
Example #2
0
        void IDisplayHandler.OnFullscreenModeChange(IWebBrowser browserControl, IBrowser browser, bool fullscreen)
        {
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            chromiumWebBrowser.InvokeOnUiThreadIfRequired(() =>
            {
                if (fullscreen)
                {
                    parent = chromiumWebBrowser.Parent;

                    parent.Controls.Remove(chromiumWebBrowser);

                    fullScreenForm = new Form();
                    fullScreenForm.FormBorderStyle = FormBorderStyle.None;
                    fullScreenForm.WindowState = FormWindowState.Maximized;

                    fullScreenForm.Controls.Add(chromiumWebBrowser);

                    fullScreenForm.ShowDialog(parent.FindForm());
                }
                else
                {
                    fullScreenForm.Controls.Remove(chromiumWebBrowser);

                    parent.Controls.Add(chromiumWebBrowser);

                    fullScreenForm.Close();
                    fullScreenForm.Dispose();
                    fullScreenForm = null;
                }
            });
        }
	    /// <summary>
	    /// Initializes a new instance of the <see cref="PageNavigationSteps" /> class.
	    /// </summary>
	    /// <param name="browser">The browser.</param>
	    /// <param name="pageMapper">The page mapper.</param>
	    /// <param name="scenarioContext">The scenario context.</param>
	    /// <param name="actionPipelineService">The action pipeline service.</param>
	    public PageNavigationSteps(IBrowser browser, IPageMapper pageMapper, IScenarioContextHelper scenarioContext, IActionPipelineService actionPipelineService)
            : base(scenarioContext)
		{
			this.browser = browser;
			this.pageMapper = pageMapper;
			this.actionPipelineService = actionPipelineService;
		}
Example #4
0
        public void WelcomeToZecco(IBrowser browser)
        {
            WelcomeToZeccoLink(browser);

            

        }
Example #5
0
 public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, string acceptLang, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage)
 {
     switch (dialogType)
     {
         case CefJsDialogType.Alert:
             MessageBox.Show(messageText);
             suppressMessage = true;
             return false;
         case CefJsDialogType.Confirm:
             var dr = MessageBox.Show(messageText, "提示", MessageBoxButton.YesNo);
             if (dr == MessageBoxResult.Yes)
                 callback.Continue(true);
             else
                 callback.Continue(false);
             suppressMessage = false;
             return true;
         case CefJsDialogType.Prompt:
             MessageBox.Show("系统不支持prompt形式的提示框", "UTMP系统提示");
             break;
     }
     //如果suppressMessage被设置为true,并且函数返回值为false,将阻止页面打开JS的弹出窗口。
     //如果suppressMessage被设置为false,并且函数返回值也是false,页面将会打开这个JS弹出窗口。
     suppressMessage = true;
     return false;
 }
 public FrameLoadStartEventArgs(IBrowser browser, IFrame frame)
 {
     Browser = browser;
     Frame = frame;
     Url = frame.Url;
     IsMainFrame = frame.IsMain;
 }
Example #7
0
        bool IGeolocationHandler.OnRequestGeolocationPermission(IWebBrowser browserControl, IBrowser browser, string requestingUrl, int requestId, IGeolocationCallback callback)
        {
            //You can execute the callback inline
            //callback.Continue(true);
            //return true;

            //You can execute the callback in an `async` fashion
            //Open a message box on the `UI` thread and ask for user input.
            //You can open a form, or do whatever you like, just make sure you either
            //execute the callback or call `Dispose` as it's an `unmanaged` wrapper.
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;
            chromiumWebBrowser.Dispatcher.BeginInvoke((Action)(() =>
            {
                //Callback wraps an unmanaged resource, so we'll make sure it's Disposed (calling Continue will also Dipose of the callback, it's safe to dispose multiple times).
                using (callback)
                {
                    var result = MessageBox.Show(String.Format("{0} wants to use your computer's location.  Allow?  ** You must set your Google API key in CefExample.Init() for this to work. **", requestingUrl), "Geolocation", MessageBoxButton.YesNo);

                    //Execute the callback, to allow/deny the request.
                    callback.Continue(result == MessageBoxResult.Yes);
                }
            }));

            //Yes we'd like to hadle this request ourselves.
            return true;
        }
Example #8
0
 bool ILifeSpanHandler.DoClose(IWebBrowser browserControl, IBrowser browser)
 {
     //The default CEF behaviour (return false) will send a OS close notification (e.g. WM_CLOSE).
     //See the doc for this method for full details.
     //return true here to handle closing yourself (no WM_CLOSE will be sent).
     return true;
 }
Example #9
0
 /// <inheritdoc/>>
 public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
 {
     bool result = false;
     Debug.WriteLine(String.Format("OnKeyEvent: KeyType: {0} 0x{1:X} Modifiers: {2}", type, windowsKeyCode, modifiers));
     // TODO: Handle MessageNeeded cases here somehow.
     return result;
 }
Example #10
0
        public void Help(IBrowser browser)
        {
            HelpLink(browser);



        }
 bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
 {
     newBrowser = null;
     //browserControl.Load(targetUrl);
     OpenInNewTab?.Invoke(this, new NewTabEventArgs(targetUrl)); //this breaks when there are multiple window.open calls from JS.
     return true;
 }
Example #12
0
 public void AddChar(IBrowser browser, char chr)
 {
     char newChar = Char.ToLower(chr);
     curString += newChar;
     IBrowserItem cur = browser.Cursor;
     if (cur.State.HasFlag(BrowserItemState.UnMarkable) == false && cur.showName.ToLower().StartsWith(curString)) return;
     List<IBrowserItem> items = browser.Items;
     foreach (IBrowserItem item in items)
     {
         if (item.State.HasFlag(BrowserItemState.UnMarkable) == false && item.showName.ToLower().StartsWith(curString))
         {
             browser.SelectItem(item);
             return;
         }
     }
     curString = new string(newChar, 1);
     foreach (IBrowserItem item in items)
     {
         if (item.State.HasFlag(BrowserItemState.UnMarkable) == false && item.showName.ToLower().StartsWith(curString))
         {
             browser.SelectItem(item);
             return;
         }
     }
     curString = "";
 }
        public IResourceHandler GetResourceHandler(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request)
        {
            // Every time we request the main GPM page allow another JS injection
            if (Regex.Match(request.Url, @"^http[s]?://play\.google\.com/music/listen", RegexOptions.IgnoreCase).Success)
            {
                firstJSOnly = true;
            }
            if (Regex.Match(request.Url, @"\.js", RegexOptions.IgnoreCase).Success && Regex.Match(request.Url, @"http", RegexOptions.IgnoreCase).Success && firstJSOnly)
            {
                firstJSOnly = false;
                using (WebClient webClient = new WebClient())
                {
                    // These are the JS files to inject into GPM
                    string custom_interface = Properties.Resources.custom_interface;

                    return ResourceHandler.FromStream(new MemoryStream(Encoding.UTF8.GetBytes(
                        webClient.DownloadString(request.Url) + ";window.onload=function(){csharpinterface.showApp();};document.addEventListener('DOMContentLoaded', function () {" +
                            "window.OBSERVER = setInterval(function() { if (document.getElementById('material-vslider')) { clearInterval(window.OBSERVER); " +
                            Properties.Resources.gmusic_min + Properties.Resources.gmusic_theme_min + Properties.Resources.gmusic_mini_player_min +
                            this.getInitCode() +
                            custom_interface +
                        "}}, 10);});")), webClient.ResponseHeaders["Content-Type"]);
                }
            }
            return null;
        }
        CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame,
            IRequest request, IRequestCallback callback) {
            if (CommonUrls.IsWithSixUrl(request.Url)) {
                var headers = request.Headers;
                headers[Common.ClientHeader] = DomainEvilGlobal.SecretData.UserInfo.ClientId.ToString();
                headers[Common.ClientHeaderV] = Common.App.ProductVersion;
                request.Headers = headers;
            }

            return CefReturnValue.Continue;
            //Example of how to set Referer
            // Same should work when setting any header
            // For this example only set Referer when using our custom scheme
            var url = new Uri(request.Url);
            if (url.Scheme == "customscheme") // CefSharpSchemeHandlerFactory.SchemeName
            {
                var headers = request.Headers;
                headers["Referer"] = "http://google.com";

                request.Headers = headers;
            }

            //NOTE: If you do not wish to implement this method returning false is the default behaviour
            // We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.
            //callback.Dispose();
            //return false;

            //NOTE: When executing the callback in an async fashion need to check to see if it's disposed
            if (!callback.IsDisposed) {
                using (callback) {
                    if (request.Method == "POST") {
                        using (var postData = request.PostData) {
                            if (postData != null) {
                                var elements = postData.Elements;

                                var charSet = request.GetCharSet();

                                foreach (var element in elements) {
                                    if (element.Type == PostDataElementType.Bytes) {
                                        var body = element.GetBody(charSet);
                                    }
                                }
                            }
                        }
                    }

                    //Note to Redirect simply set the request Url
                    //if (request.Url.StartsWith("https://www.google.com", StringComparison.OrdinalIgnoreCase))
                    //{
                    //    request.Url = "https://github.com/";
                    //}

                    //Callback in async fashion
                    //callback.Continue(true);
                    //return CefReturnValue.ContinueAsync;
                }
            }

            return CefReturnValue.Continue;
        }
Example #15
0
        CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
        {
            using (callback)
            {
                if (request.Method == "POST")
                {
                    using (var postData = request.PostData)
                    {
                        var elements = postData.Elements;

                        var charSet = request.GetCharSet();

                        foreach (var element in elements)
                        {
                            if (element.Type == PostDataElementType.Bytes)
                            {
                                var body = element.GetBody(charSet);
                            }
                        }
                    }
                }

                //Note to Redirect simply set the request Url
                //if (request.Url.StartsWith("https://www.google.com", StringComparison.OrdinalIgnoreCase))
                //{
                //    request.Url = "https://github.com/";
                //}

                //Callback in async fashion
                //callback.Continue(true);
                //return CefReturnValue.ContinueAsync;
            }
            
            return CefReturnValue.Continue;
        }
 bool IRequestHandler.OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request,
     bool isRedirect) {
     if (!frame.IsMain || CommonUrls.IsWithSixUrl(request.Url) || IsAuthUrl(new Uri(request.Url)))
         return false;
     OpenInSystemBrowser(request.Url);
     return true;
 }
        public IResourceHandler GetResourceHandler(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request)
        {
            // Every time we request the main GPM page allow another JS injection
            if (Regex.Match(request.Url, @"^http[s]?://play\.google\.com/music/listen", RegexOptions.IgnoreCase).Success)
            {
                firstJSOnly = true;
            }
            if (Regex.Match(request.Url, @"\.js", RegexOptions.IgnoreCase).Success && Regex.Match(request.Url, @"http", RegexOptions.IgnoreCase).Success && firstJSOnly)
            {
                firstJSOnly = false;
                using (WebClient webClient = new WebClient())
                {
                    // These are the JS files to inject into GPM
                    string dark_theme = Google_Play_Music.Properties.Resources.dark_theme;
                    string custom_interface = Google_Play_Music.Properties.Resources.custom_interface;
                    string mini_player = Google_Play_Music.Properties.Resources.mini_player;

                    Color c = Properties.Settings.Default.CustomColor;
                    string RGB = "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
                    string custom_color = ";(function() {window.CustomColor = '" + RGB + "';})();";

                    bool controlsOnHover = Properties.Settings.Default.HoverControls;
                    string controlsOnHoverJS = ";(function() {window.hoverControls = " + controlsOnHover.ToString().ToLower() + ";})();";

                    string setInitialZoomJS = ";(function() {csharpinterface.setInitialZoom();})();";

                    return ResourceHandler.FromStream(new MemoryStream(Encoding.UTF8.GetBytes(webClient.DownloadString(request.Url) + ";" + custom_color + controlsOnHoverJS + setInitialZoomJS + dark_theme + custom_interface + mini_player)), webClient.ResponseHeaders["Content-Type"]);
                }
            }
            return null;
        }
Example #18
0
 void IContextMenuHandler.OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
 {
     //Removing existing menu item
     model.Remove(CefMenuCommand.ViewSource); // Remove "View Source" option
     model.Remove(CefMenuCommand.Print);
     //Add new custom menu items
     model.AddItem((CefMenuCommand)ViewSource, "View Page Source");
     if (parameters.TypeFlags.HasFlag(ContextMenuType.Media) && parameters.HasImageContents)
     {
         if(OsirtHelper.HasJpegExtension(parameters.SourceUrl))
         {
             model.AddItem((CefMenuCommand)ViewImageExifData, "View image EXIF data");
         }
         model.AddItem((CefMenuCommand)MenuSaveImage, "Save image");
         model.AddItem((CefMenuCommand)CopyImgLocation, "Copy image location to clipboard");
         model.AddItem((CefMenuCommand)ReverseImageSearch, "Reverse image search using TinEye");
     }
     if(OsirtHelper.IsOnYouTube(browserControl.Address))
     {
         model.AddItem((CefMenuCommand)SaveYouTubeVideo, "Extract YouTube video");
     }
     if (OsirtHelper.IsOnFacebook(browserControl.Address))
     {
         model.AddItem((CefMenuCommand)ViewFacebookId, "Show Facebook profile ID");
     }
     if(!string.IsNullOrEmpty(parameters.UnfilteredLinkUrl))
     {
         model.AddItem((CefMenuCommand)26501, "Open link in new tab");
     }
 }
Example #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MemoryHtmlPage"/> class.
        /// </summary>
        /// <param name="browser">
        /// The browser.
        /// </param>
        /// <param name="html">
        /// The HTML.
        /// </param>
        /// <exception cref="ArgumentNullException">The <paramref name="browser"/> parameter is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">The <paramref name="html"/> parameter is <c>null</c>, empty or only contains white space.</exception>
        public MemoryHtmlPage(IBrowser browser, string html)
        {
            if (browser == null)
            {
                throw new ArgumentNullException("browser");
            }

            if (string.IsNullOrWhiteSpace(html))
            {
                throw new ArgumentException(Resources.HtmlPage_NoHtmlContentProvided, "html");
            }

            IEnumerable<HttpOutcome> outcomes = new List<HttpOutcome>
            {
                new HttpOutcome(_targetLocation, HttpMethod.Get, HttpStatusCode.OK, "OK", TimeSpan.FromMilliseconds(5))
            };
            var result = new HttpResult(outcomes);

            Initialize(browser, HttpStatusCode.OK, "OK", result);

            using (var reader = new StringReader(html))
            {
                SetContent(reader);
            }
        }
 public FrameLoadEndEventArgs(IBrowser browser, IFrame frame, int httpStatusCode)
 {
     Browser = browser;
     Frame = frame;
     Url = frame.Url;
     HttpStatusCode = httpStatusCode;
 }
Example #21
0
        public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
        {
            if (!callback.IsDisposed) {
                using (callback) {
                    string directory = Properties.Settings.Default.StorageLocation + (GlobalVariables.CurrentUnitCode != "" ? GlobalVariables.CurrentUnitCode + "/" : "");
                    Directory.CreateDirectory(directory);

                    string filename = directory + downloadItem.SuggestedFileName;
                    if (!File.Exists(filename)) {
                        callback.Continue(filename, showDialog: false);
                        ++GlobalVariables.FilesDownloaded;

                        BlackboardFile f = new BlackboardFile(downloadItem.SuggestedFileName, downloadItem.Url);
                        f.RawURL = GlobalVariables.CurrentUrl;
                        f.FirstDownloaded = DateTime.Now;
                        f.LastDownloaded = DateTime.Now;
                        f.TimesDownloaded = 1;
                        f.LocalPath = filename;

                        //We know the unit we want exists in GlobalVariables.Units because it was created before the download started, back in Crawler.cs
                        GlobalVariables.Units.First(u => u.Name == GlobalVariables.CurrentUnitCode).Files.Add(f);
                    }
                    else {
                        //FUTURE FEATURE: Allow files to be marked for redownloading.
                        ++GlobalVariables.FilesSkipped;
                    }

                    if (DownloadHandled != null)
                        DownloadHandled(new object(), new EventArgs());
                }
            }
        }
 public LoadingStateChangedEventArgs(IBrowser browser, bool canGoBack, bool canGoForward, bool isLoading)
 {
     Browser = browser;
     CanGoBack = canGoBack;
     CanGoForward = canGoForward;
     IsLoading = isLoading;
     CanReload = !isLoading;
 }
Example #23
0
        bool IRequestHandler.GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
        {
            //NOTE: If you do not wish to implement this method returning false is the default behaviour
            // We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.

            callback.Dispose();
            return false;
        }
 public static bool IsItemSelected(IBrowser browser, string pattern, uint timeout)
 {
     return browser.Describe<IWebElement>(new WebElementDescription
     {
         XPath = "//span[contains(@class,'checkbox_checked_yes')]",
         InnerText = pattern
     }).Exists(timeout);
 }
 IResourceHandler IResourceHandlerFactory.GetResourceHandler(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request)
 {
     if (request.Url.Contains("zeldaADPCM5bit.swf"))
     {
         return new FlashResourceHandler();
     }
     return null;
 }
Example #26
0
        public  void SignOut(IBrowser browser)
        //CheckPoint:Logout successfully, the Login button can be viewed. 
        {
            UserSignOut(browser);
            Assert.IsTrue(browser.Link(Find.ByClass("login-button login-signin")).Exists);
            

        }
Example #27
0
 public void Setup()
 {
     //In Custom framework we need to initalize the LeanFT SDK
     SDK.Init(new SdkConfiguration());
     
     //Open Internet Explorer
     browser = BrowserFactory.Launch(BrowserType.InternetExplorer);
 }
Example #28
0
        void IContextMenuHandler.OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
        {
            Console.WriteLine("Context menu opened");
            Console.WriteLine(parameters.MisspelledWord);

            //To disable context mode then clear
            // model.Clear();
        }
Example #29
0
 bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, int commandId, CefEventFlags eventFlags)
 {
     if (commandId == (int)CefMenuCommand.Reload)
     {
         browser.Reload();
     }
     return false;
 }
 public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
 {
     if (!callback.IsDisposed)
     {
         callback.Continue(downloadItem.SuggestedFileName, showDialog: true);
         callback.Dispose();
     }
 }