| 1 | /* |
| 2 | * Copyright (C) 2016 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 | #include <functional> |
| 29 | #include <wtf/Forward.h> |
| 30 | #include <wtf/Function.h> |
| 31 | #include <wtf/HashSet.h> |
| 32 | #include <wtf/RefCounted.h> |
| 33 | |
| 34 | #if ENABLE(CONTENT_EXTENSIONS) |
| 35 | #include "ContentExtensionActions.h" |
| 36 | #include "ContentExtensionsBackend.h" |
| 37 | #endif |
| 38 | |
| 39 | namespace WebCore { |
| 40 | |
| 41 | class DOMWrapperWorld; |
| 42 | class DocumentLoader; |
| 43 | class Page; |
| 44 | class ResourceRequest; |
| 45 | class UserMessageHandlerDescriptor; |
| 46 | class UserScript; |
| 47 | class UserStyleSheet; |
| 48 | |
| 49 | #if ENABLE(CONTENT_EXTENSIONS) |
| 50 | namespace ContentExtensions { |
| 51 | class ContentExtensionsBackend; |
| 52 | enum class ResourceType : uint16_t; |
| 53 | struct ResourceLoadInfo; |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | class UserContentProvider; |
| 58 | |
| 59 | class UserContentProviderInvalidationClient { |
| 60 | public: |
| 61 | virtual ~UserContentProviderInvalidationClient() |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | virtual void didInvalidate(UserContentProvider&) = 0; |
| 66 | }; |
| 67 | |
| 68 | class UserContentProvider : public RefCounted<UserContentProvider> { |
| 69 | public: |
| 70 | WEBCORE_EXPORT UserContentProvider(); |
| 71 | WEBCORE_EXPORT virtual ~UserContentProvider(); |
| 72 | |
| 73 | virtual void forEachUserScript(Function<void(DOMWrapperWorld&, const UserScript&)>&&) const = 0; |
| 74 | virtual void forEachUserStyleSheet(Function<void(const UserStyleSheet&)>&&) const = 0; |
| 75 | #if ENABLE(USER_MESSAGE_HANDLERS) |
| 76 | virtual void forEachUserMessageHandler(Function<void(const UserMessageHandlerDescriptor&)>&&) const = 0; |
| 77 | #endif |
| 78 | #if ENABLE(CONTENT_EXTENSIONS) |
| 79 | virtual ContentExtensions::ContentExtensionsBackend& userContentExtensionBackend() = 0; |
| 80 | #endif |
| 81 | |
| 82 | void registerForUserMessageHandlerInvalidation(UserContentProviderInvalidationClient&); |
| 83 | void unregisterForUserMessageHandlerInvalidation(UserContentProviderInvalidationClient&); |
| 84 | |
| 85 | void addPage(Page&); |
| 86 | void removePage(Page&); |
| 87 | |
| 88 | #if ENABLE(CONTENT_EXTENSIONS) |
| 89 | // FIXME: These don't really belong here. They should probably bundled up in the ContentExtensionsBackend |
| 90 | // which should always exist. |
| 91 | ContentRuleListResults processContentRuleListsForLoad(const URL&, OptionSet<ContentExtensions::ResourceType>, DocumentLoader& initiatingDocumentLoader); |
| 92 | Vector<ContentExtensions::ActionsFromContentRuleList> actionsForResourceLoad(const ContentExtensions::ResourceLoadInfo&, DocumentLoader& initiatingDocumentLoader); |
| 93 | WEBCORE_EXPORT void forEachContentExtension(const Function<void(const String&, ContentExtensions::ContentExtension&)>&, DocumentLoader& initiatingDocumentLoader); |
| 94 | #endif |
| 95 | |
| 96 | protected: |
| 97 | WEBCORE_EXPORT void invalidateAllRegisteredUserMessageHandlerInvalidationClients(); |
| 98 | WEBCORE_EXPORT void invalidateInjectedStyleSheetCacheInAllFramesInAllPages(); |
| 99 | |
| 100 | private: |
| 101 | HashSet<Page*> m_pages; |
| 102 | HashSet<UserContentProviderInvalidationClient*> m_userMessageHandlerInvalidationClients; |
| 103 | }; |
| 104 | |
| 105 | } // namespace WebCore |
| 106 | |