Changeset 52877 in webkit
- Timestamp:
- Jan 6, 2010 4:16:00 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r52875 r52877 1 2010-01-06 Adam Barth <abarth@webkit.org> 2 3 Reviewed by Eric Seidel. 4 5 [v8] Let ScriptController have more than one windowShell 6 https://bugs.webkit.org/show_bug.cgi?id=33243 7 8 This patch lets ScriptController have more than one windowShell. We're 9 currently only using one of them (for the main world), but this patch 10 lets us use other ones for isolated worlds soon. 11 12 * bindings/ScriptControllerBase.cpp: 13 (WebCore::ScriptController::executeScriptInWorld): 14 * bindings/js/ScriptController.cpp: 15 * bindings/v8/ScriptController.cpp: 16 (WebCore::ScriptController::createWorld): 17 (WebCore::ScriptController::initScript): 18 (WebCore::ScriptController::ScriptController): 19 (WebCore::ScriptController::~ScriptController): 20 (WebCore::ScriptController::updateSecurityOrigin): 21 (WebCore::ScriptController::evaluateInIsolatedWorld): 22 (WebCore::ScriptController::evaluateInWorld): 23 (WebCore::ScriptController::mainWorldWindowShell): 24 (WebCore::ScriptController::clearWindowShell): 25 (WebCore::ScriptController::clearForClose): 26 (WebCore::ScriptController::destroyWindowShell): 27 (WebCore::ScriptController::updateDocument): 28 * bindings/v8/ScriptController.h: 29 (WebCore::ScriptController::windowShell): 30 (WebCore::ScriptController::existingWindowShell): 31 (WebCore::ScriptController::globalObject): 32 (WebCore::ScriptController::proxy): 33 * bindings/v8/V8DOMWindowShell.cpp: 34 (WebCore::V8DOMWindowShell::create): 35 (WebCore::V8DOMWindowShell::V8DOMWindowShell): 36 (WebCore::V8DOMWindowShell::initContextIfNeeded): 37 * bindings/v8/V8DOMWindowShell.h: 38 * bindings/v8/V8DOMWrapper.cpp: 39 (WebCore::V8DOMWrapper::instantiateV8Object): 40 (WebCore::V8DOMWrapper::convertNewNodeToV8Object): 41 1 42 2010-01-06 Mark Rowe <mrowe@apple.com> 2 43 -
trunk/WebCore/bindings/ScriptControllerBase.cpp
r51820 r52877 54 54 } 55 55 56 ScriptValue ScriptController::executeScriptInWorld(DOMWrapperWorld* world, const String& script, bool forceUserGesture) 57 { 58 ScriptSourceCode sourceCode(script, forceUserGesture ? KURL() : m_frame->loader()->url()); 59 60 if (!isEnabled() || isPaused()) 61 return ScriptValue(); 62 63 bool wasInExecuteScript = m_inExecuteScript; 64 m_inExecuteScript = true; 65 66 ScriptValue result = evaluateInWorld(sourceCode, world); 67 68 if (!wasInExecuteScript) { 69 m_inExecuteScript = false; 70 Document::updateStyleForAllDocuments(); 71 } 72 73 return result; 74 } 56 75 57 76 bool ScriptController::executeIfJavaScriptURL(const KURL& url, bool userGesture, bool replaceDocument) -
trunk/WebCore/bindings/js/ScriptController.cpp
r51577 r52877 447 447 } 448 448 449 ScriptValue ScriptController::executeScriptInWorld(DOMWrapperWorld* world, const String& script, bool forceUserGesture)450 {451 ScriptSourceCode sourceCode(script, forceUserGesture ? KURL() : m_frame->loader()->url());452 453 if (!isEnabled() || isPaused())454 return ScriptValue();455 456 bool wasInExecuteScript = m_inExecuteScript;457 m_inExecuteScript = true;458 459 ScriptValue result = evaluateInWorld(sourceCode, world);460 461 if (!wasInExecuteScript) {462 m_inExecuteScript = false;463 Document::updateStyleForAllDocuments();464 }465 466 return result;467 }468 469 449 } // namespace WebCore -
trunk/WebCore/bindings/v8/ScriptController.cpp
r52847 r52877 61 61 namespace WebCore { 62 62 63 PassRefPtr<DOMWrapperWorld> ScriptController::createWorld() 64 { 65 return IsolatedWorld::create(); 66 } 67 68 V8DOMWindowShell* ScriptController::initScript(DOMWrapperWorld* world) 69 { 70 ASSERT(!m_windowShells.contains(world)); 71 72 RefPtr<V8DOMWindowShell> windowShell = V8DOMWindowShell::create(m_frame, world); 73 m_windowShells.add(world, windowShell); 74 windowShell->initContextIfNeeded(); 75 windowShell->updateDocument(); 76 77 m_frame->loader()->dispatchDidClearWindowObjectInWorld(world); 78 79 return windowShell.get(); 80 } 81 63 82 void ScriptController::initializeThreading() 64 83 { … … 107 126 , m_paused(false) 108 127 , m_proxy(new V8Proxy(frame)) 109 , m_windowShell(V8DOMWindowShell::create(frame))110 128 #if ENABLE(NETSCAPE_PLUGIN_API) 111 129 , m_windowScriptNPObject(0) … … 118 136 { 119 137 m_proxy->disconnectFrame(); 120 m_windowShell.clear(); 138 139 if (!m_windowShells.isEmpty()) { 140 m_windowShells.clear(); 141 m_mainWorldWindowShell = 0; 142 // JSC triggers a GC here, but we haven't historically. 143 } 121 144 } 122 145 … … 143 166 void ScriptController::updateSecurityOrigin() 144 167 { 145 m_windowShell->updateSecurityOrigin(); 168 for (ShellMap::iterator iter = m_windowShells.begin(); iter != m_windowShells.end(); ++iter) 169 iter->second->updateSecurityOrigin(); 146 170 } 147 171 … … 209 233 { 210 234 // FIXME: This will need to get reorganized once we have a windowShell for the isolated world. 211 m_windowShell->initContextIfNeeded(); 235 236 // Force the mainWindowShell to exist. 237 windowShell(mainThreadNormalWorld()); 212 238 m_proxy->evaluateInIsolatedWorld(worldID, sources, 0); 213 239 } … … 249 275 } 250 276 277 ScriptValue ScriptController::evaluateInWorld(const ScriptSourceCode&, DOMWrapperWorld*) 278 { 279 // FIXME: Move isolated world execution to here! 280 notImplemented(); 281 return ScriptValue(); 282 } 283 251 284 void ScriptController::setEventHandlerLineNumber(int lineNumber) 252 285 { … … 292 325 { 293 326 v8::V8::LowMemoryNotification(); 294 }295 296 bool ScriptController::haveInterpreter() const297 {298 return m_windowShell->isContextInitialized();299 327 } 300 328 … … 440 468 } 441 469 442 V8DOMWindowShell* ScriptController::mainWorldWindowShell() const 443 { 444 m_windowShell->initContextIfNeeded(); 445 return m_windowShell.get(); 470 V8DOMWindowShell* ScriptController::mainWorldWindowShell() 471 { 472 if (!m_mainWorldWindowShell) 473 m_mainWorldWindowShell = windowShell(mainThreadNormalWorld()); 474 return m_mainWorldWindowShell.get(); 446 475 } 447 476 … … 454 483 // when a frame is loading a new page. V8DOMWindowShell::clearForNavigation 455 484 // creates a new context for the new page. 456 m_windowShell->clearForNavigation(); 485 for (ShellMap::iterator iter = m_windowShells.begin(); iter != m_windowShells.end(); ++iter) 486 iter->second->clearForNavigation(); 457 487 } 458 488 459 489 void ScriptController::clearForClose() 460 490 { 461 m_windowShell->clearForClose(); 491 for (ShellMap::iterator iter = m_windowShells.begin(); iter != m_windowShells.end(); ++iter) 492 iter->second->clearForClose(); 462 493 } 463 494 464 495 void ScriptController::destroyWindowShell() 465 496 { 466 m_windowShell ->clearForClose();467 m_ windowShell->destroyGlobal();497 m_windowShells.clear(); 498 m_mainWorldWindowShell = 0; 468 499 } 469 500 … … 475 506 void ScriptController::updateDocument() 476 507 { 477 m_windowShell->updateDocument(); 508 // This seems redudant, but JSC does it. 509 if (!m_frame->document()) 510 return; 511 512 for (ShellMap::iterator iter = m_windowShells.begin(); iter != m_windowShells.end(); ++iter) 513 iter->second->updateDocument(); 478 514 } 479 515 -
trunk/WebCore/bindings/v8/ScriptController.h
r52847 r52877 52 52 class ScriptState; 53 53 class String; 54 class V8DOMWindow; 54 55 class Widget; 55 56 class XSSAuditor; 56 57 57 58 class ScriptController { 59 typedef WTF::HashMap< RefPtr<DOMWrapperWorld>, RefPtr<V8DOMWindowShell> > ShellMap; 60 58 61 public: 59 62 ScriptController(Frame*); 60 63 ~ScriptController(); 61 64 65 static PassRefPtr<DOMWrapperWorld> createWorld(); 66 67 V8DOMWindowShell* windowShell(DOMWrapperWorld* world) 68 { 69 ShellMap::iterator iter = m_windowShells.find(world); 70 return (iter != m_windowShells.end()) ? iter->second.get() : initScript(world); 71 } 72 V8DOMWindowShell* existingWindowShell(DOMWrapperWorld* world) const 73 { 74 ShellMap::const_iterator iter = m_windowShells.find(world); 75 return (iter != m_windowShells.end()) ? iter->second.get() : 0; 76 } 77 V8DOMWindow* globalObject(DOMWrapperWorld* world) 78 { 79 notImplemented(); 80 return 0; 81 } 82 83 static void getAllWorlds(Vector<DOMWrapperWorld*>&); 84 85 ScriptValue executeScript(const ScriptSourceCode&); 86 ScriptValue executeScript(const String& script, bool forceUserGesture = false); 87 ScriptValue executeScriptInWorld(DOMWrapperWorld* world, const String& script, bool forceUserGesture = false); 88 89 // Returns true if argument is a JavaScript URL. 90 bool executeIfJavaScriptURL(const KURL&, bool userGesture = false, bool replaceDocument = true); 91 92 // This function must be called from the main thread. It is safe to call it repeatedly. 93 static void initializeThreading(); 94 95 ScriptValue evaluate(const ScriptSourceCode&); 96 ScriptValue evaluateInWorld(const ScriptSourceCode&, DOMWrapperWorld*); 97 98 // ==== End identical match with JSC's ScriptController === // 99 62 100 // FIXME: V8Proxy should either be folded into ScriptController 63 101 // or this accessor should be made JSProxy* 64 102 V8Proxy* proxy() { return m_proxy.get(); } 65 103 66 V8DOMWindowShell* mainWorldWindowShell() const; 67 68 ScriptValue executeScript(const ScriptSourceCode&); 69 ScriptValue executeScript(const String& script, bool forceUserGesture = false); 70 71 // Returns true if argument is a JavaScript URL. 72 bool executeIfJavaScriptURL(const KURL&, bool userGesture = false, bool replaceDocument = true); 73 74 // This function must be called from the main thread. It is safe to call it repeatedly. 75 static void initializeThreading(); 76 77 // Evaluate a script file in the environment of this proxy. 78 // If succeeded, 'succ' is set to true and result is returned 79 // as a string. 80 ScriptValue evaluate(const ScriptSourceCode&); 104 // FIXME: We should eventually remove all clients of this method. The 105 // problem is that some of them are in very hot code paths. 106 V8DOMWindowShell* mainWorldWindowShell(); 81 107 82 108 void evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>&); … … 94 120 void evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>&, int extensionGroup); 95 121 96 // Masquerade 'this' as the windowShell.97 // This is a bit of a hack, but provides reasonable compatibility98 // with what JSC does as well.99 ScriptController* windowShell(DOMWrapperWorld*) { return this; }100 ScriptController* existingWindowShell(DOMWrapperWorld*) { return this; }101 102 122 XSSAuditor* xssAuditor() { return m_XSSAuditor.get(); } 103 123 … … 111 131 112 132 PassScriptInstance createScriptInstanceForWidget(Widget*); 113 114 // Check if the javascript engine has been initialized.115 bool haveInterpreter() const;116 133 117 134 bool isEnabled() const; … … 171 188 #endif 172 189 173 // Dummy method to avoid a bunch of ifdef's in WebCore.174 void evaluateInWorld(const ScriptSourceCode&, DOMWrapperWorld*) { }175 static void getAllWorlds(Vector<DOMWrapperWorld*>& worlds);176 177 190 // Script state for the main world context. 178 191 ScriptState* mainWorldScriptState(); … … 182 195 183 196 private: 197 V8DOMWindowShell* initScript(DOMWrapperWorld*); 198 199 ShellMap m_windowShells; 184 200 Frame* m_frame; 201 202 // This is a cache of the main world's windowShell. We have this 203 // because we need access to it during some wrapper operations that 204 // are performance sensitive. Those call sites are wrong, but I'm 205 // waiting to remove them until the next patch. 206 RefPtr<V8DOMWindowShell> m_mainWorldWindowShell; 207 185 208 const String* m_sourceURL; 186 209 … … 192 215 // FIXME: V8Proxy should eventually be removed. 193 216 OwnPtr<V8Proxy> m_proxy; 194 195 // For the moment, we have one of these. Soon we will have one per DOMWrapperWorld.196 RefPtr<V8DOMWindowShell> m_windowShell;197 217 198 218 typedef HashMap<Widget*, NPObject*> PluginObjectMap; -
trunk/WebCore/bindings/v8/V8DOMWindowShell.cpp
r52867 r52877 37 37 #include "DocumentLoader.h" 38 38 #include "DOMObjectsInclude.h" 39 #include "DOMWrapperWorld.h" 39 40 #include "Frame.h" 40 41 #include "FrameLoaderClient.h" … … 123 124 } 124 125 125 PassRefPtr<V8DOMWindowShell> V8DOMWindowShell::create(Frame* frame )126 { 127 return adoptRef(new V8DOMWindowShell(frame ));128 } 129 130 V8DOMWindowShell::V8DOMWindowShell(Frame* frame )126 PassRefPtr<V8DOMWindowShell> V8DOMWindowShell::create(Frame* frame, DOMWrapperWorld* world) 127 { 128 return adoptRef(new V8DOMWindowShell(frame, world)); 129 } 130 131 V8DOMWindowShell::V8DOMWindowShell(Frame* frame, DOMWrapperWorld* world) 131 132 : m_frame(frame) 133 , m_world(world) 132 134 { 133 135 } … … 312 314 setSecurityToken(); 313 315 316 // FIXME: JSC doesn't seem to make this callback. 314 317 m_frame->loader()->client()->didCreateScriptContextForFrame(); 315 316 // FIXME: This is wrong. We should actually do this for the proper world once317 // we do isolated worlds the WebCore way.318 m_frame->loader()->dispatchDidClearWindowObjectInWorld(0);319 318 } 320 319
Note: See TracChangeset
for help on using the changeset viewer.