Expose WKUserScript as API
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 May 2014 19:57:44 +0000 (19:57 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 May 2014 19:57:44 +0000 (19:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=133017
<rdar://problem/16948059>

Reviewed by Sam Weinig.

Source/WebCore:
* WebCore.exp.in:
Export symbols.

* WebCore.xcodeproj/project.pbxproj:
Change UserContentController.h to be a private header.

* page/Page.cpp:
(WebCore::Page::Page):
Set m_userContentController from the page configuration and add it if it's not null.

* page/Page.h:
Add UserContentController to PageClients.

* page/PageGroup.cpp:
(WebCore::PageGroup::addPage):
Only try to add a user content controller if the page doesn't already have one.

(WebCore::PageGroup::removePage):
Only try to remove the user content controller if it's the group one.

Source/WebKit2:
* DerivedSources.make:
Add WebUserContentController.

* Shared/API/Cocoa/WebKit.h:
Add WKUserScript.h

* Shared/API/c/WKSharedAPICast.h:
(WebKit::toUserScriptInjectionTime):
Update for WKUserScriptInjectionTime -> _WKUserScriptInjectionTime rename.

* Shared/API/c/WKUserScriptInjectionTime.h:
Rename WKUserScriptInjectionTime to _WKUserScriptInjectionTime to free up the name for the Objective-C API

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode):
Encode the user content controller ID.

(WebKit::WebPageCreationParameters::decode):
Decode the user content controller ID.

* Shared/WebPageCreationParameters.h:
Add userContentControllerID.

* UIProcess/API/C/WKPageGroup.cpp:
(WKPageGroupAddUserScript):
Update for WKUserScriptInjectionTime -> _WKUserScriptInjectionTime rename.

* UIProcess/API/C/WKPageGroup.h:
Update for WKUserScriptInjectionTime -> _WKUserScriptInjectionTime rename.

* UIProcess/API/Cocoa/WKBrowsingContextGroup.h:
Update for WKUserScriptInjectionTime -> _WKUserScriptInjectionTime rename.

* UIProcess/API/Cocoa/WKBrowsingContextGroup.mm:
(-[WKBrowsingContextGroup addUserScript:baseURL:whitelistedURLPatterns:blacklistedURLPatterns:injectionTime:mainFrameOnly:]):
Update for WKUserScriptInjectionTime -> _WKUserScriptInjectionTime rename.

* UIProcess/API/Cocoa/WKUserContentController.h:
Add new methods.

* UIProcess/API/Cocoa/WKUserContentController.mm:
(-[WKUserContentController init]):
Create the WebUserContentControllerProxy object and user scripts array.

(-[WKUserContentController userScripts]):
Return the user scripts array.

(toWebCoreUserScriptInjectionTime):
Helper for converting from a WKUserScriptInjectionTime enum to WebCore::UserScriptInjectionTime.

(-[WKUserContentController addUserScript:]):
Call through to the _userContentControllerProxy object.

(-[WKUserContentController removeAllUserScripts]):
Call through to the _userContentControllerProxy object.

* UIProcess/API/Cocoa/WKUserContentControllerInternal.h: Added.
Add WebUserContentControllerProxy ivar.

* UIProcess/API/Cocoa/WKUserScript.h: Added.
Add new header.

* UIProcess/API/Cocoa/WKUserScript.mm:
(-[WKUserScript initWithSource:injectionTime:forMainFrameOnly:]):
Initialize the WKUserScript object.

(-[WKUserScript source]):
(-[WKUserScript injectionTime]):
(-[WKUserScript isForMainFrameOnly]):
Add getters.

(-[WKUserScript copyWithZone:]):
Since WKUserScript is immutable, just return a retained object.

* UIProcess/API/Cocoa/WKUserScriptInternal.h:
Add ivars.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView initWithFrame:configuration:]):
Set the user content controller from the configuration.

* UIProcess/UserContent/WebUserContentControllerProxy.cpp: Added.
(WebKit::generateIdentifier):
Return a unique identifier.

(WebKit::WebUserContentControllerProxy::create):
Return a new WebUserContentControllerProxy object.

(WebKit::WebUserContentControllerProxy::WebUserContentControllerProxy):
Initialize m_identifier.

(WebKit::WebUserContentControllerProxy::~WebUserContentControllerProxy):
Add destructor.

(WebKit::WebUserContentControllerProxy::addProcess):
Add the process to the m_processes set. If it's the first time doing so, add the user scripts we know about.

(WebKit::WebUserContentControllerProxy::removeProcess):
Remove the process from m_processes.

(WebKit::WebUserContentControllerProxy::addUserScript):
Add the user script and let all the web processes know that it was added.

(WebKit::WebUserContentControllerProxy::removeAllUserScripts):
Remove all user scripts and tell all the web processes about it.

* UIProcess/UserContent/WebUserContentControllerProxy.h:
Add new class.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy):
If the process is already running, add it to the user content controller.

(WebKit::WebPageProxy::close):
If the process is running, remove it from the user content controller.

(WebKit::WebPageProxy::connectionWillOpen):
Add the process to the user content controller.

(WebKit::WebPageProxy::resetStateAfterProcessExited):
Remove the process from the user content controller.

(WebKit::WebPageProxy::creationParameters):
Pass along the user content controller ID when creating the web page.

* UIProcess/WebPageProxy.h:
Add a WebUserContentControllerProxy object to the web page configuration.

* WebKit2.xcodeproj/project.pbxproj:
Add new files.

* WebProcess/InjectedBundle/API/c/WKBundle.cpp:
* WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:
Update for WKUserScriptInjectionTime -> _WKUserScriptInjectionTime rename.

* WebProcess/UserContent/WebUserContentController.cpp: Added.
New class that manages a WebCore::UserContentController object.

(WebKit::WebUserContentController::getOrCreate):
Look up (or create) a WebUserContentController object given its identifier.

(WebKit::WebUserContentController::WebUserContentController):
Add ourselves as a message receiver.

(WebKit::WebUserContentController::~WebUserContentController):
Remove ourselves as a message receiver.

(WebKit::WebUserContentController::addUserScripts):
Add all passed in user scripts to the WebCore user content controller object.

(WebKit::WebUserContentController::removeAllUserScripts):
Remove all user scripts from the WebCore user content controller object.

* WebProcess/UserContent/WebUserContentController.messages.in: Added.
Add new messages file.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
Get a WebUserContentController object and pass it along to WebCore.

* WebProcess/WebPage/WebPage.h:
Add WebUserContentController member.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@168994 268f45cc-cd09-0410-ab3c-d52691b4dbfc

36 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebCore/page/PageGroup.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/DerivedSources.make
Source/WebKit2/Shared/API/Cocoa/WebKit.h
Source/WebKit2/Shared/API/c/WKSharedAPICast.h
Source/WebKit2/Shared/API/c/WKUserScriptInjectionTime.h
Source/WebKit2/Shared/WebPageCreationParameters.cpp
Source/WebKit2/Shared/WebPageCreationParameters.h
Source/WebKit2/UIProcess/API/C/WKPageGroup.cpp
Source/WebKit2/UIProcess/API/C/WKPageGroup.h
Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextGroup.h
Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextGroup.mm
Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.h
Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.mm
Source/WebKit2/UIProcess/API/Cocoa/WKUserContentControllerInternal.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/Cocoa/WKUserScript.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/Cocoa/WKUserScript.mm [new file with mode: 0644]
Source/WebKit2/UIProcess/API/Cocoa/WKUserScriptInternal.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h [new file with mode: 0644]
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h
Source/WebKit2/WebProcess/UserContent/WebUserContentController.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/UserContent/WebUserContentController.h [new file with mode: 0644]
Source/WebKit2/WebProcess/UserContent/WebUserContentController.messages.in [new file with mode: 0644]
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h

index 5605837d736be4b06f99085d3ebe0f8ae6516c1c..a888d92ca41c2605554cb9c50b6b3ab1a166b4c5 100644 (file)
@@ -1,3 +1,31 @@
+2014-05-16  Anders Carlsson  <andersca@apple.com>
+
+        Expose WKUserScript as API
+        https://bugs.webkit.org/show_bug.cgi?id=133017
+        <rdar://problem/16948059>
+
+        Reviewed by Sam Weinig.
+
+        * WebCore.exp.in:
+        Export symbols.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        Change UserContentController.h to be a private header.
+
+        * page/Page.cpp:
+        (WebCore::Page::Page):
+        Set m_userContentController from the page configuration and add it if it's not null.
+
+        * page/Page.h:
+        Add UserContentController to PageClients.
+
+        * page/PageGroup.cpp:
+        (WebCore::PageGroup::addPage):
+        Only try to add a user content controller if the page doesn't already have one.
+
+        (WebCore::PageGroup::removePage):
+        Only try to remove the user content controller if it's the group one.
+
 2014-05-17  Andreas Kling  <akling@apple.com>
 
         REGRESSION (r166422): All RenderBox objects grew 104 bytes from adding repaint timers.
index ca89d2d55371539e6e879cf1fa01f6b0fa9eb323..4af43c6ccce67ed9d1d50e42f6960edaab339f32 100644 (file)
@@ -2189,6 +2189,10 @@ __ZN7WebCore20ResourceHandleClient23didReceiveResponseAsyncEPNS_14ResourceHandle
 __ZN7WebCore20applicationIsHRBlockEv
 __ZN7WebCore20builtInPDFPluginNameEv
 __ZN7WebCore21DeviceOrientationData6createEbdbdbdbb
+__ZN7WebCore21UserContentController13addUserScriptERNS_15DOMWrapperWorldENSt3__110unique_ptrINS_10UserScriptENS3_14default_deleteIS5_EEEE
+__ZN7WebCore21UserContentController17removeUserScriptsERNS_15DOMWrapperWorldE
+__ZN7WebCore21UserContentController6createEv
+__ZN7WebCore21UserContentControllerD1Ev
 __ZN7WebCore21applicationIsApertureEv
 __ZN7WebCore21applicationIsVersionsEv
 __ZN7WebCore21reportThreadViolationEPKcNS_20ThreadViolationRoundE
index 86175f2baef121e4eb5fb6cffefda5d25099933c..41799a4b5e396784963a35ab2c7e47ff6736838a 100644 (file)
                1AE2AEC70A1D297B00B42B25 /* JSHTMLQuoteElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE2AEC30A1D297B00B42B25 /* JSHTMLQuoteElement.cpp */; };
                1AE2AEC80A1D297B00B42B25 /* JSHTMLQuoteElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AE2AEC40A1D297B00B42B25 /* JSHTMLQuoteElement.h */; };
                1AE79D42188DB61F002239C2 /* UserContentController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE79D40188DB61F002239C2 /* UserContentController.cpp */; };
-               1AE79D43188DB61F002239C2 /* UserContentController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AE79D41188DB61F002239C2 /* UserContentController.h */; };
+               1AE79D43188DB61F002239C2 /* UserContentController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AE79D41188DB61F002239C2 /* UserContentController.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1AE82F8F0CAAFA9D002237AE /* JSDatabase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE82F8D0CAAFA9D002237AE /* JSDatabase.cpp */; };
                1AE82F900CAAFA9D002237AE /* JSDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AE82F8E0CAAFA9D002237AE /* JSDatabase.h */; };
                1AE82FEC0CAB07EE002237AE /* JSSQLResultSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE82FEA0CAB07EE002237AE /* JSSQLResultSet.cpp */; };
index 1fa7407136713d38a4578cc25f1fc5f5e06ba742..11e893432b700272a9027ecb86f2ccfd113cc01a 100644 (file)
@@ -197,13 +197,17 @@ Page::Page(PageClients& pageClients)
 #endif
     , m_lastSpatialNavigationCandidatesCount(0) // NOTE: Only called from Internals for Spatial Navigation testing.
     , m_framesHandlingBeforeUnloadEvent(0)
+    , m_userContentController(std::move(pageClients.userContentController))
     , m_visitedLinkStore(std::move(pageClients.visitedLinkStore))
     , m_sessionID(SessionID::defaultSessionID())
 {
     ASSERT(m_editorClient);
     
     setTimerThrottlingEnabled(m_viewState & ViewState::IsVisuallyIdle);
-    
+
+    if (m_userContentController)
+        m_userContentController->addPage(*this);
+
     if (m_visitedLinkStore)
         m_visitedLinkStore->addPage(*this);
 
index 9d3686c7b75e36e1c2a84549a6c5c86798813e00..4bf056a478d4d013fc054a21c0e261055e0555ba 100644 (file)
@@ -118,6 +118,7 @@ public:
     static void updateStyleForAllPagesAfterGlobalChangeInEnvironment();
 
     // It is up to the platform to ensure that non-null clients are provided where required.
+    // FIXME: Rename this to PageConfiguration and move it to its own class.
     struct PageClients {
         WTF_MAKE_NONCOPYABLE(PageClients); WTF_MAKE_FAST_ALLOCATED;
     public:
@@ -138,6 +139,7 @@ public:
         ValidationMessageClient* validationMessageClient;
         FrameLoaderClient* loaderClientForMainFrame;
 
+        RefPtr<UserContentController> userContentController;
         RefPtr<VisitedLinkStore> visitedLinkStore;
     };
 
index 3385e7b69e6554e336cd009a79fbb16d68512132..37a6c985a6476d79818538491bb95852739d4c0e 100644 (file)
@@ -167,7 +167,8 @@ void PageGroup::addPage(Page& page)
     ASSERT(!m_pages.contains(&page));
     m_pages.add(&page);
 
-    page.setUserContentController(m_userContentController.get());
+    if (!page.userContentController())
+        page.setUserContentController(m_userContentController.get());
 }
 
 void PageGroup::removePage(Page& page)
@@ -175,7 +176,8 @@ void PageGroup::removePage(Page& page)
     ASSERT(m_pages.contains(&page));
     m_pages.remove(&page);
 
-    page.setUserContentController(nullptr);
+    if (page.userContentController() == m_userContentController)
+        page.setUserContentController(nullptr);
 }
 
 VisitedLinkStore& PageGroup::visitedLinkStore()
index 830945580c775366327e630d2b43e412b0dc9236..a1b57703eb1fda9b4f46df97f0e0e1c24b7341cb 100644 (file)
@@ -1,3 +1,174 @@
+2014-05-16  Anders Carlsson  <andersca@apple.com>
+
+        Expose WKUserScript as API
+        https://bugs.webkit.org/show_bug.cgi?id=133017
+        <rdar://problem/16948059>
+
+        Reviewed by Sam Weinig.
+
+        * DerivedSources.make:
+        Add WebUserContentController.
+
+        * Shared/API/Cocoa/WebKit.h:
+        Add WKUserScript.h
+
+        * Shared/API/c/WKSharedAPICast.h:
+        (WebKit::toUserScriptInjectionTime):
+        Update for WKUserScriptInjectionTime -> _WKUserScriptInjectionTime rename.
+
+        * Shared/API/c/WKUserScriptInjectionTime.h:
+        Rename WKUserScriptInjectionTime to _WKUserScriptInjectionTime to free up the name for the Objective-C API
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode):
+        Encode the user content controller ID.
+
+        (WebKit::WebPageCreationParameters::decode):
+        Decode the user content controller ID.
+
+        * Shared/WebPageCreationParameters.h:
+        Add userContentControllerID.
+
+        * UIProcess/API/C/WKPageGroup.cpp:
+        (WKPageGroupAddUserScript):
+        Update for WKUserScriptInjectionTime -> _WKUserScriptInjectionTime rename.
+
+        * UIProcess/API/C/WKPageGroup.h:
+        Update for WKUserScriptInjectionTime -> _WKUserScriptInjectionTime rename.
+
+        * UIProcess/API/Cocoa/WKBrowsingContextGroup.h:
+        Update for WKUserScriptInjectionTime -> _WKUserScriptInjectionTime rename.
+
+        * UIProcess/API/Cocoa/WKBrowsingContextGroup.mm:
+        (-[WKBrowsingContextGroup addUserScript:baseURL:whitelistedURLPatterns:blacklistedURLPatterns:injectionTime:mainFrameOnly:]):
+        Update for WKUserScriptInjectionTime -> _WKUserScriptInjectionTime rename.
+
+        * UIProcess/API/Cocoa/WKUserContentController.h:
+        Add new methods.
+
+        * UIProcess/API/Cocoa/WKUserContentController.mm:
+        (-[WKUserContentController init]):
+        Create the WebUserContentControllerProxy object and user scripts array.
+
+        (-[WKUserContentController userScripts]):
+        Return the user scripts array.
+
+        (toWebCoreUserScriptInjectionTime):
+        Helper for converting from a WKUserScriptInjectionTime enum to WebCore::UserScriptInjectionTime.
+
+        (-[WKUserContentController addUserScript:]):
+        Call through to the _userContentControllerProxy object.
+
+        (-[WKUserContentController removeAllUserScripts]):
+        Call through to the _userContentControllerProxy object.
+        
+        * UIProcess/API/Cocoa/WKUserContentControllerInternal.h: Added.
+        Add WebUserContentControllerProxy ivar.
+
+        * UIProcess/API/Cocoa/WKUserScript.h: Added.
+        Add new header.
+
+        * UIProcess/API/Cocoa/WKUserScript.mm:
+        (-[WKUserScript initWithSource:injectionTime:forMainFrameOnly:]):
+        Initialize the WKUserScript object.
+
+        (-[WKUserScript source]):
+        (-[WKUserScript injectionTime]):
+        (-[WKUserScript isForMainFrameOnly]):
+        Add getters.
+
+        (-[WKUserScript copyWithZone:]):
+        Since WKUserScript is immutable, just return a retained object.
+
+        * UIProcess/API/Cocoa/WKUserScriptInternal.h:
+        Add ivars.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView initWithFrame:configuration:]):
+        Set the user content controller from the configuration.
+
+        * UIProcess/UserContent/WebUserContentControllerProxy.cpp: Added.
+        (WebKit::generateIdentifier):
+        Return a unique identifier.
+
+        (WebKit::WebUserContentControllerProxy::create):
+        Return a new WebUserContentControllerProxy object.
+
+        (WebKit::WebUserContentControllerProxy::WebUserContentControllerProxy):
+        Initialize m_identifier.
+
+        (WebKit::WebUserContentControllerProxy::~WebUserContentControllerProxy):
+        Add destructor.
+
+        (WebKit::WebUserContentControllerProxy::addProcess):
+        Add the process to the m_processes set. If it's the first time doing so, add the user scripts we know about.
+
+        (WebKit::WebUserContentControllerProxy::removeProcess):
+        Remove the process from m_processes.
+
+        (WebKit::WebUserContentControllerProxy::addUserScript):
+        Add the user script and let all the web processes know that it was added.
+
+        (WebKit::WebUserContentControllerProxy::removeAllUserScripts):
+        Remove all user scripts and tell all the web processes about it.
+        
+        * UIProcess/UserContent/WebUserContentControllerProxy.h:
+        Add new class.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::WebPageProxy):
+        If the process is already running, add it to the user content controller.
+
+        (WebKit::WebPageProxy::close):
+        If the process is running, remove it from the user content controller.
+
+        (WebKit::WebPageProxy::connectionWillOpen):
+        Add the process to the user content controller.
+
+        (WebKit::WebPageProxy::resetStateAfterProcessExited):
+        Remove the process from the user content controller.
+
+        (WebKit::WebPageProxy::creationParameters):
+        Pass along the user content controller ID when creating the web page.
+
+        * UIProcess/WebPageProxy.h:
+        Add a WebUserContentControllerProxy object to the web page configuration.
+
+        * WebKit2.xcodeproj/project.pbxproj:
+        Add new files.
+
+        * WebProcess/InjectedBundle/API/c/WKBundle.cpp:
+        * WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:
+        Update for WKUserScriptInjectionTime -> _WKUserScriptInjectionTime rename.
+        
+        * WebProcess/UserContent/WebUserContentController.cpp: Added.
+        New class that manages a WebCore::UserContentController object.
+
+        (WebKit::WebUserContentController::getOrCreate):
+        Look up (or create) a WebUserContentController object given its identifier.
+
+        (WebKit::WebUserContentController::WebUserContentController):
+        Add ourselves as a message receiver.
+
+        (WebKit::WebUserContentController::~WebUserContentController):
+        Remove ourselves as a message receiver.
+
+        (WebKit::WebUserContentController::addUserScripts):
+        Add all passed in user scripts to the WebCore user content controller object.
+
+        (WebKit::WebUserContentController::removeAllUserScripts):
+        Remove all user scripts from the WebCore user content controller object.
+
+        * WebProcess/UserContent/WebUserContentController.messages.in: Added.
+        Add new messages file.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage):
+        Get a WebUserContentController object and pass it along to WebCore.
+
+        * WebProcess/WebPage/WebPage.h:
+        Add WebUserContentController member.
+
 2014-05-16  Piotr Grad  <p.grad@samsung.com>
 
         [GTK] Build break after 168978.
index 33ce16198a0a018025aff3c734224733121b00a9..05990d74ce1d27de9ef3565513702293fb0fd463 100644 (file)
@@ -49,6 +49,7 @@ VPATH = \
     $(WebKit2)/WebProcess/ResourceCache \
     $(WebKit2)/WebProcess/Scrolling \
     $(WebKit2)/WebProcess/Storage \
+    $(WebKit2)/WebProcess/UserContent \
     $(WebKit2)/WebProcess/WebCoreSupport \
     $(WebKit2)/WebProcess/WebPage \
     $(WebKit2)/WebProcess/ios \
@@ -133,6 +134,7 @@ MESSAGE_RECEIVERS = \
     WebResourceCacheManager \
     WebResourceCacheManagerProxy \
     WebResourceLoader \
+    WebUserContentController \
     WebVideoFullscreenManager \
     WebVideoFullscreenManagerProxy \
 #
index ad4cc91d426a3cda4c65fcc08ce185c41cb249e7..52416c8a09458ee9afb6d1f7960bbddad748b926 100644 (file)
@@ -37,6 +37,7 @@
 #import <WebKit/WKScriptMessageHandler.h>
 #import <WebKit/WKUIDelegate.h>
 #import <WebKit/WKUserContentController.h>
+#import <WebKit/WKUserScript.h>
 #import <WebKit/WKWebView.h>
 #import <WebKit/WKWebViewConfiguration.h>
 #import <WebKit/WebKitLegacy.h>
index 03cbdd21df6e9b85cd46d069337f2b284a731412..cfe779251ac5654d10d3c6cc76cd3a1b56b22256 100644 (file)
@@ -895,7 +895,7 @@ inline SnapshotOptions toSnapshotOptions(WKSnapshotOptions wkSnapshotOptions)
     return snapshotOptions;
 }
 
-inline WebCore::UserScriptInjectionTime toUserScriptInjectionTime(WKUserScriptInjectionTime wkInjectedTime)
+inline WebCore::UserScriptInjectionTime toUserScriptInjectionTime(_WKUserScriptInjectionTime wkInjectedTime)
 {
     switch (wkInjectedTime) {
     case kWKInjectAtDocumentStart:
index f4d38b2c1ca1c0d37bbcc1cad0e0787aabfcb6f3..45d241072b389e14e0ce180af10e7844a3965526 100644 (file)
 #ifndef WKUserScriptInjectionTime_h
 #define WKUserScriptInjectionTime_h
 
-enum WKUserScriptInjectionTime {
+enum _WKUserScriptInjectionTime {
     kWKInjectAtDocumentStart,
     kWKInjectAtDocumentEnd
 };
-typedef enum WKUserScriptInjectionTime WKUserScriptInjectionTime;
+typedef enum _WKUserScriptInjectionTime _WKUserScriptInjectionTime;
 
 #endif /* WKUserScriptInjectionTime_h */
index 408d7179abd2787dc9084111fa8b1b52a422334f..5c0a2146f52117943d3e495afe8d14a990eb4646 100644 (file)
@@ -51,6 +51,7 @@ void WebPageCreationParameters::encode(IPC::ArgumentEncoder& encoder) const
     encoder << sessionState;
     encoder << sessionID;
     encoder << highestUsedBackForwardItemID;
+    encoder << userContentControllerID;
     encoder << visitedLinkTableID;
     encoder << canRunBeforeUnloadConfirmPanel;
     encoder << canRunModal;
@@ -115,6 +116,8 @@ bool WebPageCreationParameters::decode(IPC::ArgumentDecoder& decoder, WebPageCre
         return false;
     if (!decoder.decode(parameters.highestUsedBackForwardItemID))
         return false;
+    if (!decoder.decode(parameters.userContentControllerID))
+        return false;
     if (!decoder.decode(parameters.visitedLinkTableID))
         return false;
     if (!decoder.decode(parameters.canRunBeforeUnloadConfirmPanel))
index 8a432f4749895af352ee7029a65855815a151565..7a9c230d16d5c42ae38c4b32cd6d770b76b36605 100644 (file)
@@ -85,6 +85,7 @@ struct WebPageCreationParameters {
     WebCore::SessionID sessionID;
     uint64_t highestUsedBackForwardItemID;
 
+    uint64_t userContentControllerID;
     uint64_t visitedLinkTableID;
     bool canRunBeforeUnloadConfirmPanel;
     bool canRunModal;
index 677757ddb9cc295f82ff58817e7bdcf07239c9f0..d7f445994e9bbd367ff114fc93a7e2fd700068df 100644 (file)
@@ -68,7 +68,7 @@ void WKPageGroupRemoveAllUserStyleSheets(WKPageGroupRef pageGroupRef)
     toImpl(pageGroupRef)->removeAllUserStyleSheets();
 }
 
-void WKPageGroupAddUserScript(WKPageGroupRef pageGroupRef, WKStringRef sourceRef, WKURLRef baseURL, WKArrayRef whitelistedURLPatterns, WKArrayRef blacklistedURLPatterns, WKUserContentInjectedFrames injectedFrames, WKUserScriptInjectionTime injectionTime)
+void WKPageGroupAddUserScript(WKPageGroupRef pageGroupRef, WKStringRef sourceRef, WKURLRef baseURL, WKArrayRef whitelistedURLPatterns, WKArrayRef blacklistedURLPatterns, WKUserContentInjectedFrames injectedFrames, _WKUserScriptInjectionTime injectionTime)
 {
     toImpl(pageGroupRef)->addUserScript(toWTFString(sourceRef), toWTFString(baseURL), toImpl(whitelistedURLPatterns), toImpl(blacklistedURLPatterns), toUserContentInjectedFrames(injectedFrames), toUserScriptInjectionTime(injectionTime));
 }
index 149b1a30bd97d71b12fb230fb3a0fd4a11e59ddc..1bca1f2c3b1b0c160a52640af845f0df80f10ee0 100644 (file)
@@ -46,7 +46,7 @@ WK_EXPORT WKPreferencesRef WKPageGroupGetPreferences(WKPageGroupRef pageGroup);
 WK_EXPORT void WKPageGroupAddUserStyleSheet(WKPageGroupRef pageGroup, WKStringRef source, WKURLRef baseURL, WKArrayRef whitelistedURLPatterns, WKArrayRef blacklistedURLPatterns, WKUserContentInjectedFrames);
 WK_EXPORT void WKPageGroupRemoveAllUserStyleSheets(WKPageGroupRef pageGroup);
     
-WK_EXPORT void WKPageGroupAddUserScript(WKPageGroupRef pageGroup, WKStringRef source, WKURLRef baseURL, WKArrayRef whitelistedURLPatterns, WKArrayRef blacklistedURLPatterns, WKUserContentInjectedFrames, WKUserScriptInjectionTime);
+WK_EXPORT void WKPageGroupAddUserScript(WKPageGroupRef pageGroup, WKStringRef source, WKURLRef baseURL, WKArrayRef whitelistedURLPatterns, WKArrayRef blacklistedURLPatterns, WKUserContentInjectedFrames, _WKUserScriptInjectionTime);
 WK_EXPORT void WKPageGroupRemoveAllUserScripts(WKPageGroupRef pageGroup);
 
 #ifdef __cplusplus
index 59ddeb69be1aa9b0ae21dee7b8913cf4e04c726e..5d1511830c7f174dfe327da70950a2c393559190 100644 (file)
@@ -40,7 +40,7 @@ WK_CLASS_AVAILABLE(10_10, 8_0)
 - (void)addUserStyleSheet:(NSString *)source baseURL:(NSURL *)baseURL whitelistedURLPatterns:(NSArray *)whitelist blacklistedURLPatterns:(NSArray *)blacklist mainFrameOnly:(BOOL)mainFrameOnly;
 - (void)removeAllUserStyleSheets;
 
-- (void)addUserScript:(NSString *)source baseURL:(NSURL *)baseURL whitelistedURLPatterns:(NSArray *)whitelist blacklistedURLPatterns:(NSArray *)blacklist injectionTime:(WKUserScriptInjectionTime)injectionTime mainFrameOnly:(BOOL)mainFrameOnly;
+- (void)addUserScript:(NSString *)source baseURL:(NSURL *)baseURL whitelistedURLPatterns:(NSArray *)whitelist blacklistedURLPatterns:(NSArray *)blacklist injectionTime:(_WKUserScriptInjectionTime)injectionTime mainFrameOnly:(BOOL)mainFrameOnly;
 - (void)removeAllUserScripts;
 
 
index 68d3d15477b3d9c16f11311a74facf5811379665..0c0695d87ca5373298dc035d1b137b01639bc661 100644 (file)
@@ -148,7 +148,7 @@ static WKRetainPtr<WKArrayRef> createWKArray(NSArray *array)
     WKPageGroupRemoveAllUserStyleSheets(toAPI(_pageGroup.get()));
 }
 
-- (void)addUserScript:(NSString *)source baseURL:(NSURL *)baseURL whitelistedURLPatterns:(NSArray *)whitelist blacklistedURLPatterns:(NSArray *)blacklist injectionTime:(WKUserScriptInjectionTime)injectionTime mainFrameOnly:(BOOL)mainFrameOnly
+- (void)addUserScript:(NSString *)source baseURL:(NSURL *)baseURL whitelistedURLPatterns:(NSArray *)whitelist blacklistedURLPatterns:(NSArray *)blacklist injectionTime:(_WKUserScriptInjectionTime)injectionTime mainFrameOnly:(BOOL)mainFrameOnly
 {
     if (!source)
         CRASH();
index 3dd68dfedc2aa54ec4fd9232bcf16301a74a068f..bb1170bd5bf6ca6291b5dde109feadaec55dab09 100644 (file)
@@ -29,6 +29,7 @@
 
 #import <Foundation/Foundation.h>
 
+@class WKUserScript;
 @protocol WKScriptMessageHandler;
 
 /*! WKUserContentController provides a way for JavaScript to post messages to the @link WKWebView @/link.
 WK_CLASS_AVAILABLE(10_10, 8_0)
 @interface WKUserContentController : NSObject
 
+/*! @abstract The user scripts associated with this user content controller.
+*/
+@property (nonatomic, readonly) NSArray *userScripts;
+
+/*! @abstract Adds a user script.
+ @param userScript The user script to add.
+*/
+- (void)addUserScript:(WKUserScript *)userScript;
+
+/*! @abstract Removes all associated user scripts.
+*/
+- (void)removeAllUserScripts;
+
 /*! @abstract Adds a script message handler.
  @param scriptMessageHandler The message handler where the messages should be delivered.
  @param name The name of the message handler.
index a062142fb261e80db090557d4b1814729866c9bd..fee2442c15e4d45a48c1c5a9ed41198ce711939e 100644 (file)
  */
 
 #import "config.h"
-#import "WKUserContentControllerPrivate.h"
+#import "WKUserContentControllerInternal.h"
 
 #if WK_API_ENABLED
 
+#import "WKUserScriptInternal.h"
+#import "WebUserContentControllerProxy.h"
 #import "_WKScriptWorld.h"
+#import <WebCore/UserScript.h>
 
-@implementation WKUserContentController
+@implementation WKUserContentController {
+    RetainPtr<NSMutableArray> _userScripts;
+}
+
+- (instancetype)init
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _userContentControllerProxy = WebKit::WebUserContentControllerProxy::create();
+    _userScripts = adoptNS([[NSMutableArray alloc] init]);
+
+    return self;
+}
+
+- (NSArray *)userScripts
+{
+    return _userScripts.get();
+}
+
+static WebCore::UserScriptInjectionTime toWebCoreUserScriptInjectionTime(WKUserScriptInjectionTime injectionTime)
+{
+    switch (injectionTime) {
+    case WKUserScriptInjectionTimeAtDocumentStart:
+        return WebCore::InjectAtDocumentStart;
+
+    case WKUserScriptInjectionTimeAtDocumentEnd:
+        return WebCore::InjectAtDocumentEnd;
+    }
+
+    ASSERT_NOT_REACHED();
+    return WebCore::InjectAtDocumentEnd;
+}
+
+- (void)addUserScript:(WKUserScript *)userScript
+{
+    [_userScripts addObject:userScript];
+
+    _userContentControllerProxy->addUserScript(WebCore::UserScript { userScript->_source.get(), WebCore::blankURL(), { }, { }, toWebCoreUserScriptInjectionTime(userScript->_injectionTime), userScript->_forMainFrameOnly ? WebCore::InjectInTopFrameOnly : WebCore::InjectInAllFrames });
+}
+
+- (void)removeAllUserScripts
+{
+    [_userScripts removeAllObjects];
+
+    _userContentControllerProxy->removeAllUserScripts();
+}
 
 - (void)addScriptMessageHandler:(id <WKScriptMessageHandler>)scriptMessageHandler name:(NSString *)name
 {
diff --git a/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentControllerInternal.h b/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentControllerInternal.h
new file mode 100644 (file)
index 0000000..14d873c
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "WKUserContentControllerPrivate.h"
+
+#if WK_API_ENABLED
+
+#import <wtf/RefPtr.h>
+
+namespace WebKit {
+class WebUserContentControllerProxy;
+}
+
+@interface WKUserContentController () {
+@package
+    RefPtr<WebKit::WebUserContentControllerProxy> _userContentControllerProxy;
+}
+@end
+
+#endif
diff --git a/Source/WebKit2/UIProcess/API/Cocoa/WKUserScript.h b/Source/WebKit2/UIProcess/API/Cocoa/WKUserScript.h
new file mode 100644 (file)
index 0000000..e9d0b30
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <WebKit/WKFoundation.h>
+
+#if WK_API_ENABLED
+
+#import <Foundation/Foundation.h>
+
+/*! @enum WKUserScriptInjectionTime
+ @abstract when a user script should be injected into a web page.
+ @constant WKUserScriptInjectionTimeAtDocumentStart    Inject the script after the document element has been created, but before any other content has been loaded.
+ @constant WKUserScriptInjectionTimeAtDocumentEnd      Inject the script after the document has finished loading, but before any subresources may have finished loading.
+ */
+typedef NS_ENUM(NSInteger, WKUserScriptInjectionTime) {
+    WKUserScriptInjectionTimeAtDocumentStart,
+    WKUserScriptInjectionTimeAtDocumentEnd
+} WK_ENUM_AVAILABLE(10_10, 8_0);
+
+/*! A @link WKUserScript @/link object represents a script that can be injected into web pages.
+ */
+WK_CLASS_AVAILABLE(10_10, 8_0)
+@interface WKUserScript : NSObject <NSCopying>
+
+/*! @abstract Returns an initialized user script that can be added to a @link WKUserContentController @/link.
+ @param source The script source.
+ @param injectionTime When the script should be injected.
+ @param forMainFrameOnly Whether the script should be injected into all frames or just the main frame.
+ */
+- (instancetype)initWithSource:(NSString *)source injectionTime:(WKUserScriptInjectionTime)injectionTime forMainFrameOnly:(BOOL)forMainFrameOnly;
+
+/* @abstract The script source code. */
+@property (nonatomic, readonly) NSString *source;
+
+/* @abstract When the script should be injected. */
+@property (nonatomic, readonly) WKUserScriptInjectionTime injectionTime;
+
+/* @abstract Whether the script should be injected into all frames or just the main frame. */
+@property (nonatomic, readonly, getter=isForMainFrameOnly) BOOL forMainFrameOnly;
+
+@end
+
+#endif
diff --git a/Source/WebKit2/UIProcess/API/Cocoa/WKUserScript.mm b/Source/WebKit2/UIProcess/API/Cocoa/WKUserScript.mm
new file mode 100644 (file)
index 0000000..aae9260
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WKUserScriptInternal.h"
+
+#if WK_API_ENABLED
+
+@implementation WKUserScript
+
+- (instancetype)initWithSource:(NSString *)source injectionTime:(WKUserScriptInjectionTime)injectionTime forMainFrameOnly:(BOOL)forMainFrameOnly
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _source = adoptNS([source copy]);
+    _injectionTime = injectionTime;
+    _forMainFrameOnly = forMainFrameOnly;
+
+    return self;
+}
+
+- (NSString *)source
+{
+    return _source.get();
+}
+
+- (WKUserScriptInjectionTime)injectionTime
+{
+    return _injectionTime;
+}
+
+- (BOOL)isForMainFrameOnly
+{
+    return _forMainFrameOnly;
+}
+
+- (id)copyWithZone:(NSZone *)zone
+{
+    return [self retain];
+}
+
+@end
+
+#endif
diff --git a/Source/WebKit2/UIProcess/API/Cocoa/WKUserScriptInternal.h b/Source/WebKit2/UIProcess/API/Cocoa/WKUserScriptInternal.h
new file mode 100644 (file)
index 0000000..566e7d7
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "WKUserScript.h"
+
+#if WK_API_ENABLED
+
+#import <wtf/RetainPtr.h>
+
+@interface WKUserScript () {
+@package
+    RetainPtr<NSString> _source;
+    WKUserScriptInjectionTime _injectionTime;
+    BOOL _forMainFrameOnly;
+}
+
+@end
+
+#endif
index f65beacca89246c0d06e844cfdf01d5dcc6111c3..7890ca6025216729d0b981d99a1fc7587f45c318 100644 (file)
@@ -48,7 +48,7 @@
 #import "WKPreferencesInternal.h"
 #import "WKProcessPoolInternal.h"
 #import "WKUIDelegate.h"
-#import "WKUserContentController.h"
+#import "WKUserContentControllerInternal.h"
 #import "WKWebViewConfigurationInternal.h"
 #import "WKWebViewContentProvider.h"
 #import "WebBackForwardList.h"
     if (WKWebView *relatedWebView = [_configuration _relatedWebView])
         webPageConfiguration.relatedPage = relatedWebView->_page.get();
 
+    webPageConfiguration.userContentController = [_configuration userContentController]->_userContentControllerProxy.get();
     webPageConfiguration.visitedLinkProvider = [_configuration _visitedLinkProvider]->_visitedLinkProvider.get();
     webPageConfiguration.session = [_configuration _websiteDataStore]->_session.get();
     
diff --git a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp b/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp
new file mode 100644 (file)
index 0000000..405b134
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebUserContentControllerProxy.h"
+
+#include "WebProcessProxy.h"
+#include "WebUserContentControllerMessages.h"
+
+namespace WebKit {
+
+static uint64_t generateIdentifier()
+{
+    static uint64_t identifier;
+
+    return ++identifier;
+}
+
+PassRefPtr<WebUserContentControllerProxy> WebUserContentControllerProxy::create()
+{
+    return adoptRef(new WebUserContentControllerProxy);
+}
+
+WebUserContentControllerProxy::WebUserContentControllerProxy()
+    : m_identifier(generateIdentifier())
+{
+}
+
+WebUserContentControllerProxy::~WebUserContentControllerProxy()
+{
+}
+
+void WebUserContentControllerProxy::addProcess(WebProcessProxy& webProcessProxy)
+{
+    ASSERT(webProcessProxy.state() == WebProcessProxy::State::Running);
+
+    if (!m_processes.add(&webProcessProxy).isNewEntry)
+        return;
+
+    webProcessProxy.connection()->send(Messages::WebUserContentController::AddUserScripts(m_userScripts), m_identifier);
+}
+
+void WebUserContentControllerProxy::removeProcess(WebProcessProxy& webProcessProxy)
+{
+    ASSERT(m_processes.contains(&webProcessProxy));
+
+    m_processes.remove(&webProcessProxy);
+}
+
+void WebUserContentControllerProxy::addUserScript(WebCore::UserScript userScript)
+{
+    m_userScripts.append(std::move(userScript));
+
+    for (auto& processAndCount : m_processes)
+        processAndCount.key->connection()->send(Messages::WebUserContentController::AddUserScripts({ m_userScripts.last() }), m_identifier);
+}
+
+void WebUserContentControllerProxy::removeAllUserScripts()
+{
+    m_userScripts.clear();
+
+    for (auto& processAndCount : m_processes)
+        processAndCount.key->connection()->send(Messages::WebUserContentController::RemoveAllUserScripts(), m_identifier);
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h b/Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h
new file mode 100644 (file)
index 0000000..0ea944b
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebUserContentControllerProxy_h
+#define WebUserContentControllerProxy_h
+
+#include <wtf/HashCountedSet.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+class UserScript;
+}
+
+namespace WebKit {
+
+class WebProcessProxy;
+
+class WebUserContentControllerProxy : public RefCounted<WebUserContentControllerProxy> {
+public:
+    static PassRefPtr<WebUserContentControllerProxy> create();
+    ~WebUserContentControllerProxy();
+
+    uint64_t identifier() const { return m_identifier; }
+
+    void addProcess(WebProcessProxy&);
+    void removeProcess(WebProcessProxy&);
+
+    void addUserScript(WebCore::UserScript);
+    void removeAllUserScripts();
+
+private:
+    explicit WebUserContentControllerProxy();
+
+    uint64_t m_identifier;
+    HashCountedSet<WebProcessProxy*> m_processes;
+
+    Vector<WebCore::UserScript> m_userScripts;
+};
+
+} // namespace WebKit
+
+#endif // WebUserContentControllerProxy_h
index 79b66d414d80e25cdcde82cab8039e5c48051a45..5434cda4e0876bd7666814894628cadb3ba561fa 100644 (file)
@@ -88,6 +88,7 @@
 #include "WebProcessProxy.h"
 #include "WebProtectionSpace.h"
 #include "WebSecurityOrigin.h"
+#include "WebUserContentControllerProxy.h"
 #include <WebCore/DragController.h>
 #include <WebCore/DragData.h>
 #include <WebCore/FloatRect.h>
@@ -263,6 +264,7 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uin
     , m_process(process)
     , m_pageGroup(*configuration.pageGroup)
     , m_preferences(*configuration.preferences)
+    , m_userContentController(configuration.userContentController)
     , m_visitedLinkProvider(*configuration.visitedLinkProvider)
     , m_mainFrame(nullptr)
     , m_userAgent(standardUserAgent())
@@ -358,8 +360,11 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uin
     , m_scrollPinningBehavior(DoNotPin)
     , m_navigationID(0)
 {
-    if (m_process->state() == WebProcessProxy::State::Running)
+    if (m_process->state() == WebProcessProxy::State::Running) {
+        if (m_userContentController)
+            m_userContentController->addProcess(m_process.get());
         m_visitedLinkProvider->addProcess(m_process.get());
+    }
 
     updateViewState();
     updateActivityToken();
@@ -618,8 +623,11 @@ void WebPageProxy::close()
 
     m_isClosed = true;
 
-    if (m_process->state() == WebProcessProxy::State::Running)
+    if (m_process->state() == WebProcessProxy::State::Running) {
+        if (m_userContentController)
+            m_userContentController->removeProcess(m_process.get());
         m_visitedLinkProvider->removeProcess(m_process.get());
+    }
 
     m_backForwardList->pageClosed();
     m_pageClient.pageClosed();
@@ -2898,6 +2906,8 @@ void WebPageProxy::connectionWillOpen(IPC::Connection* connection)
 {
     ASSERT(connection == m_process->connection());
 
+    if (m_userContentController)
+        m_userContentController->addProcess(m_process.get());
     m_visitedLinkProvider->addProcess(m_process.get());
 
     m_process->context().storageManager().setAllowedSessionStorageNamespaceConnection(m_pageID, connection);
@@ -4198,8 +4208,11 @@ void WebPageProxy::resetStateAfterProcessExited()
     // FIXME: It's weird that resetStateAfterProcessExited() is called even though the process is launching.
     ASSERT(m_process->state() == WebProcessProxy::State::Launching || m_process->state() == WebProcessProxy::State::Terminated);
 
-    if (m_process->state() == WebProcessProxy::State::Terminated)
+    if (m_process->state() == WebProcessProxy::State::Terminated) {
+        if (m_userContentController)
+            m_userContentController->removeProcess(m_process.get());
         m_visitedLinkProvider->removeProcess(m_process.get());
+    }
 
     m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID);
 
@@ -4268,6 +4281,7 @@ WebPageCreationParameters WebPageProxy::creationParameters()
     parameters.sessionState = SessionState(m_backForwardList->entries(), m_backForwardList->currentIndex());
     parameters.sessionID = m_session->getID();
     parameters.highestUsedBackForwardItemID = WebBackForwardListItem::highedUsedItemID();
+    parameters.userContentControllerID = m_userContentController ? m_userContentController->identifier() : 0;
     parameters.visitedLinkTableID = m_visitedLinkProvider->identifier();
     parameters.canRunBeforeUnloadConfirmPanel = m_uiClient->canRunBeforeUnloadConfirmPanel();
     parameters.canRunModal = m_canRunModal;
index 2936a6f136816487f36e6cbf2c1d2597bd8d481e..8a1236c6822770b9fb91f7689297881e931f097e 100644 (file)
@@ -163,6 +163,7 @@ class WebMouseEvent;
 class WebOpenPanelResultListenerProxy;
 class WebPageGroup;
 class WebProcessProxy;
+class WebUserContentControllerProxy;
 class WebWheelEvent;
 struct AttributedString;
 struct ColorSpaceData;
@@ -427,7 +428,9 @@ private:
 struct WebPageConfiguration {
     WebPageGroup* pageGroup = nullptr;
     WebPreferences* preferences = nullptr;
+    WebUserContentControllerProxy* userContentController = nullptr;
     VisitedLinkProvider* visitedLinkProvider = nullptr;
+
     API::Session* session = nullptr;
     WebPageProxy* relatedPage = nullptr;
 };
@@ -1454,6 +1457,7 @@ private:
     Ref<WebProcessProxy> m_process;
     Ref<WebPageGroup> m_pageGroup;
     Ref<WebPreferences> m_preferences;
+    const RefPtr<WebUserContentControllerProxy> m_userContentController;
     Ref<VisitedLinkProvider> m_visitedLinkProvider;
 
     RefPtr<WebFrameProxy> m_mainFrame;
index 84d3f8ac6f1868aaea259b5574569e72a3e949b5..a6cf86a11e5c5614dd3535d2b76695a127679118 100644 (file)
                1AAB4A8D1296F0A20023952F /* SandboxExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AAB4A8C1296F0A20023952F /* SandboxExtension.h */; };
                1AAB4AAA1296F1540023952F /* SandboxExtensionMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AAB4AA91296F1540023952F /* SandboxExtensionMac.mm */; };
                1AABFE3A1829C1ED005B070E /* _WKRemoteObjectInterfaceInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AABFE391829C1ED005B070E /* _WKRemoteObjectInterfaceInternal.h */; };
+               1AAF089A19267EE500B6390C /* WKUserScript.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AAF089819267EE500B6390C /* WKUserScript.mm */; };
+               1AAF089B19267EE500B6390C /* WKUserScript.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AAF089919267EE500B6390C /* WKUserScript.h */; settings = {ATTRIBUTES = (Public, ); }; };
+               1AAF089D19267FC800B6390C /* WKUserScriptInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AAF089C19267FC800B6390C /* WKUserScriptInternal.h */; };
+               1AAF08A1192681D100B6390C /* WebUserContentControllerProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AAF089F192681D100B6390C /* WebUserContentControllerProxy.cpp */; };
+               1AAF08A2192681D100B6390C /* WebUserContentControllerProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AAF08A0192681D100B6390C /* WebUserContentControllerProxy.h */; };
+               1AAF08A4192682DA00B6390C /* WKUserContentControllerInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AAF08A3192682DA00B6390C /* WKUserContentControllerInternal.h */; };
+               1AAF08AD1926936700B6390C /* WebUserContentController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AAF08AB1926936700B6390C /* WebUserContentController.cpp */; };
+               1AAF08AE1926936700B6390C /* WebUserContentController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AAF08AC1926936700B6390C /* WebUserContentController.h */; };
+               1AAF08B719269E6D00B6390C /* WebUserContentControllerMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AAF08B519269E6D00B6390C /* WebUserContentControllerMessageReceiver.cpp */; };
+               1AAF08B819269E6D00B6390C /* WebUserContentControllerMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AAF08B619269E6D00B6390C /* WebUserContentControllerMessages.h */; };
                1AAF0C4A12B16334008E49E2 /* ArgumentCodersCF.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AAF0C4812B16334008E49E2 /* ArgumentCodersCF.h */; };
                1AAF0C4B12B16334008E49E2 /* ArgumentCodersCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AAF0C4912B16334008E49E2 /* ArgumentCodersCF.cpp */; };
                1AAF263814687C39004A1E8A /* TiledCoreAnimationDrawingArea.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AAF263614687C39004A1E8A /* TiledCoreAnimationDrawingArea.mm */; };
                1AAB4AA91296F1540023952F /* SandboxExtensionMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SandboxExtensionMac.mm; sourceTree = "<group>"; };
                1AABFE391829C1ED005B070E /* _WKRemoteObjectInterfaceInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKRemoteObjectInterfaceInternal.h; sourceTree = "<group>"; };
                1AADE6FE10D855FC00D3D63D /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = System/Library/Frameworks/ApplicationServices.framework; sourceTree = SDKROOT; };
+               1AAF089819267EE500B6390C /* WKUserScript.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKUserScript.mm; sourceTree = "<group>"; };
+               1AAF089919267EE500B6390C /* WKUserScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKUserScript.h; sourceTree = "<group>"; };
+               1AAF089C19267FC800B6390C /* WKUserScriptInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKUserScriptInternal.h; sourceTree = "<group>"; };
+               1AAF089F192681D100B6390C /* WebUserContentControllerProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebUserContentControllerProxy.cpp; sourceTree = "<group>"; };
+               1AAF08A0192681D100B6390C /* WebUserContentControllerProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebUserContentControllerProxy.h; sourceTree = "<group>"; };
+               1AAF08A3192682DA00B6390C /* WKUserContentControllerInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKUserContentControllerInternal.h; sourceTree = "<group>"; };
+               1AAF08AB1926936700B6390C /* WebUserContentController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebUserContentController.cpp; sourceTree = "<group>"; };
+               1AAF08AC1926936700B6390C /* WebUserContentController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebUserContentController.h; sourceTree = "<group>"; };
+               1AAF08B419269E2400B6390C /* WebUserContentController.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebUserContentController.messages.in; sourceTree = "<group>"; };
+               1AAF08B519269E6D00B6390C /* WebUserContentControllerMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebUserContentControllerMessageReceiver.cpp; sourceTree = "<group>"; };
+               1AAF08B619269E6D00B6390C /* WebUserContentControllerMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebUserContentControllerMessages.h; sourceTree = "<group>"; };
                1AAF0C4812B16334008E49E2 /* ArgumentCodersCF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArgumentCodersCF.h; sourceTree = "<group>"; };
                1AAF0C4912B16334008E49E2 /* ArgumentCodersCF.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = ArgumentCodersCF.cpp; sourceTree = "<group>"; };
                1AAF263614687C39004A1E8A /* TiledCoreAnimationDrawingArea.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TiledCoreAnimationDrawingArea.mm; sourceTree = "<group>"; };
                        path = Plugins;
                        sourceTree = "<group>";
                };
+               1AAF089E192681AC00B6390C /* UserContent */ = {
+                       isa = PBXGroup;
+                       children = (
+                               1AAF089F192681D100B6390C /* WebUserContentControllerProxy.cpp */,
+                               1AAF08A0192681D100B6390C /* WebUserContentControllerProxy.h */,
+                       );
+                       path = UserContent;
+                       sourceTree = "<group>";
+               };
+               1AAF08AA1926930B00B6390C /* UserContent */ = {
+                       isa = PBXGroup;
+                       children = (
+                               1AAF08AB1926936700B6390C /* WebUserContentController.cpp */,
+                               1AAF08AC1926936700B6390C /* WebUserContentController.h */,
+                               1AAF08B419269E2400B6390C /* WebUserContentController.messages.in */,
+                       );
+                       path = UserContent;
+                       sourceTree = "<group>";
+               };
                1AAF0C4712B16328008E49E2 /* cf */ = {
                        isa = PBXGroup;
                        children = (
                                3743925718BC4C60001C8675 /* WKUIDelegatePrivate.h */,
                                1AFA3AC718E61C61003CCBAE /* WKUserContentController.h */,
                                1AFA3AC618E61C61003CCBAE /* WKUserContentController.mm */,
+                               1AAF08A3192682DA00B6390C /* WKUserContentControllerInternal.h */,
                                7CC99A3318EF7B120048C8B4 /* WKUserContentControllerPrivate.h */,
+                               1AAF089919267EE500B6390C /* WKUserScript.h */,
+                               1AAF089819267EE500B6390C /* WKUserScript.mm */,
+                               1AAF089C19267FC800B6390C /* WKUserScriptInternal.h */,
                                1A3CC16518906ACF001E6ED8 /* WKWebView.h */,
                                1A3CC16418906ACF001E6ED8 /* WKWebView.mm */,
                                1ADF59191890528E0043C145 /* WKWebViewConfiguration.h */,
                                3336762B130C9978006C9DE2 /* ResourceCache */,
                                0F59478C187B3B2A00437857 /* Scrolling */,
                                1AAC4DDE16B1CBF6009425E3 /* Storage */,
+                               1AAF08AA1926930B00B6390C /* UserContent */,
                                BC032D5D10F437220058C15A /* WebCoreSupport */,
                                BC032D5E10F4372B0058C15A /* WebPage */,
                                BCE9C0CF1485965D00E33D61 /* WebConnectionToUIProcess.cpp */,
                                1AEFCC0511D01F34008219D3 /* Plugins */,
                                0F594793187B3B4C00437857 /* Scrolling */,
                                1A44B95816B73F8C00B7BBD8 /* Storage */,
+                               1AAF089E192681AC00B6390C /* UserContent */,
                                1AE52F8F19201DA700A1FA37 /* APIContextConfiguration.cpp */,
                                1AE52F9019201DA700A1FA37 /* APIContextConfiguration.h */,
                                BCF69FA11176D01400471A52 /* APINavigationData.cpp */,
                C0CE729D1247E71D00BC0EC4 /* Derived Sources */ = {
                        isa = PBXGroup;
                        children = (
+                               1AAF08B519269E6D00B6390C /* WebUserContentControllerMessageReceiver.cpp */,
+                               1AAF08B619269E6D00B6390C /* WebUserContentControllerMessages.h */,
                                2DE6943B18BD2A68005C15E5 /* SmartMagnificationControllerMessageReceiver.cpp */,
                                2DE6943C18BD2A68005C15E5 /* SmartMagnificationControllerMessages.h */,
                                512F58A012A883AD00629530 /* AuthenticationManagerMessageReceiver.cpp */,
                                1A79D9F218EB5EF100914CC5 /* WKBackForwardListPrivate.h in Headers */,
                                BCCF6B2512C93E7A008F9C35 /* ImageOptions.h in Headers */,
                                1A1E093418861D3800D2DC49 /* WebProgressTrackerClient.h in Headers */,
+                               1AAF08AE1926936700B6390C /* WebUserContentController.h in Headers */,
                                BC64697011DBE603006455B0 /* APIArray.h in Headers */,
                                BCBCB0CB1215E32100DE59CA /* ImmutableDictionary.h in Headers */,
                                BC204EE311C83E98008F3375 /* InjectedBundle.h in Headers */,
                                3760881F150413E900FC82C7 /* WebRenderObject.h in Headers */,
                                51217465164C21370037A5C1 /* WebResourceBuffer.h in Headers */,
                                33367630130C9998006C9DE2 /* WebResourceCacheManager.h in Headers */,
+                               1AAF089B19267EE500B6390C /* WKUserScript.h in Headers */,
                                33367656130C9ECA006C9DE2 /* WebResourceCacheManagerMessages.h in Headers */,
                                2DA944A41884E4F000ED86DB /* GestureTypes.h in Headers */,
                                33367636130C99B2006C9DE2 /* WebResourceCacheManagerProxy.h in Headers */,
                                0F931C1C18C5711900DBA7C3 /* ScrollingTreeOverflowScrollingNodeIOS.h in Headers */,
                                510AFFBA16542048001BA05E /* WebResourceLoader.h in Headers */,
                                51F060E01654317F00F3281B /* WebResourceLoaderMessages.h in Headers */,
+                               1AAF08A4192682DA00B6390C /* WKUserContentControllerInternal.h in Headers */,
                                D3B9484911FF4B6500032B39 /* WebSearchPopupMenu.h in Headers */,
                                1FB00AC9185F76460019142E /* WKWebProcessPlugInPageGroupInternal.h in Headers */,
                                F634445612A885C8000612D8 /* WebSecurityOrigin.h in Headers */,
                                517DD5BF180DA7D30081660B /* DatabaseProcessProxy.h in Headers */,
                                935EEB9B1277617C003322B8 /* WKBundleBackForwardListItem.h in Headers */,
                                51EFC1CF1524E62500C9A938 /* WKBundleDOMWindowExtension.h in Headers */,
+                               1AAF08A2192681D100B6390C /* WebUserContentControllerProxy.h in Headers */,
                                BCD25F1711D6BDE100169B0E /* WKBundleFrame.h in Headers */,
                                BCF049E611FE20F600F86A58 /* WKBundleFramePrivate.h in Headers */,
                                29232DF418B29D6800D0596F /* WKAccessibilityWebPageObjectMac.h in Headers */,
                                BC5D24C216CD706D007D5461 /* WKDOMNodePrivate.h in Headers */,
                                1AABFE3A1829C1ED005B070E /* _WKRemoteObjectInterfaceInternal.h in Headers */,
                                BC5D24C516CD7088007D5461 /* WKDOMRangePrivate.h in Headers */,
+                               1AAF089D19267FC800B6390C /* WKUserScriptInternal.h in Headers */,
                                1A9E328D182165A900F5D04C /* _WKRemoteObjectInterface.h in Headers */,
                                51290993183ACEAF005522A6 /* WebIDBServerConnection.h in Headers */,
                                370F34A31829BE1E009027C8 /* WKNavigationData.h in Headers */,
                                3336763B130C99DC006C9DE2 /* WKResourceCacheManager.h in Headers */,
                                BC8A501511765F5600757573 /* WKRetainPtr.h in Headers */,
                                F634445D12A885E9000612D8 /* WKSecurityOrigin.h in Headers */,
+                               1AAF08B819269E6D00B6390C /* WebUserContentControllerMessages.h in Headers */,
                                BC407604124FF0270068F20A /* WKSerializedScriptValue.h in Headers */,
                                0FCB4E4C18BBE044000FCFC9 /* WKContentView.h in Headers */,
                                37A64E5718F38F4600EB30F1 /* _WKFormInputSession.h in Headers */,
                                1A910072126675C4001842F5 /* FindIndicator.cpp in Sources */,
                                BCE81D8C1319F7EF00241910 /* FontInfo.cpp in Sources */,
                                378E1A4918208CD60031007A /* WKNSString.mm in Sources */,
+                               1AAF08B719269E6D00B6390C /* WebUserContentControllerMessageReceiver.cpp in Sources */,
                                1AD01BCC1905D54900C9C45F /* WKReloadFrameErrorRecoveryAttempter.mm in Sources */,
                                C55CB5B818C2A5D600CA81E1 /* WKFormSelectPicker.mm in Sources */,
                                BC06F43012DBB9B6002D78DE /* GeolocationPermissionRequestManager.cpp in Sources */,
                                1AE4976911FF658E0048B464 /* NPJSObject.cpp in Sources */,
                                1A2D82A4127F4EAB001EB962 /* NPObjectMessageReceiver.cpp in Sources */,
                                1A2D8439127F65D5001EB962 /* NPObjectMessageReceiverMessageReceiver.cpp in Sources */,
+                               1AAF08AD1926936700B6390C /* WebUserContentController.cpp in Sources */,
                                1A2D82A6127F4EAB001EB962 /* NPObjectProxy.cpp in Sources */,
                                1A2D82A8127F4EAB001EB962 /* NPRemoteObjectMap.cpp in Sources */,
                                1A2161B111F37664008AD0F5 /* NPRuntimeObjectMap.cpp in Sources */,
                                BC5744EF12638FB3006F0F12 /* WebPopupItem.cpp in Sources */,
                                0F931C1D18C5711900DBA7C3 /* ScrollingTreeOverflowScrollingNodeIOS.mm in Sources */,
                                D3B9484611FF4B6500032B39 /* WebPopupMenu.cpp in Sources */,
+                               1AAF08A1192681D100B6390C /* WebUserContentControllerProxy.cpp in Sources */,
                                BCC43AC7127B99DE00317F16 /* WebPopupMenuMac.mm in Sources */,
                                BC5750981268F3C6006F0F12 /* WebPopupMenuProxyMac.mm in Sources */,
                                BCD59800112B57BE00EC8C23 /* WebPreferences.cpp in Sources */,
                                BCD0139C110FA420003B8A67 /* WKFrame.cpp in Sources */,
                                BCB9F6A61123DD0D00A137E0 /* WKFramePolicyListener.cpp in Sources */,
                                E1AEA23014687BDB00804569 /* WKFullKeyboardAccessWatcher.mm in Sources */,
+                               1AAF089A19267EE500B6390C /* WKUserScript.mm in Sources */,
                                CDCA85C8132ABA4E00E961DF /* WKFullScreenWindowController.mm in Sources */,
                                1AE00D6B18327C1200087DD7 /* StringReference.cpp in Sources */,
                                BC54CC1312D674EE005C67B0 /* WKGeolocationManager.cpp in Sources */,
index 247f9e7d938bbeca4407c649920ae4eec9ec88c5..e60b2df92968deebd85320a6dad41fdf24313330 100644 (file)
@@ -98,7 +98,7 @@ void WKBundleSetAlwaysAcceptCookies(WKBundleRef bundleRef, bool accept)
     toImpl(bundleRef)->setAlwaysAcceptCookies(accept);
 }
 
-void WKBundleAddUserScript(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, WKBundleScriptWorldRef scriptWorldRef, WKStringRef sourceRef, WKURLRef urlRef, WKArrayRef whitelistRef, WKArrayRef blacklistRef, WKUserScriptInjectionTime injectionTimeRef, WKUserContentInjectedFrames injectedFramesRef)
+void WKBundleAddUserScript(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, WKBundleScriptWorldRef scriptWorldRef, WKStringRef sourceRef, WKURLRef urlRef, WKArrayRef whitelistRef, WKArrayRef blacklistRef, _WKUserScriptInjectionTime injectionTimeRef, WKUserContentInjectedFrames injectedFramesRef)
 {
     toImpl(bundleRef)->addUserScript(toImpl(pageGroupRef), toImpl(scriptWorldRef), toWTFString(sourceRef), toWTFString(urlRef), toImpl(whitelistRef), toImpl(blacklistRef), toUserScriptInjectionTime(injectionTimeRef), toUserContentInjectedFrames(injectedFramesRef));
 }
index e3be56ea8aba930d18692c182a344d132f1c3752..900c8cb37bcb9944cc46557525e19fe0063c8aa2 100644 (file)
@@ -72,7 +72,7 @@ WK_EXPORT WKDataRef WKBundleCreateWKDataFromUInt8Array(WKBundleRef bundle, JSCon
 WK_EXPORT void WKBundleSetAsynchronousSpellCheckingEnabled(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, bool enabled);
 
 // UserContent API
-WK_EXPORT void WKBundleAddUserScript(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKBundleScriptWorldRef scriptWorld, WKStringRef source, WKURLRef url, WKArrayRef whitelist, WKArrayRef blacklist, WKUserScriptInjectionTime injectionTime, WKUserContentInjectedFrames injectedFrames);
+WK_EXPORT void WKBundleAddUserScript(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKBundleScriptWorldRef scriptWorld, WKStringRef source, WKURLRef url, WKArrayRef whitelist, WKArrayRef blacklist, _WKUserScriptInjectionTime injectionTime, WKUserContentInjectedFrames injectedFrames);
 WK_EXPORT void WKBundleAddUserStyleSheet(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKBundleScriptWorldRef scriptWorld, WKStringRef source, WKURLRef url, WKArrayRef whitelist, WKArrayRef blacklist, WKUserContentInjectedFrames injectedFrames);
 WK_EXPORT void WKBundleRemoveUserScript(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKBundleScriptWorldRef scriptWorld, WKURLRef url);
 WK_EXPORT void WKBundleRemoveUserStyleSheet(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKBundleScriptWorldRef scriptWorld, WKURLRef url);
diff --git a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.cpp b/Source/WebKit2/WebProcess/UserContent/WebUserContentController.cpp
new file mode 100644 (file)
index 0000000..6933d0e
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebUserContentController.h"
+
+#include "WebProcess.h"
+#include "WebUserContentControllerMessages.h"
+#include <WebCore/DOMWrapperWorld.h>
+#include <WebCore/ScriptController.h>
+#include <wtf/NeverDestroyed.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+static HashMap<uint64_t, WebUserContentController*>& userContentControllers()
+{
+    static NeverDestroyed<HashMap<uint64_t, WebUserContentController*>> userContentControllers;
+
+    return userContentControllers;
+}
+
+PassRefPtr<WebUserContentController> WebUserContentController::getOrCreate(uint64_t identifier)
+{
+    auto& userContentControllerPtr = userContentControllers().add(identifier, nullptr).iterator->value;
+    if (userContentControllerPtr)
+        return userContentControllerPtr;
+
+    RefPtr<WebUserContentController> userContentController = adoptRef(new WebUserContentController(identifier));
+    userContentControllerPtr = userContentController.get();
+
+    return userContentController.release();
+}
+
+WebUserContentController::WebUserContentController(uint64_t identifier)
+    : m_identifier(identifier)
+    , m_userContentController(*UserContentController::create())
+{
+    WebProcess::shared().addMessageReceiver(Messages::WebUserContentController::messageReceiverName(), m_identifier, *this);
+}
+
+WebUserContentController::~WebUserContentController()
+{
+    ASSERT(userContentControllers().contains(m_identifier));
+
+    WebProcess::shared().removeMessageReceiver(Messages::WebUserContentController::messageReceiverName(), m_identifier);
+
+    userContentControllers().remove(m_identifier);
+}
+
+void WebUserContentController::addUserScripts(const Vector<WebCore::UserScript>& userScripts)
+{
+    for (const auto& userScript : userScripts)
+        m_userContentController->addUserScript(mainThreadNormalWorld(), std::make_unique<WebCore::UserScript>(userScript));
+}
+
+void WebUserContentController::removeAllUserScripts()
+{
+    m_userContentController->removeUserScripts(mainThreadNormalWorld());
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.h b/Source/WebKit2/WebProcess/UserContent/WebUserContentController.h
new file mode 100644 (file)
index 0000000..0f3c580
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebUserContentController_h
+#define WebUserContentController_h
+
+#include "MessageReceiver.h"
+#include <WebCore/UserContentController.h>
+#include <wtf/RefCounted.h>
+
+namespace WebKit {
+
+class WebUserContentController final : public RefCounted<WebUserContentController>, private IPC::MessageReceiver  {
+public:
+    static PassRefPtr<WebUserContentController> getOrCreate(uint64_t identifier);
+    virtual ~WebUserContentController();
+
+    WebCore::UserContentController& userContentController() { return m_userContentController.get(); }
+
+private:
+    explicit WebUserContentController(uint64_t identifier);
+
+    // IPC::MessageReceiver.
+    virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override;
+
+    void addUserScripts(const Vector<WebCore::UserScript>& userScripts);
+    void removeAllUserScripts();
+
+    uint64_t m_identifier;
+    Ref<WebCore::UserContentController> m_userContentController;
+};
+
+} // namespace WebKit
+
+#endif // WebUserContentController_h
diff --git a/Source/WebKit2/WebProcess/UserContent/WebUserContentController.messages.in b/Source/WebKit2/WebProcess/UserContent/WebUserContentController.messages.in
new file mode 100644 (file)
index 0000000..bdd365a
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+messages -> WebUserContentController {
+    AddUserScripts(Vector<WebCore::UserScript> userScripts);
+    RemoveAllUserScripts()
+}
index 6a2c572984b1d18e22b68959c5c368ddb18506e6..72da9595dc9be161aa10f62f416144738eb90a2c 100644 (file)
@@ -92,6 +92,7 @@
 #include "WebProcessProxyMessages.h"
 #include "WebProgressTrackerClient.h"
 #include "WebUndoStep.h"
+#include "WebUserContentController.h"
 #include <JavaScriptCore/APICast.h>
 #include <WebCore/ArchiveResource.h>
 #include <WebCore/Chrome.h>
@@ -270,6 +271,7 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
 #if ENABLE(INPUT_TYPE_COLOR)
     , m_activeColorChooser(0)
 #endif
+    , m_userContentController(parameters.userContentControllerID ? WebUserContentController::getOrCreate(parameters.userContentControllerID) : nullptr)
 #if ENABLE(GEOLOCATION)
     , m_geolocationPermissionRequestManager(this)
 #endif
@@ -342,6 +344,7 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
     pageClients.loaderClientForMainFrame = new WebFrameLoaderClient;
     pageClients.progressTrackerClient = new WebProgressTrackerClient(*this);
 
+    pageClients.userContentController = m_userContentController ? &m_userContentController->userContentController() : nullptr;
     pageClients.visitedLinkStore = VisitedLinkTableController::getOrCreate(parameters.visitedLinkTableID);
 
     m_page = std::make_unique<Page>(pageClients);
index 235a146b77b8217584e79cdafa592e0fc1699331..6f399ab2e6c9b42818314aa777012203212e5a53 100644 (file)
@@ -159,6 +159,7 @@ class WebOpenPanelResultListener;
 class WebPageGroupProxy;
 class WebPopupMenu;
 class WebUndoStep;
+class WebUserContentController;
 class WebVideoFullscreenManager;
 class WebWheelEvent;
 struct AssistedNodeInformation;
@@ -1139,6 +1140,8 @@ private:
     RefPtr<WebOpenPanelResultListener> m_activeOpenPanelResultListener;
     RefPtr<NotificationPermissionRequestManager> m_notificationPermissionRequestManager;
 
+    RefPtr<WebUserContentController> m_userContentController;
+
 #if ENABLE(GEOLOCATION)
     GeolocationPermissionRequestManager m_geolocationPermissionRequestManager;
 #endif