Commit f6cbb76a authored by aroben@apple.com's avatar aroben@apple.com

Replace worldIDs with world objects

Part of <http://webkit.org/b/31414> Implement new SPI for dealing with
user scripts/stylesheets and isolated worlds

Reviewed by Sam Weinig.

WebCore:

Covered by existing tests.

* WebCore.base.exp: Update exported symbols to match what now exists
and is needed by WebKit.

* bindings/js/ScheduledAction.cpp:
(WebCore::ScheduledAction::execute): Updated for function rename.

* bindings/js/ScriptController.cpp: Removed code that dealt with
worldIDs.
(WebCore::ScriptController::createWorld): Added. Returns a new world
suitable for use on the main thread.
(WebCore::ScriptController::executeScriptInWorld): Renamed from
executeScriptInIsolatedWorld, since this works just fine with a
"normal" world.

* bindings/js/ScriptController.h: Added createWorld, removed functions
that took worldIDs, renamed executeScriptInIsolatedWorld to
executeScriptInWorld.

* page/Frame.cpp:
(WebCore::Frame::injectUserScripts):
(WebCore::Frame::injectUserScriptsForWorld):
Updated for changes to UserScriptMap and ScriptController.

* page/Frame.h: Changed injectUserScriptsForWorld to take a
DOMWrapperWorld* instead of a worldID.

* page/PageGroup.cpp:
(WebCore::PageGroup::addUserScriptToWorld):
(WebCore::PageGroup::addUserStyleSheetToWorld):
(WebCore::PageGroup::removeUserScriptFromWorld):
(WebCore::PageGroup::removeUserStyleSheetFromWorld):
(WebCore::PageGroup::removeUserScriptsFromWorld):
(WebCore::PageGroup::removeUserStyleSheetsFromWorld):
* page/PageGroup.h:
Changed these functions to take a DOMWrapperWorld* instead of a
worldID. Also updated for changes to UserScript and UserStyleSheet.

* page/UserScript.h:
* page/UserStyleSheet.h: Changed not to hold a worldID, since it was
never used.

* page/UserScriptTypes.h:
* page/UserStyleSheetTypes.h: Changed UserScriptMap and
UserStyleSheetMap to use a RefPtr<DOMWrapperWorld> instead of a
worldID as their key type.

WebKit:

* WebKit.xcodeproj/project.pbxproj: Added WebScriptWorld to the project.

WebKit/mac:

WebScriptWorld is the new object that represents a world.  The only
place worldID is still used is in -[WebFrame
_stringByEvaluatingJavaScriptInIsolatedWorld:WithGlobalObject:FromString:],
but that will change soon.

* WebKit.exp: Export WebScriptWorld.

* WebView/WebFrame.mm:
(-[WebFrame _stringByEvaluatingJavaScriptInIsolatedWorld:WithGlobalObject:FromString:]):
Moved the bizarre world caching/creation logic that DRT depends on
here from the findWorld function in ScriptController.cpp. Updated to
use ScriptController::executeScriptInWorld instead of
ScriptController::executeScriptInIsolatedWorld.
(-[WebFrame _contextForWorld:]): Renamed from contextForWorldID:. Now
takes a WebScriptWorld.

* WebView/WebFramePrivate.h: Replaced contextForWorldID: with
_contextForWorld:.

* WebView/WebScriptWorld.h: Added.
* WebView/WebScriptWorld.mm: Added.
(-[WebScriptWorld initWithWorld:]): Store the passed-in world in our
_private member.
(-[WebScriptWorld init]): Create a new DOMWrapperWorld and pass it to
-initWithWorld:.
(-[WebScriptWorld dealloc]): Release _private.
(+[WebScriptWorld standardWorld]): Returns a shared instance that
represents WebCore's mainThreadNormalWorld().
(+[WebScriptWorld world]): Returns a new instance.
(core): Returns the DOMWrapperWorld for this WebScriptWorld.

* WebView/WebScriptWorldInternal.h: Added.

* WebView/WebView.mm:
(+[WebView _addUserScriptToGroup:world:source:url:whitelist:blacklist:injectionTime:]):
(+[WebView _addUserStyleSheetToGroup:world:source:url:whitelist:blacklist:]):
(+[WebView _removeUserScriptFromGroup:world:url:]):
(+[WebView _removeUserStyleSheetFromGroup:world:url:]):
(+[WebView _removeUserScriptsFromGroup:world:]):
(+[WebView _removeUserStyleSheetsFromGroup:world:]):
* WebView/WebViewPrivate.h:
Changed these functions to take a WebScriptWorld instead of a worldID.

WebKit/win:

WebScriptWorld is the new object that represents a world.  The only
place worldID is still used is in
IWebFramePrivate::stringByEvaluatingJavaScriptInIsolatedWorld, but
that will change soon.

* ForEachCoClass.h: Added WebScriptWorld.

* Interfaces/IWebFramePrivate.idl: Replaced contextForWorldID with
contextForWorld.

* Interfaces/IWebScriptWorld.idl: Added.

* Interfaces/IWebViewPrivate.idl: Changed the user script/stylesheet
functions to take an IWebScriptWorld instead of a worldID.

* Interfaces/WebKit.idl: Added WebScriptWorld.

* WebFrame.cpp:
(WebFrame::contextForWorld): Renamed from contextForWorldID. Now takes
an IWebScriptWorld.
(WebFrame::stringByEvaluatingJavaScriptInIsolatedWorld): Moved the
bizarre world caching/creation logic that DRT depends on here from the
findWorld function in ScriptController.cpp. Updated to use
ScriptController::executeScriptInWorld instead of
ScriptController::executeScriptInIsolatedWorld.

* WebFrame.h: Replaced contextForWorldID with contextForWorld.

* WebScriptWorld.cpp: Added.
(WebScriptWorld::WebScriptWorld):
(WebScriptWorld::~WebScriptWorld):
(WebScriptWorld::createInstance):
(WebScriptWorld::AddRef):
(WebScriptWorld::Release):
(WebScriptWorld::QueryInterface):
Standard COM class implementations.

(WebScriptWorld::standardWorld): Returns a shared instance that represents
WebCore's mainThreadNormalWorld().

* WebScriptWorld.h: Added.
(WebScriptWorld::world): Simple getter.

* WebKit.vcproj/Interfaces.vcproj: Added IWebScriptWorld.idl.

* WebKit.vcproj/WebKit.vcproj: Added WebScriptWorld.

* WebKitClassFactory.cpp: Added WebScriptWorld.

* WebView.cpp:
(WebView::addUserScriptToGroup):
(WebView::addUserStyleSheetToGroup):
(WebView::removeUserScriptFromGroup):
(WebView::removeUserStyleSheetFromGroup):
(WebView::removeUserScriptsFromGroup):
(WebView::removeUserStyleSheetsFromGroup):
* WebView.h:
Changed these functions to take an IWebScriptWorld instead of a worldID.

WebKitTools:

* DumpRenderTree/mac/LayoutTestControllerMac.mm:
(LayoutTestController::addUserScript):
(LayoutTestController::addUserStyleSheet):
* DumpRenderTree/win/LayoutTestControllerWin.cpp:
(LayoutTestController::addUserScript):
(LayoutTestController::addUserStyleSheet):
Changed these functions to create a new WebJSWorld each time they're
called and to pass that world to WebKit.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@50907 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b3145606
2009-11-12 Adam Roben <aroben@apple.com>
Replace worldIDs with world objects
Part of <http://webkit.org/b/31414> Implement new SPI for dealing with
user scripts/stylesheets and isolated worlds
Reviewed by Sam Weinig.
Covered by existing tests.
* WebCore.base.exp: Update exported symbols to match what now exists
and is needed by WebKit.
* bindings/js/ScheduledAction.cpp:
(WebCore::ScheduledAction::execute): Updated for function rename.
* bindings/js/ScriptController.cpp: Removed code that dealt with
worldIDs.
(WebCore::ScriptController::createWorld): Added. Returns a new world
suitable for use on the main thread.
(WebCore::ScriptController::executeScriptInWorld): Renamed from
executeScriptInIsolatedWorld, since this works just fine with a
"normal" world.
* bindings/js/ScriptController.h: Added createWorld, removed functions
that took worldIDs, renamed executeScriptInIsolatedWorld to
executeScriptInWorld.
* page/Frame.cpp:
(WebCore::Frame::injectUserScripts):
(WebCore::Frame::injectUserScriptsForWorld):
Updated for changes to UserScriptMap and ScriptController.
* page/Frame.h: Changed injectUserScriptsForWorld to take a
DOMWrapperWorld* instead of a worldID.
* page/PageGroup.cpp:
(WebCore::PageGroup::addUserScriptToWorld):
(WebCore::PageGroup::addUserStyleSheetToWorld):
(WebCore::PageGroup::removeUserScriptFromWorld):
(WebCore::PageGroup::removeUserStyleSheetFromWorld):
(WebCore::PageGroup::removeUserScriptsFromWorld):
(WebCore::PageGroup::removeUserStyleSheetsFromWorld):
* page/PageGroup.h:
Changed these functions to take a DOMWrapperWorld* instead of a
worldID. Also updated for changes to UserScript and UserStyleSheet.
* page/UserScript.h:
* page/UserStyleSheet.h: Changed not to hold a worldID, since it was
never used.
* page/UserScriptTypes.h:
* page/UserStyleSheetTypes.h: Changed UserScriptMap and
UserStyleSheetMap to use a RefPtr<DOMWrapperWorld> instead of a
worldID as their key type.
2009-11-12 Brian Weinstein <bweinstein@apple.com> 2009-11-12 Brian Weinstein <bweinstein@apple.com>
Reviewed by Tim Hatcher. Reviewed by Tim Hatcher.
...@@ -326,6 +326,7 @@ __ZN7WebCore15BackForwardList8goToItemEPNS_11HistoryItemE ...@@ -326,6 +326,7 @@ __ZN7WebCore15BackForwardList8goToItemEPNS_11HistoryItemE
__ZN7WebCore15BackForwardList9goForwardEv __ZN7WebCore15BackForwardList9goForwardEv
__ZN7WebCore15BackForwardListC1EPNS_4PageE __ZN7WebCore15BackForwardListC1EPNS_4PageE
__ZN7WebCore15BackForwardListD1Ev __ZN7WebCore15BackForwardListD1Ev
__ZN7WebCore15DOMWrapperWorldD1Ev
__ZN7WebCore15DatabaseTracker12deleteOriginEPNS_14SecurityOriginE __ZN7WebCore15DatabaseTracker12deleteOriginEPNS_14SecurityOriginE
__ZN7WebCore15DatabaseTracker14deleteDatabaseEPNS_14SecurityOriginERKNS_6StringE __ZN7WebCore15DatabaseTracker14deleteDatabaseEPNS_14SecurityOriginERKNS_6StringE
__ZN7WebCore15DatabaseTracker14quotaForOriginEPNS_14SecurityOriginE __ZN7WebCore15DatabaseTracker14quotaForOriginEPNS_14SecurityOriginE
...@@ -338,7 +339,6 @@ __ZN7WebCore15DatabaseTracker7originsERN3WTF6VectorINS1_6RefPtrINS_14SecurityOri ...@@ -338,7 +339,6 @@ __ZN7WebCore15DatabaseTracker7originsERN3WTF6VectorINS1_6RefPtrINS_14SecurityOri
__ZN7WebCore15DatabaseTracker7trackerEv __ZN7WebCore15DatabaseTracker7trackerEv
__ZN7WebCore15DatabaseTracker8setQuotaEPNS_14SecurityOriginEy __ZN7WebCore15DatabaseTracker8setQuotaEPNS_14SecurityOriginEy
__ZN7WebCore15DatabaseTracker9setClientEPNS_21DatabaseTrackerClientE __ZN7WebCore15DatabaseTracker9setClientEPNS_21DatabaseTrackerClientE
__ZN7WebCore15DOMWrapperWorldD1Ev
__ZN7WebCore15FocusController10setFocusedEb __ZN7WebCore15FocusController10setFocusedEb
__ZN7WebCore15FocusController15setFocusedFrameEN3WTF10PassRefPtrINS_5FrameEEE __ZN7WebCore15FocusController15setFocusedFrameEN3WTF10PassRefPtrINS_5FrameEEE
__ZN7WebCore15FocusController15setInitialFocusENS_14FocusDirectionEPNS_13KeyboardEventE __ZN7WebCore15FocusController15setInitialFocusENS_14FocusDirectionEPNS_13KeyboardEventE
...@@ -373,10 +373,10 @@ __ZN7WebCore16NavigationActionC1ERKNS_4KURLENS_13FrameLoadTypeEb ...@@ -373,10 +373,10 @@ __ZN7WebCore16NavigationActionC1ERKNS_4KURLENS_13FrameLoadTypeEb
__ZN7WebCore16NavigationActionC1ERKNS_4KURLENS_14NavigationTypeE __ZN7WebCore16NavigationActionC1ERKNS_4KURLENS_14NavigationTypeE
__ZN7WebCore16NavigationActionC1Ev __ZN7WebCore16NavigationActionC1Ev
__ZN7WebCore16ScriptController10initScriptEPNS_15DOMWrapperWorldE __ZN7WebCore16ScriptController10initScriptEPNS_15DOMWrapperWorldE
__ZN7WebCore16ScriptController12globalObjectEj __ZN7WebCore16ScriptController11createWorldEv
__ZN7WebCore16ScriptController13executeScriptERKNS_6StringEb __ZN7WebCore16ScriptController13executeScriptERKNS_6StringEb
__ZN7WebCore16ScriptController18windowScriptObjectEv __ZN7WebCore16ScriptController18windowScriptObjectEv
__ZN7WebCore16ScriptController28executeScriptInIsolatedWorldEjRKNS_6StringEb __ZN7WebCore16ScriptController20executeScriptInWorldEPNS_15DOMWrapperWorldERKNS_6StringEb
__ZN7WebCore16VisibleSelectionC1EPKNS_5RangeENS_9EAffinityE __ZN7WebCore16VisibleSelectionC1EPKNS_5RangeENS_9EAffinityE
__ZN7WebCore16VisibleSelectionC1ERKNS_15VisiblePositionES3_ __ZN7WebCore16VisibleSelectionC1ERKNS_15VisiblePositionES3_
__ZN7WebCore16colorFromNSColorEP7NSColor __ZN7WebCore16colorFromNSColorEP7NSColor
...@@ -733,15 +733,15 @@ __ZN7WebCore9PageCache11setCapacityEi ...@@ -733,15 +733,15 @@ __ZN7WebCore9PageCache11setCapacityEi
__ZN7WebCore9PageCache27releaseAutoreleasedPagesNowEv __ZN7WebCore9PageCache27releaseAutoreleasedPagesNowEv
__ZN7WebCore9PageGroup14addVisitedLinkEPKtm __ZN7WebCore9PageGroup14addVisitedLinkEPKtm
__ZN7WebCore9PageGroup17closeLocalStorageEv __ZN7WebCore9PageGroup17closeLocalStorageEv
__ZN7WebCore9PageGroup20addUserScriptToWorldEjRKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS7_6VectorIS1_Lm0EEEEESB_NS_23UserScriptInjectionTimeE __ZN7WebCore9PageGroup20addUserScriptToWorldEPNS_15DOMWrapperWorldERKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS9_6VectorIS3_Lm0EEEEESD_NS_23UserScriptInjectionTimeE
__ZN7WebCore9PageGroup20removeAllUserContentEv __ZN7WebCore9PageGroup20removeAllUserContentEv
__ZN7WebCore9PageGroup21removeAllVisitedLinksEv __ZN7WebCore9PageGroup21removeAllVisitedLinksEv
__ZN7WebCore9PageGroup24addUserStyleSheetToWorldEjRKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS7_6VectorIS1_Lm0EEEEESB_ __ZN7WebCore9PageGroup24addUserStyleSheetToWorldEPNS_15DOMWrapperWorldERKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS9_6VectorIS3_Lm0EEEEESD_
__ZN7WebCore9PageGroup25removeUserScriptFromWorldEjRKNS_4KURLE __ZN7WebCore9PageGroup25removeUserScriptFromWorldEPNS_15DOMWrapperWorldERKNS_4KURLE
__ZN7WebCore9PageGroup26removeUserScriptsFromWorldEj __ZN7WebCore9PageGroup26removeUserScriptsFromWorldEPNS_15DOMWrapperWorldE
__ZN7WebCore9PageGroup26setShouldTrackVisitedLinksEb __ZN7WebCore9PageGroup26setShouldTrackVisitedLinksEb
__ZN7WebCore9PageGroup29removeUserStyleSheetFromWorldEjRKNS_4KURLE __ZN7WebCore9PageGroup29removeUserStyleSheetFromWorldEPNS_15DOMWrapperWorldERKNS_4KURLE
__ZN7WebCore9PageGroup30removeUserStyleSheetsFromWorldEj __ZN7WebCore9PageGroup30removeUserStyleSheetsFromWorldEPNS_15DOMWrapperWorldE
__ZN7WebCore9PageGroup9pageGroupERKNS_6StringE __ZN7WebCore9PageGroup9pageGroupERKNS_6StringE
__ZN7WebCore9TimerBase4stopEv __ZN7WebCore9TimerBase4stopEv
__ZN7WebCore9TimerBase5startEdd __ZN7WebCore9TimerBase5startEdd
......
...@@ -126,7 +126,7 @@ void ScheduledAction::execute(Document* document) ...@@ -126,7 +126,7 @@ void ScheduledAction::execute(Document* document)
executeFunctionInContext(window, window->shell()); executeFunctionInContext(window, window->shell());
Document::updateStyleForAllDocuments(); Document::updateStyleForAllDocuments();
} else } else
frame->script()->executeScriptInIsolatedWorld(m_isolatedWorld.get(), m_code); frame->script()->executeScriptInWorld(m_isolatedWorld.get(), m_code);
frame->script()->setProcessingTimerCallback(false); frame->script()->setProcessingTimerCallback(false);
} }
......
...@@ -165,42 +165,9 @@ public: ...@@ -165,42 +165,9 @@ public:
static PassRefPtr<IsolatedWorld> create(JSGlobalData* globalData) { return adoptRef(new IsolatedWorld(globalData)); } static PassRefPtr<IsolatedWorld> create(JSGlobalData* globalData) { return adoptRef(new IsolatedWorld(globalData)); }
}; };
static PassRefPtr<IsolatedWorld> findWorld(unsigned worldID) PassRefPtr<DOMWrapperWorld> ScriptController::createWorld()
{ {
if (!worldID) return IsolatedWorld::create(JSDOMWindow::commonJSGlobalData());
return IsolatedWorld::create(JSDOMWindow::commonJSGlobalData());
typedef HashMap<unsigned, RefPtr<IsolatedWorld> > WorldMap;
DEFINE_STATIC_LOCAL(WorldMap, isolatedWorlds, ());
WorldMap::iterator iter = isolatedWorlds.find(worldID);
if (iter != isolatedWorlds.end())
return iter->second;
RefPtr<IsolatedWorld> newWorld = IsolatedWorld::create(JSDOMWindow::commonJSGlobalData());
isolatedWorlds.add(worldID, newWorld);
return newWorld;
}
JSDOMWindow* ScriptController::globalObject(unsigned worldID)
{
RefPtr<DOMWrapperWorld> world = findWorld(worldID);
return windowShell(world.get())->window();
}
ScriptValue ScriptController::evaluateInIsolatedWorld(unsigned worldID, const ScriptSourceCode& sourceCode)
{
RefPtr<DOMWrapperWorld> world = findWorld(worldID);
return evaluateInWorld(sourceCode, world.get());
}
void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sourceCode)
{
RefPtr<DOMWrapperWorld> world = findWorld(worldID);
unsigned size = sourceCode.size();
for (unsigned i = 0; i < size; ++i)
evaluateInWorld(sourceCode[i], world.get());
} }
void ScriptController::clearWindowShell() void ScriptController::clearWindowShell()
...@@ -476,27 +443,7 @@ void ScriptController::clearScriptObjects() ...@@ -476,27 +443,7 @@ void ScriptController::clearScriptObjects()
#endif #endif
} }
ScriptValue ScriptController::executeScriptInIsolatedWorld(unsigned worldID, const String& script, bool forceUserGesture) ScriptValue ScriptController::executeScriptInWorld(DOMWrapperWorld* world, const String& script, bool forceUserGesture)
{
ScriptSourceCode sourceCode(script, forceUserGesture ? KURL() : m_frame->loader()->url());
if (!isEnabled() || isPaused())
return ScriptValue();
bool wasInExecuteScript = m_inExecuteScript;
m_inExecuteScript = true;
ScriptValue result = evaluateInIsolatedWorld(worldID, sourceCode);
if (!wasInExecuteScript) {
m_inExecuteScript = false;
Document::updateStyleForAllDocuments();
}
return result;
}
ScriptValue ScriptController::executeScriptInIsolatedWorld(DOMWrapperWorld* world, const String& script, bool forceUserGesture)
{ {
ScriptSourceCode sourceCode(script, forceUserGesture ? KURL() : m_frame->loader()->url()); ScriptSourceCode sourceCode(script, forceUserGesture ? KURL() : m_frame->loader()->url());
......
...@@ -70,6 +70,8 @@ public: ...@@ -70,6 +70,8 @@ public:
ScriptController(Frame*); ScriptController(Frame*);
~ScriptController(); ~ScriptController();
static PassRefPtr<DOMWrapperWorld> createWorld();
JSDOMWindowShell* windowShell(DOMWrapperWorld* world) JSDOMWindowShell* windowShell(DOMWrapperWorld* world)
{ {
ShellMap::iterator iter = m_windowShells.find(world); ShellMap::iterator iter = m_windowShells.find(world);
...@@ -84,12 +86,10 @@ public: ...@@ -84,12 +86,10 @@ public:
{ {
return windowShell(world)->window(); return windowShell(world)->window();
} }
JSDOMWindow* globalObject(unsigned worldID);
ScriptValue executeScript(const ScriptSourceCode&); ScriptValue executeScript(const ScriptSourceCode&);
ScriptValue executeScript(const String& script, bool forceUserGesture = false); ScriptValue executeScript(const String& script, bool forceUserGesture = false);
ScriptValue executeScriptInIsolatedWorld(unsigned worldID, const String& script, bool forceUserGesture = false); ScriptValue executeScriptInWorld(DOMWrapperWorld* world, const String& script, bool forceUserGesture = false);
ScriptValue executeScriptInIsolatedWorld(DOMWrapperWorld* world, const String& script, bool forceUserGesture = false);
// Returns true if argument is a JavaScript URL. // Returns true if argument is a JavaScript URL.
bool executeIfJavaScriptURL(const KURL&, bool userGesture = false, bool replaceDocument = true); bool executeIfJavaScriptURL(const KURL&, bool userGesture = false, bool replaceDocument = true);
...@@ -100,8 +100,6 @@ public: ...@@ -100,8 +100,6 @@ public:
ScriptValue evaluate(const ScriptSourceCode&); ScriptValue evaluate(const ScriptSourceCode&);
ScriptValue evaluateInWorld(const ScriptSourceCode&, DOMWrapperWorld*); ScriptValue evaluateInWorld(const ScriptSourceCode&, DOMWrapperWorld*);
ScriptValue evaluateInIsolatedWorld(unsigned /*worldID*/, const ScriptSourceCode&);
void evaluateInIsolatedWorld(unsigned /*worldID*/, const Vector<ScriptSourceCode>&);
void setEventHandlerLineNumber(int lineno) { m_handlerLineNumber = lineno; } void setEventHandlerLineNumber(int lineno) { m_handlerLineNumber = lineno; }
int eventHandlerLineNumber() { return m_handlerLineNumber; } int eventHandlerLineNumber() { return m_handlerLineNumber; }
......
...@@ -874,10 +874,10 @@ void Frame::injectUserScripts(UserScriptInjectionTime injectionTime) ...@@ -874,10 +874,10 @@ void Frame::injectUserScripts(UserScriptInjectionTime injectionTime)
return; return;
UserScriptMap::const_iterator end = userScripts->end(); UserScriptMap::const_iterator end = userScripts->end();
for (UserScriptMap::const_iterator it = userScripts->begin(); it != end; ++it) for (UserScriptMap::const_iterator it = userScripts->begin(); it != end; ++it)
injectUserScriptsForWorld(it->first, *it->second, injectionTime); injectUserScriptsForWorld(it->first.get(), *it->second, injectionTime);
} }
void Frame::injectUserScriptsForWorld(unsigned worldID, const UserScriptVector& userScripts, UserScriptInjectionTime injectionTime) void Frame::injectUserScriptsForWorld(DOMWrapperWorld* world, const UserScriptVector& userScripts, UserScriptInjectionTime injectionTime)
{ {
if (userScripts.isEmpty()) if (userScripts.isEmpty())
return; return;
...@@ -891,9 +891,8 @@ void Frame::injectUserScriptsForWorld(unsigned worldID, const UserScriptVector& ...@@ -891,9 +891,8 @@ void Frame::injectUserScriptsForWorld(unsigned worldID, const UserScriptVector&
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->whitelist(), script->blacklist())) if (script->injectionTime() == injectionTime && UserContentURLPattern::matchesPatterns(doc->url(), script->whitelist(), script->blacklist()))
sourceCode.append(ScriptSourceCode(script->source(), script->url())); m_script.evaluateInWorld(ScriptSourceCode(script->source(), script->url()), world);
} }
script()->evaluateInIsolatedWorld(worldID, sourceCode);
} }
bool Frame::shouldChangeSelection(const VisibleSelection& newSelection) const bool Frame::shouldChangeSelection(const VisibleSelection& newSelection) const
......
...@@ -131,7 +131,7 @@ namespace WebCore { ...@@ -131,7 +131,7 @@ namespace WebCore {
void injectUserScripts(UserScriptInjectionTime); void injectUserScripts(UserScriptInjectionTime);
private: private:
void injectUserScriptsForWorld(unsigned worldID, const UserScriptVector&, UserScriptInjectionTime); void injectUserScriptsForWorld(DOMWrapperWorld*, const UserScriptVector&, UserScriptInjectionTime);
private: private:
Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*); Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
......
...@@ -200,29 +200,29 @@ StorageNamespace* PageGroup::localStorage() ...@@ -200,29 +200,29 @@ StorageNamespace* PageGroup::localStorage()
} }
#endif #endif
void PageGroup::addUserScriptToWorld(unsigned worldID, const String& source, const KURL& url, PassOwnPtr<Vector<String> > whitelist, void PageGroup::addUserScriptToWorld(DOMWrapperWorld* world, const String& source, const KURL& url, PassOwnPtr<Vector<String> > whitelist,
PassOwnPtr<Vector<String> > blacklist, UserScriptInjectionTime injectionTime) PassOwnPtr<Vector<String> > blacklist, UserScriptInjectionTime injectionTime)
{ {
if (worldID == UINT_MAX) ASSERT_ARG(world, world);
return;
OwnPtr<UserScript> userScript(new UserScript(source, url, whitelist, blacklist, worldID, injectionTime)); OwnPtr<UserScript> userScript(new UserScript(source, url, whitelist, blacklist, 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(world, 0).first->second;
if (!scriptsInWorld) if (!scriptsInWorld)
scriptsInWorld = new UserScriptVector; scriptsInWorld = new UserScriptVector;
scriptsInWorld->append(userScript.release()); scriptsInWorld->append(userScript.release());
} }
void PageGroup::addUserStyleSheetToWorld(unsigned worldID, const String& source, const KURL& url, PassOwnPtr<Vector<String> > whitelist, void PageGroup::addUserStyleSheetToWorld(DOMWrapperWorld* world, const String& source, const KURL& url, PassOwnPtr<Vector<String> > whitelist,
PassOwnPtr<Vector<String> > blacklist) PassOwnPtr<Vector<String> > blacklist)
{ {
if (worldID == UINT_MAX) ASSERT_ARG(world, world);
return;
OwnPtr<UserStyleSheet> userStyleSheet(new UserStyleSheet(source, url, whitelist, blacklist, worldID)); OwnPtr<UserStyleSheet> userStyleSheet(new UserStyleSheet(source, url, whitelist, blacklist));
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(world, 0).first->second;
if (!styleSheetsInWorld) if (!styleSheetsInWorld)
styleSheetsInWorld = new UserStyleSheetVector; styleSheetsInWorld = new UserStyleSheetVector;
styleSheetsInWorld->append(userStyleSheet.release()); styleSheetsInWorld->append(userStyleSheet.release());
...@@ -235,12 +235,14 @@ void PageGroup::addUserStyleSheetToWorld(unsigned worldID, const String& source, ...@@ -235,12 +235,14 @@ void PageGroup::addUserStyleSheetToWorld(unsigned worldID, const String& source,
} }
} }
void PageGroup::removeUserScriptFromWorld(unsigned worldID, const KURL& url) void PageGroup::removeUserScriptFromWorld(DOMWrapperWorld* world, const KURL& url)
{ {
ASSERT_ARG(world, world);
if (!m_userScripts) if (!m_userScripts)
return; return;
UserScriptMap::iterator it = m_userScripts->find(worldID); UserScriptMap::iterator it = m_userScripts->find(world);
if (it == m_userScripts->end()) if (it == m_userScripts->end())
return; return;
...@@ -257,12 +259,14 @@ void PageGroup::removeUserScriptFromWorld(unsigned worldID, const KURL& url) ...@@ -257,12 +259,14 @@ void PageGroup::removeUserScriptFromWorld(unsigned worldID, const KURL& url)
m_userScripts->remove(it); m_userScripts->remove(it);
} }
void PageGroup::removeUserStyleSheetFromWorld(unsigned worldID, const KURL& url) void PageGroup::removeUserStyleSheetFromWorld(DOMWrapperWorld* world, const KURL& url)
{ {
ASSERT_ARG(world, world);
if (!m_userStyleSheets) if (!m_userStyleSheets)
return; return;
UserStyleSheetMap::iterator it = m_userStyleSheets->find(worldID); UserStyleSheetMap::iterator it = m_userStyleSheets->find(world);
bool sheetsChanged = false; bool sheetsChanged = false;
if (it == m_userStyleSheets->end()) if (it == m_userStyleSheets->end())
return; return;
...@@ -291,12 +295,14 @@ void PageGroup::removeUserStyleSheetFromWorld(unsigned worldID, const KURL& url) ...@@ -291,12 +295,14 @@ void PageGroup::removeUserStyleSheetFromWorld(unsigned worldID, const KURL& url)
} }
} }
void PageGroup::removeUserScriptsFromWorld(unsigned worldID) void PageGroup::removeUserScriptsFromWorld(DOMWrapperWorld* world)
{ {
ASSERT_ARG(world, world);
if (!m_userScripts) if (!m_userScripts)
return; return;
UserScriptMap::iterator it = m_userScripts->find(worldID); UserScriptMap::iterator it = m_userScripts->find(world);
if (it == m_userScripts->end()) if (it == m_userScripts->end())
return; return;
...@@ -304,12 +310,14 @@ void PageGroup::removeUserScriptsFromWorld(unsigned worldID) ...@@ -304,12 +310,14 @@ void PageGroup::removeUserScriptsFromWorld(unsigned worldID)
m_userScripts->remove(it); m_userScripts->remove(it);
} }
void PageGroup::removeUserStyleSheetsFromWorld(unsigned worldID) void PageGroup::removeUserStyleSheetsFromWorld(DOMWrapperWorld* world)
{ {
ASSERT_ARG(world, world);
if (!m_userStyleSheets) if (!m_userStyleSheets)
return; return;
UserStyleSheetMap::iterator it = m_userStyleSheets->find(worldID); UserStyleSheetMap::iterator it = m_userStyleSheets->find(world);
if (it == m_userStyleSheets->end()) if (it == m_userStyleSheets->end())
return; return;
......
...@@ -70,17 +70,17 @@ namespace WebCore { ...@@ -70,17 +70,17 @@ namespace WebCore {
bool hasLocalStorage() { return m_localStorage; } bool hasLocalStorage() { return m_localStorage; }
#endif #endif
void addUserScriptToWorld(unsigned worldID, const String& source, const KURL&, void addUserScriptToWorld(DOMWrapperWorld*, const String& source, const KURL&,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist, PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserScriptInjectionTime); UserScriptInjectionTime);
void addUserStyleSheetToWorld(unsigned worldID, const String& source, const KURL&, void addUserStyleSheetToWorld(DOMWrapperWorld*, const String& source, const KURL&,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist); PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist);
void removeUserScriptFromWorld(unsigned, const KURL&); void removeUserScriptFromWorld(DOMWrapperWorld*, const KURL&);
void removeUserStyleSheetFromWorld(unsigned, const KURL&); void removeUserStyleSheetFromWorld(DOMWrapperWorld*, const KURL&);
void removeUserScriptsFromWorld(unsigned); void removeUserScriptsFromWorld(DOMWrapperWorld*);
void removeUserStyleSheetsFromWorld(unsigned); void removeUserStyleSheetsFromWorld(DOMWrapperWorld*);
void removeAllUserContent(); void removeAllUserContent();
......
...@@ -38,12 +38,11 @@ class UserScript : public Noncopyable { ...@@ -38,12 +38,11 @@ class UserScript : public Noncopyable {
public: public:
UserScript(const String& source, const KURL& url, UserScript(const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist, PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
unsigned worldID, UserScriptInjectionTime injectionTime) UserScriptInjectionTime injectionTime)
: m_source(source) : m_source(source)
, m_url(url) , m_url(url)
, m_whitelist(whitelist) , m_whitelist(whitelist)
, m_blacklist(blacklist) , m_blacklist(blacklist)
, m_worldID(worldID)
, m_injectionTime(injectionTime) , m_injectionTime(injectionTime)
{ {
} }
...@@ -52,7 +51,6 @@ public: ...@@ -52,7 +51,6 @@ public:
const KURL& url() const { return m_url; } const KURL& url() const { return m_url; }
const Vector<String>* whitelist() const { return m_whitelist.get(); } const Vector<String>* whitelist() const { return m_whitelist.get(); }
const Vector<String>* blacklist() const { return m_blacklist.get(); } const Vector<String>* blacklist() const { return m_blacklist.get(); }
unsigned worldID() const { return m_worldID; }
UserScriptInjectionTime injectionTime() const { return m_injectionTime; } UserScriptInjectionTime injectionTime() const { return m_injectionTime; }
private: private:
...@@ -60,7 +58,6 @@ private: ...@@ -60,7 +58,6 @@ private:
KURL m_url; KURL m_url;
OwnPtr<Vector<String> > m_whitelist; OwnPtr<Vector<String> > m_whitelist;
OwnPtr<Vector<String> > m_blacklist; OwnPtr<Vector<String> > m_blacklist;
unsigned m_worldID;
UserScriptInjectionTime m_injectionTime; UserScriptInjectionTime m_injectionTime;
}; };
......
...@@ -33,10 +33,11 @@ namespace WebCore { ...@@ -33,10 +33,11 @@ namespace WebCore {
enum UserScriptInjectionTime { InjectAtDocumentStart, InjectAtDocumentEnd }; enum UserScriptInjectionTime { InjectAtDocumentStart, InjectAtDocumentEnd };
class DOMWrapperWorld;
class UserScript; class UserScript;
typedef Vector<OwnPtr<UserScript> > UserScriptVector; typedef Vector<OwnPtr<UserScript> > UserScriptVector;
typedef HashMap<unsigned, UserScriptVector*> UserScriptMap; typedef HashMap<RefPtr<DOMWrapperWorld>, UserScriptVector*> UserScriptMap;
} // namespace WebCore } // namespace WebCore
......
...@@ -37,13 +37,11 @@ namespace WebCore { ...@@ -37,13 +37,11 @@ namespace WebCore {
class UserStyleSheet : public Noncopyable { class UserStyleSheet : public Noncopyable {
public: public:
UserStyleSheet(const String& source, const KURL& url, UserStyleSheet(const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist, PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist)
unsigned worldID)
: m_source(source) : m_source(source)
, m_url(url) , m_url(url)
, m_whitelist(whitelist) , m_whitelist(whitelist)
, m_blacklist(blacklist) , m_blacklist(blacklist)
, m_worldID(worldID)
{ {
} }
...@@ -51,14 +49,12 @@ public: ...@@ -51,14 +49,12 @@ public:
const KURL& url() const { return m_url; } const KURL& url() const { return m_url; }
const Vector<String>* whitelist() const { return m_whitelist.get(); } const Vector<String>* whitelist() const { return m_whitelist.get(); }
const Vector<String