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>
Reviewed by Tim Hatcher.
......@@ -326,6 +326,7 @@ __ZN7WebCore15BackForwardList8goToItemEPNS_11HistoryItemE
__ZN7WebCore15BackForwardList9goForwardEv
__ZN7WebCore15BackForwardListC1EPNS_4PageE
__ZN7WebCore15BackForwardListD1Ev
__ZN7WebCore15DOMWrapperWorldD1Ev
__ZN7WebCore15DatabaseTracker12deleteOriginEPNS_14SecurityOriginE
__ZN7WebCore15DatabaseTracker14deleteDatabaseEPNS_14SecurityOriginERKNS_6StringE
__ZN7WebCore15DatabaseTracker14quotaForOriginEPNS_14SecurityOriginE
......@@ -338,7 +339,6 @@ __ZN7WebCore15DatabaseTracker7originsERN3WTF6VectorINS1_6RefPtrINS_14SecurityOri
__ZN7WebCore15DatabaseTracker7trackerEv
__ZN7WebCore15DatabaseTracker8setQuotaEPNS_14SecurityOriginEy
__ZN7WebCore15DatabaseTracker9setClientEPNS_21DatabaseTrackerClientE
__ZN7WebCore15DOMWrapperWorldD1Ev
__ZN7WebCore15FocusController10setFocusedEb
__ZN7WebCore15FocusController15setFocusedFrameEN3WTF10PassRefPtrINS_5FrameEEE
__ZN7WebCore15FocusController15setInitialFocusENS_14FocusDirectionEPNS_13KeyboardEventE
......@@ -373,10 +373,10 @@ __ZN7WebCore16NavigationActionC1ERKNS_4KURLENS_13FrameLoadTypeEb
__ZN7WebCore16NavigationActionC1ERKNS_4KURLENS_14NavigationTypeE
__ZN7WebCore16NavigationActionC1Ev
__ZN7WebCore16ScriptController10initScriptEPNS_15DOMWrapperWorldE
__ZN7WebCore16ScriptController12globalObjectEj
__ZN7WebCore16ScriptController11createWorldEv
__ZN7WebCore16ScriptController13executeScriptERKNS_6StringEb
__ZN7WebCore16ScriptController18windowScriptObjectEv
__ZN7WebCore16ScriptController28executeScriptInIsolatedWorldEjRKNS_6StringEb
__ZN7WebCore16ScriptController20executeScriptInWorldEPNS_15DOMWrapperWorldERKNS_6StringEb
__ZN7WebCore16VisibleSelectionC1EPKNS_5RangeENS_9EAffinityE
__ZN7WebCore16VisibleSelectionC1ERKNS_15VisiblePositionES3_
__ZN7WebCore16colorFromNSColorEP7NSColor
......@@ -733,15 +733,15 @@ __ZN7WebCore9PageCache11setCapacityEi
__ZN7WebCore9PageCache27releaseAutoreleasedPagesNowEv
__ZN7WebCore9PageGroup14addVisitedLinkEPKtm
__ZN7WebCore9PageGroup17closeLocalStorageEv
__ZN7WebCore9PageGroup20addUserScriptToWorldEjRKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS7_6VectorIS1_Lm0EEEEESB_NS_23UserScriptInjectionTimeE
__ZN7WebCore9PageGroup20addUserScriptToWorldEPNS_15DOMWrapperWorldERKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS9_6VectorIS3_Lm0EEEEESD_NS_23UserScriptInjectionTimeE
__ZN7WebCore9PageGroup20removeAllUserContentEv
__ZN7WebCore9PageGroup21removeAllVisitedLinksEv
__ZN7WebCore9PageGroup24addUserStyleSheetToWorldEjRKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS7_6VectorIS1_Lm0EEEEESB_
__ZN7WebCore9PageGroup25removeUserScriptFromWorldEjRKNS_4KURLE
__ZN7WebCore9PageGroup26removeUserScriptsFromWorldEj
__ZN7WebCore9PageGroup24addUserStyleSheetToWorldEPNS_15DOMWrapperWorldERKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS9_6VectorIS3_Lm0EEEEESD_
__ZN7WebCore9PageGroup25removeUserScriptFromWorldEPNS_15DOMWrapperWorldERKNS_4KURLE
__ZN7WebCore9PageGroup26removeUserScriptsFromWorldEPNS_15DOMWrapperWorldE
__ZN7WebCore9PageGroup26setShouldTrackVisitedLinksEb
__ZN7WebCore9PageGroup29removeUserStyleSheetFromWorldEjRKNS_4KURLE
__ZN7WebCore9PageGroup30removeUserStyleSheetsFromWorldEj
__ZN7WebCore9PageGroup29removeUserStyleSheetFromWorldEPNS_15DOMWrapperWorldERKNS_4KURLE
__ZN7WebCore9PageGroup30removeUserStyleSheetsFromWorldEPNS_15DOMWrapperWorldE
__ZN7WebCore9PageGroup9pageGroupERKNS_6StringE
__ZN7WebCore9TimerBase4stopEv
__ZN7WebCore9TimerBase5startEdd
......
......@@ -126,7 +126,7 @@ void ScheduledAction::execute(Document* document)
executeFunctionInContext(window, window->shell());
Document::updateStyleForAllDocuments();
} else
frame->script()->executeScriptInIsolatedWorld(m_isolatedWorld.get(), m_code);
frame->script()->executeScriptInWorld(m_isolatedWorld.get(), m_code);
frame->script()->setProcessingTimerCallback(false);
}
......
......@@ -165,42 +165,9 @@ public:
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());
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());
return IsolatedWorld::create(JSDOMWindow::commonJSGlobalData());
}
void ScriptController::clearWindowShell()
......@@ -476,27 +443,7 @@ void ScriptController::clearScriptObjects()
#endif
}
ScriptValue ScriptController::executeScriptInIsolatedWorld(unsigned worldID, 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)
ScriptValue ScriptController::executeScriptInWorld(DOMWrapperWorld* world, const String& script, bool forceUserGesture)
{
ScriptSourceCode sourceCode(script, forceUserGesture ? KURL() : m_frame->loader()->url());
......
......@@ -70,6 +70,8 @@ public:
ScriptController(Frame*);
~ScriptController();
static PassRefPtr<DOMWrapperWorld> createWorld();
JSDOMWindowShell* windowShell(DOMWrapperWorld* world)
{
ShellMap::iterator iter = m_windowShells.find(world);
......@@ -84,12 +86,10 @@ public:
{
return windowShell(world)->window();
}
JSDOMWindow* globalObject(unsigned worldID);
ScriptValue executeScript(const ScriptSourceCode&);
ScriptValue executeScript(const String& script, bool forceUserGesture = false);
ScriptValue executeScriptInIsolatedWorld(unsigned worldID, const String& script, bool forceUserGesture = false);
ScriptValue executeScriptInIsolatedWorld(DOMWrapperWorld* world, const String& script, bool forceUserGesture = false);
ScriptValue executeScriptInWorld(DOMWrapperWorld* world, const String& script, bool forceUserGesture = false);
// Returns true if argument is a JavaScript URL.
bool executeIfJavaScriptURL(const KURL&, bool userGesture = false, bool replaceDocument = true);
......@@ -100,8 +100,6 @@ public:
ScriptValue evaluate(const ScriptSourceCode&);
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; }
int eventHandlerLineNumber() { return m_handlerLineNumber; }
......
......@@ -874,10 +874,10 @@ void Frame::injectUserScripts(UserScriptInjectionTime injectionTime)
return;
UserScriptMap::const_iterator end = userScripts->end();
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())
return;
......@@ -891,9 +891,8 @@ void Frame::injectUserScriptsForWorld(unsigned worldID, const UserScriptVector&
for (unsigned i = 0; i < count; ++i) {
UserScript* script = userScripts[i].get();
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
......
......@@ -131,7 +131,7 @@ namespace WebCore {
void injectUserScripts(UserScriptInjectionTime);
private:
void injectUserScriptsForWorld(unsigned worldID, const UserScriptVector&, UserScriptInjectionTime);
void injectUserScriptsForWorld(DOMWrapperWorld*, const UserScriptVector&, UserScriptInjectionTime);
private:
Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
......
......@@ -200,29 +200,29 @@ StorageNamespace* PageGroup::localStorage()
}
#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)
{
if (worldID == UINT_MAX)
return;
OwnPtr<UserScript> userScript(new UserScript(source, url, whitelist, blacklist, worldID, injectionTime));
ASSERT_ARG(world, world);
OwnPtr<UserScript> userScript(new UserScript(source, url, whitelist, blacklist, injectionTime));
if (!m_userScripts)
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)
scriptsInWorld = new UserScriptVector;
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)
{
if (worldID == UINT_MAX)
return;
OwnPtr<UserStyleSheet> userStyleSheet(new UserStyleSheet(source, url, whitelist, blacklist, worldID));
ASSERT_ARG(world, world);
OwnPtr<UserStyleSheet> userStyleSheet(new UserStyleSheet(source, url, whitelist, blacklist));
if (!m_userStyleSheets)
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)
styleSheetsInWorld = new UserStyleSheetVector;
styleSheetsInWorld->append(userStyleSheet.release());
......@@ -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)
return;
UserScriptMap::iterator it = m_userScripts->find(worldID);
UserScriptMap::iterator it = m_userScripts->find(world);
if (it == m_userScripts->end())
return;
......@@ -257,12 +259,14 @@ void PageGroup::removeUserScriptFromWorld(unsigned worldID, const KURL& url)
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)
return;
UserStyleSheetMap::iterator it = m_userStyleSheets->find(worldID);
UserStyleSheetMap::iterator it = m_userStyleSheets->find(world);
bool sheetsChanged = false;
if (it == m_userStyleSheets->end())
return;
......@@ -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)
return;
UserScriptMap::iterator it = m_userScripts->find(worldID);
UserScriptMap::iterator it = m_userScripts->find(world);
if (it == m_userScripts->end())
return;
......@@ -304,12 +310,14 @@ void PageGroup::removeUserScriptsFromWorld(unsigned worldID)
m_userScripts->remove(it);
}
void PageGroup::removeUserStyleSheetsFromWorld(unsigned worldID)
void PageGroup::removeUserStyleSheetsFromWorld(DOMWrapperWorld* world)
{
ASSERT_ARG(world, world);
if (!m_userStyleSheets)
return;
UserStyleSheetMap::iterator it = m_userStyleSheets->find(worldID);
UserStyleSheetMap::iterator it = m_userStyleSheets->find(world);
if (it == m_userStyleSheets->end())
return;
......
......@@ -70,17 +70,17 @@ namespace WebCore {
bool hasLocalStorage() { return m_localStorage; }
#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,
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);
void removeUserScriptFromWorld(unsigned, const KURL&);
void removeUserStyleSheetFromWorld(unsigned, const KURL&);
void removeUserScriptFromWorld(DOMWrapperWorld*, const KURL&);
void removeUserStyleSheetFromWorld(DOMWrapperWorld*, const KURL&);
void removeUserScriptsFromWorld(unsigned);
void removeUserStyleSheetsFromWorld(unsigned);
void removeUserScriptsFromWorld(DOMWrapperWorld*);
void removeUserStyleSheetsFromWorld(DOMWrapperWorld*);
void removeAllUserContent();
......
......@@ -38,12 +38,11 @@ class UserScript : public Noncopyable {
public:
UserScript(const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
unsigned worldID, UserScriptInjectionTime injectionTime)
UserScriptInjectionTime injectionTime)
: m_source(source)
, m_url(url)
, m_whitelist(whitelist)
, m_blacklist(blacklist)
, m_worldID(worldID)
, m_injectionTime(injectionTime)
{
}
......@@ -52,7 +51,6 @@ public:
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(); }
unsigned worldID() const { return m_worldID; }
UserScriptInjectionTime injectionTime() const { return m_injectionTime; }
private:
......@@ -60,7 +58,6 @@ private:
KURL m_url;
OwnPtr<Vector<String> > m_whitelist;
OwnPtr<Vector<String> > m_blacklist;
unsigned m_worldID;
UserScriptInjectionTime m_injectionTime;
};
......
......@@ -33,10 +33,11 @@ namespace WebCore {
enum UserScriptInjectionTime { InjectAtDocumentStart, InjectAtDocumentEnd };
class DOMWrapperWorld;
class UserScript;
typedef Vector<OwnPtr<UserScript> > UserScriptVector;
typedef HashMap<unsigned, UserScriptVector*> UserScriptMap;
typedef HashMap<RefPtr<DOMWrapperWorld>, UserScriptVector*> UserScriptMap;
} // namespace WebCore
......
......@@ -37,13 +37,11 @@ namespace WebCore {
class UserStyleSheet : public Noncopyable {
public:
UserStyleSheet(const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
unsigned worldID)
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist)
: m_source(source)
, m_url(url)
, m_whitelist(whitelist)
, m_blacklist(blacklist)
, m_worldID(worldID)
{
}
......@@ -51,14 +49,12 @@ public:
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(); }
unsigned worldID() const { return m_worldID; }
private:
String m_source;
KURL m_url;
OwnPtr<Vector<String> > m_whitelist;
OwnPtr<Vector<String> > m_blacklist;
unsigned m_worldID;
};
} // namespace WebCore
......
......@@ -31,10 +31,11 @@
namespace WebCore {
class DOMWrapperWorld;
class UserStyleSheet;
typedef Vector<OwnPtr<UserStyleSheet> > UserStyleSheetVector;
typedef HashMap<unsigned, UserStyleSheetVector*> UserStyleSheetMap;
typedef HashMap<RefPtr<DOMWrapperWorld>, UserStyleSheetVector*> UserStyleSheetMap;
} // namespace WebCore
......
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.
* WebKit.xcodeproj/project.pbxproj: Added WebScriptWorld to the project.
2009-11-12 Chris Fleizach <cfleizach@apple.com>
Reviewed by Darin Adler.
......
......@@ -333,6 +333,9 @@
BC97E7E210963D260010D361 /* WebViewEventHandling.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC97E7E110963D260010D361 /* WebViewEventHandling.mm */; };
C0167BF80D7F5DD00028696E /* WebScriptDebugger.h in Headers */ = {isa = PBXBuildFile; fileRef = C0167BF60D7F5DD00028696E /* WebScriptDebugger.h */; };
C0167BF90D7F5DD00028696E /* WebScriptDebugger.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0167BF70D7F5DD00028696E /* WebScriptDebugger.mm */; };
C0B1F7E810AC8E3100C925D9 /* WebScriptWorld.h in Headers */ = {isa = PBXBuildFile; fileRef = C0B1F7E510AC8E3100C925D9 /* WebScriptWorld.h */; settings = {ATTRIBUTES = (Private, ); }; };
C0B1F7E910AC8E3100C925D9 /* WebScriptWorld.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0B1F7E610AC8E3100C925D9 /* WebScriptWorld.mm */; };
C0B1F7EA10AC8E3100C925D9 /* WebScriptWorldInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = C0B1F7E710AC8E3100C925D9 /* WebScriptWorldInternal.h */; };
DD7CDEE70A23BA9E00069928 /* WebTypesInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = DD7CDEE60A23BA9E00069928 /* WebTypesInternal.h */; };
DD89682009AA87240097E7F0 /* WebElementDictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = DD89681E09AA87240097E7F0 /* WebElementDictionary.h */; };
DD89682109AA87240097E7F0 /* WebElementDictionary.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD89681F09AA87240097E7F0 /* WebElementDictionary.mm */; };
......@@ -621,6 +624,9 @@
BEE52D4B0473032500CA289C /* WebKitSystemBits.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = WebKitSystemBits.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
C0167BF60D7F5DD00028696E /* WebScriptDebugger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptDebugger.h; sourceTree = "<group>"; };
C0167BF70D7F5DD00028696E /* WebScriptDebugger.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebScriptDebugger.mm; sourceTree = "<group>"; };
C0B1F7E510AC8E3100C925D9 /* WebScriptWorld.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptWorld.h; sourceTree = "<group>"; };
C0B1F7E610AC8E3100C925D9 /* WebScriptWorld.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebScriptWorld.mm; sourceTree = "<group>"; };
C0B1F7E710AC8E3100C925D9 /* WebScriptWorldInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptWorldInternal.h; sourceTree = "<group>"; };
DD7CDEE60A23BA9E00069928 /* WebTypesInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebTypesInternal.h; sourceTree = "<group>"; };
DD89681E09AA87240097E7F0 /* WebElementDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebElementDictionary.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
DD89681F09AA87240097E7F0 /* WebElementDictionary.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebElementDictionary.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
......@@ -1130,6 +1136,9 @@
7E6FEF0608985A7200C44C3F /* WebScriptDebugDelegate.mm */,
C0167BF60D7F5DD00028696E /* WebScriptDebugger.h */,
C0167BF70D7F5DD00028696E /* WebScriptDebugger.mm */,
C0B1F7E510AC8E3100C925D9 /* WebScriptWorld.h */,
C0B1F7E610AC8E3100C925D9 /* WebScriptWorld.mm */,
C0B1F7E710AC8E3100C925D9 /* WebScriptWorldInternal.h */,
936A2DE90FD2D08400D312DB /* WebTextCompletionController.h */,
936A2DE70FD2D08000D312DB /* WebTextCompletionController.mm */,
F834AAD50E64B1C700E2737C /* WebTextIterator.h */,
......@@ -1513,6 +1522,8 @@
0FD3B0F41076C3E900039B96 /* WebVideoFullscreenHUDWindowController.h in Headers */,
0FD3B0F81076C3F700039B96 /* WebWindowAnimation.h in Headers */,
0A2D87FD107AF52B00CDDEE3 /* WebPluginHalterClient.h in Headers */,
C0B1F7E810AC8E3100C925D9 /* WebScriptWorld.h in Headers */,
C0B1F7EA10AC8E3100C925D9 /* WebScriptWorldInternal.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -1853,6 +1864,7 @@
0FD3B0F91076C3F700039B96 /* WebWindowAnimation.m in Sources */,
0A2D87FE107AF52B00CDDEE3 /* WebPluginHalterClient.mm in Sources */,
BC97E7E210963D260010D361 /* WebViewEventHandling.mm in Sources */,
C0B1F7E910AC8E3100C925D9 /* WebScriptWorld.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
2009-11-12 Adam Roben <aroben@apple.com>
Replace worldIDs with world objects
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.
Part of <http://webkit.org/b/31414> Implement new SPI for dealing with
user scripts/stylesheets and isolated worlds
Reviewed by Sam Weinig.
* 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.
2009-11-12 Chris Fleizach <cfleizach@apple.com>
Reviewed by Darin Adler.
......
......@@ -28,6 +28,7 @@
.objc_class_name_WebRenderNode
.objc_class_name_WebResource
.objc_class_name_WebScriptCallFrame
.objc_class_name_WebScriptWorld
.objc_class_name_WebSecurityOrigin
.objc_class_name_WebStringTruncator
.objc_class_name_WebTextIterator
......
......@@ -49,6 +49,7 @@
#import "WebNSObjectExtras.h"
#import "WebNSURLExtras.h"
#import "WebScriptDebugger.h"