2 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef UserContentController_h
27 #define UserContentController_h
29 #include "UserScriptTypes.h"
30 #include "UserStyleSheetTypes.h"
31 #include <wtf/HashSet.h>
32 #include <wtf/RefCounted.h>
33 #include <wtf/RefPtr.h>
35 #if ENABLE(USER_MESSAGE_HANDLERS)
36 #include "UserMessageHandlerDescriptorTypes.h"
41 class DOMWrapperWorld;
44 class ResourceRequest;
45 class StyleSheetContents;
49 class UserMessageHandlerDescriptor;
51 enum class ResourceType : uint16_t;
53 struct ResourceLoadInfo;
55 namespace ContentExtensions {
56 class CompiledContentExtension;
57 class ContentExtensionsBackend;
61 class UserContentController : public RefCounted<UserContentController> {
63 WEBCORE_EXPORT static RefPtr<UserContentController> create();
64 WEBCORE_EXPORT ~UserContentController();
67 void removePage(Page&);
69 const UserScriptMap* userScripts() const { return m_userScripts.get(); }
71 WEBCORE_EXPORT void addUserScript(DOMWrapperWorld&, std::unique_ptr<UserScript>);
72 WEBCORE_EXPORT void removeUserScript(DOMWrapperWorld&, const URL&);
73 WEBCORE_EXPORT void removeUserScripts(DOMWrapperWorld&);
75 const UserStyleSheetMap* userStyleSheets() const { return m_userStyleSheets.get(); }
77 WEBCORE_EXPORT void addUserStyleSheet(DOMWrapperWorld&, std::unique_ptr<UserStyleSheet>, UserStyleInjectionTime);
78 WEBCORE_EXPORT void removeUserStyleSheet(DOMWrapperWorld&, const URL&);
79 WEBCORE_EXPORT void removeUserStyleSheets(DOMWrapperWorld&);
81 WEBCORE_EXPORT void removeAllUserContent();
83 #if ENABLE(USER_MESSAGE_HANDLERS)
84 const UserMessageHandlerDescriptorMap* userMessageHandlerDescriptors() const { return m_userMessageHandlerDescriptors.get(); }
86 WEBCORE_EXPORT void addUserMessageHandlerDescriptor(UserMessageHandlerDescriptor&);
87 WEBCORE_EXPORT void removeUserMessageHandlerDescriptor(UserMessageHandlerDescriptor&);
90 #if ENABLE(CONTENT_EXTENSIONS)
91 WEBCORE_EXPORT void addUserContentExtension(const String& name, RefPtr<ContentExtensions::CompiledContentExtension>);
92 WEBCORE_EXPORT void removeUserContentExtension(const String& name);
93 WEBCORE_EXPORT void removeAllUserContentExtensions();
95 void processContentExtensionRulesForLoad(ResourceRequest&, ResourceType, DocumentLoader& initiatingDocumentLoader);
96 Vector<ContentExtensions::Action> actionsForResourceLoad(const ResourceLoadInfo&);
100 UserContentController();
102 void invalidateInjectedStyleSheetCacheInAllFrames();
104 HashSet<Page*> m_pages;
106 std::unique_ptr<UserScriptMap> m_userScripts;
107 std::unique_ptr<UserStyleSheetMap> m_userStyleSheets;
108 #if ENABLE(USER_MESSAGE_HANDLERS)
109 std::unique_ptr<UserMessageHandlerDescriptorMap> m_userMessageHandlerDescriptors;
111 #if ENABLE(CONTENT_EXTENSIONS)
112 std::unique_ptr<ContentExtensions::ContentExtensionsBackend> m_contentExtensionBackend;
116 } // namespace WebCore
118 #endif // UserContentController_h