InjectedBundle.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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. #include "config.h"
  26. #include "InjectedBundle.h"
  27. #include "Arguments.h"
  28. #include "ImmutableArray.h"
  29. #include "InjectedBundleScriptWorld.h"
  30. #include "InjectedBundleUserMessageCoders.h"
  31. #include "LayerTreeHost.h"
  32. #include "NotificationPermissionRequestManager.h"
  33. #include "WKAPICast.h"
  34. #include "WKBundleAPICast.h"
  35. #include "WebApplicationCacheManager.h"
  36. #include "WebConnectionToUIProcess.h"
  37. #include "WebContextMessageKinds.h"
  38. #include "WebCookieManager.h"
  39. #include "WebCoreArgumentCoders.h"
  40. #include "WebData.h"
  41. #include "WebDatabaseManager.h"
  42. #include "WebFrame.h"
  43. #include "WebFrameNetworkingContext.h"
  44. #include "WebPage.h"
  45. #include "WebPreferencesStore.h"
  46. #include "WebProcess.h"
  47. #include <JavaScriptCore/APICast.h>
  48. #include <JavaScriptCore/JSLock.h>
  49. #include <WebCore/ApplicationCache.h>
  50. #include <WebCore/ApplicationCacheStorage.h>
  51. #include <WebCore/Frame.h>
  52. #include <WebCore/FrameLoader.h>
  53. #include <WebCore/FrameView.h>
  54. #include <WebCore/GCController.h>
  55. #include <WebCore/GeolocationClient.h>
  56. #include <WebCore/GeolocationController.h>
  57. #include <WebCore/GeolocationPosition.h>
  58. #include <WebCore/JSDOMWindow.h>
  59. #include <WebCore/JSNotification.h>
  60. #include <WebCore/JSUint8Array.h>
  61. #include <WebCore/Page.h>
  62. #include <WebCore/PageGroup.h>
  63. #include <WebCore/PrintContext.h>
  64. #include <WebCore/ResourceHandle.h>
  65. #include <WebCore/ResourceLoadScheduler.h>
  66. #include <WebCore/ScriptController.h>
  67. #include <WebCore/SecurityOrigin.h>
  68. #include <WebCore/SecurityPolicy.h>
  69. #include <WebCore/Settings.h>
  70. #include <WebCore/UserGestureIndicator.h>
  71. #include <wtf/OwnArrayPtr.h>
  72. #include <wtf/PassOwnArrayPtr.h>
  73. #if ENABLE(SHADOW_DOM) || ENABLE(CSS_REGIONS) || ENABLE(IFRAME_SEAMLESS) || ENABLE(CSS_COMPOSITING)
  74. #include <WebCore/RuntimeEnabledFeatures.h>
  75. #endif
  76. #if PLATFORM(MAC)
  77. #include "WebSystemInterface.h"
  78. #endif
  79. #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
  80. #include "WebNotificationManager.h"
  81. #endif
  82. using namespace WebCore;
  83. using namespace JSC;
  84. namespace WebKit {
  85. InjectedBundle::InjectedBundle(const String& path)
  86. : m_path(path)
  87. , m_platformBundle(0)
  88. {
  89. initializeClient(0);
  90. }
  91. InjectedBundle::~InjectedBundle()
  92. {
  93. }
  94. void InjectedBundle::initializeClient(WKBundleClient* client)
  95. {
  96. m_client.initialize(client);
  97. }
  98. void InjectedBundle::postMessage(const String& messageName, APIObject* messageBody)
  99. {
  100. OwnPtr<CoreIPC::MessageEncoder> encoder = CoreIPC::MessageEncoder::create(WebContextLegacyMessages::messageReceiverName(), WebContextLegacyMessages::postMessageMessageName(), 0);
  101. encoder->encode(messageName);
  102. encoder->encode(InjectedBundleUserMessageEncoder(messageBody));
  103. WebProcess::shared().parentProcessConnection()->sendMessage(encoder.release());
  104. }
  105. void InjectedBundle::postSynchronousMessage(const String& messageName, APIObject* messageBody, RefPtr<APIObject>& returnData)
  106. {
  107. InjectedBundleUserMessageDecoder messageDecoder(returnData);
  108. uint64_t syncRequestID;
  109. OwnPtr<CoreIPC::MessageEncoder> encoder = WebProcess::shared().parentProcessConnection()->createSyncMessageEncoder(WebContextLegacyMessages::messageReceiverName(), WebContextLegacyMessages::postSynchronousMessageMessageName(), 0, syncRequestID);
  110. encoder->encode(messageName);
  111. encoder->encode(InjectedBundleUserMessageEncoder(messageBody));
  112. OwnPtr<CoreIPC::MessageDecoder> replyDecoder = WebProcess::shared().parentProcessConnection()->sendSyncMessage(syncRequestID, encoder.release(), CoreIPC::Connection::NoTimeout);
  113. if (!replyDecoder || !replyDecoder->decode(messageDecoder)) {
  114. returnData = nullptr;
  115. return;
  116. }
  117. }
  118. WebConnection* InjectedBundle::webConnectionToUIProcess() const
  119. {
  120. return WebProcess::shared().webConnectionToUIProcess();
  121. }
  122. void InjectedBundle::setShouldTrackVisitedLinks(bool shouldTrackVisitedLinks)
  123. {
  124. WebProcess::shared().setShouldTrackVisitedLinks(shouldTrackVisitedLinks);
  125. }
  126. void InjectedBundle::setAlwaysAcceptCookies(bool accept)
  127. {
  128. WebProcess::shared().supplement<WebCookieManager>()->setHTTPCookieAcceptPolicy(accept ? HTTPCookieAcceptPolicyAlways : HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain);
  129. }
  130. void InjectedBundle::removeAllVisitedLinks()
  131. {
  132. PageGroup::removeAllVisitedLinks();
  133. }
  134. void InjectedBundle::setCacheModel(uint32_t cacheModel)
  135. {
  136. WebProcess::shared().setCacheModel(cacheModel);
  137. }
  138. void InjectedBundle::overrideBoolPreferenceForTestRunner(WebPageGroupProxy* pageGroup, const String& preference, bool enabled)
  139. {
  140. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  141. if (preference == "WebKitTabToLinksPreferenceKey") {
  142. WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::tabsToLinksKey(), enabled);
  143. for (HashSet<Page*>::iterator i = pages.begin(); i != pages.end(); ++i) {
  144. WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient((*i)->mainFrame()->loader()->client());
  145. ASSERT(webFrameLoaderClient);
  146. webFrameLoaderClient->webFrame()->page()->setTabToLinksEnabled(enabled);
  147. }
  148. }
  149. if (preference == "WebKit2AsynchronousPluginInitializationEnabled") {
  150. WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::asynchronousPluginInitializationEnabledKey(), enabled);
  151. for (HashSet<Page*>::iterator i = pages.begin(); i != pages.end(); ++i) {
  152. WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient((*i)->mainFrame()->loader()->client());
  153. ASSERT(webFrameLoaderClient);
  154. webFrameLoaderClient->webFrame()->page()->setAsynchronousPluginInitializationEnabled(enabled);
  155. }
  156. }
  157. if (preference == "WebKit2AsynchronousPluginInitializationEnabledForAllPlugins") {
  158. WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::asynchronousPluginInitializationEnabledForAllPluginsKey(), enabled);
  159. for (HashSet<Page*>::iterator i = pages.begin(); i != pages.end(); ++i) {
  160. WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient((*i)->mainFrame()->loader()->client());
  161. ASSERT(webFrameLoaderClient);
  162. webFrameLoaderClient->webFrame()->page()->setAsynchronousPluginInitializationEnabledForAllPlugins(enabled);
  163. }
  164. }
  165. if (preference == "WebKit2ArtificialPluginInitializationDelayEnabled") {
  166. WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::artificialPluginInitializationDelayEnabledKey(), enabled);
  167. for (HashSet<Page*>::iterator i = pages.begin(); i != pages.end(); ++i) {
  168. WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient((*i)->mainFrame()->loader()->client());
  169. ASSERT(webFrameLoaderClient);
  170. webFrameLoaderClient->webFrame()->page()->setArtificialPluginInitializationDelayEnabled(enabled);
  171. }
  172. }
  173. #if ENABLE(CSS_REGIONS)
  174. if (preference == "WebKitCSSRegionsEnabled")
  175. RuntimeEnabledFeatures::setCSSRegionsEnabled(enabled);
  176. #endif
  177. #if ENABLE(CSS_COMPOSITING)
  178. if (preference == "WebKitCSSCompositingEnabled")
  179. RuntimeEnabledFeatures::setCSSCompositingEnabled(enabled);
  180. #endif
  181. // Map the names used in LayoutTests with the names used in WebCore::Settings and WebPreferencesStore.
  182. #define FOR_EACH_OVERRIDE_BOOL_PREFERENCE(macro) \
  183. macro(WebKitAcceleratedCompositingEnabled, AcceleratedCompositingEnabled, acceleratedCompositingEnabled) \
  184. macro(WebKitCanvasUsesAcceleratedDrawing, CanvasUsesAcceleratedDrawing, canvasUsesAcceleratedDrawing) \
  185. macro(WebKitCSSCustomFilterEnabled, CSSCustomFilterEnabled, cssCustomFilterEnabled) \
  186. macro(WebKitCSSGridLayoutEnabled, CSSGridLayoutEnabled, cssGridLayoutEnabled) \
  187. macro(WebKitFrameFlatteningEnabled, FrameFlatteningEnabled, frameFlatteningEnabled) \
  188. macro(WebKitJavaEnabled, JavaEnabled, javaEnabled) \
  189. macro(WebKitJavaScriptEnabled, ScriptEnabled, javaScriptEnabled) \
  190. macro(WebKitLoadSiteIconsKey, LoadsSiteIconsIgnoringImageLoadingSetting, loadsSiteIconsIgnoringImageLoadingPreference) \
  191. macro(WebKitOfflineWebApplicationCacheEnabled, OfflineWebApplicationCacheEnabled, offlineWebApplicationCacheEnabled) \
  192. macro(WebKitPageCacheSupportsPluginsPreferenceKey, PageCacheSupportsPlugins, pageCacheSupportsPlugins) \
  193. macro(WebKitPluginsEnabled, PluginsEnabled, pluginsEnabled) \
  194. macro(WebKitUsesPageCachePreferenceKey, UsesPageCache, usesPageCache) \
  195. macro(WebKitWebAudioEnabled, WebAudioEnabled, webAudioEnabled) \
  196. macro(WebKitWebGLEnabled, WebGLEnabled, webGLEnabled) \
  197. macro(WebKitXSSAuditorEnabled, XSSAuditorEnabled, xssAuditorEnabled) \
  198. macro(WebKitShouldRespectImageOrientation, ShouldRespectImageOrientation, shouldRespectImageOrientation) \
  199. macro(WebKitEnableCaretBrowsing, CaretBrowsingEnabled, caretBrowsingEnabled) \
  200. macro(WebKitDisplayImagesKey, LoadsImagesAutomatically, loadsImagesAutomatically)
  201. if (preference == "WebKitAcceleratedCompositingEnabled")
  202. enabled = enabled && LayerTreeHost::supportsAcceleratedCompositing();
  203. #define OVERRIDE_PREFERENCE_AND_SET_IN_EXISTING_PAGES(TestRunnerName, SettingsName, WebPreferencesName) \
  204. if (preference == #TestRunnerName) { \
  205. WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::WebPreferencesName##Key(), enabled); \
  206. for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter) \
  207. (*iter)->settings()->set##SettingsName(enabled); \
  208. return; \
  209. }
  210. FOR_EACH_OVERRIDE_BOOL_PREFERENCE(OVERRIDE_PREFERENCE_AND_SET_IN_EXISTING_PAGES)
  211. #if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
  212. OVERRIDE_PREFERENCE_AND_SET_IN_EXISTING_PAGES(WebKitHiddenPageDOMTimerThrottlingEnabled, HiddenPageDOMTimerThrottlingEnabled, hiddenPageDOMTimerThrottlingEnabled)
  213. #endif
  214. #undef OVERRIDE_PREFERENCE_AND_SET_IN_EXISTING_PAGES
  215. #undef FOR_EACH_OVERRIDE_BOOL_PREFERENCE
  216. }
  217. void InjectedBundle::overrideXSSAuditorEnabledForTestRunner(WebPageGroupProxy* pageGroup, bool enabled)
  218. {
  219. // Override the preference for all future pages.
  220. WebPreferencesStore::overrideBoolValueForKey(WebPreferencesKey::xssAuditorEnabledKey(), enabled);
  221. // Change the setting for existing ones.
  222. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  223. for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
  224. (*iter)->settings()->setXSSAuditorEnabled(enabled);
  225. }
  226. void InjectedBundle::setAllowUniversalAccessFromFileURLs(WebPageGroupProxy* pageGroup, bool enabled)
  227. {
  228. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  229. for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
  230. (*iter)->settings()->setAllowUniversalAccessFromFileURLs(enabled);
  231. }
  232. void InjectedBundle::setAllowFileAccessFromFileURLs(WebPageGroupProxy* pageGroup, bool enabled)
  233. {
  234. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  235. for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
  236. (*iter)->settings()->setAllowFileAccessFromFileURLs(enabled);
  237. }
  238. void InjectedBundle::setMinimumLogicalFontSize(WebPageGroupProxy* pageGroup, int size)
  239. {
  240. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  241. for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
  242. (*iter)->settings()->setMinimumLogicalFontSize(size);
  243. }
  244. void InjectedBundle::setFrameFlatteningEnabled(WebPageGroupProxy* pageGroup, bool enabled)
  245. {
  246. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  247. for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
  248. (*iter)->settings()->setFrameFlatteningEnabled(enabled);
  249. }
  250. void InjectedBundle::setPluginsEnabled(WebPageGroupProxy* pageGroup, bool enabled)
  251. {
  252. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  253. for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
  254. (*iter)->settings()->setPluginsEnabled(enabled);
  255. }
  256. void InjectedBundle::setJavaScriptCanAccessClipboard(WebPageGroupProxy* pageGroup, bool enabled)
  257. {
  258. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  259. for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
  260. (*iter)->settings()->setJavaScriptCanAccessClipboard(enabled);
  261. }
  262. void InjectedBundle::setPrivateBrowsingEnabled(WebPageGroupProxy* pageGroup, bool enabled)
  263. {
  264. // FIXME (NetworkProcess): This test-only function doesn't work with NetworkProcess, <https://bugs.webkit.org/show_bug.cgi?id=115274>.
  265. #if PLATFORM(MAC) || USE(CFNETWORK)
  266. if (enabled)
  267. WebFrameNetworkingContext::ensurePrivateBrowsingSession();
  268. else
  269. WebFrameNetworkingContext::destroyPrivateBrowsingSession();
  270. #endif
  271. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  272. for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
  273. (*iter)->settings()->setPrivateBrowsingEnabled(enabled);
  274. }
  275. void InjectedBundle::setPopupBlockingEnabled(WebPageGroupProxy* pageGroup, bool enabled)
  276. {
  277. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  278. HashSet<Page*>::const_iterator end = pages.end();
  279. for (HashSet<Page*>::const_iterator iter = pages.begin(); iter != end; ++iter)
  280. (*iter)->settings()->setJavaScriptCanOpenWindowsAutomatically(!enabled);
  281. }
  282. void InjectedBundle::switchNetworkLoaderToNewTestingSession()
  283. {
  284. #if PLATFORM(MAC) || USE(CFNETWORK)
  285. // FIXME (NetworkProcess): Do this in network process, too.
  286. InitWebCoreSystemInterface();
  287. NetworkStorageSession::switchToNewTestingSession();
  288. #endif
  289. }
  290. void InjectedBundle::setAuthorAndUserStylesEnabled(WebPageGroupProxy* pageGroup, bool enabled)
  291. {
  292. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  293. for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
  294. (*iter)->settings()->setAuthorAndUserStylesEnabled(enabled);
  295. }
  296. void InjectedBundle::setSpatialNavigationEnabled(WebPageGroupProxy* pageGroup, bool enabled)
  297. {
  298. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  299. for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
  300. (*iter)->settings()->setSpatialNavigationEnabled(enabled);
  301. }
  302. void InjectedBundle::addOriginAccessWhitelistEntry(const String& sourceOrigin, const String& destinationProtocol, const String& destinationHost, bool allowDestinationSubdomains)
  303. {
  304. SecurityPolicy::addOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
  305. }
  306. void InjectedBundle::removeOriginAccessWhitelistEntry(const String& sourceOrigin, const String& destinationProtocol, const String& destinationHost, bool allowDestinationSubdomains)
  307. {
  308. SecurityPolicy::removeOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
  309. }
  310. void InjectedBundle::resetOriginAccessWhitelists()
  311. {
  312. SecurityPolicy::resetOriginAccessWhitelists();
  313. }
  314. void InjectedBundle::setAsynchronousSpellCheckingEnabled(WebPageGroupProxy* pageGroup, bool enabled)
  315. {
  316. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  317. for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
  318. (*iter)->settings()->setAsynchronousSpellCheckingEnabled(enabled);
  319. }
  320. void InjectedBundle::clearAllDatabases()
  321. {
  322. #if ENABLE(SQL_DATABASE)
  323. WebProcess::shared().supplement<WebDatabaseManager>()->deleteAllDatabases();
  324. #endif
  325. }
  326. void InjectedBundle::setDatabaseQuota(uint64_t quota)
  327. {
  328. #if ENABLE(SQL_DATABASE)
  329. // Historically, we've used the following (somewhat non-sensical) string
  330. // for the databaseIdentifier of local files.
  331. WebProcess::shared().supplement<WebDatabaseManager>()->setQuotaForOrigin("file__0", quota);
  332. #endif
  333. }
  334. void InjectedBundle::clearApplicationCache()
  335. {
  336. WebProcess::shared().supplement<WebApplicationCacheManager>()->deleteAllEntries();
  337. }
  338. void InjectedBundle::clearApplicationCacheForOrigin(const String& originString)
  339. {
  340. RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(originString);
  341. ApplicationCache::deleteCacheForOrigin(origin.get());
  342. }
  343. void InjectedBundle::setAppCacheMaximumSize(uint64_t size)
  344. {
  345. WebProcess::shared().supplement<WebApplicationCacheManager>()->setAppCacheMaximumSize(size);
  346. }
  347. uint64_t InjectedBundle::appCacheUsageForOrigin(const String& originString)
  348. {
  349. RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(originString);
  350. return ApplicationCache::diskUsageForOrigin(origin.get());
  351. }
  352. void InjectedBundle::setApplicationCacheOriginQuota(const String& originString, uint64_t bytes)
  353. {
  354. RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(originString);
  355. cacheStorage().storeUpdatedQuotaForOrigin(origin.get(), bytes);
  356. }
  357. void InjectedBundle::resetApplicationCacheOriginQuota(const String& originString)
  358. {
  359. RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(originString);
  360. cacheStorage().storeUpdatedQuotaForOrigin(origin.get(), cacheStorage().defaultOriginQuota());
  361. }
  362. PassRefPtr<ImmutableArray> InjectedBundle::originsWithApplicationCache()
  363. {
  364. HashSet<RefPtr<SecurityOrigin>> origins;
  365. cacheStorage().getOriginsWithCache(origins);
  366. Vector< RefPtr<APIObject>> originsVector;
  367. HashSet<RefPtr<SecurityOrigin>>::iterator it = origins.begin();
  368. HashSet<RefPtr<SecurityOrigin>>::iterator end = origins.end();
  369. for ( ; it != end; ++it)
  370. originsVector.append(WebString::create((*it)->databaseIdentifier()));
  371. return ImmutableArray::adopt(originsVector);
  372. }
  373. int InjectedBundle::numberOfPages(WebFrame* frame, double pageWidthInPixels, double pageHeightInPixels)
  374. {
  375. Frame* coreFrame = frame ? frame->coreFrame() : 0;
  376. if (!coreFrame)
  377. return -1;
  378. if (!pageWidthInPixels)
  379. pageWidthInPixels = coreFrame->view()->width();
  380. if (!pageHeightInPixels)
  381. pageHeightInPixels = coreFrame->view()->height();
  382. return PrintContext::numberOfPages(coreFrame, FloatSize(pageWidthInPixels, pageHeightInPixels));
  383. }
  384. int InjectedBundle::pageNumberForElementById(WebFrame* frame, const String& id, double pageWidthInPixels, double pageHeightInPixels)
  385. {
  386. Frame* coreFrame = frame ? frame->coreFrame() : 0;
  387. if (!coreFrame)
  388. return -1;
  389. Element* element = coreFrame->document()->getElementById(AtomicString(id));
  390. if (!element)
  391. return -1;
  392. if (!pageWidthInPixels)
  393. pageWidthInPixels = coreFrame->view()->width();
  394. if (!pageHeightInPixels)
  395. pageHeightInPixels = coreFrame->view()->height();
  396. return PrintContext::pageNumberForElement(element, FloatSize(pageWidthInPixels, pageHeightInPixels));
  397. }
  398. String InjectedBundle::pageSizeAndMarginsInPixels(WebFrame* frame, int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft)
  399. {
  400. Frame* coreFrame = frame ? frame->coreFrame() : 0;
  401. if (!coreFrame)
  402. return String();
  403. return PrintContext::pageSizeAndMarginsInPixels(coreFrame, pageIndex, width, height, marginTop, marginRight, marginBottom, marginLeft);
  404. }
  405. bool InjectedBundle::isPageBoxVisible(WebFrame* frame, int pageIndex)
  406. {
  407. Frame* coreFrame = frame ? frame->coreFrame() : 0;
  408. if (!coreFrame)
  409. return false;
  410. return PrintContext::isPageBoxVisible(coreFrame, pageIndex);
  411. }
  412. bool InjectedBundle::isProcessingUserGesture()
  413. {
  414. return ScriptController::processingUserGesture();
  415. }
  416. static Vector<String> toStringVector(ImmutableArray* patterns)
  417. {
  418. Vector<String> patternsVector;
  419. if (!patterns)
  420. return patternsVector;
  421. size_t size = patterns->size();
  422. if (!size)
  423. return patternsVector;
  424. patternsVector.reserveInitialCapacity(size);
  425. for (size_t i = 0; i < size; ++i) {
  426. WebString* entry = patterns->at<WebString>(i);
  427. if (entry)
  428. patternsVector.uncheckedAppend(entry->string());
  429. }
  430. return patternsVector;
  431. }
  432. void InjectedBundle::addUserScript(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserScriptInjectionTime injectionTime, WebCore::UserContentInjectedFrames injectedFrames)
  433. {
  434. // url is not from KURL::string(), i.e. it has not already been parsed by KURL, so we have to use the relative URL constructor for KURL instead of the ParsedURLStringTag version.
  435. PageGroup::pageGroup(pageGroup->identifier())->addUserScriptToWorld(scriptWorld->coreWorld(), source, KURL(KURL(), url), toStringVector(whitelist), toStringVector(blacklist), injectionTime, injectedFrames);
  436. }
  437. void InjectedBundle::addUserStyleSheet(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserContentInjectedFrames injectedFrames)
  438. {
  439. // url is not from KURL::string(), i.e. it has not already been parsed by KURL, so we have to use the relative URL constructor for KURL instead of the ParsedURLStringTag version.
  440. PageGroup::pageGroup(pageGroup->identifier())->addUserStyleSheetToWorld(scriptWorld->coreWorld(), source, KURL(KURL(), url), toStringVector(whitelist), toStringVector(blacklist), injectedFrames);
  441. }
  442. void InjectedBundle::removeUserScript(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld, const String& url)
  443. {
  444. // url is not from KURL::string(), i.e. it has not already been parsed by KURL, so we have to use the relative URL constructor for KURL instead of the ParsedURLStringTag version.
  445. PageGroup::pageGroup(pageGroup->identifier())->removeUserScriptFromWorld(scriptWorld->coreWorld(), KURL(KURL(), url));
  446. }
  447. void InjectedBundle::removeUserStyleSheet(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld, const String& url)
  448. {
  449. // url is not from KURL::string(), i.e. it has not already been parsed by KURL, so we have to use the relative URL constructor for KURL instead of the ParsedURLStringTag version.
  450. PageGroup::pageGroup(pageGroup->identifier())->removeUserStyleSheetFromWorld(scriptWorld->coreWorld(), KURL(KURL(), url));
  451. }
  452. void InjectedBundle::removeUserScripts(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld)
  453. {
  454. PageGroup::pageGroup(pageGroup->identifier())->removeUserScriptsFromWorld(scriptWorld->coreWorld());
  455. }
  456. void InjectedBundle::removeUserStyleSheets(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld)
  457. {
  458. PageGroup::pageGroup(pageGroup->identifier())->removeUserStyleSheetsFromWorld(scriptWorld->coreWorld());
  459. }
  460. void InjectedBundle::removeAllUserContent(WebPageGroupProxy* pageGroup)
  461. {
  462. PageGroup::pageGroup(pageGroup->identifier())->removeAllUserContent();
  463. }
  464. void InjectedBundle::garbageCollectJavaScriptObjects()
  465. {
  466. gcController().garbageCollectNow();
  467. }
  468. void InjectedBundle::garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(bool waitUntilDone)
  469. {
  470. gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
  471. }
  472. size_t InjectedBundle::javaScriptObjectsCount()
  473. {
  474. JSLockHolder lock(JSDOMWindow::commonVM());
  475. #if PLATFORM(MANX) && 0
  476. // Use our more precise object count algorithm that takes zapped blocks into account
  477. return JSDOMWindow::commonVM()->heap.objectCount(true);
  478. #else
  479. return JSDOMWindow::commonVM()->heap.objectCount();
  480. #endif
  481. }
  482. void InjectedBundle::reportException(JSContextRef context, JSValueRef exception)
  483. {
  484. if (!context || !exception)
  485. return;
  486. JSC::ExecState* execState = toJS(context);
  487. JSLockHolder lock(execState);
  488. // Make sure the context has a DOMWindow global object, otherwise this context didn't originate from a Page.
  489. if (!toJSDOMWindow(execState->lexicalGlobalObject()))
  490. return;
  491. WebCore::reportException(execState, toJS(execState, exception));
  492. }
  493. void InjectedBundle::didCreatePage(WebPage* page)
  494. {
  495. m_client.didCreatePage(this, page);
  496. }
  497. void InjectedBundle::willDestroyPage(WebPage* page)
  498. {
  499. m_client.willDestroyPage(this, page);
  500. }
  501. void InjectedBundle::didInitializePageGroup(WebPageGroupProxy* pageGroup)
  502. {
  503. m_client.didInitializePageGroup(this, pageGroup);
  504. }
  505. void InjectedBundle::didReceiveMessage(const String& messageName, APIObject* messageBody)
  506. {
  507. m_client.didReceiveMessage(this, messageName, messageBody);
  508. }
  509. void InjectedBundle::didReceiveMessageToPage(WebPage* page, const String& messageName, APIObject* messageBody)
  510. {
  511. m_client.didReceiveMessageToPage(this, page, messageName, messageBody);
  512. }
  513. void InjectedBundle::setUserStyleSheetLocation(WebPageGroupProxy* pageGroup, const String& location)
  514. {
  515. const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
  516. for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
  517. (*iter)->settings()->setUserStyleSheetLocation(KURL(KURL(), location));
  518. }
  519. void InjectedBundle::setWebNotificationPermission(WebPage* page, const String& originString, bool allowed)
  520. {
  521. #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
  522. page->notificationPermissionRequestManager()->setPermissionLevelForTesting(originString, allowed);
  523. #else
  524. UNUSED_PARAM(page);
  525. UNUSED_PARAM(originString);
  526. UNUSED_PARAM(allowed);
  527. #endif
  528. }
  529. void InjectedBundle::removeAllWebNotificationPermissions(WebPage* page)
  530. {
  531. #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
  532. page->notificationPermissionRequestManager()->removeAllPermissionsForTesting();
  533. #else
  534. UNUSED_PARAM(page);
  535. #endif
  536. }
  537. uint64_t InjectedBundle::webNotificationID(JSContextRef jsContext, JSValueRef jsNotification)
  538. {
  539. #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
  540. WebCore::Notification* notification = toNotification(toJS(toJS(jsContext), jsNotification));
  541. if (!notification)
  542. return 0;
  543. return WebProcess::shared().supplement<WebNotificationManager>()->notificationIDForTesting(notification);
  544. #else
  545. UNUSED_PARAM(jsContext);
  546. UNUSED_PARAM(jsNotification);
  547. return 0;
  548. #endif
  549. }
  550. PassRefPtr<WebData> InjectedBundle::createWebDataFromUint8Array(JSContextRef context, JSValueRef data)
  551. {
  552. JSC::ExecState* execState = toJS(context);
  553. RefPtr<Uint8Array> arrayData = WebCore::toUint8Array(toJS(execState, data));
  554. return WebData::create(static_cast<unsigned char*>(arrayData->baseAddress()), arrayData->byteLength());
  555. }
  556. void InjectedBundle::setTabKeyCyclesThroughElements(WebPage* page, bool enabled)
  557. {
  558. page->corePage()->setTabKeyCyclesThroughElements(enabled);
  559. }
  560. void InjectedBundle::setSerialLoadingEnabled(bool enabled)
  561. {
  562. resourceLoadScheduler()->setSerialLoadingEnabled(enabled);
  563. }
  564. void InjectedBundle::setShadowDOMEnabled(bool enabled)
  565. {
  566. #if ENABLE(SHADOW_DOM)
  567. RuntimeEnabledFeatures::setShadowDOMEnabled(enabled);
  568. #else
  569. UNUSED_PARAM(enabled);
  570. #endif
  571. }
  572. void InjectedBundle::setCSSRegionsEnabled(bool enabled)
  573. {
  574. #if ENABLE(CSS_REGIONS)
  575. RuntimeEnabledFeatures::setCSSRegionsEnabled(enabled);
  576. #else
  577. UNUSED_PARAM(enabled);
  578. #endif
  579. }
  580. void InjectedBundle::setCSSCompositingEnabled(bool enabled)
  581. {
  582. #if ENABLE(CSS_COMPOSITING)
  583. RuntimeEnabledFeatures::setCSSCompositingEnabled(enabled);
  584. #else
  585. UNUSED_PARAM(enabled);
  586. #endif
  587. }
  588. void InjectedBundle::setSeamlessIFramesEnabled(bool enabled)
  589. {
  590. #if ENABLE(IFRAME_SEAMLESS)
  591. RuntimeEnabledFeatures::setSeamlessIFramesEnabled(enabled);
  592. #else
  593. UNUSED_PARAM(enabled);
  594. #endif
  595. }
  596. void InjectedBundle::dispatchPendingLoadRequests()
  597. {
  598. resourceLoadScheduler()->servePendingRequests();
  599. }
  600. } // namespace WebKit