| 1 | /* | 
| 2 |  * Copyright (C) 2010-2018 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 "APIInjectedBundleBundleClient.h" | 
| 29 | #include "APIObject.h" | 
| 30 | #include "SandboxExtension.h" | 
| 31 | #include <JavaScriptCore/JavaScript.h> | 
| 32 | #include <WebCore/UserContentTypes.h> | 
| 33 | #include <WebCore/UserScriptTypes.h> | 
| 34 | #include <wtf/RefPtr.h> | 
| 35 | #include <wtf/RetainPtr.h> | 
| 36 | #include <wtf/text/WTFString.h> | 
| 37 |  | 
| 38 | #if USE(GLIB) | 
| 39 | typedef struct _GModule GModule; | 
| 40 | #endif | 
| 41 |  | 
| 42 | #if USE(FOUNDATION) | 
| 43 | OBJC_CLASS NSSet; | 
| 44 | OBJC_CLASS NSBundle; | 
| 45 | OBJC_CLASS NSMutableDictionary; | 
| 46 | OBJC_CLASS WKWebProcessBundleParameters; | 
| 47 | #endif | 
| 48 |  | 
| 49 | namespace API { | 
| 50 | class Array; | 
| 51 | class Data; | 
| 52 | } | 
| 53 |  | 
| 54 | namespace IPC { | 
| 55 | class Decoder; | 
| 56 | class Connection; | 
| 57 | class DataReference; | 
| 58 | } | 
| 59 |  | 
| 60 | namespace WebKit { | 
| 61 |  | 
| 62 | #if USE(FOUNDATION) | 
| 63 | typedef NSBundle *PlatformBundle; | 
| 64 | #elif USE(GLIB) | 
| 65 | typedef ::GModule* PlatformBundle; | 
| 66 | #else | 
| 67 | typedef void* PlatformBundle; | 
| 68 | #endif | 
| 69 |  | 
| 70 | class InjectedBundleScriptWorld; | 
| 71 | class WebCertificateInfo; | 
| 72 | class WebConnection; | 
| 73 | class WebFrame; | 
| 74 | class WebPage; | 
| 75 | class WebPageGroupProxy; | 
| 76 | struct WebProcessCreationParameters; | 
| 77 |  | 
| 78 | class InjectedBundle : public API::ObjectImpl<API::Object::Type::Bundle> { | 
| 79 | public: | 
| 80 |     static RefPtr<InjectedBundle> create(WebProcessCreationParameters&, API::Object* initializationUserData); | 
| 81 |  | 
| 82 |     ~InjectedBundle(); | 
| 83 |  | 
| 84 |     bool initialize(const WebProcessCreationParameters&, API::Object* initializationUserData); | 
| 85 |  | 
| 86 |     void setBundleParameter(const String&, const IPC::DataReference&); | 
| 87 |     void setBundleParameters(const IPC::DataReference&); | 
| 88 |  | 
| 89 |     // API | 
| 90 |     void setClient(std::unique_ptr<API::InjectedBundle::Client>&&); | 
| 91 |     void postMessage(const String&, API::Object*); | 
| 92 |     void postSynchronousMessage(const String&, API::Object*, RefPtr<API::Object>& returnData); | 
| 93 |     void setServiceWorkerProxyCreationCallback(void (*)(uint64_t)); | 
| 94 |  | 
| 95 |     WebConnection* webConnectionToUIProcess() const; | 
| 96 |  | 
| 97 |     // TestRunner only SPI | 
| 98 |     void overrideBoolPreferenceForTestRunner(WebPageGroupProxy*, const String& preference, bool enabled); | 
| 99 |     void setAllowUniversalAccessFromFileURLs(WebPageGroupProxy*, bool); | 
| 100 |     void setAllowFileAccessFromFileURLs(WebPageGroupProxy*, bool); | 
| 101 |     void setNeedsStorageAccessFromFileURLsQuirk(WebPageGroupProxy*, bool); | 
| 102 |     void setMinimumLogicalFontSize(WebPageGroupProxy*, int size); | 
| 103 |     void setFrameFlatteningEnabled(WebPageGroupProxy*, bool); | 
| 104 |     void setAsyncFrameScrollingEnabled(WebPageGroupProxy*, bool); | 
| 105 |     void setPluginsEnabled(WebPageGroupProxy*, bool); | 
| 106 |     void setJavaScriptCanAccessClipboard(WebPageGroupProxy*, bool); | 
| 107 |     void setPrivateBrowsingEnabled(WebPageGroupProxy*, bool); | 
| 108 |     void setUseDashboardCompatibilityMode(WebPageGroupProxy*, bool); | 
| 109 |     void (WebPageGroupProxy*, bool); | 
| 110 |     void setAuthorAndUserStylesEnabled(WebPageGroupProxy*, bool); | 
| 111 |     void setSpatialNavigationEnabled(WebPageGroupProxy*, bool); | 
| 112 |     void addOriginAccessWhitelistEntry(const String&, const String&, const String&, bool); | 
| 113 |     void removeOriginAccessWhitelistEntry(const String&, const String&, const String&, bool); | 
| 114 |     void resetOriginAccessWhitelists(); | 
| 115 |     void setAsynchronousSpellCheckingEnabled(WebPageGroupProxy*, bool); | 
| 116 |     int numberOfPages(WebFrame*, double, double); | 
| 117 |     int pageNumberForElementById(WebFrame*, const String&, double, double); | 
| 118 |     String pageSizeAndMarginsInPixels(WebFrame*, int, int, int, int, int, int, int); | 
| 119 |     bool isPageBoxVisible(WebFrame*, int); | 
| 120 |     void setUserStyleSheetLocation(WebPageGroupProxy*, const String&); | 
| 121 |     void setWebNotificationPermission(WebPage*, const String& originString, bool allowed); | 
| 122 |     void removeAllWebNotificationPermissions(WebPage*); | 
| 123 |     uint64_t webNotificationID(JSContextRef, JSValueRef); | 
| 124 |     Ref<API::Data> createWebDataFromUint8Array(JSContextRef, JSValueRef); | 
| 125 |      | 
| 126 |     typedef HashMap<uint64_t, String> DocumentIDToURLMap; | 
| 127 |     DocumentIDToURLMap liveDocumentURLs(WebPageGroupProxy*, bool excludeDocumentsInPageGroupPages); | 
| 128 |  | 
| 129 |     // UserContent API | 
| 130 |     void addUserScript(WebPageGroupProxy*, InjectedBundleScriptWorld*, String&& source, String&& url, API::Array* whitelist, API::Array* blacklist, WebCore::UserScriptInjectionTime, WebCore::UserContentInjectedFrames); | 
| 131 |     void addUserStyleSheet(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& source, const String& url, API::Array* whitelist, API::Array* blacklist, WebCore::UserContentInjectedFrames); | 
| 132 |     void removeUserScript(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& url); | 
| 133 |     void removeUserStyleSheet(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& url); | 
| 134 |     void removeUserScripts(WebPageGroupProxy*, InjectedBundleScriptWorld*); | 
| 135 |     void removeUserStyleSheets(WebPageGroupProxy*, InjectedBundleScriptWorld*); | 
| 136 |     void removeAllUserContent(WebPageGroupProxy*); | 
| 137 |  | 
| 138 |     // Garbage collection API | 
| 139 |     void garbageCollectJavaScriptObjects(); | 
| 140 |     void garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(bool waitUntilDone); | 
| 141 |     size_t javaScriptObjectsCount(); | 
| 142 |  | 
| 143 |     // Callback hooks | 
| 144 |     void didCreatePage(WebPage*); | 
| 145 |     void willDestroyPage(WebPage*); | 
| 146 |     void didInitializePageGroup(WebPageGroupProxy*); | 
| 147 |     void didReceiveMessage(const String&, API::Object*); | 
| 148 |     void didReceiveMessageToPage(WebPage*, const String&, API::Object*); | 
| 149 |  | 
| 150 |     static void reportException(JSContextRef, JSValueRef exception); | 
| 151 |  | 
| 152 |     static bool isProcessingUserGesture(); | 
| 153 |  | 
| 154 |     void setTabKeyCyclesThroughElements(WebPage*, bool enabled); | 
| 155 |     void setSerialLoadingEnabled(bool); | 
| 156 |     void setWebAnimationsEnabled(bool); | 
| 157 |     void setWebAnimationsCSSIntegrationEnabled(bool); | 
| 158 |     void dispatchPendingLoadRequests(); | 
| 159 |  | 
| 160 | #if PLATFORM(COCOA) | 
| 161 |     WKWebProcessBundleParameters *bundleParameters(); | 
| 162 |  | 
| 163 |     void extendClassesForParameterCoder(API::Array& classes); | 
| 164 |     NSSet* classesForCoder(); | 
| 165 | #endif | 
| 166 |  | 
| 167 | private: | 
| 168 |     explicit InjectedBundle(const WebProcessCreationParameters&); | 
| 169 |  | 
| 170 |     String m_path; | 
| 171 |     PlatformBundle m_platformBundle; // This is leaked right now, since we never unload the bundle/module. | 
| 172 |  | 
| 173 |     RefPtr<SandboxExtension> m_sandboxExtension; | 
| 174 |  | 
| 175 |     std::unique_ptr<API::InjectedBundle::Client> m_client; | 
| 176 |  | 
| 177 | #if PLATFORM(COCOA) | 
| 178 |     RetainPtr<WKWebProcessBundleParameters> m_bundleParameters; | 
| 179 |     RetainPtr<NSSet> m_classesForCoder; | 
| 180 | #endif | 
| 181 | }; | 
| 182 |  | 
| 183 | } // namespace WebKit | 
| 184 |  | 
| 185 |  |