| 1 | /* |
| 2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 | * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 | * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 | * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 6 | * Copyright (C) 2004-2010, 2012-2013, 2015 Apple Inc. All rights reserved. |
| 7 | * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
| 8 | * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 9 | * Copyright (C) 2011 Google Inc. All rights reserved. |
| 10 | * |
| 11 | * This library is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU Library General Public |
| 13 | * License as published by the Free Software Foundation; either |
| 14 | * version 2 of the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This library is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * Library General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU Library General Public License |
| 22 | * along with this library; see the file COPYING.LIB. If not, write to |
| 23 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 24 | * Boston, MA 02110-1301, USA. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #pragma once |
| 29 | |
| 30 | #include <memory> |
| 31 | #include <wtf/FastMalloc.h> |
| 32 | #include <wtf/HashMap.h> |
| 33 | #include <wtf/RefPtr.h> |
| 34 | #include <wtf/Vector.h> |
| 35 | #include <wtf/text/WTFString.h> |
| 36 | |
| 37 | #if ENABLE(CONTENT_EXTENSIONS) |
| 38 | #include "ContentExtensionStyleSheet.h" |
| 39 | #endif |
| 40 | |
| 41 | namespace WebCore { |
| 42 | |
| 43 | class CSSStyleSheet; |
| 44 | class Document; |
| 45 | class Node; |
| 46 | class StyleSheet; |
| 47 | class StyleSheetContents; |
| 48 | class StyleSheetList; |
| 49 | |
| 50 | class ExtensionStyleSheets { |
| 51 | WTF_MAKE_FAST_ALLOCATED; |
| 52 | public: |
| 53 | explicit ExtensionStyleSheets(Document&); |
| 54 | |
| 55 | CSSStyleSheet* pageUserSheet(); |
| 56 | const Vector<RefPtr<CSSStyleSheet>>& documentUserStyleSheets() const { return m_userStyleSheets; } |
| 57 | const Vector<RefPtr<CSSStyleSheet>>& injectedUserStyleSheets() const; |
| 58 | const Vector<RefPtr<CSSStyleSheet>>& injectedAuthorStyleSheets() const; |
| 59 | const Vector<RefPtr<CSSStyleSheet>>& authorStyleSheetsForTesting() const { return m_authorStyleSheetsForTesting; } |
| 60 | |
| 61 | void clearPageUserSheet(); |
| 62 | void updatePageUserSheet(); |
| 63 | void invalidateInjectedStyleSheetCache(); |
| 64 | void updateInjectedStyleSheetCache() const; |
| 65 | |
| 66 | WEBCORE_EXPORT void addUserStyleSheet(Ref<StyleSheetContents>&&); |
| 67 | |
| 68 | WEBCORE_EXPORT void addAuthorStyleSheetForTesting(Ref<StyleSheetContents>&&); |
| 69 | |
| 70 | #if ENABLE(CONTENT_EXTENSIONS) |
| 71 | void addDisplayNoneSelector(const String& identifier, const String& selector, uint32_t selectorID); |
| 72 | void maybeAddContentExtensionSheet(const String& identifier, StyleSheetContents&); |
| 73 | #endif |
| 74 | |
| 75 | void detachFromDocument(); |
| 76 | |
| 77 | private: |
| 78 | Document& m_document; |
| 79 | |
| 80 | RefPtr<CSSStyleSheet> m_pageUserSheet; |
| 81 | |
| 82 | mutable Vector<RefPtr<CSSStyleSheet>> m_injectedUserStyleSheets; |
| 83 | mutable Vector<RefPtr<CSSStyleSheet>> m_injectedAuthorStyleSheets; |
| 84 | mutable bool m_injectedStyleSheetCacheValid { false }; |
| 85 | |
| 86 | Vector<RefPtr<CSSStyleSheet>> m_userStyleSheets; |
| 87 | Vector<RefPtr<CSSStyleSheet>> m_authorStyleSheetsForTesting; |
| 88 | |
| 89 | #if ENABLE(CONTENT_EXTENSIONS) |
| 90 | HashMap<String, RefPtr<CSSStyleSheet>> m_contentExtensionSheets; |
| 91 | HashMap<String, RefPtr<ContentExtensions::ContentExtensionStyleSheet>> m_contentExtensionSelectorSheets; |
| 92 | #endif |
| 93 | }; |
| 94 | |
| 95 | } // namespace WebCore |
| 96 | |