InjectedBundle.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. #ifndef InjectedBundle_h
  26. #define InjectedBundle_h
  27. #include "APIObject.h"
  28. #include "InjectedBundleClient.h"
  29. #include "SandboxExtension.h"
  30. #include "WKBundle.h"
  31. #include <WebCore/UserContentTypes.h>
  32. #include <WebCore/UserScriptTypes.h>
  33. #include <wtf/PassRefPtr.h>
  34. #include <wtf/text/WTFString.h>
  35. #if PLATFORM(QT)
  36. #include <QLibrary>
  37. #endif
  38. #if PLATFORM(GTK)
  39. typedef struct _GModule GModule;
  40. #endif
  41. #if PLATFORM(EFL)
  42. #include <Eina.h>
  43. #endif
  44. #if PLATFORM(MAC)
  45. OBJC_CLASS NSBundle;
  46. #endif
  47. #if PLATFORM(MANX)
  48. #include "WKBundleManx.h"
  49. #include <manx/Bundle.h>
  50. #endif
  51. namespace CoreIPC {
  52. class ArgumentDecoder;
  53. class Connection;
  54. }
  55. namespace WebKit {
  56. #if PLATFORM(MAC)
  57. typedef NSBundle *PlatformBundle;
  58. #elif PLATFORM(QT)
  59. typedef QLibrary PlatformBundle;
  60. #elif PLATFORM(GTK)
  61. typedef ::GModule* PlatformBundle;
  62. #elif PLATFORM(MANX)
  63. typedef Manx::Bundle* PlatformBundle;
  64. #elif PLATFORM(EFL)
  65. typedef Eina_Module* PlatformBundle;
  66. #endif
  67. class ImmutableArray;
  68. class InjectedBundleScriptWorld;
  69. class WebCertificateInfo;
  70. class WebConnection;
  71. class WebData;
  72. class WebFrame;
  73. class WebPage;
  74. class WebPageGroupProxy;
  75. class InjectedBundle : public TypedAPIObject<APIObject::TypeBundle> {
  76. public:
  77. static PassRefPtr<InjectedBundle> create(const String& path)
  78. {
  79. return adoptRef(new InjectedBundle(path));
  80. }
  81. ~InjectedBundle();
  82. bool load(APIObject* initializationUserData);
  83. void setSandboxExtension(PassRefPtr<SandboxExtension> sandboxExtension) { m_sandboxExtension = sandboxExtension; }
  84. // API
  85. void initializeClient(WKBundleClient*);
  86. void postMessage(const String&, APIObject*);
  87. void postSynchronousMessage(const String&, APIObject*, RefPtr<APIObject>& returnData);
  88. #if PLATFORM(MANX)
  89. void initializeGCClient(WKBundleGarbageCollectClient*);
  90. void getFastMallocStatistics(size_t* usedBytes, size_t* reservedBytes);
  91. void javaScriptHeapStatistics(size_t* usedBytes, size_t* reservedBytes);
  92. void shutdownProcess();
  93. #endif
  94. WebConnection* webConnectionToUIProcess() const;
  95. // TestRunner only SPI
  96. void setShouldTrackVisitedLinks(bool);
  97. void setAlwaysAcceptCookies(bool);
  98. void removeAllVisitedLinks();
  99. void setCacheModel(uint32_t);
  100. void activateMacFontAscentHack();
  101. void overrideBoolPreferenceForTestRunner(WebPageGroupProxy*, const String& preference, bool enabled);
  102. void overrideXSSAuditorEnabledForTestRunner(WebPageGroupProxy* pageGroup, bool enabled);
  103. void setAllowUniversalAccessFromFileURLs(WebPageGroupProxy*, bool);
  104. void setAllowFileAccessFromFileURLs(WebPageGroupProxy*, bool);
  105. void setMinimumLogicalFontSize(WebPageGroupProxy*, int size);
  106. void setFrameFlatteningEnabled(WebPageGroupProxy*, bool);
  107. void setPluginsEnabled(WebPageGroupProxy*, bool);
  108. void setJavaScriptCanAccessClipboard(WebPageGroupProxy*, bool);
  109. void setPrivateBrowsingEnabled(WebPageGroupProxy*, bool);
  110. void setPopupBlockingEnabled(WebPageGroupProxy*, bool);
  111. void switchNetworkLoaderToNewTestingSession();
  112. void setAuthorAndUserStylesEnabled(WebPageGroupProxy*, bool);
  113. void setSpatialNavigationEnabled(WebPageGroupProxy*, bool);
  114. void addOriginAccessWhitelistEntry(const String&, const String&, const String&, bool);
  115. void removeOriginAccessWhitelistEntry(const String&, const String&, const String&, bool);
  116. void resetOriginAccessWhitelists();
  117. void setAsynchronousSpellCheckingEnabled(WebPageGroupProxy*, bool);
  118. int numberOfPages(WebFrame*, double, double);
  119. int pageNumberForElementById(WebFrame*, const String&, double, double);
  120. String pageSizeAndMarginsInPixels(WebFrame*, int, int, int, int, int, int, int);
  121. bool isPageBoxVisible(WebFrame*, int);
  122. void setUserStyleSheetLocation(WebPageGroupProxy*, const String&);
  123. void setWebNotificationPermission(WebPage*, const String& originString, bool allowed);
  124. void removeAllWebNotificationPermissions(WebPage*);
  125. uint64_t webNotificationID(JSContextRef, JSValueRef);
  126. PassRefPtr<WebData> createWebDataFromUint8Array(JSContextRef, JSValueRef);
  127. // UserContent API
  128. void addUserScript(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserScriptInjectionTime, WebCore::UserContentInjectedFrames);
  129. void addUserStyleSheet(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserContentInjectedFrames);
  130. void removeUserScript(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& url);
  131. void removeUserStyleSheet(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& url);
  132. void removeUserScripts(WebPageGroupProxy*, InjectedBundleScriptWorld*);
  133. void removeUserStyleSheets(WebPageGroupProxy*, InjectedBundleScriptWorld*);
  134. void removeAllUserContent(WebPageGroupProxy*);
  135. // Local storage API
  136. void clearAllDatabases();
  137. void setDatabaseQuota(uint64_t);
  138. // Application Cache API
  139. void clearApplicationCache();
  140. void clearApplicationCacheForOrigin(const String& origin);
  141. void setAppCacheMaximumSize(uint64_t);
  142. uint64_t appCacheUsageForOrigin(const String& origin);
  143. void setApplicationCacheOriginQuota(const String& origin, uint64_t);
  144. void resetApplicationCacheOriginQuota(const String& origin);
  145. PassRefPtr<ImmutableArray> originsWithApplicationCache();
  146. // Garbage collection API
  147. void garbageCollectJavaScriptObjects();
  148. void garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(bool waitUntilDone);
  149. size_t javaScriptObjectsCount();
  150. // Callback hooks
  151. void didCreatePage(WebPage*);
  152. void willDestroyPage(WebPage*);
  153. void didInitializePageGroup(WebPageGroupProxy*);
  154. void didReceiveMessage(const String&, APIObject*);
  155. void didReceiveMessageToPage(WebPage*, const String&, APIObject*);
  156. static void reportException(JSContextRef, JSValueRef exception);
  157. static bool isProcessingUserGesture();
  158. void setTabKeyCyclesThroughElements(WebPage*, bool enabled);
  159. void setSerialLoadingEnabled(bool);
  160. void setShadowDOMEnabled(bool);
  161. void setCSSRegionsEnabled(bool);
  162. void setCSSCompositingEnabled(bool);
  163. void setSeamlessIFramesEnabled(bool);
  164. void dispatchPendingLoadRequests();
  165. private:
  166. explicit InjectedBundle(const String&);
  167. String m_path;
  168. PlatformBundle m_platformBundle; // This is leaked right now, since we never unload the bundle/module.
  169. RefPtr<SandboxExtension> m_sandboxExtension;
  170. InjectedBundleClient m_client;
  171. };
  172. } // namespace WebKit
  173. #endif // InjectedBundle_h