Exemple #1
0
        private static string GetChromeUrl(IntPtr hwnd)
        {
            var chromeRenderHwnd = FindDescendantWindows(hwnd, "Chrome_RenderWidgetHostHWND").FirstOrDefault();

            if (chromeRenderHwnd == IntPtr.Zero)
            {
                return(null);
            }
            var doc = AccessibleObjectHelper.FindChild(AccessibleObjectHelper.GetAccessibleObjectFromWindow(chromeRenderHwnd),
                                                       role: AccessibleRole.Document);

            if (doc == null)
            {
                return(null);
            }

            var test = doc.accFocus as IAccessible;

            if (test != null)
            {
                LogAccessibleObject(0, hwnd, test);
                return(doc.accValue[0]);
            }

            return(null);
        }
Exemple #2
0
        private static bool EnumWindows(IntPtr hWnd, IntPtr lParam)
        {
            var className = GetClassName(hWnd);

            sFile.WriteLine("{0}[{1}]", hWnd.ToString("X"), className);

            if (className == "MozillaWindowClass")
            {
                WriteUrl(GetFirefoxUrl(hWnd));
            }
            else if (className == "IEFrame")
            {
                WriteUrl(GetInternetExplorerUrl(hWnd));
            }
            else if (className == "ApplicationFrameWindow")
            {
                WriteUrl(GetEdgeUrl(hWnd));
            }
            else if (className.StartsWith("Chrome_WidgetWin_") ||
                     className.StartsWith("YandexBrowser_WidgetWin_"))
            {
                WriteUrl(GetChromeUrl(hWnd));
            }

            if (SupportedTopLevelWindowClasses.Contains(className))
            {
                try
                {
                    var accessibleObject = AccessibleObjectHelper.GetAccessibleObjectFromWindow(hWnd);

                    try
                    {
                        LogAccessibleObject(0, hWnd, accessibleObject);
                    }
                    catch (Exception ex)
                    {
                        sFile.WriteLine("Exception: " + ex.Message);
                    }

                    LogChildren(accessibleObject, 1);
                }
                catch (Exception ex)
                {
                    sFile.WriteLine("Exception: " + ex.Message);
                }
            }
            return(true);
        }
Exemple #3
0
        private static string GetInternetExplorerUrl(IntPtr hwnd)
        {
            var ieServerHwnd = FindDescendantWindows(hwnd, "Internet Explorer_Server").First();
            var ieServer     = AccessibleObjectHelper.GetAccessibleObjectFromWindow(ieServerHwnd);

            if (ieServer == null)
            {
                return(null);
            }

            /*
             * var test = ieServer.accFocus as IAccessible;
             * LogAccessibleObject(0, hwnd, test);
             *
             * ieServer = AccessibleObjectHelper.FindAncestor(test, AccessibleRole.Client);
             */
            return(ieServer.accName[0]);
        }
Exemple #4
0
        private static string GetEdgeUrl(IntPtr hwnd)
        {
            var coreWindowHwnd = FindDescendantWindows(hwnd, "Windows.UI.Core.CoreWindow").FirstOrDefault();

            if (coreWindowHwnd == IntPtr.Zero)
            {
                return(null);
            }
            var addressBar = AccessibleObjectHelper.FindChild(AccessibleObjectHelper.FindChild(AccessibleObjectHelper.GetAccessibleObjectFromWindow(coreWindowHwnd),
                                                                                               role: AccessibleRole.Window),
                                                              role: AccessibleRole.Text);

            if (addressBar == null)
            {
                return(null);
            }
            return(addressBar.accValue[0]);
        }
Exemple #5
0
        private static string GetFirefoxUrl(IntPtr hwnd)
        {
            var propertyPage = AccessibleObjectHelper.FindChild(AccessibleObjectHelper.FindChild(AccessibleObjectHelper.FindChild(AccessibleObjectHelper.GetAccessibleObjectFromWindow(hwnd),
                                                                                                                                  role: AccessibleRole.Application),
                                                                                                 role: AccessibleRole.Grouping,
                                                                                                 hasNotState: AccessibleStates.Invisible),
                                                                role: AccessibleRole.PropertyPage,
                                                                hasNotState: AccessibleStates.Offscreen /*(inactive tab)*/);

            var browser = AccessibleObjectHelper.FindChild(propertyPage, customRole: "browser, http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul") // Firefox 59+
                          ?? AccessibleObjectHelper.FindChild(propertyPage, customRole: "browser");                                                            // Firefox <59

            var doc = AccessibleObjectHelper.FindChild(browser, role: AccessibleRole.Document);

            return(doc?.accValue[0]);
        }
Exemple #6
0
        private static void LogChildren(IAccessible accessibleObject, int depth)
        {
            var hWnd = AccessibleObjectHelper.GetWindowHandleFromAccessibleObject(accessibleObject);

            sProcessedWindowHandles.Add(hWnd);

            sLogStack.Push(accessibleObject);

            var children = AccessibleObjectHelper.GetChildren(accessibleObject).ToList();

            if (children.Any())
            {
                sFile.WriteLine(new String(' ', depth) + "==Accessible Children==");
            }

            foreach (var child in children)
            {
                if (!sLogStack.Contains(child, new AccessibleObjectComparer()))                 // Avoid infinite recursion
                {
                    var childWindowHandle = AccessibleObjectHelper.GetWindowHandleFromAccessibleObject(child);
                    sProcessedWindowHandles.Add(childWindowHandle);

                    try
                    {
                        LogAccessibleObject(depth, childWindowHandle, child);
                    }
                    catch (Exception ex)
                    {
                        sFile.WriteLine("Exception: " + ex.Message);
                    }
                    LogChildren(child, depth + 1);
                }
            }

            var first = true;

            if (hWnd != IntPtr.Zero)
            {
                var childWindowHandle = IntPtr.Zero;
                do
                {
                    childWindowHandle = FindWindowEx(hWnd, childWindowHandle, null, null);

                    if (!sProcessedWindowHandles.Contains(childWindowHandle))
                    {
                        if (first)
                        {
                            first = false;
                            sFile.WriteLine(new String(' ', depth) + "==Window Children==");
                        }

                        sProcessedWindowHandles.Add(childWindowHandle);
                        try
                        {
                            var child = AccessibleObjectHelper.GetAccessibleObjectFromWindow(childWindowHandle);
                            LogAccessibleObject(depth, childWindowHandle, child);
                            LogChildren(child, depth + 1);
                        }
                        catch (Exception ex)
                        {
                            sFile.WriteLine("Exception: " + ex.Message);
                        }
                    }
                } while (childWindowHandle != IntPtr.Zero);
            }

            if (!first || children.Any())
            {
                sFile.WriteLine(new String(' ', depth) + "====");
            }

            sLogStack.Pop();
        }