1/* 2 * Copyright (C) 2010 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#ifndef InjectedBundle_h 27#define InjectedBundle_h 28 29#include "APIObject.h" 30#include "InjectedBundleClient.h" 31#include "SandboxExtension.h" 32#include "WKBundle.h" 33#include <WebCore/UserContentTypes.h> 34#include <WebCore/UserScriptTypes.h> 35#include <wtf/PassRefPtr.h> 36#include <wtf/RetainPtr.h> 37#include <wtf/text/WTFString.h> 38 39#if PLATFORM(GTK) 40typedef struct _GModule GModule; 41#endif 42 43#if PLATFORM(EFL) 44#include <Eina.h> 45#endif 46 47#if USE(FOUNDATION) 48OBJC_CLASS NSBundle; 49OBJC_CLASS NSMutableDictionary; 50OBJC_CLASS WKWebProcessBundleParameters; 51#endif 52 53namespace API { 54class Array; 55class Data; 56} 57 58namespace IPC { 59class ArgumentDecoder; 60class Connection; 61class DataReference; 62} 63 64namespace WebKit { 65 66#if USE(FOUNDATION) 67typedef NSBundle *PlatformBundle; 68#elif PLATFORM(GTK) 69typedef ::GModule* PlatformBundle; 70#elif PLATFORM(EFL) 71typedef Eina_Module* PlatformBundle; 72#endif 73 74class InjectedBundleScriptWorld; 75class WebCertificateInfo; 76class WebConnection; 77class WebFrame; 78class WebPage; 79class WebPageGroupProxy; 80struct WebProcessCreationParameters; 81 82class InjectedBundle : public API::ObjectImpl<API::Object::Type::Bundle> { 83public: 84 static PassRefPtr<InjectedBundle> create(const WebProcessCreationParameters&, API::Object* initializationUserData); 85 86 ~InjectedBundle(); 87 88 bool initialize(const WebProcessCreationParameters&, API::Object* initializationUserData); 89 90 void setBundleParameter(const String& key, const IPC::DataReference&); 91 92 // API 93 void initializeClient(const WKBundleClientBase*); 94 void postMessage(const String&, API::Object*); 95 void postSynchronousMessage(const String&, API::Object*, RefPtr<API::Object>& returnData); 96 97 WebConnection* webConnectionToUIProcess() const; 98 99 // TestRunner only SPI 100 void setAlwaysAcceptCookies(bool); 101 void removeAllVisitedLinks(); 102 void setCacheModel(uint32_t); 103 void overrideBoolPreferenceForTestRunner(WebPageGroupProxy*, const String& preference, bool enabled); 104 void overrideXSSAuditorEnabledForTestRunner(WebPageGroupProxy* pageGroup, bool enabled); 105 void setAllowUniversalAccessFromFileURLs(WebPageGroupProxy*, bool); 106 void setAllowFileAccessFromFileURLs(WebPageGroupProxy*, bool); 107 void setMinimumLogicalFontSize(WebPageGroupProxy*, int size); 108 void setFrameFlatteningEnabled(WebPageGroupProxy*, bool); 109 void setPluginsEnabled(WebPageGroupProxy*, bool); 110 void setJavaScriptCanAccessClipboard(WebPageGroupProxy*, bool); 111 void setPrivateBrowsingEnabled(WebPageGroupProxy*, bool); 112 void setPopupBlockingEnabled(WebPageGroupProxy*, bool); 113 void setAuthorAndUserStylesEnabled(WebPageGroupProxy*, bool); 114 void setSpatialNavigationEnabled(WebPageGroupProxy*, bool); 115 void addOriginAccessWhitelistEntry(const String&, const String&, const String&, bool); 116 void removeOriginAccessWhitelistEntry(const String&, const String&, const String&, bool); 117 void resetOriginAccessWhitelists(); 118 void setAsynchronousSpellCheckingEnabled(WebPageGroupProxy*, bool); 119 int numberOfPages(WebFrame*, double, double); 120 int pageNumberForElementById(WebFrame*, const String&, double, double); 121 String pageSizeAndMarginsInPixels(WebFrame*, int, int, int, int, int, int, int); 122 bool isPageBoxVisible(WebFrame*, int); 123 void setUserStyleSheetLocation(WebPageGroupProxy*, const String&); 124 void setWebNotificationPermission(WebPage*, const String& originString, bool allowed); 125 void removeAllWebNotificationPermissions(WebPage*); 126 uint64_t webNotificationID(JSContextRef, JSValueRef); 127 PassRefPtr<API::Data> createWebDataFromUint8Array(JSContextRef, JSValueRef); 128 129 // UserContent API 130 void addUserScript(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& source, const 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 // Local storage API 139 void clearAllDatabases(); 140 void setDatabaseQuota(uint64_t); 141 142 // Application Cache API 143 void clearApplicationCache(); 144 void clearApplicationCacheForOrigin(const String& origin); 145 void setAppCacheMaximumSize(uint64_t); 146 uint64_t appCacheUsageForOrigin(const String& origin); 147 void setApplicationCacheOriginQuota(const String& origin, uint64_t); 148 void resetApplicationCacheOriginQuota(const String& origin); 149 PassRefPtr<API::Array> originsWithApplicationCache(); 150 151 // Garbage collection API 152 void garbageCollectJavaScriptObjects(); 153 void garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(bool waitUntilDone); 154 size_t javaScriptObjectsCount(); 155 156 // Callback hooks 157 void didCreatePage(WebPage*); 158 void willDestroyPage(WebPage*); 159 void didInitializePageGroup(WebPageGroupProxy*); 160 void didReceiveMessage(const String&, API::Object*); 161 void didReceiveMessageToPage(WebPage*, const String&, API::Object*); 162 163 static void reportException(JSContextRef, JSValueRef exception); 164 165 static bool isProcessingUserGesture(); 166 167 void setTabKeyCyclesThroughElements(WebPage*, bool enabled); 168 void setSerialLoadingEnabled(bool); 169 void setCSSRegionsEnabled(bool); 170 void setCSSCompositingEnabled(bool); 171 void dispatchPendingLoadRequests(); 172 173#if PLATFORM(COCOA) && WK_API_ENABLED 174 WKWebProcessBundleParameters *bundleParameters(); 175#endif 176 177private: 178 explicit InjectedBundle(const WebProcessCreationParameters&); 179 180 String m_path; 181 PlatformBundle m_platformBundle; // This is leaked right now, since we never unload the bundle/module. 182 183 RefPtr<SandboxExtension> m_sandboxExtension; 184 185 InjectedBundleClient m_client; 186 187#if PLATFORM(COCOA) && WK_API_ENABLED 188 RetainPtr<WKWebProcessBundleParameters> m_bundleParameters; 189#endif 190}; 191 192} // namespace WebKit 193 194#endif // InjectedBundle_h 195