private void GetIEWebsite() { IEHelper ieWeb = new IEHelper(); List <WebSiteModel> iesites = ieWeb.MonitorIE(); if (iesites != null && iesites.Count > 0) { if (_ieChkListBox == null) { _ieChkListBox = new CheckedListBoxControl(); grpIE.Controls.Add(_ieChkListBox); _ieChkListBox.Dock = DockStyle.Fill; } foreach (var item in iesites) { if (Regex.Match(item.url, "http://item.jd.com/(\\d{1,14}).html", RegexOptions.IgnoreCase).Success) { if (_ieChkListBox.Items.IndexOf(item.url.TrimEnd()) >= 0) { continue; } _ieChkListBox.Items.Add(item.url.TrimEnd(), true); } } if (_ieChkListBox.CheckedItemsCount > 0) { IEPage.AllowNext = true; } } }
/// <summary> /// Gets a list of all IE Windows & tabs with the captions of the instances /// </summary> /// <returns>List with KeyValuePair of WindowDetails and string</returns> public static List <KeyValuePair <WindowDetails, string> > GetBrowserTabs() { var ieHandleList = new List <IntPtr>(); var browserWindows = new Dictionary <WindowDetails, List <string> >(); // Find the IE windows foreach (var ieWindow in GetIeWindows()) { try { if (ieHandleList.Contains(ieWindow.Handle)) { continue; } if ("IEFrame".Equals(ieWindow.ClassName)) { var directUiwd = IEHelper.GetDirectUI(ieWindow); if (directUiwd != null) { var accessible = new Accessible(directUiwd.Handle); browserWindows.Add(ieWindow, accessible.IETabCaptions); } } else if (CoreConfig.WindowClassesToCheckForIE != null && CoreConfig.WindowClassesToCheckForIE.Contains(ieWindow.ClassName)) { var singleWindowText = new List <string>(); try { var document2 = GetHtmlDocument(ieWindow); string title = document2.title; Marshal.ReleaseComObject(document2); if (string.IsNullOrEmpty(title)) { singleWindowText.Add(ieWindow.Text); } else { singleWindowText.Add(ieWindow.Text + " - " + title); } } catch { singleWindowText.Add(ieWindow.Text); } browserWindows.Add(ieWindow, singleWindowText); } ieHandleList.Add(ieWindow.Handle); } catch (Exception) { Log.Warn("Can't get Info from " + ieWindow.ClassName); } } var returnList = new List <KeyValuePair <WindowDetails, string> >(); foreach (var windowDetails in browserWindows.Keys) { foreach (string tab in browserWindows[windowDetails]) { returnList.Add(new KeyValuePair <WindowDetails, string>(windowDetails, tab)); } } return(returnList); }
/// <summary> /// Gets a list of all IE Windows & tabs with the captions of the instances /// </summary> /// <returns>List<KeyValuePair<WindowDetails, string>></returns> public static List <KeyValuePair <WindowDetails, string> > GetBrowserTabs() { List <IntPtr> ieHandleList = new List <IntPtr>(); Dictionary <WindowDetails, List <string> > browserWindows = new Dictionary <WindowDetails, List <string> >(); // Find the IE windows foreach (WindowDetails ieWindow in GetIEWindows()) { try { if (!ieHandleList.Contains(ieWindow.Handle)) { if ("IEFrame".Equals(ieWindow.ClassName)) { WindowDetails directUIWD = IEHelper.GetDirectUI(ieWindow); if (directUIWD != null) { Accessible accessible = new Accessible(directUIWD.Handle); browserWindows.Add(ieWindow, accessible.IETabCaptions); } } else if (configuration.WindowClassesToCheckForIE != null && configuration.WindowClassesToCheckForIE.Contains(ieWindow.ClassName)) { List <string> singleWindowText = new List <string>(); try { IHTMLDocument2 document2 = getHTMLDocument(ieWindow); string title = document2.title; Marshal.ReleaseComObject(document2); if (string.IsNullOrEmpty(title)) { singleWindowText.Add(ieWindow.Text); } else { singleWindowText.Add(ieWindow.Text + " - " + title); } } catch { singleWindowText.Add(ieWindow.Text); } browserWindows.Add(ieWindow, singleWindowText); } ieHandleList.Add(ieWindow.Handle); } } catch (Exception) { LOG.Warn("Can't get Info from " + ieWindow.ClassName); } } List <KeyValuePair <WindowDetails, string> > returnList = new List <KeyValuePair <WindowDetails, string> >(); foreach (WindowDetails windowDetails in browserWindows.Keys) { foreach (string tab in browserWindows[windowDetails]) { returnList.Add(new KeyValuePair <WindowDetails, string>(windowDetails, tab)); } } return(returnList); }
// Helper method to activate a certain IE Tab public static void ActivateIETab(WindowDetails ieWindowDetails, int tabIndex) { WindowDetails directUIWindowDetails = IEHelper.GetDirectUI(ieWindowDetails); // Bring window to the front ieWindowDetails.Restore(); // Get accessible Accessible ieAccessible = new Accessible(directUIWindowDetails.Handle); // Activate Tab ieAccessible.ActivateIETab(tabIndex); }
// Helper method to activate a certain IE Tab public static void ActivateIeTab(IInteropWindow nativeIeWindow, int tabIndex) { var directUiInteropWindow = IEHelper.GetDirectUi(nativeIeWindow); if (directUiInteropWindow != null) { // Bring window to the front nativeIeWindow.Restore(); // Get accessible var ieAccessible = new Accessible(directUiInteropWindow.Handle); // Activate Tab ieAccessible.ActivateIETab(tabIndex); } }
private static IEnumerable <string> GetBrowserUrls() { HashSet <string> urls = new HashSet <string>(); // FireFox foreach (WindowDetails window in WindowDetails.GetAllWindows("MozillaWindowClass")) { if (window.Text.Length == 0) { continue; } AutomationElement currentElement = AutomationElement.FromHandle(window.Handle); Condition conditionCustom = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom), new PropertyCondition(AutomationElement.IsOffscreenProperty, false)); for (int i = 5; i > 0 && currentElement != null; i--) { currentElement = currentElement.FindFirst(TreeScope.Children, conditionCustom); } if (currentElement == null) { continue; } Condition conditionDocument = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document), new PropertyCondition(AutomationElement.IsOffscreenProperty, false)); AutomationElement docElement = currentElement.FindFirst(TreeScope.Children, conditionDocument); if (docElement == null) { continue; } foreach (AutomationPattern pattern in docElement.GetSupportedPatterns()) { if (pattern.ProgrammaticName != "ValuePatternIdentifiers.Pattern") { continue; } string url = (docElement.GetCurrentPattern(pattern) as ValuePattern).Current.Value.ToString(); if (!string.IsNullOrEmpty(url)) { urls.Add(url); break; } } } foreach (string url in IEHelper.GetIEUrls()) { urls.Add(url); } return(urls); }
public static List <JiraIssue> GetCurrentJiras() { // Make sure we suppress the login List <string> jirakeys = new List <string>(); foreach (string url in IEHelper.GetIEUrls()) { if (url == null) { continue; } MatchCollection jiraKeyMatch = JIRA_KEY_REGEX.Matches(url); if (jiraKeyMatch != null && jiraKeyMatch.Count > 0) { string jiraKey = jiraKeyMatch[0].Groups[1].Value; jirakeys.Add(jiraKey); } } if (!string.IsNullOrEmpty(config.LastUsedJira) && !jirakeys.Contains(config.LastUsedJira)) { jirakeys.Add(config.LastUsedJira); } if (jirakeys.Count > 0) { List <JiraIssue> jiraIssues = new List <JiraIssue>(); foreach (string jiraKey in jirakeys) { try { JiraIssue issue = JiraPlugin.Instance.JiraConnector.getIssue(jiraKey); if (issue != null) { jiraIssues.Add(issue); } } catch {} } if (jiraIssues.Count > 0) { return(jiraIssues); } } return(null); }
/// <summary> /// Gets a list of all IE Windows with the captions of the open tabs /// </summary> /// <returns>List<KeyValuePair<WindowDetails, string>></returns> public static List <KeyValuePair <WindowDetails, string> > GetTabList() { List <IntPtr> ieHandleList = new List <IntPtr>(); Dictionary <WindowDetails, List <string> > browserWindows = new Dictionary <WindowDetails, List <string> >(); // Find the IE windows foreach (WindowDetails ieWindow in WindowDetails.GetAllWindows("IEFrame")) { try { if (!ieHandleList.Contains(ieWindow.Handle)) { WindowDetails directUIWD = IEHelper.GetDirectUI(ieWindow); if (directUIWD != null) { Accessible accessible = new Accessible(directUIWD.Handle); browserWindows.Add(ieWindow, accessible.IETabCaptions); } else { List <string> singleWindowText = new List <string>(); singleWindowText.Add(ieWindow.Text); browserWindows.Add(ieWindow, singleWindowText); } ieHandleList.Add(ieWindow.Handle); } } catch (Exception) { LOG.Warn("Can't get Info from " + ieWindow.ClassName); } } List <KeyValuePair <WindowDetails, string> > returnList = new List <KeyValuePair <WindowDetails, string> >(); foreach (WindowDetails windowDetails in browserWindows.Keys) { foreach (string tab in browserWindows[windowDetails]) { returnList.Add(new KeyValuePair <WindowDetails, string>(windowDetails, tab)); } } return(returnList); }
/// <summary> /// Find the DirectUI window for MSAA (Accessible) /// </summary> /// <param name="browserWindowDetails">The browser WindowDetails</param> /// <returns>WindowDetails for the DirectUI window</returns> private static WindowDetails GetDirectUI(WindowDetails browserWindowDetails) { WindowDetails tmpWD = browserWindowDetails; // Since IE 9 the TabBandClass is less deep! if (IEHelper.IEVersion() < 9) { tmpWD = tmpWD.GetChild("CommandBarClass"); if (tmpWD != null) { tmpWD = tmpWD.GetChild("ReBarWindow32"); } } if (tmpWD != null) { tmpWD = tmpWD.GetChild("TabBandClass"); } if (tmpWD != null) { tmpWD = tmpWD.GetChild("DirectUIHWND");; } return(tmpWD); }
public OAuthLoginForm(string browserTitle, Size size, string authorizationLink, string callbackUrl) { // Make sure Greenshot uses the correct browser version IEHelper.FixBrowserVersion(false); _callbackUrl = callbackUrl; // Fix for BUG-2071 if (callbackUrl.EndsWith("/")) { _callbackUrl = callbackUrl.Substring(0, callbackUrl.Length - 1); } InitializeComponent(); ClientSize = size; Icon = GreenshotResources.GetGreenshotIcon(); Text = browserTitle; _addressTextBox.Text = authorizationLink; // The script errors are suppressed by using the ExtendedWebBrowser _browser.ScriptErrorsSuppressed = false; _browser.DocumentCompleted += Browser_DocumentCompleted; _browser.Navigated += Browser_Navigated; _browser.Navigating += Browser_Navigating; _browser.Navigate(new Uri(authorizationLink)); }
public static List <Page> GetCurrentPages(ConfluenceConnector confluenceConnector) { var pages = new List <Page>(); var pageIdRegex = new Regex(@"pageId=(\d+)"); var spacePageRegex = new Regex(@"\/display\/([^\/]+)\/([^#]+)"); foreach (var browserurl in IEHelper.GetIEUrls().Distinct()) { string url; try { url = Uri.UnescapeDataString(browserurl).Replace("+", " "); } catch { Log.Warn().WriteLine("Error processing URL: {0}", browserurl); continue; } var pageIdMatch = pageIdRegex.Matches(url); if (pageIdMatch != null && pageIdMatch.Count > 0) { var pageId = long.Parse(pageIdMatch[0].Groups[1].Value); try { var pageDouble = false; foreach (var page in pages) { if (page.Id == pageId) { pageDouble = true; Log.Debug().WriteLine("Skipping double page with ID {0}", pageId); break; } } if (!pageDouble) { var page = confluenceConnector.GetPage(pageId); Log.Debug().WriteLine("Adding page {0}", page.Title); pages.Add(page); } continue; } catch (Exception ex) { // Preventing security problems Log.Debug().WriteLine("Couldn't get page details for PageID {0}", pageId); Log.Warn().WriteLine(ex); } } var spacePageMatch = spacePageRegex.Matches(url); if (spacePageMatch != null && spacePageMatch.Count > 0) { if (spacePageMatch[0].Groups.Count >= 2) { var space = spacePageMatch[0].Groups[1].Value; var title = spacePageMatch[0].Groups[2].Value; if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(space)) { continue; } if (title.EndsWith("#")) { title = title.Substring(0, title.Length - 1); } try { var pageDouble = false; foreach (var page in pages) { if (page.Title.Equals(title)) { Log.Debug().WriteLine("Skipping double page with title {0}", title); pageDouble = true; break; } } if (!pageDouble) { var page = confluenceConnector.GetPage(space, title); Log.Debug().WriteLine("Adding page {0}", page.Title); pages.Add(page); } } catch (Exception ex) { // Preventing security problems Log.Debug().WriteLine("Couldn't get page details for space {0} / title {1}", space, title); Log.Warn().WriteLine(ex); } } } } return(pages); }
/// <summary> /// Helper method which will retrieve the IHTMLDocument2 for the supplied window, /// or return the first if none is supplied. /// </summary> /// <param name="browserWindow">The WindowDetails to get the IHTMLDocument2 for</param> /// <param name="document2">Ref to the IHTMLDocument2 to return</param> /// <returns>The WindowDetails to which the IHTMLDocument2 belongs</returns> private static DocumentContainer CreateDocumentContainer(WindowDetails browserWindow) { DocumentContainer returnDocumentContainer = null; WindowDetails returnWindow = null; IHTMLDocument2 returnDocument2 = null; // alternative if no match WindowDetails alternativeReturnWindow = null; IHTMLDocument2 alternativeReturnDocument2 = null; // Find the IE windows foreach (WindowDetails ieWindow in GetIEWindows()) { LOG.DebugFormat("Processing {0} - {1}", ieWindow.ClassName, ieWindow.Text); Accessible ieAccessible = null; WindowDetails directUIWD = IEHelper.GetDirectUI(ieWindow); if (directUIWD != null) { ieAccessible = new Accessible(directUIWD.Handle); } if (ieAccessible == null) { if (browserWindow != null) { LOG.InfoFormat("Active Window is {0}", browserWindow.Text); } if (!ieWindow.Equals(browserWindow)) { LOG.WarnFormat("No ieAccessible for {0}", ieWindow.Text); continue; } LOG.DebugFormat("No ieAccessible, but the active window is an IE window: {0}, ", ieWindow.Text); } try { // Get the Document IHTMLDocument2 document2 = getHTMLDocument(ieWindow); if (document2 == null) { continue; } // Get the content window handle for the shellWindow.Document IOleWindow oleWindow = (IOleWindow)document2; IntPtr contentWindowHandle = IntPtr.Zero; if (oleWindow != null) { oleWindow.GetWindow(out contentWindowHandle); } if (contentWindowHandle != IntPtr.Zero) { // Get the HTMLDocument to check the hasFocus // See: http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/60c6c95d-377c-4bf4-860d-390840fce31c/ IHTMLDocument4 document4 = (IHTMLDocument4)document2; if (document4.hasFocus()) { LOG.DebugFormat("Matched focused document: {0}", document2.title); // Look no further, we got what we wanted! returnDocument2 = document2; returnWindow = new WindowDetails(contentWindowHandle); break; } try { if (ieWindow.Equals(browserWindow)) { returnDocument2 = document2; returnWindow = new WindowDetails(contentWindowHandle); break; } else if (ieAccessible != null && returnWindow == null && document2.title.Equals(ieAccessible.IEActiveTabCaption)) { LOG.DebugFormat("Title: {0}", document2.title); returnDocument2 = document2; returnWindow = new WindowDetails(contentWindowHandle); } else { alternativeReturnDocument2 = document2; alternativeReturnWindow = new WindowDetails(contentWindowHandle); } } catch (Exception) { alternativeReturnDocument2 = document2; alternativeReturnWindow = new WindowDetails(contentWindowHandle); } } } catch (Exception e) { LOG.ErrorFormat("Major problem: Problem retrieving Document from {0}", ieWindow.Text); LOG.Error(e); } } // check if we have something to return if (returnWindow != null) { // As it doesn't have focus, make sure it's active returnWindow.Restore(); returnWindow.GetParent(); // Create the container try { returnDocumentContainer = new DocumentContainer(returnDocument2, returnWindow); } catch (Exception e) { LOG.Error("Major problem: Problem retrieving Document."); LOG.Error(e); } } if (returnDocumentContainer == null && alternativeReturnDocument2 != null) { // As it doesn't have focus, make sure it's active alternativeReturnWindow.Restore(); alternativeReturnWindow.GetParent(); // Create the container try { returnDocumentContainer = new DocumentContainer(alternativeReturnDocument2, alternativeReturnWindow); } catch (Exception e) { LOG.Error("Major problem: Problem retrieving Document."); LOG.Error(e); } } return(returnDocumentContainer); }
/// <summary> /// Helper method which will retrieve the IHTMLDocument2 for the supplied window, /// or return the first if none is supplied. /// </summary> /// <param name="browserWindowDetails">The WindowDetails to get the IHTMLDocument2 for</param> /// <param name="document2">Ref to the IHTMLDocument2 to return</param> /// <returns>The WindowDetails to which the IHTMLDocument2 belongs</returns> private static DocumentContainer GetDocument(WindowDetails activeWindow) { DocumentContainer returnDocumentContainer = null; WindowDetails returnWindow = null; IHTMLDocument2 returnDocument2 = null; // alternative if no match WindowDetails alternativeReturnWindow = null; IHTMLDocument2 alternativeReturnDocument2 = null; // Find the IE window foreach (WindowDetails ieWindow in WindowDetails.GetAllWindows("IEFrame")) { LOG.DebugFormat("Processing {0} - {1}", ieWindow.ClassName, ieWindow.Text); Accessible ieAccessible = null; WindowDetails directUIWD = IEHelper.GetDirectUI(ieWindow); if (directUIWD != null) { ieAccessible = new Accessible(directUIWD.Handle); } if (ieAccessible == null) { LOG.InfoFormat("Active Window is {0}", activeWindow.Text); if (!ieWindow.Equals(activeWindow)) { LOG.WarnFormat("No ieAccessible for {0}", ieWindow.Text); continue; } LOG.DebugFormat("No ieAccessible, but the active window is an IE window: {0}, ", ieWindow.Text); } try { // Get the Document IHTMLDocument2 document2 = null; uint windowMessage = User32.RegisterWindowMessage("WM_HTML_GETOBJECT"); if (windowMessage == 0) { LOG.WarnFormat("Couldn't register WM_HTML_GETOBJECT"); continue; } WindowDetails ieServer = ieWindow.GetChild("Internet Explorer_Server"); if (ieServer == null) { LOG.WarnFormat("No Internet Explorer_Server for {0}", ieWindow.Text); continue; } LOG.DebugFormat("Trying WM_HTML_GETOBJECT on {0}", ieServer.ClassName); UIntPtr response; User32.SendMessageTimeout(ieServer.Handle, windowMessage, IntPtr.Zero, IntPtr.Zero, SendMessageTimeoutFlags.SMTO_NORMAL, 1000, out response); if (response != UIntPtr.Zero) { document2 = (IHTMLDocument2)Accessible.ObjectFromLresult(response, typeof(IHTMLDocument).GUID, IntPtr.Zero); if (document2 == null) { LOG.Error("No IHTMLDocument2 found"); continue; } } else { LOG.Error("No answer on WM_HTML_GETOBJECT."); continue; } // Get the content window handle for the shellWindow.Document IOleWindow oleWindow = (IOleWindow)document2; IntPtr contentWindowHandle = IntPtr.Zero; if (oleWindow != null) { oleWindow.GetWindow(out contentWindowHandle); } if (contentWindowHandle != IntPtr.Zero) { // Get the HTMLDocument to check the hasFocus // See: http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/60c6c95d-377c-4bf4-860d-390840fce31c/ IHTMLDocument4 document4 = (IHTMLDocument4)document2; if (document4.hasFocus()) { LOG.DebugFormat("Matched focused document: {0}", document2.title); // Look no further, we got what we wanted! returnDocument2 = document2; returnWindow = new WindowDetails(contentWindowHandle); break; } try { if (ieWindow.Equals(activeWindow)) { returnDocument2 = document2; returnWindow = new WindowDetails(contentWindowHandle); break; } else if (ieAccessible != null && returnWindow == null && document2.title.Equals(ieAccessible.IEActiveTabCaption)) { LOG.DebugFormat("Title: {0}", document2.title); returnDocument2 = document2; returnWindow = new WindowDetails(contentWindowHandle); } else { alternativeReturnDocument2 = document2; alternativeReturnWindow = new WindowDetails(contentWindowHandle); } } catch (Exception) { alternativeReturnDocument2 = document2; alternativeReturnWindow = new WindowDetails(contentWindowHandle); } } } catch (Exception e) { LOG.Error(e); LOG.DebugFormat("Major problem: Problem retrieving Document from {0}", ieWindow.Text); } } // check if we have something to return if (returnWindow != null) { // As it doesn't have focus, make sure it's active returnWindow.Restore(); returnWindow.GetParent(); // Create the container returnDocumentContainer = new DocumentContainer(returnDocument2, returnWindow); } if (returnDocumentContainer == null && alternativeReturnDocument2 != null) { // As it doesn't have focus, make sure it's active alternativeReturnWindow.Restore(); alternativeReturnWindow.GetParent(); // Create the container returnDocumentContainer = new DocumentContainer(alternativeReturnDocument2, alternativeReturnWindow); } return(returnDocumentContainer); }