Commit 1a6cf377 authored by weinig@apple.com's avatar weinig@apple.com

Make UserScript and UserStyleSheet value objects that are copyable

https://bugs.webkit.org/show_bug.cgi?id=99275

Reviewed by Tim Horton.

Source/WebCore:

Simplify UserScript and UserStyleSheet and make them more easily usable
without sticking them in an OwnPtr.

* WebCore.exp.in:
Update exports.

* page/PageGroup.cpp:
(WebCore::PageGroup::addUserScriptToWorld):
(WebCore::PageGroup::addUserStyleSheetToWorld):
* page/PageGroup.h:
(PageGroup):
* page/UserContentURLPattern.cpp:
(WebCore::UserContentURLPattern::matchesPatterns):
* page/UserContentURLPattern.h:
(UserContentURLPattern):
Update to not assume whitelist and blacklist are in Vector<String>*.

* page/UserScript.h:
(UserScript):
(WebCore::UserScript::UserScript):
(WebCore::UserScript::whitelist):
(WebCore::UserScript::blacklist):
* page/UserStyleSheet.h:
(UserStyleSheet):
(WebCore::UserStyleSheet::UserStyleSheet):
(WebCore::UserStyleSheet::whitelist):
(WebCore::UserStyleSheet::blacklist):
Switch OwnPtr<Vector<String> > to Vector<String> and remove Noncopyable restriction.

Source/WebKit/chromium:

* src/WebViewImpl.cpp:
(WebKit::WebView::addUserScript):
(WebKit::WebView::addUserStyleSheet):
Update for new PageGroup function signatures.

Source/WebKit/efl:

* WebCoreSupport/DumpRenderTreeSupportEfl.cpp:
(DumpRenderTreeSupportEfl::addUserScript):
(DumpRenderTreeSupportEfl::addUserStyleSheet):
Update for new PageGroup function signatures.

Source/WebKit/mac:

* WebView/WebView.mm:
(-[WebView _injectMailQuirksScript]):
(-[WebView _injectOutlookQuirksScript]):
Update for new PageGroup function signatures.

Source/WebKit2:

* Shared/UserContentContainer.cpp:
(WebKit::toStringVector):
(WebKit::UserContentContainer::Item::Item):
(WebKit::UserContentContainer::Item::encode):
(WebKit::UserContentContainer::Item::decode):
* Shared/UserContentContainer.h:
(WebKit::UserContentContainer::Item::whitelist):
(WebKit::UserContentContainer::Item::blacklist):
Switch UserContentContainer::Item to store Vector<String> instead of ImmutableArray, easing
transition to new PageGroup function signatures.

* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::toStringVector):
* WebProcess/WebPage/qt/WebPageQt.cpp:
(WebKit::WebPage::setUserScripts):
Update for new PageGroup function signatures.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@131275 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b126f002
2012-10-14 Sam Weinig <sam@webkit.org>
Make UserScript and UserStyleSheet value objects that are copyable
https://bugs.webkit.org/show_bug.cgi?id=99275
Reviewed by Tim Horton.
Simplify UserScript and UserStyleSheet and make them more easily usable
without sticking them in an OwnPtr.
* WebCore.exp.in:
Update exports.
* page/PageGroup.cpp:
(WebCore::PageGroup::addUserScriptToWorld):
(WebCore::PageGroup::addUserStyleSheetToWorld):
* page/PageGroup.h:
(PageGroup):
* page/UserContentURLPattern.cpp:
(WebCore::UserContentURLPattern::matchesPatterns):
* page/UserContentURLPattern.h:
(UserContentURLPattern):
Update to not assume whitelist and blacklist are in Vector<String>*.
* page/UserScript.h:
(UserScript):
(WebCore::UserScript::UserScript):
(WebCore::UserScript::whitelist):
(WebCore::UserScript::blacklist):
* page/UserStyleSheet.h:
(UserStyleSheet):
(WebCore::UserStyleSheet::UserStyleSheet):
(WebCore::UserStyleSheet::whitelist):
(WebCore::UserStyleSheet::blacklist):
Switch OwnPtr<Vector<String> > to Vector<String> and remove Noncopyable restriction.
2012-10-14 Tim Horton <timothy_horton@apple.com>
[wk2] Implement PDFPlugin
......
......@@ -1052,10 +1052,10 @@ __ZN7WebCore9PageGroup14addVisitedLinkEPKtm
__ZN7WebCore9PageGroup17closeLocalStorageEv
__ZN7WebCore9PageGroup18addVisitedLinkHashEy
__ZN7WebCore9PageGroup18numberOfPageGroupsEv
__ZN7WebCore9PageGroup20addUserScriptToWorldEPNS_15DOMWrapperWorldERKN3WTF6StringERKNS_4KURLENS3_10PassOwnPtrINS3_6VectorIS4_Lm0EEEEESD_NS_23UserScriptInjectionTimeENS_25UserContentInjectedFramesE
__ZN7WebCore9PageGroup20addUserScriptToWorldEPNS_15DOMWrapperWorldERKN3WTF6StringERKNS_4KURLERKNS3_6VectorIS4_Lm0EEESD_NS_23UserScriptInjectionTimeENS_25UserContentInjectedFramesE
__ZN7WebCore9PageGroup20removeAllUserContentEv
__ZN7WebCore9PageGroup21removeAllVisitedLinksEv
__ZN7WebCore9PageGroup24addUserStyleSheetToWorldEPNS_15DOMWrapperWorldERKN3WTF6StringERKNS_4KURLENS3_10PassOwnPtrINS3_6VectorIS4_Lm0EEEEESD_NS_25UserContentInjectedFramesENS_14UserStyleLevelENS_22UserStyleInjectionTimeE
__ZN7WebCore9PageGroup24addUserStyleSheetToWorldEPNS_15DOMWrapperWorldERKN3WTF6StringERKNS_4KURLERKNS3_6VectorIS4_Lm0EEESD_NS_25UserContentInjectedFramesENS_14UserStyleLevelENS_22UserStyleInjectionTimeE
__ZN7WebCore9PageGroup25removeUserScriptFromWorldEPNS_15DOMWrapperWorldERKNS_4KURLE
__ZN7WebCore9PageGroup26removeUserScriptsFromWorldEPNS_15DOMWrapperWorldE
__ZN7WebCore9PageGroup26setShouldTrackVisitedLinksEb
......
......@@ -262,7 +262,7 @@ StorageNamespace* PageGroup::localStorage()
}
void PageGroup::addUserScriptToWorld(DOMWrapperWorld* world, const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
const Vector<String>& whitelist, const Vector<String>& blacklist,
UserScriptInjectionTime injectionTime, UserContentInjectedFrames injectedFrames)
{
ASSERT_ARG(world, world);
......@@ -277,7 +277,7 @@ void PageGroup::addUserScriptToWorld(DOMWrapperWorld* world, const String& sourc
}
void PageGroup::addUserStyleSheetToWorld(DOMWrapperWorld* world, const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
const Vector<String>& whitelist, const Vector<String>& blacklist,
UserContentInjectedFrames injectedFrames,
UserStyleLevel level,
UserStyleInjectionTime injectionTime)
......
......@@ -83,10 +83,10 @@ namespace WebCore {
bool hasLocalStorage() { return m_localStorage; }
void addUserScriptToWorld(DOMWrapperWorld*, const String& source, const KURL&,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
const Vector<String>& whitelist, const Vector<String>& blacklist,
UserScriptInjectionTime, UserContentInjectedFrames);
void addUserStyleSheetToWorld(DOMWrapperWorld*, const String& source, const KURL&,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
const Vector<String>& whitelist, const Vector<String>& blacklist,
UserContentInjectedFrames,
UserStyleLevel level = UserStyleUserLevel,
UserStyleInjectionTime injectionTime = InjectInExistingDocuments);
......
......@@ -25,19 +25,21 @@
#include "config.h"
#include "UserContentURLPattern.h"
#include "KURL.h"
#include <wtf/StdLibExtras.h>
namespace WebCore {
bool UserContentURLPattern::matchesPatterns(const KURL& url, const Vector<String>* whitelist, const Vector<String>* blacklist)
bool UserContentURLPattern::matchesPatterns(const KURL& url, const Vector<String>& whitelist, const Vector<String>& blacklist)
{
// In order for a URL to be a match it has to be present in the whitelist and not present in the blacklist.
// If there is no whitelist at all, then all URLs are assumed to be in the whitelist.
bool matchesWhitelist = !whitelist || whitelist->isEmpty();
bool matchesWhitelist = whitelist.isEmpty();
if (!matchesWhitelist) {
for (unsigned i = 0; i < whitelist->size(); ++i) {
UserContentURLPattern contentPattern(whitelist->at(i));
size_t whitelistSize = whitelist.size();
for (size_t i = 0; i < whitelistSize; ++i) {
UserContentURLPattern contentPattern(whitelist[i]);
if (contentPattern.matches(url)) {
matchesWhitelist = true;
break;
......@@ -46,9 +48,10 @@ bool UserContentURLPattern::matchesPatterns(const KURL& url, const Vector<String
}
bool matchesBlacklist = false;
if (blacklist) {
for (unsigned i = 0; i < blacklist->size(); ++i) {
UserContentURLPattern contentPattern(blacklist->at(i));
if (!blacklist.isEmpty()) {
size_t blacklistSize = blacklist.size();
for (size_t i = 0; i < blacklistSize; ++i) {
UserContentURLPattern contentPattern(blacklist[i]);
if (contentPattern.matches(url)) {
matchesBlacklist = true;
break;
......
......@@ -53,7 +53,7 @@ public:
bool matchSubdomains() const { return m_matchSubdomains; }
static bool matchesPatterns(const KURL&, const Vector<String>* whitelist, const Vector<String>* blacklist);
static bool matchesPatterns(const KURL&, const Vector<String>& whitelist, const Vector<String>& blacklist);
private:
bool parse(const String& pattern);
......
......@@ -29,18 +29,14 @@
#include "KURL.h"
#include "UserContentTypes.h"
#include "UserScriptTypes.h"
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
class UserScript {
WTF_MAKE_NONCOPYABLE(UserScript); WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_FAST_ALLOCATED;
public:
UserScript(const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserScriptInjectionTime injectionTime, UserContentInjectedFrames injectedFrames)
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)
, m_whitelist(whitelist)
......@@ -52,16 +48,16 @@ public:
const String& source() const { return m_source; }
const KURL& url() const { return m_url; }
const Vector<String>* whitelist() const { return m_whitelist.get(); }
const Vector<String>* blacklist() const { return m_blacklist.get(); }
const Vector<String>& whitelist() const { return m_whitelist; }
const Vector<String>& blacklist() const { return m_blacklist; }
UserScriptInjectionTime injectionTime() const { return m_injectionTime; }
UserContentInjectedFrames injectedFrames() const { return m_injectedFrames; }
private:
String m_source;
KURL m_url;
OwnPtr<Vector<String> > m_whitelist;
OwnPtr<Vector<String> > m_blacklist;
Vector<String> m_whitelist;
Vector<String> m_blacklist;
UserScriptInjectionTime m_injectionTime;
UserContentInjectedFrames m_injectedFrames;
};
......
......@@ -29,18 +29,14 @@
#include "KURL.h"
#include "UserContentTypes.h"
#include "UserStyleSheetTypes.h"
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
class UserStyleSheet {
WTF_MAKE_NONCOPYABLE(UserStyleSheet); WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_FAST_ALLOCATED;
public:
UserStyleSheet(const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserContentInjectedFrames injectedFrames, UserStyleLevel level)
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)
, m_whitelist(whitelist)
......@@ -52,16 +48,16 @@ public:
const String& source() const { return m_source; }
const KURL& url() const { return m_url; }
const Vector<String>* whitelist() const { return m_whitelist.get(); }
const Vector<String>* blacklist() const { return m_blacklist.get(); }
const Vector<String>& whitelist() const { return m_whitelist; }
const Vector<String>& blacklist() const { return m_blacklist; }
UserContentInjectedFrames injectedFrames() const { return m_injectedFrames; }
UserStyleLevel level() const { return m_level; }
private:
String m_source;
KURL m_url;
OwnPtr<Vector<String> > m_whitelist;
OwnPtr<Vector<String> > m_blacklist;
Vector<String> m_whitelist;
Vector<String> m_blacklist;
UserContentInjectedFrames m_injectedFrames;
UserStyleLevel m_level;
};
......
2012-10-14 Sam Weinig <sam@webkit.org>
Make UserScript and UserStyleSheet value objects that are copyable
https://bugs.webkit.org/show_bug.cgi?id=99275
Reviewed by Tim Horton.
* src/WebViewImpl.cpp:
(WebKit::WebView::addUserScript):
(WebKit::WebView::addUserStyleSheet):
Update for new PageGroup function signatures.
2012-10-12 Adam Barth <abarth@webkit.org>
[Chromium] Remove used frameForEnteredContext API
......
......@@ -3512,13 +3512,13 @@ void WebView::addUserScript(const WebString& sourceCode,
WebView::UserScriptInjectAt injectAt,
WebView::UserContentInjectIn injectIn)
{
OwnPtr<Vector<String> > patterns = adoptPtr(new Vector<String>);
Vector<String> patterns;
for (size_t i = 0; i < patternsIn.size(); ++i)
patterns->append(patternsIn[i]);
patterns.append(patternsIn[i]);
PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
RefPtr<DOMWrapperWorld> world(DOMWrapperWorld::createUninitializedWorld());
pageGroup->addUserScriptToWorld(world.get(), sourceCode, WebURL(), patterns.release(), nullptr,
pageGroup->addUserScriptToWorld(world.get(), sourceCode, WebURL(), patterns, Vector<String>(),
static_cast<UserScriptInjectionTime>(injectAt),
static_cast<UserContentInjectedFrames>(injectIn));
}
......@@ -3528,9 +3528,9 @@ void WebView::addUserStyleSheet(const WebString& sourceCode,
WebView::UserContentInjectIn injectIn,
WebView::UserStyleInjectionTime injectionTime)
{
OwnPtr<Vector<String> > patterns = adoptPtr(new Vector<String>);
Vector<String> patterns;
for (size_t i = 0; i < patternsIn.size(); ++i)
patterns->append(patternsIn[i]);
patterns.append(patternsIn[i]);
PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
RefPtr<DOMWrapperWorld> world(DOMWrapperWorld::createUninitializedWorld());
......@@ -3539,7 +3539,7 @@ void WebView::addUserStyleSheet(const WebString& sourceCode,
// callers specify this though, since in other cases the caller will probably want "user" level.
//
// FIXME: It would be nice to populate the URL correctly, instead of passing an empty URL.
pageGroup->addUserStyleSheetToWorld(world.get(), sourceCode, WebURL(), patterns.release(), nullptr,
pageGroup->addUserStyleSheetToWorld(world.get(), sourceCode, WebURL(), patterns, Vector<String>(),
static_cast<UserContentInjectedFrames>(injectIn),
UserStyleAuthorLevel,
static_cast<WebCore::UserStyleInjectionTime>(injectionTime));
......
2012-10-14 Sam Weinig <sam@webkit.org>
Make UserScript and UserStyleSheet value objects that are copyable
https://bugs.webkit.org/show_bug.cgi?id=99275
Reviewed by Tim Horton.
* WebCoreSupport/DumpRenderTreeSupportEfl.cpp:
(DumpRenderTreeSupportEfl::addUserScript):
(DumpRenderTreeSupportEfl::addUserStyleSheet):
Update for new PageGroup function signatures.
2012-10-11 Gyuyoung Kim <gyuyoung.kim@samsung.com>
[EFL] Remove "web" word in web inspector
......
......@@ -296,7 +296,7 @@ void DumpRenderTreeSupportEfl::addUserScript(const Evas_Object* ewkView, const S
DRT_SUPPRT_PAGE_GET_OR_RETURN(ewkView, page);
page->group().addUserScriptToWorld(WebCore::mainThreadNormalWorld(), sourceCode, WebCore::KURL(),
nullptr, nullptr, runAtStart ? WebCore::InjectAtDocumentStart : WebCore::InjectAtDocumentEnd,
Vector<String>(), Vector<String>(), runAtStart ? WebCore::InjectAtDocumentStart : WebCore::InjectAtDocumentEnd,
allFrames ? WebCore::InjectInAllFrames : WebCore::InjectInTopFrameOnly);
}
......@@ -311,7 +311,7 @@ void DumpRenderTreeSupportEfl::addUserStyleSheet(const Evas_Object* ewkView, con
{
DRT_SUPPRT_PAGE_GET_OR_RETURN(ewkView, page);
page->group().addUserStyleSheetToWorld(WebCore::mainThreadNormalWorld(), sourceCode, WebCore::KURL(), nullptr, nullptr, allFrames ? WebCore::InjectInAllFrames : WebCore::InjectInTopFrameOnly);
page->group().addUserStyleSheetToWorld(WebCore::mainThreadNormalWorld(), sourceCode, WebCore::KURL(), Vector<String>(), Vector<String>(), allFrames ? WebCore::InjectInAllFrames : WebCore::InjectInTopFrameOnly);
}
void DumpRenderTreeSupportEfl::clearUserStyleSheets(const Evas_Object* ewkView)
......
......@@ -208,7 +208,7 @@ void DumpRenderTreeSupportGtk::addUserStyleSheet(WebKitWebFrame* frame, const ch
WebKitWebView* webView = getViewFromFrame(frame);
Page* page = core(webView);
page->group().addUserStyleSheetToWorld(mainThreadNormalWorld(), sourceCode, KURL(), nullptr, nullptr, allFrames ? InjectInAllFrames : InjectInTopFrameOnly);
page->group().addUserStyleSheetToWorld(mainThreadNormalWorld(), sourceCode, KURL(), Vector<String>(), Vector<String>(), allFrames ? InjectInAllFrames : InjectInTopFrameOnly);
}
/**
......
2012-10-14 Sam Weinig <sam@webkit.org>
Make UserScript and UserStyleSheet value objects that are copyable
https://bugs.webkit.org/show_bug.cgi?id=99275
Reviewed by Tim Horton.
* WebView/WebView.mm:
(-[WebView _injectMailQuirksScript]):
(-[WebView _injectOutlookQuirksScript]):
Update for new PageGroup function signatures.
2012-10-10 Brady Eidson <beidson@apple.com>
Switch ResourceLoader::resourceData() from SharedBuffer to ResourceBuffer
......
......@@ -682,7 +682,7 @@ static NSString *leakMailQuirksUserScriptContents()
{
static NSString *mailQuirksScriptContents = leakMailQuirksUserScriptContents();
core(self)->group().addUserScriptToWorld(core([WebScriptWorld world]),
mailQuirksScriptContents, KURL(), nullptr, nullptr, InjectAtDocumentEnd, InjectInAllFrames);
mailQuirksScriptContents, KURL(), Vector<String>(), Vector<String>(), InjectAtDocumentEnd, InjectInAllFrames);
}
static bool needsOutlookQuirksScript()
......@@ -703,7 +703,7 @@ static NSString *leakOutlookQuirksUserScriptContents()
{
static NSString *outlookQuirksScriptContents = leakOutlookQuirksUserScriptContents();
core(self)->group().addUserScriptToWorld(core([WebScriptWorld world]),
outlookQuirksScriptContents, KURL(), nullptr, nullptr, InjectAtDocumentEnd, InjectInAllFrames);
outlookQuirksScriptContents, KURL(), Vector<String>(), Vector<String>(), InjectAtDocumentEnd, InjectInAllFrames);
}
static bool shouldRespectPriorityInCSSAttributeSetters()
......@@ -2627,19 +2627,20 @@ static inline IMP getMethod(id o, SEL s)
_private->page->focusController()->setActive([[self window] _hasKeyAppearance]);
}
static PassOwnPtr<Vector<String> > toStringVector(NSArray* patterns)
static Vector<String> toStringVector(NSArray* patterns)
{
// Convert the patterns into Vectors.
Vector<String> patternsVector;
NSUInteger count = [patterns count];
if (count == 0)
return nullptr;
OwnPtr<Vector<String> > patternsVector = adoptPtr(new Vector<String>);
if (!count)
return patternsVector;
for (NSUInteger i = 0; i < count; ++i) {
id entry = [patterns objectAtIndex:i];
if ([entry isKindOfClass:[NSString class]])
patternsVector->append(String((NSString*)entry));
patternsVector.append(String((NSString *)entry));
}
return patternsVector.release();
return patternsVector;
}
+ (void)_addUserScriptToGroup:(NSString *)groupName world:(WebScriptWorld *)world source:(NSString *)source url:(NSURL *)url
......
......@@ -835,7 +835,7 @@ void DumpRenderTreeSupportQt::evaluateScriptInIsolatedWorld(QWebFrame* frame, in
void DumpRenderTreeSupportQt::addUserStyleSheet(QWebPage* page, const QString& sourceCode)
{
page->handle()->page->group().addUserStyleSheetToWorld(mainThreadNormalWorld(), sourceCode, QUrl(), nullptr, nullptr, WebCore::InjectInAllFrames);
page->handle()->page->group().addUserStyleSheetToWorld(mainThreadNormalWorld(), sourceCode, QUrl(), Vector<String>(), Vector<String>(), WebCore::InjectInAllFrames);
}
void DumpRenderTreeSupportQt::removeUserStyleSheets(QWebPage* page)
......
2012-10-14 Sam Weinig <sam@webkit.org>
Make UserScript and UserStyleSheet value objects that are copyable
https://bugs.webkit.org/show_bug.cgi?id=99275
Reviewed by Tim Horton.
* Shared/UserContentContainer.cpp:
(WebKit::toStringVector):
(WebKit::UserContentContainer::Item::Item):
(WebKit::UserContentContainer::Item::encode):
(WebKit::UserContentContainer::Item::decode):
* Shared/UserContentContainer.h:
(WebKit::UserContentContainer::Item::whitelist):
(WebKit::UserContentContainer::Item::blacklist):
Switch UserContentContainer::Item to store Vector<String> instead of ImmutableArray, easing
transition to new PageGroup function signatures.
* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::toStringVector):
* WebProcess/WebPage/qt/WebPageQt.cpp:
(WebKit::WebPage::setUserScripts):
Update for new PageGroup function signatures.
2012-10-14 Tim Horton <timothy_horton@apple.com>
[wk2] Implement PDFPlugin
......
......@@ -32,6 +32,26 @@
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()
{
}
......@@ -39,65 +59,30 @@ 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(whitelist)
, m_blacklist(blacklist)
, m_whitelist(toStringVector(whitelist.get()))
, m_blacklist(toStringVector(blacklist.get()))
, m_injectedFrames(injectedFrames)
, m_type(type)
{
ASSERT(m_source);
}
static void encodeStringArray(CoreIPC::ArgumentEncoder* encoder, ImmutableArray* array)
{
ASSERT(encoder);
uint32_t size = array ? array->size() : 0;
encoder->encode(size);
for (uint32_t i = 0; i < size; ++i) {
WebString* webString = array->at<WebString>(i);
ASSERT(webString);
encoder->encode(webString->string());
}
}
void UserContentContainer::Item::encode(CoreIPC::ArgumentEncoder* encoder) const
{
encoder->encode(m_source->string());
encoder->encode(m_url ? m_url->string() : String());
encodeStringArray(encoder, m_whitelist.get());
encodeStringArray(encoder, m_blacklist.get());
encoder->encode(m_whitelist);
encoder->encode(m_blacklist);
encoder->encode(static_cast<uint32_t>(m_injectedFrames));
encoder->encode(static_cast<uint32_t>(m_type));
}
static bool decodeStringArray(CoreIPC::ArgumentDecoder* decoder, Vector<RefPtr<APIObject> >& vector)
{
ASSERT(decoder);
ASSERT(vector.isEmpty());
uint32_t size;
if (!decoder->decode(size))
return false;
if (!size)
return true;
vector.reserveInitialCapacity(size);
for (uint32_t i = 0; i < size; ++i) {
String string;
if (!decoder->decode(string))
return false;
vector.uncheckedAppend(WebString::create(string));
}
return true;
}
bool UserContentContainer::Item::decode(CoreIPC::ArgumentDecoder* decoder, UserContentContainer::Item& item)
{
ASSERT(!item.m_source);
ASSERT(!item.m_url);
ASSERT(!item.m_whitelist);
ASSERT(!item.m_blacklist);
ASSERT(item.m_whitelist.isEmpty());
ASSERT(item.m_blacklist.isEmpty());
String source;
if (!decoder->decode(source))
......@@ -109,15 +94,10 @@ bool UserContentContainer::Item::decode(CoreIPC::ArgumentDecoder* decoder, UserC
return false;
item.m_url = WebURL::create(url);
Vector<RefPtr<APIObject> > whitelist;
if (!decodeStringArray(decoder, whitelist))
if (!decoder->decode(item.m_whitelist))
return false;
item.m_whitelist = ImmutableArray::adopt(whitelist);
Vector<RefPtr<APIObject> > blacklist;
if (!decodeStringArray(decoder, blacklist))
if (!decoder->decode(item.m_blacklist))
return false;
item.m_blacklist = ImmutableArray::adopt(blacklist);
uint32_t injectedFrames;
if (!decoder->decode(injectedFrames))
......@@ -132,36 +112,6 @@ bool UserContentContainer::Item::decode(CoreIPC::ArgumentDecoder* decoder, UserC
return true;
}
static PassOwnPtr<Vector<String> > toStringVector(ImmutableArray* array)
{
if (!array)
return nullptr;
size_t size = array->size();
if (!size)
return nullptr;
OwnPtr<Vector<String> > stringVector = adoptPtr(new Vector<String>());
stringVector->reserveInitialCapacity(size);
for (size_t i = 0; i < size; ++i) {
WebString* webString = array->at<WebString>(i);
ASSERT(webString);
stringVector->uncheckedAppend(webString->string());
}
return stringVector.release();
}
PassOwnPtr<Vector<String> > UserContentContainer::Item::whitelist() const
{
return toStringVector(m_whitelist.get());
}
PassOwnPtr<Vector<String> > UserContentContainer::Item::blacklist() const
{
return toStringVector(m_blacklist.get());
}
void UserContentContainer::encode(CoreIPC::ArgumentEncoder* encoder) const
{
encoder->encode(m_userContent);
......
......@@ -31,6 +31,7 @@
#include "WebURL.h"
#include <WebCore/KURL.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
namespace CoreIPC {
class ArgumentDecoder;
......@@ -61,16 +62,16 @@ public:
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()); }
PassOwnPtr<Vector<String> > whitelist() const;
PassOwnPtr<Vector<String> > blacklist() const;
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;
RefPtr<ImmutableArray> m_whitelist;
RefPtr<ImmutableArray> m_blacklist;
Vector<String> m_whitelist;
Vector<String> m_blacklist;
InjectedFrames m_injectedFrames;
Type m_type;
};
......
......@@ -426,23 +426,24 @@ bool InjectedBundle::isProcessingUserGesture()
return ScriptController::processingUserGesture();
}
static PassOwnPtr<Vector<String> > toStringVector(ImmutableArray* patterns)
static Vector<String> toStringVector(ImmutableArray* patterns)
{
Vector<String> patternsVector;
if (!patterns)
return nullptr;
return patternsVector;
size_t size = patterns->size();
size_t size = patterns->size();
if (!size)
return nullptr;
return patternsVector;
OwnPtr<Vector<String> > patternsVector = adoptPtr(new Vector<String>);
patternsVector->reserveInitialCapacity(size);
patternsVector.reserveInitialCapacity(size);
for (size_t i = 0; i < size; ++i) {
WebString* entry = patterns->at<WebString>(i);
if (entry)
patternsVector->uncheckedAppend(entry->string());
patternsVector.uncheckedAppend(entry->string());
}
return patternsVector.release();
return patternsVector;
}
void InjectedBundle::addUserScript(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserScriptInjectionTime injectionTime, WebCore::UserContentInjectedFrames injectedFrames)
......
......@@ -423,7 +423,7 @@ void WebPage::setUserScripts(const Vector<String>& scripts)
PageGroup* pageGroup = PageGroup::pageGroup(this->pageGroup()->identifier());
pageGroup->removeUserScriptsFromWorld(mainThreadNormalWorld());