Commit 214f9aca authored by weinig@apple.com's avatar weinig@apple.com

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.

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: http://svn.webkit.org/repository/webkit/trunk@131281 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2ee4bbe6
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
......
......@@ -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)
......
......@@ -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)
......
......@@ -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
......
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
......
......@@ -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 \
......
......@@ -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;
......
......@@ -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
/*
* 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
/*
* 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
......@@ -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
......@@ -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
......
......@@ -26,19 +26,35 @@
#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
......@@ -26,13 +26,14 @@
#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
......
......@@ -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 \
......
......@@ -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)
......
......@@ -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);