Commit 19fd5912 authored by hyatt@apple.com's avatar hyatt@apple.com

Add support for blacklist patterns to user stylesheets and scripts in addition...

Add support for blacklist patterns to user stylesheets and scripts in addition to whitelist patterns.

Reviewed by Adam Roben.

WebCore: 

* WebCore.base.exp:
* dom/Document.cpp:
(WebCore::Document::pageGroupUserSheets):
* page/Frame.cpp:
(WebCore::Frame::injectUserScriptsForWorld):
* page/PageGroup.cpp:
(WebCore::PageGroup::addUserScript):
(WebCore::PageGroup::addUserStyleSheet):
(WebCore::PageGroup::removeUserContentWithURLForWorld):
(WebCore::PageGroup::removeUserContentForWorld):
* page/PageGroup.h:
* page/UserContentURLPattern.cpp:
(WebCore::UserContentURLPattern::matchesPatterns):
* page/UserContentURLPattern.h:
* page/UserScript.h:
(WebCore::UserScript::UserScript):
(WebCore::UserScript::whitelist):
(WebCore::UserScript::blacklist):
* page/UserStyleSheet.h:
(WebCore::UserStyleSheet::UserStyleSheet):
(WebCore::UserStyleSheet::whitelist):
(WebCore::UserStyleSheet::blacklist):

WebKit/mac: 

* WebView/WebView.mm:
(toStringVector):
(+[WebView _addUserScriptToGroup:source:url:worldID:whitelist:blacklist:injectionTime:]):
(+[WebView _addUserStyleSheetToGroup:source:url:worldID:whitelist:blacklist:]):
* WebView/WebViewPrivate.h:

WebKit/win: 

* Interfaces/IWebViewPrivate.idl:
* WebView.cpp:
(toStringVector):
(WebView::addUserScriptToGroup):
(WebView::addUserStyleSheetToGroup):
* WebView.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49033 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 21a8cae5
2009-10-02 Dave Hyatt <hyatt@apple.com>
Reviewed by Adam Roben.
Add support for blacklist patterns to user stylesheets and scripts in addition to whitelist patterns.
* WebCore.base.exp:
* dom/Document.cpp:
(WebCore::Document::pageGroupUserSheets):
* page/Frame.cpp:
(WebCore::Frame::injectUserScriptsForWorld):
* page/PageGroup.cpp:
(WebCore::PageGroup::addUserScript):
(WebCore::PageGroup::addUserStyleSheet):
(WebCore::PageGroup::removeUserContentWithURLForWorld):
(WebCore::PageGroup::removeUserContentForWorld):
* page/PageGroup.h:
* page/UserContentURLPattern.cpp:
(WebCore::UserContentURLPattern::matchesPatterns):
* page/UserContentURLPattern.h:
* page/UserScript.h:
(WebCore::UserScript::UserScript):
(WebCore::UserScript::whitelist):
(WebCore::UserScript::blacklist):
* page/UserStyleSheet.h:
(WebCore::UserStyleSheet::UserStyleSheet):
(WebCore::UserStyleSheet::whitelist):
(WebCore::UserStyleSheet::blacklist):
2009-10-02 Laszlo Gombos <laszlo.1.gombos@nokia.com> 2009-10-02 Laszlo Gombos <laszlo.1.gombos@nokia.com>
Reviewed by Darin Adler. Reviewed by Darin Adler.
...@@ -721,9 +721,9 @@ __ZN7WebCore9HTMLNames9iframeTagE ...@@ -721,9 +721,9 @@ __ZN7WebCore9HTMLNames9iframeTagE
__ZN7WebCore9HTMLNames9scriptTagE __ZN7WebCore9HTMLNames9scriptTagE
__ZN7WebCore9PageCache11setCapacityEi __ZN7WebCore9PageCache11setCapacityEi
__ZN7WebCore9PageCache27releaseAutoreleasedPagesNowEv __ZN7WebCore9PageCache27releaseAutoreleasedPagesNowEv
__ZN7WebCore9PageGroup13addUserScriptERKNS_6StringERKNS_4KURLERKN3WTF6VectorIS1_Lm0EEEjNS_23UserScriptInjectionTimeE __ZN7WebCore9PageGroup17addUserStyleSheetERKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS7_6VectorIS1_Lm0EEEEESB_j
__ZN7WebCore9PageGroup13addUserScriptERKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS7_6VectorIS1_Lm0EEEEESB_jNS_23UserScriptInjectionTimeE
__ZN7WebCore9PageGroup14addVisitedLinkEPKtm __ZN7WebCore9PageGroup14addVisitedLinkEPKtm
__ZN7WebCore9PageGroup17addUserStyleSheetERKNS_6StringERKNS_4KURLERKN3WTF6VectorIS1_Lm0EEEj
__ZN7WebCore9PageGroup17closeLocalStorageEv __ZN7WebCore9PageGroup17closeLocalStorageEv
__ZN7WebCore9PageGroup20removeAllUserContentEv __ZN7WebCore9PageGroup20removeAllUserContentEv
__ZN7WebCore9PageGroup21removeAllVisitedLinksEv __ZN7WebCore9PageGroup21removeAllVisitedLinksEv
......
...@@ -1969,7 +1969,7 @@ const Vector<RefPtr<CSSStyleSheet> >* Document::pageGroupUserSheets() const ...@@ -1969,7 +1969,7 @@ const Vector<RefPtr<CSSStyleSheet> >* Document::pageGroupUserSheets() const
const UserStyleSheetVector* sheets = it->second; const UserStyleSheetVector* sheets = it->second;
for (unsigned i = 0; i < sheets->size(); ++i) { for (unsigned i = 0; i < sheets->size(); ++i) {
const UserStyleSheet* sheet = sheets->at(i).get(); const UserStyleSheet* sheet = sheets->at(i).get();
if (!UserContentURLPattern::matchesPatterns(url(), sheet->patterns())) if (!UserContentURLPattern::matchesPatterns(url(), sheet->whitelist(), sheet->blacklist()))
continue; continue;
RefPtr<CSSStyleSheet> parsedSheet = CSSStyleSheet::create(const_cast<Document*>(this), sheet->url()); RefPtr<CSSStyleSheet> parsedSheet = CSSStyleSheet::create(const_cast<Document*>(this), sheet->url());
parsedSheet->setIsUserStyleSheet(true); parsedSheet->setIsUserStyleSheet(true);
......
...@@ -881,12 +881,11 @@ void Frame::injectUserScriptsForWorld(unsigned worldID, const UserScriptVector& ...@@ -881,12 +881,11 @@ void Frame::injectUserScriptsForWorld(unsigned worldID, const UserScriptVector&
if (!doc) if (!doc)
return; return;
// FIXME: Need to implement pattern checking.
Vector<ScriptSourceCode> sourceCode; Vector<ScriptSourceCode> sourceCode;
unsigned count = userScripts.size(); unsigned count = userScripts.size();
for (unsigned i = 0; i < count; ++i) { for (unsigned i = 0; i < count; ++i) {
UserScript* script = userScripts[i].get(); UserScript* script = userScripts[i].get();
if (script->injectionTime() == injectionTime && UserContentURLPattern::matchesPatterns(doc->url(), script->patterns())) if (script->injectionTime() == injectionTime && UserContentURLPattern::matchesPatterns(doc->url(), script->whitelist(), script->blacklist()))
sourceCode.append(ScriptSourceCode(script->source(), script->url())); sourceCode.append(ScriptSourceCode(script->source(), script->url()));
} }
script()->evaluateInIsolatedWorld(worldID, sourceCode); script()->evaluateInIsolatedWorld(worldID, sourceCode);
......
...@@ -199,12 +199,12 @@ StorageNamespace* PageGroup::localStorage() ...@@ -199,12 +199,12 @@ StorageNamespace* PageGroup::localStorage()
} }
#endif #endif
void PageGroup::addUserScript(const String& source, const KURL& url, const Vector<String>& patterns, void PageGroup::addUserScript(const String& source, const KURL& url, PassOwnPtr<Vector<String> > whitelist,
unsigned worldID, UserScriptInjectionTime injectionTime) PassOwnPtr<Vector<String> > blacklist, unsigned worldID, UserScriptInjectionTime injectionTime)
{ {
if (worldID == UINT_MAX) if (worldID == UINT_MAX)
return; return;
OwnPtr<UserScript> userScript(new UserScript(source, url, patterns, worldID, injectionTime)); OwnPtr<UserScript> userScript(new UserScript(source, url, whitelist, blacklist, worldID, injectionTime));
if (!m_userScripts) if (!m_userScripts)
m_userScripts.set(new UserScriptMap); m_userScripts.set(new UserScriptMap);
UserScriptVector*& scriptsInWorld = m_userScripts->add(worldID, 0).first->second; UserScriptVector*& scriptsInWorld = m_userScripts->add(worldID, 0).first->second;
...@@ -213,11 +213,12 @@ void PageGroup::addUserScript(const String& source, const KURL& url, const Vecto ...@@ -213,11 +213,12 @@ void PageGroup::addUserScript(const String& source, const KURL& url, const Vecto
scriptsInWorld->append(userScript.release()); scriptsInWorld->append(userScript.release());
} }
void PageGroup::addUserStyleSheet(const String& source, const KURL& url, const Vector<String>& patterns, unsigned worldID) void PageGroup::addUserStyleSheet(const String& source, const KURL& url, PassOwnPtr<Vector<String> > whitelist,
PassOwnPtr<Vector<String> > blacklist, unsigned worldID)
{ {
if (worldID == UINT_MAX) if (worldID == UINT_MAX)
return; return;
OwnPtr<UserStyleSheet> userStyleSheet(new UserStyleSheet(source, url, patterns, worldID)); OwnPtr<UserStyleSheet> userStyleSheet(new UserStyleSheet(source, url, whitelist, blacklist, worldID));
if (!m_userStyleSheets) if (!m_userStyleSheets)
m_userStyleSheets.set(new UserStyleSheetMap); m_userStyleSheets.set(new UserStyleSheetMap);
UserStyleSheetVector*& styleSheetsInWorld = m_userStyleSheets->add(worldID, 0).first->second; UserStyleSheetVector*& styleSheetsInWorld = m_userStyleSheets->add(worldID, 0).first->second;
...@@ -245,8 +246,8 @@ void PageGroup::removeUserContentWithURLForWorld(const KURL& url, unsigned world ...@@ -245,8 +246,8 @@ void PageGroup::removeUserContentWithURLForWorld(const KURL& url, unsigned world
} }
if (scripts->isEmpty()) { if (scripts->isEmpty()) {
m_userScripts->remove(it);
delete it->second; delete it->second;
m_userScripts->remove(it);
} }
} }
} }
...@@ -264,8 +265,8 @@ void PageGroup::removeUserContentWithURLForWorld(const KURL& url, unsigned world ...@@ -264,8 +265,8 @@ void PageGroup::removeUserContentWithURLForWorld(const KURL& url, unsigned world
} }
if (stylesheets->isEmpty()) { if (stylesheets->isEmpty()) {
m_userStyleSheets->remove(it);
delete it->second; delete it->second;
m_userStyleSheets->remove(it);
} }
} }
...@@ -285,8 +286,8 @@ void PageGroup::removeUserContentForWorld(unsigned worldID) ...@@ -285,8 +286,8 @@ void PageGroup::removeUserContentForWorld(unsigned worldID)
if (m_userScripts) { if (m_userScripts) {
UserScriptMap::iterator it = m_userScripts->find(worldID); UserScriptMap::iterator it = m_userScripts->find(worldID);
if (it != m_userScripts->end()) { if (it != m_userScripts->end()) {
m_userScripts->remove(it);
delete it->second; delete it->second;
m_userScripts->remove(it);
} }
} }
...@@ -294,9 +295,9 @@ void PageGroup::removeUserContentForWorld(unsigned worldID) ...@@ -294,9 +295,9 @@ void PageGroup::removeUserContentForWorld(unsigned worldID)
bool sheetsChanged = false; bool sheetsChanged = false;
UserStyleSheetMap::iterator it = m_userStyleSheets->find(worldID); UserStyleSheetMap::iterator it = m_userStyleSheets->find(worldID);
if (it != m_userStyleSheets->end()) { if (it != m_userStyleSheets->end()) {
delete it->second;
m_userStyleSheets->remove(it); m_userStyleSheets->remove(it);
sheetsChanged = true; sheetsChanged = true;
delete it->second;
} }
if (sheetsChanged) { if (sheetsChanged) {
......
...@@ -70,11 +70,14 @@ namespace WebCore { ...@@ -70,11 +70,14 @@ namespace WebCore {
bool hasLocalStorage() { return m_localStorage; } bool hasLocalStorage() { return m_localStorage; }
#endif #endif
void addUserScript(const String& source, const KURL&, const Vector<String>& patterns, void addUserScript(const String& source, const KURL&,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
unsigned worldID, UserScriptInjectionTime); unsigned worldID, UserScriptInjectionTime);
const UserScriptMap* userScripts() const { return m_userScripts.get(); } const UserScriptMap* userScripts() const { return m_userScripts.get(); }
void addUserStyleSheet(const String& source, const KURL&, const Vector<String>& patterns, unsigned worldID); void addUserStyleSheet(const String& source, const KURL&,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
unsigned worldID);
const UserStyleSheetMap* userStyleSheets() const { return m_userStyleSheets.get(); } const UserStyleSheetMap* userStyleSheets() const { return m_userStyleSheets.get(); }
void removeUserContentForWorld(unsigned); void removeUserContentForWorld(unsigned);
......
...@@ -30,19 +30,33 @@ ...@@ -30,19 +30,33 @@
namespace WebCore { namespace WebCore {
bool UserContentURLPattern::matchesPatterns(const KURL& url, const Vector<String>& patterns) bool UserContentURLPattern::matchesPatterns(const KURL& url, const Vector<String>* whitelist, const Vector<String>* blacklist)
{ {
// Treat no patterns at all as though a pattern of * was specified. // In order for a URL to be a match it has to be present in the whitelist and not present in the blacklist.
if (patterns.isEmpty()) // If there is no whitelist at all, then all URLs are assumed to be in the whitelist.
return true; bool matchesWhitelist = !whitelist || whitelist->isEmpty();
if (!matchesWhitelist) {
for (unsigned i = 0; i < whitelist->size(); ++i) {
UserContentURLPattern contentPattern(whitelist->at(i));
if (contentPattern.matches(url)) {
matchesWhitelist = true;
break;
}
}
}
for (unsigned i = 0; i < patterns.size(); ++i) { bool matchesBlacklist = false;
UserContentURLPattern contentPattern(patterns[i]); if (blacklist) {
if (contentPattern.matches(url)) for (unsigned i = 0; i < blacklist->size(); ++i) {
return true; UserContentURLPattern contentPattern(blacklist->at(i));
if (contentPattern.matches(url)) {
matchesBlacklist = true;
break;
}
}
} }
return false; return matchesWhitelist && !matchesBlacklist;
} }
bool UserContentURLPattern::parse(const String& pattern) bool UserContentURLPattern::parse(const String& pattern)
......
...@@ -49,7 +49,7 @@ public: ...@@ -49,7 +49,7 @@ public:
bool matchSubdomains() const { return m_matchSubdomains; } bool matchSubdomains() const { return m_matchSubdomains; }
static bool matchesPatterns(const KURL&, const Vector<String>&); static bool matchesPatterns(const KURL&, const Vector<String>* whitelist, const Vector<String>* blacklist);
private: private:
bool parse(const String& pattern); bool parse(const String& pattern);
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "KURL.h" #include "KURL.h"
#include "UserScriptTypes.h" #include "UserScriptTypes.h"
#include <wtf/OwnPtr.h> #include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/Vector.h> #include <wtf/Vector.h>
namespace WebCore { namespace WebCore {
...@@ -36,11 +37,12 @@ namespace WebCore { ...@@ -36,11 +37,12 @@ namespace WebCore {
class UserScript { class UserScript {
public: public:
UserScript(const String& source, const KURL& url, UserScript(const String& source, const KURL& url,
const Vector<String>& patterns, unsigned worldID, PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserScriptInjectionTime injectionTime) unsigned worldID, UserScriptInjectionTime injectionTime)
: m_source(source) : m_source(source)
, m_url(url) , m_url(url)
, m_patterns(patterns) , m_whitelist(whitelist)
, m_blacklist(blacklist)
, m_worldID(worldID) , m_worldID(worldID)
, m_injectionTime(injectionTime) , m_injectionTime(injectionTime)
{ {
...@@ -48,14 +50,16 @@ public: ...@@ -48,14 +50,16 @@ public:
const String& source() const { return m_source; } const String& source() const { return m_source; }
const KURL& url() const { return m_url; } const KURL& url() const { return m_url; }
const Vector<String>& patterns() const { return m_patterns; } const Vector<String>* whitelist() const { return m_whitelist.get(); }
const Vector<String>* blacklist() const { return m_blacklist.get(); }
unsigned worldID() const { return m_worldID; } unsigned worldID() const { return m_worldID; }
UserScriptInjectionTime injectionTime() const { return m_injectionTime; } UserScriptInjectionTime injectionTime() const { return m_injectionTime; }
private: private:
String m_source; String m_source;
KURL m_url; KURL m_url;
Vector<String> m_patterns; OwnPtr<Vector<String> > m_whitelist;
OwnPtr<Vector<String> > m_blacklist;
unsigned m_worldID; unsigned m_worldID;
UserScriptInjectionTime m_injectionTime; UserScriptInjectionTime m_injectionTime;
}; };
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "KURL.h" #include "KURL.h"
#include "UserStyleSheetTypes.h" #include "UserStyleSheetTypes.h"
#include <wtf/OwnPtr.h> #include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/Vector.h> #include <wtf/Vector.h>
namespace WebCore { namespace WebCore {
...@@ -36,23 +37,27 @@ namespace WebCore { ...@@ -36,23 +37,27 @@ namespace WebCore {
class UserStyleSheet { class UserStyleSheet {
public: public:
UserStyleSheet(const String& source, const KURL& url, UserStyleSheet(const String& source, const KURL& url,
const Vector<String>& patterns, unsigned worldID) PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
unsigned worldID)
: m_source(source) : m_source(source)
, m_url(url) , m_url(url)
, m_patterns(patterns) , m_whitelist(whitelist)
, m_blacklist(blacklist)
, m_worldID(worldID) , m_worldID(worldID)
{ {
} }
const String& source() const { return m_source; } const String& source() const { return m_source; }
const KURL& url() const { return m_url; } const KURL& url() const { return m_url; }
const Vector<String>& patterns() const { return m_patterns; } const Vector<String>* whitelist() const { return m_whitelist.get(); }
const Vector<String>* blacklist() const { return m_blacklist.get(); }
unsigned worldID() const { return m_worldID; } unsigned worldID() const { return m_worldID; }
private: private:
String m_source; String m_source;
KURL m_url; KURL m_url;
Vector<String> m_patterns; OwnPtr<Vector<String> > m_whitelist;
OwnPtr<Vector<String> > m_blacklist;
unsigned m_worldID; unsigned m_worldID;
}; };
......
2009-10-02 Dave Hyatt <hyatt@apple.com>
Reviewed by Adam Roben.
Add support for blacklist patterns to user stylesheets and scripts in addition to whitelist patterns.
* WebView/WebView.mm:
(toStringVector):
(+[WebView _addUserScriptToGroup:source:url:worldID:whitelist:blacklist:injectionTime:]):
(+[WebView _addUserStyleSheetToGroup:source:url:worldID:whitelist:blacklist:]):
* WebView/WebViewPrivate.h:
2009-10-01 Mark Rowe <mrowe@apple.com> 2009-10-01 Mark Rowe <mrowe@apple.com>
Fix the Tiger build. Don't unconditionally enable 3D canvas as it is not supported on Tiger. Fix the Tiger build. Don't unconditionally enable 3D canvas as it is not supported on Tiger.
......
...@@ -2128,7 +2128,23 @@ static inline IMP getMethod(id o, SEL s) ...@@ -2128,7 +2128,23 @@ static inline IMP getMethod(id o, SEL s)
_private->page->focusController()->setActive([[self window] isKeyWindow]); _private->page->focusController()->setActive([[self window] isKeyWindow]);
} }
+ (void)_addUserScriptToGroup:(NSString *)groupName source:(NSString *)source url:(NSURL *)url worldID:(unsigned)worldID patterns:(NSArray *)patterns injectionTime:(WebUserScriptInjectionTime)injectionTime static PassOwnPtr<Vector<String> > toStringVector(NSArray* patterns)
{
// Convert the patterns into Vectors.
NSUInteger count = [patterns count];
if (count == 0)
return 0;
Vector<String>* patternsVector = new Vector<String>;
for (NSUInteger i = 0; i < count; ++i) {
id entry = [patterns objectAtIndex:i];
if ([entry isKindOfClass:[NSString class]])
patternsVector->append(String((NSString*)entry));
}
return patternsVector;
}
+ (void)_addUserScriptToGroup:(NSString *)groupName source:(NSString *)source url:(NSURL *)url worldID:(unsigned)worldID
whitelist:(NSArray *)whitelist blacklist:(NSArray *)blacklist injectionTime:(WebUserScriptInjectionTime)injectionTime
{ {
String group(groupName); String group(groupName);
if (group.isEmpty() || worldID == UINT_MAX) if (group.isEmpty() || worldID == UINT_MAX)
...@@ -2138,20 +2154,12 @@ static inline IMP getMethod(id o, SEL s) ...@@ -2138,20 +2154,12 @@ static inline IMP getMethod(id o, SEL s)
if (!pageGroup) if (!pageGroup)
return; return;
// Convert the patterns into a Vector. pageGroup->addUserScript(source, url, toStringVector(whitelist), toStringVector(blacklist), worldID,
Vector<String> patternsVector;
NSUInteger count = [patterns count];
for (NSUInteger i = 0; i < count; ++i) {
id entry = [patterns objectAtIndex: i];
if ([entry isKindOfClass:[NSString class]])
patternsVector.append(String((NSString*)entry));
}
pageGroup->addUserScript(source, url, patternsVector, worldID,
injectionTime == WebInjectAtDocumentStart ? InjectAtDocumentStart : InjectAtDocumentEnd); injectionTime == WebInjectAtDocumentStart ? InjectAtDocumentStart : InjectAtDocumentEnd);
} }
+ (void)_addUserStyleSheetToGroup:(NSString *)groupName source:(NSString *)source url:(NSURL *)url worldID:(unsigned)worldID patterns:(NSArray *)patterns + (void)_addUserStyleSheetToGroup:(NSString *)groupName source:(NSString *)source url:(NSURL *)url worldID:(unsigned)worldID
whitelist:(NSArray *)whitelist blacklist:(NSArray *)blacklist
{ {
String group(groupName); String group(groupName);
if (group.isEmpty() || worldID == UINT_MAX) if (group.isEmpty() || worldID == UINT_MAX)
...@@ -2160,17 +2168,8 @@ static inline IMP getMethod(id o, SEL s) ...@@ -2160,17 +2168,8 @@ static inline IMP getMethod(id o, SEL s)
PageGroup* pageGroup = PageGroup::pageGroup(group); PageGroup* pageGroup = PageGroup::pageGroup(group);
if (!pageGroup) if (!pageGroup)
return; return;
// Convert the patterns into a Vector. pageGroup->addUserStyleSheet(source, url, toStringVector(whitelist), toStringVector(blacklist), worldID);
Vector<String> patternsVector;
NSUInteger count = [patterns count];
for (NSUInteger i = 0; i < count; ++i) {
id entry = [patterns objectAtIndex: i];
if ([entry isKindOfClass:[NSString class]])
patternsVector.append(String((NSString*)entry));
}
pageGroup->addUserStyleSheet(source, url, patternsVector, worldID);
} }
+ (void)_removeUserContentFromGroup:(NSString *)groupName url:(NSURL *)url worldID:(unsigned)worldID + (void)_removeUserContentFromGroup:(NSString *)groupName url:(NSURL *)url worldID:(unsigned)worldID
......
...@@ -471,8 +471,8 @@ Could be worth adding to the API. ...@@ -471,8 +471,8 @@ Could be worth adding to the API.
// Removes all white list entries created with _whiteListAccessFromOrigin. // Removes all white list entries created with _whiteListAccessFromOrigin.
+ (void)_resetOriginAccessWhiteLists; + (void)_resetOriginAccessWhiteLists;
+ (void)_addUserScriptToGroup:(NSString *)groupName source:(NSString *)source url:(NSURL *)url worldID:(unsigned)worldID patterns:(NSArray *)patterns injectionTime:(WebUserScriptInjectionTime)injectionTime; + (void)_addUserScriptToGroup:(NSString *)groupName source:(NSString *)source url:(NSURL *)url worldID:(unsigned)worldID whitelist:(NSArray *)whitelist blacklist:(NSArray *)blacklist injectionTime:(WebUserScriptInjectionTime)injectionTime;
+ (void)_addUserStyleSheetToGroup:(NSString *)groupName source:(NSString *)source url:(NSURL *)url worldID:(unsigned)worldID patterns:(NSArray *)patterns; + (void)_addUserStyleSheetToGroup:(NSString *)groupName source:(NSString *)source url:(NSURL *)url worldID:(unsigned)worldID whitelist:(NSArray *)whitelist blacklist:(NSArray *)blacklist;
+ (void)_removeUserContentFromGroup:(NSString *)groupName url:(NSURL *)url worldID:(unsigned)worldID; + (void)_removeUserContentFromGroup:(NSString *)groupName url:(NSURL *)url worldID:(unsigned)worldID;
+ (void)_removeUserContentFromGroup:(NSString *)groupName worldID:(unsigned)worldID; + (void)_removeUserContentFromGroup:(NSString *)groupName worldID:(unsigned)worldID;
+ (void)_removeAllUserContentFromGroup:(NSString *)groupName; + (void)_removeAllUserContentFromGroup:(NSString *)groupName;
......
2009-10-02 Dave Hyatt <hyatt@apple.com>
Reviewed by Adam Roben.
Add support for blacklist patterns to user stylesheets and scripts in addition to whitelist patterns.
* Interfaces/IWebViewPrivate.idl:
* WebView.cpp:
(toStringVector):
(WebView::addUserScriptToGroup):
(WebView::addUserStyleSheetToGroup):
* WebView.h:
2009-10-02 Steve Falkenburg <sfalken@apple.com> 2009-10-02 Steve Falkenburg <sfalken@apple.com>
Reviewed by Mark Rowe. Reviewed by Mark Rowe.
......
...@@ -181,8 +181,13 @@ interface IWebViewPrivate : IUnknown ...@@ -181,8 +181,13 @@ interface IWebViewPrivate : IUnknown
HRESULT MIMETypeForExtension([in] BSTR extension, [out, retval] BSTR* mimeType); HRESULT MIMETypeForExtension([in] BSTR extension, [out, retval] BSTR* mimeType);
// For the following functions, 0 < worldID < UINT_MAX. // For the following functions, 0 < worldID < UINT_MAX.
HRESULT addUserScriptToGroup([in] BSTR groupName, [in] unsigned worldID, [in] BSTR source, [in] BSTR url, [in] unsigned patternsCount, [in, size_is(patternsCount)] BSTR* patterns, [in] WebUserScriptInjectionTime injectionTime); HRESULT addUserScriptToGroup([in] BSTR groupName, [in] unsigned worldID, [in] BSTR source, [in] BSTR url,
HRESULT addUserStyleSheetToGroup([in] BSTR groupName, [in] unsigned worldID, [in] BSTR source, [in] BSTR url, [in] unsigned patternsCount, [in, size_is(patternsCount)] BSTR* patterns); [in] unsigned whitelistCount, [in, size_is(whitelistCount)] BSTR* whitelist,
[in] unsigned blacklistCount, [in, size_is(blacklistCount)] BSTR* blacklist,
[in] WebUserScriptInjectionTime injectionTime);
HRESULT addUserStyleSheetToGroup([in] BSTR groupName, [in] unsigned worldID, [in] BSTR source, [in] BSTR url,
[in] unsigned whitelistCount, [in, size_is(whitelistCount)] BSTR* whitelist,
[in] unsigned blacklistCount, [in, size_is(blacklistCount)] BSTR* blacklist);
HRESULT removeUserContentWithURLFromGroup([in] BSTR groupName, [in] unsigned worldID, [in] BSTR url); HRESULT removeUserContentWithURLFromGroup([in] BSTR groupName, [in] unsigned worldID, [in] BSTR url);
HRESULT removeUserContentFromGroup([in] BSTR groupName, [in] unsigned worldID); HRESULT removeUserContentFromGroup([in] BSTR groupName, [in] unsigned worldID);
HRESULT removeAllUserContentFromGroup([in] BSTR groupName); HRESULT removeAllUserContentFromGroup([in] BSTR groupName);
......
...@@ -5433,7 +5433,21 @@ HRESULT WebView::setCanStartPlugins(BOOL canStartPlugins) ...@@ -5433,7 +5433,21 @@ HRESULT WebView::setCanStartPlugins(BOOL canStartPlugins)
return S_OK; return S_OK;
} }
HRESULT WebView::addUserScriptToGroup(BSTR groupName, unsigned worldID, BSTR source, BSTR url, unsigned patternsCount, BSTR* patterns, WebUserScriptInjectionTime injectionTime) static PassOwnPtr<Vector<String> > toStringVector(unsigned patternsCount, BSTR* patterns)
{
// Convert the patterns into a Vector.
if (patternsCount == 0)
return 0;
Vector<String>* patternsVector = new Vector<String>;
for (unsigned i = 0; i < patternsCount; ++i)
patternsVector.append(String(patterns[i], SysStringLen(patterns[i])));
return patternsVector;
}
HRESULT WebView::addUserScriptToGroup(BSTR groupName, unsigned worldID, BSTR source, BSTR url,
unsigned whitelistCount, BSTR* whitelist,
unsigned blacklistCount, BSTR* blacklist,
WebUserScriptInjectionTime injectionTime)
{ {
String group(groupName, SysStringLen(groupName)); String group(groupName, SysStringLen(groupName));
if (group.isEmpty() || !worldID || worldID == numeric_limits<unsigned>::max()) if (group.isEmpty() || !worldID || worldID == numeric_limits<unsigned>::max())
...@@ -5444,18 +5458,16 @@ HRESULT WebView::addUserScriptToGroup(BSTR groupName, unsigned worldID, BSTR sou ...@@ -5444,18 +5458,16 @@ HRESULT WebView::addUserScriptToGroup(BSTR groupName, unsigned worldID, BSTR sou
if (!pageGroup) if (!pageGroup)
return E_FAIL; return E_FAIL;
// Convert the patterns into a Vector. pageGroup->addUserScript(String(source, SysStringLen(source)), KURL(KURL(), String(url, SysStringLen(url))),
Vector<String> patternsVector; toStringVector(whitelist), toStringVector(blacklist), worldID,
for (unsigned i = 0; i < patternsCount; ++i)
patternsVector.append(String(patterns[i], SysStringLen(patterns[i])));
pageGroup->addUserScript(String(source, SysStringLen(source)), KURL(KURL(), String(url, SysStringLen(url))), patternsVector, worldID,
injectionTime == WebInjectAtDocumentStart ? InjectAtDocumentStart : InjectAtDocumentEnd); injectionTime == WebInjectAtDocumentStart ? InjectAtDocumentStart : InjectAtDocumentEnd);
return S_OK; return S_OK;
} }
HRESULT WebView::addUserStyleSheetToGroup(BSTR groupName, unsigned worldID, BSTR source, BSTR url, unsigned patternsCount, BSTR* patterns) HRESULT WebView::addUserStyleSheetToGroup(BSTR groupName, unsigned worldID, BSTR source, BSTR url
unsigned whitelistCount, BSTR* whitelist,
unsigned blacklistCount, BSTR* blacklist)
{ {
String group(groupName, SysStringLen(groupName)); String group(groupName, SysStringLen(groupName));
if (group.isEmpty() || !worldID || worldID == numeric_limits<unsigned>::max()) if (group.isEmpty() || !worldID || worldID == numeric_limits<unsigned>::max())
...@@ -5466,12 +5478,8 @@ HRESULT WebView::addUserStyleSheetToGroup(BSTR groupName, unsigned worldID, BSTR ...@@ -5466,12 +5478,8 @@ HRESULT WebView::addUserStyleSheetToGroup(BSTR groupName, unsigned worldID, BSTR
if (!pageGroup) if (!pageGroup)
return E_FAIL; return E_FAIL;
// Convert the patterns into a Vector. pageGroup->addUserStyleSheet(String(source, SysStringLen(source)), KURL(KURL(), String(url, SysStringLen(url))),
Vector<String> patternsVector; toStringVector(whitelist), toStringVector(blacklist), worldID);
for (unsigned i = 0; i < patternsCount; ++i)
patternsVector.append(String(patterns[i], SysStringLen(patterns[i])));
pageGroup->addUserStyleSheet(String(source, SysStringLen(source)), KURL(KURL(), String(url, SysStringLen(url))), patternsVector, worldID);
return S_OK; return S_OK;
}