| 1 | /* |
| 2 | * Copyright (C) 2014, 2015 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #if ENABLE(CONTENT_EXTENSIONS) |
| 29 | |
| 30 | #include "ContentExtension.h" |
| 31 | #include "ContentExtensionRule.h" |
| 32 | #include <wtf/HashMap.h> |
| 33 | #include <wtf/text/StringHash.h> |
| 34 | #include <wtf/text/WTFString.h> |
| 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | class DocumentLoader; |
| 39 | class ResourceRequest; |
| 40 | |
| 41 | namespace ContentExtensions { |
| 42 | |
| 43 | class CompiledContentExtension; |
| 44 | struct ResourceLoadInfo; |
| 45 | |
| 46 | // The ContentExtensionsBackend is the internal model of all the content extensions. |
| 47 | // |
| 48 | // It provides two services: |
| 49 | // 1) It stores the rules for each content extension. |
| 50 | // 2) It provides APIs for the WebCore interfaces to use those rules efficiently. |
| 51 | class ContentExtensionsBackend { |
| 52 | public: |
| 53 | // - Rule management interface. This can be used by upper layer. |
| 54 | |
| 55 | // Set a list of rules for a given name. If there were existing rules for the name, they are overridden. |
| 56 | // The identifier cannot be empty. |
| 57 | WEBCORE_EXPORT void addContentExtension(const String& identifier, Ref<CompiledContentExtension>, ContentExtension::ShouldCompileCSS = ContentExtension::ShouldCompileCSS::Yes); |
| 58 | WEBCORE_EXPORT void removeContentExtension(const String& identifier); |
| 59 | WEBCORE_EXPORT void removeAllContentExtensions(); |
| 60 | |
| 61 | // - Internal WebCore Interface. |
| 62 | WEBCORE_EXPORT Vector<ActionsFromContentRuleList> actionsForResourceLoad(const ResourceLoadInfo&) const; |
| 63 | WEBCORE_EXPORT StyleSheetContents* globalDisplayNoneStyleSheet(const String& identifier) const; |
| 64 | |
| 65 | ContentRuleListResults processContentRuleListsForLoad(const URL&, OptionSet<ResourceType>, DocumentLoader& initiatingDocumentLoader); |
| 66 | WEBCORE_EXPORT ContentRuleListResults processContentRuleListsForPingLoad(const URL&, const URL& mainDocumentURL); |
| 67 | |
| 68 | static const String& displayNoneCSSRule(); |
| 69 | |
| 70 | void forEach(const Function<void(const String&, ContentExtension&)>&); |
| 71 | |
| 72 | private: |
| 73 | HashMap<String, Ref<ContentExtension>> m_contentExtensions; |
| 74 | }; |
| 75 | |
| 76 | } // namespace ContentExtensions |
| 77 | } // namespace WebCore |
| 78 | |
| 79 | #endif // ENABLE(CONTENT_EXTENSIONS) |
| 80 | |