Simplify user content in WebKit2 by using WebCore::UserStyleSheet and WebCore::UserSc...
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 14 Oct 2012 23:55:23 +0000 (23:55 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 14 Oct 2012 23:55:23 +0000 (23:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=99276

Reviewed by Anders Carlsson.

Source/WebCore:

Add default constructors for UserScript and UserStyleSheet so they can be used in CoreIPC encoding/decoding.

* page/UserScript.h:
(WebCore::UserScript::UserScript):
(UserScript):
* page/UserStyleSheet.h:
(WebCore::UserStyleSheet::UserStyleSheet):
(UserStyleSheet):

Source/WebKit2:

- Removes UserContentContainer in favor of Vector<UserStyleSheet> and Vector<UserScript> right on WebPageGroupData.
- Adds support for UserScripts, but does not expose API for it just yet.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebKit2.xcodeproj/project.pbxproj:
* win/WebKit2.vcproj:
* Shared/UserContentContainer.cpp: Removed.
* Shared/UserContentContainer.h: Removed.
Remove UserContentContainer.h/cpp.

* Shared/API/c/WKBase.h:
* Shared/API/c/WKSharedAPICast.h:
(WebKit::toUserScriptInjectionTime):
(WebKit::toUserContentInjectedFrames):
* WebProcess/InjectedBundle/API/c/WKBundleAPICast.h:
* WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:
Move UserContent enums to WKBase.h so they can be used from both processes, and move the
casts to WKSharedAPICast.

* Shared/WebCoreArgumentCoders.cpp:
* Shared/WebCoreArgumentCoders.h:
Add coders for UserStyleSheet and UserScript.

* Shared/WebPageGroupData.cpp:
(WebKit::WebPageGroupData::encode):
(WebKit::WebPageGroupData::decode):
* Shared/WebPageGroupData.h:
(WebPageGroupData):
Replace UserContentContainer with Vector<UserStyleSheet> and Vector<UserScript>. Stop using
CoreIPC::In() and CoreIPC::Out(), and instead just call encode/decode multiple times.

* UIProcess/API/C/WKPageGroup.cpp:
(WKPageGroupAddUserStyleSheet):
Pass the parameters with as little conversion as possible to the C++ to avoid doing too much
work in the API layer.

* UIProcess/WebPageGroup.cpp:
(WebKit::toStringVector):
(WebKit::WebPageGroup::addUserStyleSheet):
(WebKit::WebPageGroup::addUserScript):
(WebKit::WebPageGroup::removeAllUserStyleSheets):
(WebKit::WebPageGroup::removeAllUserScripts):
(WebKit::WebPageGroup::removeAllUserContent):
* UIProcess/WebPageGroup.h:
* WebProcess/WebPage/WebPageGroupProxy.cpp:
(WebKit::WebPageGroupProxy::WebPageGroupProxy):
(WebKit::WebPageGroupProxy::addUserStyleSheet):
(WebKit::WebPageGroupProxy::addUserScript):
(WebKit::WebPageGroupProxy::removeAllUserScripts):
(WebKit::WebPageGroupProxy::removeAllUserContent):
* WebProcess/WebPage/WebPageGroupProxy.h:
(WebPageGroupProxy):
* WebProcess/WebPage/WebPageGroupProxy.messages.in:
Add support for user scripts and update to use UserScript and UserStyleSheet directly.

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

25 files changed:
Source/WebCore/ChangeLog
Source/WebCore/page/UserScript.h
Source/WebCore/page/UserStyleSheet.h
Source/WebKit2/CMakeLists.txt
Source/WebKit2/ChangeLog
Source/WebKit2/GNUmakefile.list.am
Source/WebKit2/Shared/API/c/WKBase.h
Source/WebKit2/Shared/API/c/WKSharedAPICast.h
Source/WebKit2/Shared/UserContentContainer.cpp [deleted file]
Source/WebKit2/Shared/UserContentContainer.h [deleted file]
Source/WebKit2/Shared/WebCoreArgumentCoders.cpp
Source/WebKit2/Shared/WebCoreArgumentCoders.h
Source/WebKit2/Shared/WebPageGroupData.cpp
Source/WebKit2/Shared/WebPageGroupData.h
Source/WebKit2/Target.pri
Source/WebKit2/UIProcess/API/C/WKPageGroup.cpp
Source/WebKit2/UIProcess/WebPageGroup.cpp
Source/WebKit2/UIProcess/WebPageGroup.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleAPICast.h
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h
Source/WebKit2/WebProcess/WebPage/WebPageGroupProxy.cpp
Source/WebKit2/WebProcess/WebPage/WebPageGroupProxy.h
Source/WebKit2/WebProcess/WebPage/WebPageGroupProxy.messages.in
Source/WebKit2/win/WebKit2.vcproj

index 9587d0c..8535836 100644 (file)
@@ -1,3 +1,19 @@
+2012-10-14  Sam Weinig  <sam@webkit.org>
+
+        Simplify user content in WebKit2 by using WebCore::UserStyleSheet and WebCore::UserScript directly
+        https://bugs.webkit.org/show_bug.cgi?id=99276
+
+        Reviewed by Anders Carlsson.
+
+        Add default constructors for UserScript and UserStyleSheet so they can be used in CoreIPC encoding/decoding.
+
+        * page/UserScript.h:
+        (WebCore::UserScript::UserScript):
+        (UserScript):
+        * page/UserStyleSheet.h:
+        (WebCore::UserStyleSheet::UserStyleSheet):
+        (UserStyleSheet):
+
 2012-10-14  Jon Lee  <jonlee@apple.com>
 
         Allow notification origin permission request when no js callback is provided
index 40c5cba..8bbfa49 100644 (file)
@@ -36,6 +36,12 @@ namespace WebCore {
 class UserScript {
     WTF_MAKE_FAST_ALLOCATED;
 public:
+    UserScript()
+        : m_injectionTime(InjectAtDocumentStart)
+        , m_injectedFrames(InjectInAllFrames)
+    {
+    }
+
     UserScript(const String& source, const KURL& url, const Vector<String>& whitelist, const Vector<String>& blacklist, UserScriptInjectionTime injectionTime, UserContentInjectedFrames injectedFrames)
         : m_source(source)
         , m_url(url)
index fbc7706..fc67d7a 100644 (file)
@@ -36,6 +36,12 @@ namespace WebCore {
 class UserStyleSheet {
     WTF_MAKE_FAST_ALLOCATED;
 public:
+    UserStyleSheet()
+        : m_injectedFrames(InjectInAllFrames)
+        , m_level(UserStyleUserLevel)
+    {
+    }
+
     UserStyleSheet(const String& source, const KURL& url, const Vector<String>& whitelist, const Vector<String>& blacklist, UserContentInjectedFrames injectedFrames, UserStyleLevel level)
         : m_source(source)
         , m_url(url)
index 20e7d34..8564d98 100644 (file)
@@ -152,7 +152,6 @@ SET(WebKit2_SOURCES
     Shared/StatisticsData.cpp
     Shared/SurfaceUpdateInfo.cpp
     Shared/UpdateInfo.cpp
-    Shared/UserContentContainer.cpp
     Shared/VisitedLinkTable.cpp
     Shared/WebBackForwardListItem.cpp
     Shared/WebBatteryStatus.cpp
index b9ae373..0a23cca 100644 (file)
@@ -1,3 +1,67 @@
+2012-10-14  Sam Weinig  <sam@webkit.org>
+
+        Simplify user content in WebKit2 by using WebCore::UserStyleSheet and WebCore::UserScript directly
+        https://bugs.webkit.org/show_bug.cgi?id=99276
+
+        Reviewed by Anders Carlsson.
+
+        - Removes UserContentContainer in favor of Vector<UserStyleSheet> and Vector<UserScript> right on WebPageGroupData.
+        - Adds support for UserScripts, but does not expose API for it just yet.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebKit2.xcodeproj/project.pbxproj:
+        * win/WebKit2.vcproj:
+        * Shared/UserContentContainer.cpp: Removed.
+        * Shared/UserContentContainer.h: Removed.
+        Remove UserContentContainer.h/cpp.
+
+        * Shared/API/c/WKBase.h:
+        * Shared/API/c/WKSharedAPICast.h:
+        (WebKit::toUserScriptInjectionTime):
+        (WebKit::toUserContentInjectedFrames):
+        * WebProcess/InjectedBundle/API/c/WKBundleAPICast.h:
+        * WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:
+        Move UserContent enums to WKBase.h so they can be used from both processes, and move the
+        casts to WKSharedAPICast.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        * Shared/WebCoreArgumentCoders.h:
+        Add coders for UserStyleSheet and UserScript.
+
+        * Shared/WebPageGroupData.cpp:
+        (WebKit::WebPageGroupData::encode):
+        (WebKit::WebPageGroupData::decode):
+        * Shared/WebPageGroupData.h:
+        (WebPageGroupData):
+        Replace UserContentContainer with Vector<UserStyleSheet> and Vector<UserScript>. Stop using
+        CoreIPC::In() and CoreIPC::Out(), and instead just call encode/decode multiple times.
+
+        * UIProcess/API/C/WKPageGroup.cpp:
+        (WKPageGroupAddUserStyleSheet):
+        Pass the parameters with as little conversion as possible to the C++ to avoid doing too much
+        work in the API layer.
+
+        * UIProcess/WebPageGroup.cpp:
+        (WebKit::toStringVector):
+        (WebKit::WebPageGroup::addUserStyleSheet):
+        (WebKit::WebPageGroup::addUserScript):
+        (WebKit::WebPageGroup::removeAllUserStyleSheets):
+        (WebKit::WebPageGroup::removeAllUserScripts):
+        (WebKit::WebPageGroup::removeAllUserContent):
+        * UIProcess/WebPageGroup.h:
+        * WebProcess/WebPage/WebPageGroupProxy.cpp:
+        (WebKit::WebPageGroupProxy::WebPageGroupProxy):
+        (WebKit::WebPageGroupProxy::addUserStyleSheet):
+        (WebKit::WebPageGroupProxy::addUserScript):
+        (WebKit::WebPageGroupProxy::removeAllUserScripts):
+        (WebKit::WebPageGroupProxy::removeAllUserContent):
+        * WebProcess/WebPage/WebPageGroupProxy.h:
+        (WebPageGroupProxy):
+        * WebProcess/WebPage/WebPageGroupProxy.messages.in:
+        Add support for user scripts and update to use UserScript and UserStyleSheet directly.
+
 2012-10-14  Jon Lee  <jonlee@apple.com>
 
         Allow notification origin permission request when no js callback is provided
index 7f833e1..dcc2af1 100644 (file)
@@ -443,8 +443,6 @@ webkit2_sources += \
        Source/WebKit2/Shared/UserMessageCoders.h \
        Source/WebKit2/Shared/UpdateInfo.cpp \
        Source/WebKit2/Shared/UpdateInfo.h \
-       Source/WebKit2/Shared/UserContentContainer.cpp \
-       Source/WebKit2/Shared/UserContentContainer.h \
        Source/WebKit2/Shared/VisitedLinkTable.cpp \
        Source/WebKit2/Shared/VisitedLinkTable.h \
        Source/WebKit2/Shared/WebBackForwardListItem.cpp \
index f4ea606..1a27610 100644 (file)
@@ -85,6 +85,12 @@ enum WKUserContentInjectedFrames {
 };
 typedef enum WKUserContentInjectedFrames WKUserContentInjectedFrames;
 
+enum WKUserScriptInjectionTime {
+    kWKInjectAtDocumentStart,
+    kWKInjectAtDocumentEnd
+};
+typedef enum WKUserScriptInjectionTime WKUserScriptInjectionTime;
+
 /* WebKit2 main API types */
 
 typedef const struct OpaqueWKApplicationCacheManager* WKApplicationCacheManagerRef;
index 94a77e1..86940ff 100644 (file)
@@ -48,6 +48,8 @@
 #include <WebCore/FrameLoaderTypes.h>
 #include <WebCore/IntRect.h>
 #include <WebCore/LayoutMilestones.h>
+#include <WebCore/UserContentTypes.h>
+#include <WebCore/UserScriptTypes.h>
 #include <wtf/TypeTraits.h>
 
 namespace WebKit {
@@ -811,6 +813,32 @@ inline SnapshotOptions toSnapshotOptions(WKSnapshotOptions wkSnapshotOptions)
     return snapshotOptions;
 }
 
+inline WebCore::UserScriptInjectionTime toUserScriptInjectionTime(WKUserScriptInjectionTime wkInjectedTime)
+{
+    switch (wkInjectedTime) {
+    case kWKInjectAtDocumentStart:
+        return WebCore::InjectAtDocumentStart;
+    case kWKInjectAtDocumentEnd:
+        return WebCore::InjectAtDocumentEnd;
+    }
+
+    ASSERT_NOT_REACHED();
+    return WebCore::InjectAtDocumentStart;
+}
+
+inline WebCore::UserContentInjectedFrames toUserContentInjectedFrames(WKUserContentInjectedFrames wkInjectedFrames)
+{
+    switch (wkInjectedFrames) {
+    case kWKInjectInAllFrames:
+        return WebCore::InjectInAllFrames;
+    case kWKInjectInTopFrameOnly:
+        return WebCore::InjectInTopFrameOnly;
+    }
+
+    ASSERT_NOT_REACHED();
+    return WebCore::InjectInAllFrames;
+}
+
 } // namespace WebKit
 
 #endif // WKSharedAPICast_h
diff --git a/Source/WebKit2/Shared/UserContentContainer.cpp b/Source/WebKit2/Shared/UserContentContainer.cpp
deleted file mode 100644 (file)
index 505e225..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (C) 2012 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 "UserContentContainer.h"
-
-#include "ArgumentCoders.h"
-#include "ArgumentEncoder.h"
-#include "Arguments.h"
-
-namespace WebKit {
-
-static Vector<String> toStringVector(ImmutableArray* array)
-{
-    Vector<String> patternVector;
-    if (!array)
-        return patternVector;
-
-    size_t size = array->size();
-    if (!size)
-        return patternVector;
-    
-    patternVector.reserveInitialCapacity(size);
-    for (size_t i = 0; i < size; ++i) {
-        WebString* webString = array->at<WebString>(i);
-        ASSERT(webString);
-        patternVector.uncheckedAppend(webString->string());
-    }
-    
-    return patternVector;
-}
-
-UserContentContainer::Item::Item()
-{
-}
-
-UserContentContainer::Item::Item(PassRefPtr<WebString> source, PassRefPtr<WebURL> url, PassRefPtr<ImmutableArray> whitelist, PassRefPtr<ImmutableArray> blacklist, InjectedFrames injectedFrames, Type type)
-    : m_source(source)
-    , m_url(url)
-    , m_whitelist(toStringVector(whitelist.get()))
-    , m_blacklist(toStringVector(blacklist.get()))
-    , m_injectedFrames(injectedFrames)
-    , m_type(type)
-{
-    ASSERT(m_source);
-}
-
-void UserContentContainer::Item::encode(CoreIPC::ArgumentEncoder* encoder) const
-{
-    encoder->encode(m_source->string());
-    encoder->encode(m_url ? m_url->string() : String());
-    encoder->encode(m_whitelist);
-    encoder->encode(m_blacklist);
-    encoder->encode(static_cast<uint32_t>(m_injectedFrames));
-    encoder->encode(static_cast<uint32_t>(m_type));
-}
-
-bool UserContentContainer::Item::decode(CoreIPC::ArgumentDecoder* decoder, UserContentContainer::Item& item)
-{
-    ASSERT(!item.m_source);
-    ASSERT(!item.m_url);
-    ASSERT(item.m_whitelist.isEmpty());
-    ASSERT(item.m_blacklist.isEmpty());
-
-    String source;
-    if (!decoder->decode(source))
-        return false;
-    item.m_source = WebString::create(source);
-
-    String url;
-    if (!decoder->decode(url))
-        return false;
-    item.m_url = WebURL::create(url);
-
-    if (!decoder->decode(item.m_whitelist))
-        return false;
-    if (!decoder->decode(item.m_blacklist))
-        return false;
-
-    uint32_t injectedFrames;
-    if (!decoder->decode(injectedFrames))
-        return false;
-    item.m_injectedFrames = static_cast<InjectedFrames>(injectedFrames);
-
-    uint32_t type;
-    if (!decoder->decode(type))
-        return false;
-    item.m_type = static_cast<Type>(type);
-
-    return true;
-}
-
-void UserContentContainer::encode(CoreIPC::ArgumentEncoder* encoder) const
-{
-    encoder->encode(m_userContent);
-}
-
-bool UserContentContainer::decode(CoreIPC::ArgumentDecoder* decoder, UserContentContainer& userContentContainer)
-{
-    ASSERT(userContentContainer.m_userContent.isEmpty());
-    if (!decoder->decode(userContentContainer.m_userContent))
-        return false;
-    return true;
-}
-
-} // namespace WebKit
diff --git a/Source/WebKit2/Shared/UserContentContainer.h b/Source/WebKit2/Shared/UserContentContainer.h
deleted file mode 100644 (file)
index 807f46c..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2012 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 UserContentContainer_h
-#define UserContentContainer_h
-
-#include "ImmutableArray.h"
-#include "WebString.h"
-#include "WebURL.h"
-#include <WebCore/KURL.h>
-#include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
-
-namespace CoreIPC {
-class ArgumentDecoder;
-class ArgumentEncoder;
-}
-
-namespace WebKit {
-
-class UserContentContainer {
-public:
-    class Item {
-    public:
-        enum Type {
-            TypeStylesheet,
-            TypeScript
-        };
-        
-        enum InjectedFrames {
-            InjectInAllFrames,
-            InjectInTopFrameOnly
-        };
-
-        Item();
-        Item(PassRefPtr<WebString> source, PassRefPtr<WebURL>, PassRefPtr<ImmutableArray> whitelist, PassRefPtr<ImmutableArray> blacklist, InjectedFrames, Type);
-
-        void encode(CoreIPC::ArgumentEncoder*) const;
-        static bool decode(CoreIPC::ArgumentDecoder*, Item&);
-        
-        const String& source() const { return m_source->string(); }
-        WebCore::KURL url() const { return !m_url || m_url->string().isEmpty() ? WebCore::blankURL() : WebCore::KURL(WebCore::KURL(), m_url->string()); }
-        const Vector<String>& whitelist() const { return m_whitelist; }
-        const Vector<String>& blacklist() const { return m_blacklist; }
-        InjectedFrames injectedFrames() const { return m_injectedFrames; }
-        Type type() const { return m_type; }
-
-    private:
-        RefPtr<WebString> m_source;
-        RefPtr<WebURL> m_url;
-        Vector<String> m_whitelist;
-        Vector<String> m_blacklist;
-        InjectedFrames m_injectedFrames;
-        Type m_type;
-    };
-
-    void encode(CoreIPC::ArgumentEncoder*) const;
-    static bool decode(CoreIPC::ArgumentDecoder*, UserContentContainer&);
-    
-    void addItem(const Item& item) { m_userContent.append(item); }
-    void removeAllItems() { m_userContent.clear(); }
-    
-    size_t size() const { return m_userContent.size(); }
-    const Item& at(size_t i) const { return m_userContent.at(i); }
-
-private:
-    Vector<UserContentContainer::Item> m_userContent;
-};
-
-} // namespace WebKit
-
-#endif // UserContentContainer
index 0412466..c25ea95 100644 (file)
@@ -45,6 +45,8 @@
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/ResourceResponse.h>
 #include <WebCore/TextCheckerClient.h>
+#include <WebCore/UserScript.h>
+#include <WebCore/UserStyleSheet.h>
 #include <WebCore/ViewportArguments.h>
 #include <WebCore/WindowFeatures.h>
 #include <wtf/text/StringHash.h>
@@ -1038,4 +1040,84 @@ bool ArgumentCoder<WebCore::GraphicsSurfaceToken>::decode(ArgumentDecoder* decod
 
 #endif
 
+void ArgumentCoder<WebCore::UserStyleSheet>::encode(ArgumentEncoder* encoder, const WebCore::UserStyleSheet& userStyleSheet)
+{
+    encoder->encode(userStyleSheet.source());
+    encoder->encode(userStyleSheet.url());
+    encoder->encode(userStyleSheet.whitelist());
+    encoder->encode(userStyleSheet.blacklist());
+    encoder->encodeEnum(userStyleSheet.injectedFrames());
+    encoder->encodeEnum(userStyleSheet.level());
+}
+
+bool ArgumentCoder<WebCore::UserStyleSheet>::decode(ArgumentDecoder* decoder, WebCore::UserStyleSheet& userStyleSheet)
+{
+    String source;
+    if (!decoder->decode(source))
+        return false;
+
+    KURL url;
+    if (!decoder->decode(url))
+        return false;
+
+    Vector<String> whitelist;
+    if (!decoder->decode(whitelist))
+        return false;
+
+    Vector<String> blacklist;
+    if (!decoder->decode(blacklist))
+        return false;
+
+    WebCore::UserContentInjectedFrames injectedFrames;
+    if (!decoder->decodeEnum(injectedFrames))
+        return false;
+
+    WebCore::UserStyleLevel level;
+    if (!decoder->decodeEnum(level))
+        return false;
+
+    userStyleSheet = WebCore::UserStyleSheet(source, url, whitelist, blacklist, injectedFrames, level);
+    return true;
+}
+
+void ArgumentCoder<WebCore::UserScript>::encode(ArgumentEncoder* encoder, const WebCore::UserScript& userScript)
+{
+    encoder->encode(userScript.source());
+    encoder->encode(userScript.url());
+    encoder->encode(userScript.whitelist());
+    encoder->encode(userScript.blacklist());
+    encoder->encodeEnum(userScript.injectionTime());
+    encoder->encodeEnum(userScript.injectedFrames());
+}
+
+bool ArgumentCoder<WebCore::UserScript>::decode(ArgumentDecoder* decoder, WebCore::UserScript& userScript)
+{
+    String source;
+    if (!decoder->decode(source))
+        return false;
+
+    KURL url;
+    if (!decoder->decode(url))
+        return false;
+
+    Vector<String> whitelist;
+    if (!decoder->decode(whitelist))
+        return false;
+
+    Vector<String> blacklist;
+    if (!decoder->decode(blacklist))
+        return false;
+
+    WebCore::UserScriptInjectionTime injectionTime;
+    if (!decoder->decodeEnum(injectionTime))
+        return false;
+
+    WebCore::UserContentInjectedFrames injectedFrames;
+    if (!decoder->decodeEnum(injectedFrames))
+        return false;
+
+    userScript = WebCore::UserScript(source, url, whitelist, blacklist, injectionTime, injectedFrames);
+    return true;
+}
+
 } // namespace CoreIPC
index 342c8fb..581058c 100644 (file)
@@ -49,6 +49,8 @@ namespace WebCore {
     class ResourceError;
     class ResourceRequest;
     class ResourceResponse;
+    class UserStyleSheet;
+    class UserScript;
     struct CompositionUnderline;
     struct DictationAlternative;
     struct DragSession;
@@ -289,6 +291,15 @@ template<> struct ArgumentCoder<WebCore::GraphicsSurfaceToken> {
 #endif
 #endif
 
+template<> struct ArgumentCoder<WebCore::UserStyleSheet> {
+    static void encode(ArgumentEncoder*, const WebCore::UserStyleSheet&);
+    static bool decode(ArgumentDecoder*, WebCore::UserStyleSheet&);
+};
+
+template<> struct ArgumentCoder<WebCore::UserScript> {
+    static void encode(ArgumentEncoder*, const WebCore::UserScript&);
+    static bool decode(ArgumentDecoder*, WebCore::UserScript&);
+};
 
 } // namespace CoreIPC
 
index 489c1c0..c227d85 100644 (file)
 #include "config.h"
 #include "WebPageGroupData.h"
 
-#include "ArgumentCoders.h"
-#include "Arguments.h"
+#include "WebCoreArgumentCoders.h"
 
 namespace WebKit {
 
 void WebPageGroupData::encode(CoreIPC::ArgumentEncoder* encoder) const
 {
-    return encoder->encode(CoreIPC::In(identifer, pageGroupID, visibleToInjectedBundle, visibleToHistoryClient, userStyleSheets));
+    encoder->encode(identifer);
+    encoder->encode(pageGroupID);
+    encoder->encode(visibleToInjectedBundle);
+    encoder->encode(visibleToHistoryClient);
+    encoder->encode(userStyleSheets);
+    encoder->encode(userScripts);
 }
 
 bool WebPageGroupData::decode(CoreIPC::ArgumentDecoder* decoder, WebPageGroupData& data)
 {
-    return decoder->decode(CoreIPC::Out(data.identifer, data.pageGroupID, data.visibleToInjectedBundle, data.visibleToHistoryClient, data.userStyleSheets));
+    if (!decoder->decode(data.identifer))
+        return false;
+    if (!decoder->decode(data.pageGroupID))
+        return false;
+    if (!decoder->decode(data.visibleToInjectedBundle))
+        return false;
+    if (!decoder->decode(data.visibleToHistoryClient))
+        return false;
+    if (!decoder->decode(data.userStyleSheets))
+        return false;
+    if (!decoder->decode(data.userScripts))
+        return false;
+    return true;
 }
 
 } // namespace WebKit
index d97e9d0..b9aa0f8 100644 (file)
 #ifndef WebPageGroupData_h
 #define WebPageGroupData_h
 
-#include "UserContentContainer.h"
+#include <WebCore/UserScript.h>
+#include <WebCore/UserStyleSheet.h>
 #include <wtf/Vector.h>
 #include <wtf/text/WTFString.h>
 
 namespace CoreIPC {
-    class ArgumentDecoder;
-    class ArgumentEncoder;
+class ArgumentDecoder;
+class ArgumentEncoder;
 }
 
 namespace WebKit {
@@ -45,7 +46,9 @@ struct WebPageGroupData {
     uint64_t pageGroupID;
     bool visibleToInjectedBundle;
     bool visibleToHistoryClient;
-    UserContentContainer userStyleSheets;
+
+    Vector<WebCore::UserStyleSheet> userStyleSheets;
+    Vector<WebCore::UserScript> userScripts;
 };
 
 } // namespace WebKit
index e36c528..4f39307 100644 (file)
@@ -96,7 +96,6 @@ HEADERS += \
     Shared/StringPairVector.h \
     Shared/SurfaceUpdateInfo.h \
     Shared/UpdateInfo.h \
-    Shared/UserContentContainer.h \
     Shared/UserMessageCoders.h \
     Shared/VisitedLinkTable.h \
     Shared/WebCoreArgumentCoders.h \
@@ -453,7 +452,6 @@ SOURCES += \
     Shared/StatisticsData.cpp \
     Shared/SurfaceUpdateInfo.cpp \
     Shared/UpdateInfo.cpp \
-    Shared/UserContentContainer.cpp \
     Shared/VisitedLinkTable.cpp \
     Shared/WebBackForwardListItem.cpp \
     Shared/WebBatteryStatus.cpp \
index 99b783c..5559d01 100644 (file)
@@ -60,10 +60,7 @@ WKPreferencesRef WKPageGroupGetPreferences(WKPageGroupRef pageGroupRef)
 
 void WKPageGroupAddUserStyleSheet(WKPageGroupRef pageGroupRef, WKStringRef sourceRef, WKURLRef baseURL, WKArrayRef whitelist, WKArrayRef blacklist, WKUserContentInjectedFrames injectedFrames)
 {
-    if (!sourceRef)
-        return;
-
-    toImpl(pageGroupRef)->addUserStyleSheet(UserContentContainer::Item(toImpl(sourceRef), toImpl(baseURL), toImpl(whitelist), toImpl(blacklist), static_cast<UserContentContainer::Item::InjectedFrames>(injectedFrames), UserContentContainer::Item::TypeStylesheet));
+    toImpl(pageGroupRef)->addUserStyleSheet(toWTFString(sourceRef), toWTFString(baseURL), toImpl(whitelist), toImpl(blacklist), toUserContentInjectedFrames(injectedFrames), WebCore::UserStyleUserLevel);
 }
 
 void WKPageGroupRemoveAllUserStyleSheets(WKPageGroupRef pageGroupRef)
index 730df77..0cdbf81 100644 (file)
@@ -128,17 +128,66 @@ void WebPageGroup::preferencesDidChange()
         page->preferencesDidChange();
     }
 }
+
+static Vector<String> toStringVector(ImmutableArray* array)
+{
+    Vector<String> patternVector;
+    if (!array)
+        return patternVector;
+
+    size_t size = array->size();
+    if (!size)
+        return patternVector;
     
-void WebPageGroup::addUserStyleSheet(const UserContentContainer::Item& styleSheet)
+    patternVector.reserveInitialCapacity(size);
+    for (size_t i = 0; i < size; ++i) {
+        WebString* webString = array->at<WebString>(i);
+        ASSERT(webString);
+        patternVector.uncheckedAppend(webString->string());
+    }
+    
+    return patternVector;
+}
+
+void WebPageGroup::addUserStyleSheet(const String& source, const String& baseURL, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserContentInjectedFrames injectedFrames, WebCore::UserStyleLevel level)
+{
+    if (source.isEmpty())
+        return;
+
+    WebCore::UserStyleSheet userStyleSheet = WebCore::UserStyleSheet(source, (baseURL.isEmpty() ? WebCore::blankURL() : WebCore::KURL(WebCore::KURL(), baseURL)), toStringVector(whitelist), toStringVector(blacklist), injectedFrames, level);
+
+    m_data.userStyleSheets.append(userStyleSheet);
+    sendToAllProcessesInGroup(Messages::WebPageGroupProxy::AddUserStyleSheet(userStyleSheet), m_data.pageGroupID);
+}
+
+void WebPageGroup::addUserScript(const String& source, const String& baseURL, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserContentInjectedFrames injectedFrames, WebCore::UserScriptInjectionTime injectionTime)
 {
-    m_data.userStyleSheets.addItem(styleSheet);
-    sendToAllProcessesInGroup(Messages::WebPageGroupProxy::AddUserStyleSheet(styleSheet), m_data.pageGroupID);
+    if (source.isEmpty())
+        return;
+
+    WebCore::UserScript userScript = WebCore::UserScript(source, (baseURL.isEmpty() ? WebCore::blankURL() : WebCore::KURL(WebCore::KURL(), baseURL)), toStringVector(whitelist), toStringVector(blacklist), injectionTime, injectedFrames);
+
+    m_data.userScripts.append(userScript);
+    sendToAllProcessesInGroup(Messages::WebPageGroupProxy::AddUserScript(userScript), m_data.pageGroupID);
 }
 
 void WebPageGroup::removeAllUserStyleSheets()
 {
-    m_data.userStyleSheets.removeAllItems();
+    m_data.userStyleSheets.clear();
     sendToAllProcessesInGroup(Messages::WebPageGroupProxy::RemoveAllUserStyleSheets(), m_data.pageGroupID);
 }
 
+void WebPageGroup::removeAllUserScripts()
+{
+    m_data.userScripts.clear();
+    sendToAllProcessesInGroup(Messages::WebPageGroupProxy::RemoveAllUserScripts(), m_data.pageGroupID);
+}
+
+void WebPageGroup::removeAllUserContent()
+{
+    m_data.userStyleSheets.clear();
+    m_data.userScripts.clear();
+    sendToAllProcessesInGroup(Messages::WebPageGroupProxy::RemoveAllUserContent(), m_data.pageGroupID);
+}
+
 } // namespace WebKit
index d752fe5..176b9ee 100644 (file)
@@ -59,8 +59,11 @@ public:
     WebPreferences* preferences() const;
     void preferencesDidChange();
     
-    void addUserStyleSheet(const UserContentContainer::Item& styleSheet);
+    void addUserStyleSheet(const String& source, const String& baseURL, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserContentInjectedFrames, WebCore::UserStyleLevel);
+    void addUserScript(const String& source, const String& baseURL, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserContentInjectedFrames, WebCore::UserScriptInjectionTime);
     void removeAllUserStyleSheets();
+    void removeAllUserScripts();
+    void removeAllUserContent();
 
 private:
     WebPageGroup(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient);
index cfac49b..99dfade 100644 (file)
                1CA8B945127C882A00576C2B /* WebInspectorProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CA8B943127C882A00576C2B /* WebInspectorProxyMessageReceiver.cpp */; };
                1CA8B946127C882A00576C2B /* WebInspectorProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CA8B944127C882A00576C2B /* WebInspectorProxyMessages.h */; };
                1CA8B954127C891500576C2B /* WebInspectorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C8E2DAD1278C5B200BC7BD0 /* WebInspectorMac.mm */; };
-               29121707161CE7360057D451 /* UserContentContainer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29121705161CE7360057D451 /* UserContentContainer.cpp */; };
-               29121708161CE7360057D451 /* UserContentContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 29121706161CE7360057D451 /* UserContentContainer.h */; };
                293EBEAB1627D9C9005F89F1 /* WKDOMText.h in Headers */ = {isa = PBXBuildFile; fileRef = 293EBEA91627D9C9005F89F1 /* WKDOMText.h */; settings = {ATTRIBUTES = (Public, ); }; };
                293EBEAC1627D9C9005F89F1 /* WKDOMText.mm in Sources */ = {isa = PBXBuildFile; fileRef = 293EBEAA1627D9C9005F89F1 /* WKDOMText.mm */; };
                29501724162A4504004A9D71 /* WKWebProcessPlugInBrowserContextControllerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 29501723162A4504004A9D71 /* WKWebProcessPlugInBrowserContextControllerPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1CA8B935127C774E00576C2B /* WebInspectorProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebInspectorProxyMac.mm; sourceTree = "<group>"; };
                1CA8B943127C882A00576C2B /* WebInspectorProxyMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebInspectorProxyMessageReceiver.cpp; sourceTree = "<group>"; };
                1CA8B944127C882A00576C2B /* WebInspectorProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebInspectorProxyMessages.h; sourceTree = "<group>"; };
-               29121705161CE7360057D451 /* UserContentContainer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserContentContainer.cpp; sourceTree = "<group>"; };
-               29121706161CE7360057D451 /* UserContentContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserContentContainer.h; sourceTree = "<group>"; };
                293EBEA91627D9C9005F89F1 /* WKDOMText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKDOMText.h; sourceTree = "<group>"; };
                293EBEAA1627D9C9005F89F1 /* WKDOMText.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKDOMText.mm; sourceTree = "<group>"; };
                29501723162A4504004A9D71 /* WKWebProcessPlugInBrowserContextControllerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebProcessPlugInBrowserContextControllerPrivate.h; sourceTree = "<group>"; };
                                BC90A1D0122DD55E00CC8C50 /* WebURLResponse.h */,
                                F6113E24126CE1820057D0A7 /* WebUserContentURLPattern.h */,
                                C0337DD0127A2980008FF4F4 /* WebWheelEvent.cpp */,
-                               29121705161CE7360057D451 /* UserContentContainer.cpp */,
-                               29121706161CE7360057D451 /* UserContentContainer.h */,
                        );
                        path = Shared;
                        sourceTree = "<group>";
                                BC017D0916260FF4007054F5 /* WKDOMElement.h in Headers */,
                                BC017D0B16260FF4007054F5 /* WKDOMInternals.h in Headers */,
                                BC017D0D16260FF4007054F5 /* WKDOMNode.h in Headers */,
-                               29121708161CE7360057D451 /* UserContentContainer.h in Headers */,
                                BC017D2116263308007054F5 /* WKDOMTextIterator.h in Headers */,
                                BC39C4361626366F008BC689 /* WKDOMRange.h in Headers */,
                                BC8F2F2B16273A2C005FACB5 /* WKWebProcessPlugInBrowserContextController.h in Headers */,
                                BC017D0A16260FF4007054F5 /* WKDOMElement.mm in Sources */,
                                BC017D0C16260FF4007054F5 /* WKDOMInternals.mm in Sources */,
                                BC017D0E16260FF4007054F5 /* WKDOMNode.mm in Sources */,
-                               29121707161CE7360057D451 /* UserContentContainer.cpp in Sources */,
                                BC017D2016263308007054F5 /* WKDOMTextIterator.mm in Sources */,
                                BC39C4351626366F008BC689 /* WKDOMRange.mm in Sources */,
                                BC8F2F2A16273A2C005FACB5 /* WKWebProcessPlugInBrowserContextController.mm in Sources */,
index 018ef79..59c3570 100644 (file)
@@ -32,8 +32,6 @@
 #include "WKBundlePrivate.h"
 #include <WebCore/EditorInsertAction.h>
 #include <WebCore/TextAffinity.h>
-#include <WebCore/UserContentTypes.h>
-#include <WebCore/UserScriptTypes.h>
 
 namespace WebCore {
     class CSSStyleDeclaration;
@@ -107,32 +105,6 @@ inline WKAffinityType toAPI(WebCore::EAffinity affinity)
     return kWKAffinityUpstream;
 }
 
-inline WebCore::UserScriptInjectionTime toUserScriptInjectionTime(WKUserScriptInjectionTime wkInjectedTime)
-{
-    switch (wkInjectedTime) {
-    case kWKInjectAtDocumentStart:
-        return WebCore::InjectAtDocumentStart;
-    case kWKInjectAtDocumentEnd:
-        return WebCore::InjectAtDocumentEnd;
-    }
-
-    ASSERT_NOT_REACHED();
-    return WebCore::InjectAtDocumentStart;
-}
-
-inline WebCore::UserContentInjectedFrames toUserContentInjectedFrames(WKUserContentInjectedFrames wkInjectedFrames)
-{
-    switch (wkInjectedFrames) {
-    case kWKInjectInAllFrames:
-        return WebCore::InjectInAllFrames;
-    case kWKInjectInTopFrameOnly:
-        return WebCore::InjectInTopFrameOnly;
-    }
-
-    ASSERT_NOT_REACHED();
-    return WebCore::InjectInAllFrames;
-}
-
 } // namespace WebKit
 
 #endif // WKBundleAPICast_h
index 8c8f62c..369c430 100644 (file)
 extern "C" {
 #endif
 
-enum WKUserScriptInjectionTime {
-    kWKInjectAtDocumentStart,
-    kWKInjectAtDocumentEnd
-};
-typedef enum WKUserScriptInjectionTime WKUserScriptInjectionTime;
-
 // TestRunner only SPI
 WK_EXPORT void WKBundleSetShouldTrackVisitedLinks(WKBundleRef bundle, bool shouldTrackVisitedLinks);
 WK_EXPORT void WKBundleSetAlwaysAcceptCookies(WKBundleRef bundle, bool);
index 0ec7340..25ef329 100644 (file)
@@ -57,12 +57,19 @@ WebPageGroupProxy::WebPageGroupProxy(const WebPageGroupData& data)
     , m_pageGroup(WebCore::PageGroup::pageGroup(m_data.identifer))
 {
     for (size_t i = 0; i < data.userStyleSheets.size(); ++i)
-        addUserStyleSheet(data.userStyleSheets.at(i));
+        addUserStyleSheet(data.userStyleSheets[i]);
+    for (size_t i = 0; i < data.userScripts.size(); ++i)
+        addUserScript(data.userScripts[i]);
 }
 
-void WebPageGroupProxy::addUserStyleSheet(const UserContentContainer::Item& styleSheet)
+void WebPageGroupProxy::addUserStyleSheet(const WebCore::UserStyleSheet& userStyleSheet)
 {
-    m_pageGroup->addUserStyleSheetToWorld(WebCore::mainThreadNormalWorld(), styleSheet.source(), styleSheet.url(), styleSheet.whitelist(), styleSheet.blacklist(), static_cast<WebCore::UserContentInjectedFrames>(styleSheet.injectedFrames()));
+    m_pageGroup->addUserStyleSheetToWorld(WebCore::mainThreadNormalWorld(), userStyleSheet.source(), userStyleSheet.url(), userStyleSheet.whitelist(), userStyleSheet.blacklist(), userStyleSheet.injectedFrames(), userStyleSheet.level());
+}
+
+void WebPageGroupProxy::addUserScript(const WebCore::UserScript& userScript)
+{
+    m_pageGroup->addUserScriptToWorld(WebCore::mainThreadNormalWorld(), userScript.source(), userScript.url(), userScript.whitelist(), userScript.blacklist(), userScript.injectionTime(), userScript.injectedFrames());
 }
 
 void WebPageGroupProxy::removeAllUserStyleSheets()
@@ -70,4 +77,14 @@ void WebPageGroupProxy::removeAllUserStyleSheets()
     m_pageGroup->removeUserStyleSheetsFromWorld(WebCore::mainThreadNormalWorld());
 }
 
+void WebPageGroupProxy::removeAllUserScripts()
+{
+    m_pageGroup->removeUserStyleSheetsFromWorld(WebCore::mainThreadNormalWorld());
+}
+
+void WebPageGroupProxy::removeAllUserContent()
+{
+    m_pageGroup->removeAllUserContent();
+}
+
 } // namespace WebKit
index 41be506..cbb0794 100644 (file)
@@ -63,8 +63,11 @@ private:
     
     void didReceiveWebPageGroupProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
     
-    void addUserStyleSheet(const UserContentContainer::Item& styleSheet);
+    void addUserStyleSheet(const WebCore::UserStyleSheet&);
+    void addUserScript(const WebCore::UserScript&);
     void removeAllUserStyleSheets();
+    void removeAllUserScripts();
+    void removeAllUserContent();
 
     WebPageGroupData m_data;
     WebCore::PageGroup* m_pageGroup;
index 6b5ac18..8ba527a 100644 (file)
@@ -21,6 +21,9 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 messages -> WebPageGroupProxy {
-    AddUserStyleSheet(WebKit::UserContentContainer::Item styleSheet);
+    AddUserStyleSheet(WebCore::UserStyleSheet userStyleSheet);
+    AddUserScript(WebCore::UserScript userScript);
     RemoveAllUserStyleSheets();
+    RemoveAllUserScripts();
+    RemoveAllUserContent();
 }
index 1666c75..ebcd6cc 100755 (executable)
                                >
                        </File>
                        <File
-                               RelativePath="..\Shared\UserContentContainer.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\Shared\UserContentContainer.h"
-                               >
-                       </File>
-                       <File
                                RelativePath="..\Shared\UserMessageCoders.h"
                                >
                        </File>