WebCore/ChangeLog

112010-01-05 Adam Barth <abarth@webkit.org>
22
 3 Reviewed by NOBODY (OOPS!).
 4
 5 [v8] Move V8DOMWindowShell to ScriptController
 6 https://bugs.webkit.org/show_bug.cgi?id=33232
 7
 8 This patch moves V8DOMWindow shell to ScriptController, where the
 9 window shells live in JSC land. The next step will be to allow for
 10 more than one window shell per script controller.
 11
 12 * bindings/v8/ScriptController.cpp:
 13 (WebCore::ScriptController::ScriptController):
 14 (WebCore::ScriptController::~ScriptController):
 15 (WebCore::ScriptController::updateSecurityOrigin):
 16 (WebCore::ScriptController::evaluateInIsolatedWorld):
 17 (WebCore::ScriptController::haveInterpreter):
 18 (WebCore::ScriptController::mainWorldWindowShell):
 19 (WebCore::ScriptController::clearWindowShell):
 20 (WebCore::ScriptController::clearForClose):
 21 (WebCore::ScriptController::destroyWindowShell):
 22 (WebCore::ScriptController::updateDocument):
 23 * bindings/v8/ScriptController.h:
 24 * bindings/v8/V8DOMWindowShell.cpp:
 25 (WebCore::V8DOMWindowShell::~V8DOMWindowShell):
 26 * bindings/v8/V8DOMWindowShell.h:
 27 (WebCore::V8DOMWindowShell::localHandleForContext):
 28 * bindings/v8/V8DOMWrapper.cpp:
 29 (WebCore::V8DOMWrapper::instantiateV8Object):
 30 (WebCore::V8DOMWrapper::convertDocumentToV8Object):
 31 (WebCore::V8DOMWrapper::convertNewNodeToV8Object):
 32 * bindings/v8/V8IsolatedContext.cpp:
 33 (WebCore::V8IsolatedContext::V8IsolatedContext):
 34 * bindings/v8/V8Proxy.cpp:
 35 (WebCore::V8Proxy::V8Proxy):
 36 (WebCore::V8Proxy::~V8Proxy):
 37 (WebCore::V8Proxy::handleOutOfMemory):
 38 (WebCore::V8Proxy::evaluateInIsolatedWorld):
 39 (WebCore::V8Proxy::setInjectedScriptContextDebugId):
 40 (WebCore::V8Proxy::context):
 41 (WebCore::V8Proxy::mainWorldContext):
 42 (WebCore::V8Proxy::currentContext):
 43 (WebCore::V8Proxy::setContextDebugId):
 44 * bindings/v8/V8Proxy.h:
 45 * bindings/v8/WorldContextHandle.cpp:
 46 (WebCore::WorldContextHandle::adjustedContext):
 47
 482010-01-05 Adam Barth <abarth@webkit.org>
 49
350 Rubber stamped by Dimitri Glazkov.
451
552 Fix namespace indent for ScriptController.

WebCore/bindings/v8/ScriptController.cpp

@@ScriptController::ScriptController(Frame* frame)
106106 , m_processingTimerCallback(false)
107107 , m_paused(false)
108108 , m_proxy(new V8Proxy(frame))
 109 , m_windowShell(V8DOMWindowShell::create(frame))
109110#if ENABLE(NETSCAPE_PLUGIN_API)
110111 , m_windowScriptNPObject(0)
111112#endif

@@ScriptController::ScriptController(Frame* frame)
116117ScriptController::~ScriptController()
117118{
118119 m_proxy->disconnectFrame();
 120 m_windowShell.clear();
119121}
120122
121123void ScriptController::clearScriptObjects()

@@void ScriptController::clearScriptObjects()
140142
141143void ScriptController::updateSecurityOrigin()
142144{
143  m_proxy->windowShell()->updateSecurityOrigin();
 145 m_windowShell->updateSecurityOrigin();
144146}
145147
146148void ScriptController::updatePlatformScriptObjects()

@@bool ScriptController::anyPageIsProcessingUserGesture() const
205207
206208void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources)
207209{
 210 // FIXME: This will need to get reorganized once we have a windowShell for the isolated world.
 211 m_windowShell->initContextIfNeeded();
208212 m_proxy->evaluateInIsolatedWorld(worldID, sources, 0);
209213}
210214

@@void ScriptController::lowMemoryNotification()
291295
292296bool ScriptController::haveInterpreter() const
293297{
294  return m_proxy->windowShell()->isContextInitialized();
 298 return m_windowShell->isContextInitialized();
295299}
296300
297301bool ScriptController::isEnabled() const

@@NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement
435439 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(v8plugin), window);
436440}
437441
 442V8DOMWindowShell* ScriptController::mainWorldWindowShell() const
 443{
 444 m_windowShell->initContextIfNeeded();
 445 return m_windowShell.get();
 446}
438447
439448void ScriptController::clearWindowShell()
440449{
441450 m_mainWorldScriptState.clear();
 451 m_proxy->resetIsolatedWorlds();
442452
443453 // V8 binding expects ScriptController::clearWindowShell only be called
444  // when a frame is loading a new page. V8Proxy::clearForNavigation
 454 // when a frame is loading a new page. V8DOMWindowShell::clearForNavigation
445455 // creates a new context for the new page.
446  m_proxy->clearForNavigation();
 456 m_windowShell->clearForNavigation();
 457}
 458
 459void ScriptController::clearForClose()
 460{
 461 m_windowShell->clearForClose();
 462}
 463
 464void ScriptController::destroyWindowShell()
 465{
 466 m_windowShell->clearForClose();
 467 m_windowShell->destroyGlobal();
447468}
448469
449470void ScriptController::attachDebugger(void*)

@@void ScriptController::attachDebugger(void*)
453474
454475void ScriptController::updateDocument()
455476{
456  m_proxy->windowShell()->updateDocument();
 477 m_windowShell->updateDocument();
457478}
458479
459480} // namespace WebCore

WebCore/bindings/v8/ScriptController.h

@@public:
6363 // or this accessor should be made JSProxy*
6464 V8Proxy* proxy() { return m_proxy.get(); }
6565
 66 V8DOMWindowShell* mainWorldWindowShell() const;
 67
6668 ScriptValue executeScript(const ScriptSourceCode&);
6769 ScriptValue executeScript(const String& script, bool forceUserGesture = false);
6870

@@public:
153155 void clearWindowShell();
154156 void updateDocument();
155157
 158 void clearForClose();
 159
 160 // This is very destructive (e.g., out of memory).
 161 void destroyWindowShell();
 162
156163 void updateSecurityOrigin();
157164 void clearScriptObjects();
158165 void updatePlatformScriptObjects();

@@private:
182189 bool m_processingTimerCallback;
183190 bool m_paused;
184191
 192 // FIXME: V8Proxy should eventually be removed.
185193 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
186198 typedef HashMap<Widget*, NPObject*> PluginObjectMap;
187199
188200 // A mapping between Widgets and their corresponding script object.

WebCore/bindings/v8/V8DOMWindowShell.cpp

@@V8DOMWindowShell::V8DOMWindowShell(Frame* frame)
100100{
101101}
102102
 103V8DOMWindowShell::~V8DOMWindowShell()
 104{
 105 clearForClose();
 106 destroyGlobal();
 107}
 108
103109bool V8DOMWindowShell::isContextInitialized()
104110{
105111 // m_context, m_global, and m_wrapperBoilerplates should

WebCore/bindings/v8/V8DOMWindowShell.h

@@class V8DOMWindowShell : public RefCounted<V8DOMWindowShell> {
4646public:
4747 static PassRefPtr<V8DOMWindowShell> create(Frame*);
4848
 49 ~V8DOMWindowShell();
 50
4951 v8::Handle<v8::Context> context() const { return m_context; }
5052
 53 // This method is slower than |context()|, but sometimes we need local handles.
 54 v8::Local<v8::Context> localHandleForContext() const { return v8::Local<v8::Context>::New(m_context); }
 55
5156 // Update document object of the frame.
5257 void updateDocument();
5358

@@public:
6570
6671 void clearForNavigation();
6772 void clearForClose();
68 
6973 void destroyGlobal();
7074
7175 static v8::Handle<v8::Value> getHiddenObjectPrototype(v8::Handle<v8::Context>);

WebCore/bindings/v8/V8DOMWrapper.cpp

@@v8::Local<v8::Object> V8DOMWrapper::instantiateV8Object(V8Proxy* proxy, V8ClassI
802802 v8::Local<v8::Object> instance;
803803 if (proxy)
804804 // FIXME: Fix this to work properly with isolated worlds (see above).
805  instance = proxy->windowShell()->createWrapperFromCache(descriptorType);
 805 instance = proxy->frame()->script()->mainWorldWindowShell()->createWrapperFromCache(descriptorType);
806806 else {
807807 v8::Local<v8::Function> function = getTemplate(descriptorType)->GetFunction();
808808 instance = SafeAllocation::newInstance(function);

@@v8::Handle<v8::Value> V8DOMWrapper::convertDocumentToV8Object(Document* document
12041204 // instantiate a document wrapper. Therefore, we get the proxy before
12051205 // checking if the node already has a wrapper.
12061206 V8Proxy* proxy = V8Proxy::retrieve(document->frame());
1207  if (proxy)
1208  proxy->windowShell()->initContextIfNeeded();
 1207 if (proxy) {
 1208 // This code looks wacky:
 1209 // 1) The test for |proxy| above is really a test whether JavaScript
 1210 // is enabled in this frame. I have no idea if that's needed.
 1211 // 2) Calling initContextIfNeeded here is redundant becase just
 1212 // grabbing mainWorldWindowShell() already calls initContextIfNeeded.
 1213 // FIXME: I be we can clean this up a bit!
 1214 proxy->frame()->script()->mainWorldWindowShell()->initContextIfNeeded();
 1215 }
12091216
12101217 DOMWrapperMap<Node>& domNodeMap = getDOMNodeMap();
12111218 v8::Handle<v8::Object> wrapper = domNodeMap.get(document);

@@v8::Handle<v8::Value> V8DOMWrapper::convertNewNodeToV8Object(Node* node, V8Proxy
12941301 domNodeMap.set(node, v8::Persistent<v8::Object>::New(result));
12951302
12961303 if (isDocument) {
1297  if (proxy)
1298  proxy->windowShell()->updateDocumentWrapper(result);
 1304 if (proxy) {
 1305 // FIXME: Don't we need to do this for every world?
 1306 proxy->frame()->script()->mainWorldWindowShell()->updateDocumentWrapper(result);
 1307 }
12991308
13001309 if (type == V8ClassIndex::HTMLDOCUMENT) {
13011310 // Create marker object and insert it in two internal fields.

WebCore/bindings/v8/V8IsolatedContext.cpp

@@void V8IsolatedContext::contextWeakReferenceCallback(v8::Persistent<v8::Value> o
5353V8IsolatedContext::V8IsolatedContext(V8Proxy* proxy, int extensionGroup)
5454 : m_world(IsolatedWorld::create())
5555{
 56 // FIXME: None of this code belongs here! Basically, ScriptController
 57 // should create a new DOMWrapperWorld and a new windowShell and then
 58 // evaluate the script.
 59
 60 V8DOMWindowShell* mainWorldWindowShell = proxy->frame()->script()->mainWorldWindowShell();
 61
5662 v8::HandleScope scope;
5763 // FIXME: We should be creating a new V8DOMWindowShell here instead of riping out the context.
58  m_context = SharedPersistent<v8::Context>::create(proxy->windowShell()->createNewContext(v8::Handle<v8::Object>(), extensionGroup));
 64 m_context = SharedPersistent<v8::Context>::create(mainWorldWindowShell->createNewContext(v8::Handle<v8::Object>(), extensionGroup));
5965 if (m_context->get().IsEmpty())
6066 return;
6167

@@V8IsolatedContext::V8IsolatedContext(V8Proxy* proxy, int extensionGroup)
6672
6773 V8DOMWindowShell::installHiddenObjectPrototype(m_context->get());
6874 // FIXME: This will go away once we have a windowShell for the isolated world.
69  proxy->windowShell()->installDOMWindow(m_context->get(), proxy->frame()->domWindow());
 75 mainWorldWindowShell->installDOMWindow(m_context->get(), proxy->frame()->domWindow());
7076
7177 // Using the default security token means that the canAccess is always
7278 // called, which is slow.

WebCore/bindings/v8/V8Proxy.cpp

@@static void handleFatalErrorInV8()
213213
214214V8Proxy::V8Proxy(Frame* frame)
215215 : m_frame(frame)
216  , m_windowShell(V8DOMWindowShell::create(frame))
217216 , m_inlineCode(false)
218217 , m_timerCallback(false)
219218 , m_recursion(0)

@@V8Proxy::V8Proxy(Frame* frame)
222221
223222V8Proxy::~V8Proxy()
224223{
225  clearForClose();
226  windowShell()->destroyGlobal();
 224 resetIsolatedWorlds();
227225}
228226
229227v8::Handle<v8::Script> V8Proxy::compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine)

@@bool V8Proxy::handleOutOfMemory()
246244 // Warning, error, disable JS for this frame?
247245 Frame* frame = V8Proxy::retrieveFrame(context);
248246
249  V8Proxy* proxy = V8Proxy::retrieve(frame);
250  if (proxy) {
251  // Clean m_context, and event handlers.
252  proxy->clearForClose();
253 
254  proxy->windowShell()->destroyGlobal();
255  }
 247 frame->script()->destroyWindowShell();
256248
257249 ChromiumBridge::notifyJSOutOfMemory(frame);
258250

@@bool V8Proxy::handleOutOfMemory()
266258
267259void V8Proxy::evaluateInIsolatedWorld(int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup)
268260{
269  // FIXME: This will need to get reorganized once we have a windowShell for the isolated world.
270  windowShell()->initContextIfNeeded();
271 
272261 v8::HandleScope handleScope;
273262 V8IsolatedContext* isolatedContext = 0;
274263

@@bool V8Proxy::setInjectedScriptContextDebugId(v8::Handle<v8::Context> targetCont
314303{
315304 // Setup context id for JS debugger.
316305 v8::Context::Scope contextScope(targetContext);
317  v8::Handle<v8::Context> context = windowShell()->context();
 306 v8::Handle<v8::Context> context = m_frame->script()->mainWorldWindowShell()->localHandleForContext();
318307 if (context.IsEmpty())
319308 return false;
320309 int debugId = contextDebugId(context);

@@void V8Proxy::resetIsolatedWorlds()
584573 m_isolatedWorlds.clear();
585574}
586575
587 void V8Proxy::clearForClose()
588 {
589  resetIsolatedWorlds();
590  windowShell()->clearForClose();
591 }
592 
593 void V8Proxy::clearForNavigation()
594 {
595  resetIsolatedWorlds();
596  windowShell()->clearForNavigation();
597 }
598 
599576void V8Proxy::setDOMException(int exceptionCode)
600577{
601578 if (exceptionCode <= 0)

@@v8::Handle<v8::Value> V8Proxy::throwError(ErrorType type, const char* message)
655632
656633v8::Local<v8::Context> V8Proxy::context(Frame* frame)
657634{
 635 // FIXME: Move this function to ScriptController.
658636 v8::Local<v8::Context> context = V8Proxy::mainWorldContext(frame);
659637 if (context.IsEmpty())
660638 return v8::Local<v8::Context>();

@@v8::Local<v8::Context> V8Proxy::context(Frame* frame)
670648
671649v8::Local<v8::Context> V8Proxy::context()
672650{
 651 // FIXME: Move this function to ScriptController.
673652 if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered()) {
674653 RefPtr<SharedPersistent<v8::Context> > context = isolatedContext->sharedContext();
675654 if (m_frame != V8Proxy::retrieveFrame(context->get()))
676655 return v8::Local<v8::Context>();
677656 return v8::Local<v8::Context>::New(context->get());
678657 }
679  return mainWorldContext();
680 }
681 
682 v8::Local<v8::Context> V8Proxy::mainWorldContext()
683 {
684  windowShell()->initContextIfNeeded();
685  return v8::Local<v8::Context>::New(windowShell()->context());
 658 return m_frame->script()->mainWorldWindowShell()->localHandleForContext();
686659}
687660
688661v8::Local<v8::Context> V8Proxy::mainWorldContext(Frame* frame)
689662{
690  V8Proxy* proxy = retrieve(frame);
691  if (!proxy)
 663 // FIXME: Move this function to ScriptController.
 664 if (!frame->script()->isEnabled())
692665 return v8::Local<v8::Context>();
693666
694  return proxy->mainWorldContext();
 667 return frame->script()->mainWorldWindowShell()->localHandleForContext();
695668}
696669
697670v8::Local<v8::Context> V8Proxy::currentContext()
698671{
 672 // FIXME: Why does this function exist?
699673 return v8::Context::GetCurrent();
700674}
701675

@@void V8Proxy::registerExtension(v8::Extension* extension, int extensionGroup)
830804bool V8Proxy::setContextDebugId(int debugId)
831805{
832806 ASSERT(debugId > 0);
833  v8::Handle<v8::Context> context = windowShell()->context();
 807 v8::Local<v8::Context> context = m_frame->script()->mainWorldWindowShell()->localHandleForContext();
834808 if (context.IsEmpty())
835809 return false;
836810 v8::HandleScope scope;

WebCore/bindings/v8/V8Proxy.h

@@namespace WebCore {
152152
153153 Frame* frame() { return m_frame; }
154154
155  void clearForNavigation();
156  void clearForClose();
157 
158155 // FIXME: Need comment. User Gesture related.
159156 bool inlineCode() const { return m_inlineCode; }
160157 void setInlineCode(bool value) { m_inlineCode = value; }

@@namespace WebCore {
309306 static bool sourceName(String& result);
310307
311308 v8::Local<v8::Context> context();
312  v8::Local<v8::Context> mainWorldContext();
313 
314  // FIXME: This should eventually take DOMWrapperWorld argument!
315  V8DOMWindowShell* windowShell() const { return m_windowShell.get(); }
316309
317310 bool setContextDebugId(int id);
318311 static int contextDebugId(v8::Handle<v8::Context>);

@@namespace WebCore {
335328 // Report an unsafe attempt to access the given frame on the console.
336329 static void reportUnsafeAccessTo(Frame* target, DelayReporting delay);
337330
 331 // FIXME: This should move to ScriptController.
 332 void resetIsolatedWorlds();
 333
338334 private:
339335 // If m_recursionCount is 0, let LocalStorage know so we can release
340336 // the storage mutex.
341337 void releaseStorageMutex();
342338
343  void resetIsolatedWorlds();
344 
345339 // Returns false when we're out of memory in V8.
346340 bool setInjectedScriptContextDebugId(v8::Handle<v8::Context> targetContext);
347341

@@namespace WebCore {
370364
371365 Frame* m_frame;
372366
373  // For the moment, we have one of these. Soon we will have one per DOMWrapperWorld.
374  RefPtr<V8DOMWindowShell> m_windowShell;
375 
376367 // Utility context holding JavaScript functions used internally.
377368 static v8::Persistent<v8::Context> m_utilityContext;
378369

WebCore/bindings/v8/WorldContextHandle.cpp

3131#include "config.h"
3232#include "WorldContextHandle.h"
3333
 34#include "Frame.h"
3435#include "V8IsolatedContext.h"
3536
3637namespace WebCore {

@@WorldContextHandle::WorldContextHandle(WorldToUse worldToUse)
4849v8::Local<v8::Context> WorldContextHandle::adjustedContext(V8Proxy* proxy) const
4950{
5051 if (m_worldToUse == UseMainWorld)
51  return proxy->mainWorldContext();
 52 return proxy->frame()->script()->mainWorldWindowShell()->localHandleForContext();
5253 if (!m_context || m_context->get().IsEmpty())
5354 return proxy->context();
5455 return v8::Local<v8::Context>::New(m_context->get());

WebKit/chromium/ChangeLog

 12010-01-05 Adam Barth <abarth@webkit.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 [v8] Move V8DOMWindowShell to ScriptController
 6 https://bugs.webkit.org/show_bug.cgi?id=33232
 7
 8 Update FrameLoaderClientImpl.cpp to call clearForClose on
 9 ScriptController instead of on V8Proxy.
 10
 11 * src/FrameLoaderClientImpl.cpp:
 12 (WebKit::FrameLoaderClientImpl::detachedFromParent3):
 13
1142010-01-04 Maciej Stachowiak <mjs@apple.com>
215
316 Reviewed by Darin Fisher.

WebKit/chromium/src/FrameLoaderClientImpl.cpp

@@void FrameLoaderClientImpl::detachedFromParent3()
215215 // will cause a crash. If you remove/modify this, just ensure that you can
216216 // go to a page and then navigate to a new page without getting any asserts
217217 // or crashes.
218  m_webFrame->frame()->script()->proxy()->clearForClose();
219 
 218 m_webFrame->frame()->script()->clearForClose();
 219
220220 // Stop communicating with the WebFrameClient at this point since we are no
221221 // longer associated with the Page.
222222 m_webFrame->dropClient();