private static void AddStyleReference(string baseUrl, ArrayList list, string ruleName)
 {
     string listImagePath = GetPathFromStyleUrl(ruleName);
     if (listImagePath != null)
     {
         ResourceUrlInfo urlInfo = new ResourceUrlInfo();
         urlInfo.ResourceUrl = listImagePath;
         urlInfo.ResourceAbsoluteUrl = UrlHelper.EscapeRelativeURL(baseUrl, listImagePath);
         urlInfo.ResourceType = HTMLTokens.Img;
         list.Add(urlInfo);
     }
 }
        private static void AddAttributeToList(string attributeName, IHTMLElement element, ArrayList resources)
        {
            // For this element, try to find the attribute containing a relative path
            string path = null;

            Object pathObject = element.getAttribute(attributeName, HTMLAttributeFlags.DoNotEscapePaths);
            if (pathObject != DBNull.Value)
            {
                path = (string)pathObject;
            }

            // If a valid path was discovered, add it to the list
            if (path != null)
            {
                ResourceUrlInfo info = new ResourceUrlInfo();
                info.ResourceUrl = path;
                info.ResourceType = element.tagName;
                info.InnerText = element.innerText;
                resources.Add(info);
            }
        }
        // Depth is here because of an IE bug-
        /*
            index.htm
            <style>
                @import(url1.css)
            </style>

            url1.css
            @import(url2.css)

            url2.css
            @import(url3.css)

        Enumerating the import statement in url2.css will cause an out of memory exception
        and destabilize / crash IE.  The depth restriction causes us to skip imports that
        are at that depth or deeper.
        */
        private static void AddSheetReferencesToList(ArrayList list, IHTMLStyleSheet styleSheet, string baseUrl, int depth)
        {
            try
            {

                if (styleSheet.href != null)
                    baseUrl = UrlHelper.EscapeRelativeURL(baseUrl, styleSheet.href);

                // handle style sheet imports
                if (styleSheet.imports.length > 0 && depth < 2)
                {
                    IEnumerator importEnum = styleSheet.imports.GetEnumerator();
                    while (importEnum.MoveNext())
                    {
                        // Add this style sheet to the reference list
                        IHTMLStyleSheet importSheet = (IHTMLStyleSheet)importEnum.Current;
                        string sheetPath = importSheet.href;
                        if (baseUrl != "about:blank" && !UrlHelper.IsUrl(importSheet.href))
                            sheetPath = UrlHelper.EscapeRelativeURL(baseUrl, importSheet.href);

                        ResourceUrlInfo urlInfo = new ResourceUrlInfo();
                        urlInfo.ResourceUrl = importSheet.href;
                        urlInfo.ResourceAbsoluteUrl = sheetPath;
                        urlInfo.ResourceType = HTMLTokens.Style;
                        list.Add(urlInfo);

                        // Add the sheets references to the list
                        AddSheetReferencesToList(list, importSheet, baseUrl, depth + 1);
                    }
                }

                IHTMLStyleSheetRulesCollection rules = (IHTMLStyleSheetRulesCollection)styleSheet.rules;
                for (int i = 0; i < rules.length; i++)
                {
                    IHTMLStyleSheetRule rule = (IHTMLStyleSheetRule)rules.item(i);
                    IHTMLRuleStyle styleRule = (IHTMLRuleStyle)rule.style;

                    AddStyleReference(baseUrl, list, styleRule.backgroundImage);
                    AddStyleReference(baseUrl, list, styleRule.background);
                    AddStyleReference(baseUrl, list, styleRule.listStyleImage);
                    AddStyleReference(baseUrl, list, styleRule.listStyle);
                }
            }
            catch (UnauthorizedAccessException)
            {
                // We weren't permitted to access the style sheets, try manual parse
            }
            catch (Exception ex)
            {
                Trace.Fail("An unexpected exception occurred while attempting to enumerate stylesheet references. " + ex.ToString());
                // IE is a total pile, I hate it
            }
        }