diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-12 00:48:58 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-12 00:48:58 +0000 |
commit | 9a7b22e6fb1d115a694616fd5a12bfe6e491664b (patch) | |
tree | 505bc1a11530c975bf45588b19aa6c3cfbc36c13 /webkit/port | |
parent | 08da43b40e557c42b93fe490e91ab44a73d7e0dd (diff) | |
download | chromium_src-9a7b22e6fb1d115a694616fd5a12bfe6e491664b.zip chromium_src-9a7b22e6fb1d115a694616fd5a12bfe6e491664b.tar.gz chromium_src-9a7b22e6fb1d115a694616fd5a12bfe6e491664b.tar.bz2 |
Split V8Proxy::retrieveActiveFrame() into two methods.
We now have RetrieveFrameForCurrentContext() and
RetrieveFrameForEnteredContext().
These terms means the same thing they do in V8::Context --
'current' is the top of the js stack and 'entered' is the
bottom.
I needed 'entered' to fix a bug in extensions where if you
call an extension API through the web inspector we get
confused and think the web inspector's view is the one who
called.
Review URL: http://codereview.chromium.org/113085
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15828 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/port')
-rw-r--r-- | webkit/port/bindings/v8/JSXPathNSResolver.cpp | 2 | ||||
-rw-r--r-- | webkit/port/bindings/v8/ScriptController.cpp | 11 | ||||
-rw-r--r-- | webkit/port/bindings/v8/ScriptController.h | 14 | ||||
-rw-r--r-- | webkit/port/bindings/v8/v8_custom.cpp | 2 | ||||
-rw-r--r-- | webkit/port/bindings/v8/v8_proxy.cpp | 17 | ||||
-rw-r--r-- | webkit/port/bindings/v8/v8_proxy.h | 26 |
6 files changed, 52 insertions, 20 deletions
diff --git a/webkit/port/bindings/v8/JSXPathNSResolver.cpp b/webkit/port/bindings/v8/JSXPathNSResolver.cpp index 2fb2849..b1ede2e 100644 --- a/webkit/port/bindings/v8/JSXPathNSResolver.cpp +++ b/webkit/port/bindings/v8/JSXPathNSResolver.cpp @@ -58,7 +58,7 @@ String JSXPathNSResolver::lookupNamespaceURI(const String& prefix) { } if (lookupNamespaceURIFunc.IsEmpty() && !m_resolver->IsFunction()) { - Frame* frame = V8Proxy::retrieveActiveFrame(); + Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); log_info(frame, "XPathNSResolver does not have a lookupNamespaceURI method.", String()); return String(); } diff --git a/webkit/port/bindings/v8/ScriptController.cpp b/webkit/port/bindings/v8/ScriptController.cpp index bde1b3d..1865cd5 100644 --- a/webkit/port/bindings/v8/ScriptController.cpp +++ b/webkit/port/bindings/v8/ScriptController.cpp @@ -80,9 +80,14 @@ void ScriptController::setFlags(const char* str, int length) v8::V8::SetFlagsFromString(str, length); } -Frame* ScriptController::retrieveActiveFrame() +Frame* ScriptController::retrieveFrameForEnteredContext() { - return V8Proxy::retrieveActiveFrame(); + return V8Proxy::retrieveFrameForEnteredContext(); +} + +Frame* ScriptController::retrieveFrameForCurrentContext() +{ + return V8Proxy::retrieveFrameForCurrentContext(); } bool ScriptController::isSafeScript(Frame* target) @@ -155,7 +160,7 @@ void ScriptController::disconnectFrame() bool ScriptController::processingUserGesture() const { - Frame* active_frame = V8Proxy::retrieveActiveFrame(); + Frame* active_frame = V8Proxy::retrieveFrameForEnteredContext(); // No script is running, must be run by users. if (!active_frame) return true; diff --git a/webkit/port/bindings/v8/ScriptController.h b/webkit/port/bindings/v8/ScriptController.h index 4009a71..6f052d2 100644 --- a/webkit/port/bindings/v8/ScriptController.h +++ b/webkit/port/bindings/v8/ScriptController.h @@ -198,13 +198,13 @@ public: // --- Static methods assume we are running VM in single thread, --- // --- and there is only one VM instance. --- - // Returns the frame of the calling code is in. - // Not necessary the frame of this proxy. - // For example, JS code in frame A calls windowB.open(...). - // Window::open method has the frame pointer of B, but - // the execution context is in frame A, so it needs - // frame A's loader to complete URL. - static Frame* retrieveActiveFrame(); + // Returns the frame for the entered context. See comments in + // V8Proxy::retrieveFrameForEnteredContext() for more information. + static Frame* retrieveFrameForEnteredContext(); + + // Returns the frame for the current context. See comments in + // V8Proxy::retrieveFrameForEnteredContext() for more information. + static Frame* retrieveFrameForCurrentContext(); // Check whether it is safe to access a frame in another domain. static bool isSafeScript(Frame* target); diff --git a/webkit/port/bindings/v8/v8_custom.cpp b/webkit/port/bindings/v8/v8_custom.cpp index bf8cefc..795e34f 100644 --- a/webkit/port/bindings/v8/v8_custom.cpp +++ b/webkit/port/bindings/v8/v8_custom.cpp @@ -1083,7 +1083,7 @@ ACCESSOR_SETTER(ElementEventHandler) { // the document might be created using createDocument, // which does not have a frame, use the active frame if (!proxy) - proxy = V8Proxy::retrieve(V8Proxy::retrieveActiveFrame()); + proxy = V8Proxy::retrieve(V8Proxy::retrieveFrameForEnteredContext()); if (!proxy) return; diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp index 5685375..8413219 100644 --- a/webkit/port/bindings/v8/v8_proxy.cpp +++ b/webkit/port/bindings/v8/v8_proxy.cpp @@ -622,7 +622,7 @@ void ConsoleMessageManager::ProcessDelayedMessages() // context. If that for some bizarre reason does not // exist, we clear the list of delayed messages to avoid // posting messages. We still deallocate the vector. - Frame* frame = V8Proxy::retrieveActiveFrame(); + Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); Page* page = NULL; if (frame) page = frame->page(); @@ -663,7 +663,7 @@ static void HandleConsoleMessage(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data) { // Use the frame where JavaScript is called from. - Frame* frame = V8Proxy::retrieveActiveFrame(); + Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); if (!frame) return; @@ -700,7 +700,7 @@ static void ReportUnsafeAccessTo(Frame* target, DelayReporting delay) if (!targetDocument) return; - Frame* source = V8Proxy::retrieveActiveFrame(); + Frame* source = V8Proxy::retrieveFrameForEnteredContext(); if (!source || !source->document()) return; // Ignore error if the source document is gone. @@ -1632,7 +1632,7 @@ Frame* V8Proxy::retrieveFrame(v8::Handle<v8::Context> context) } -Frame* V8Proxy::retrieveActiveFrame() +Frame* V8Proxy::retrieveFrameForEnteredContext() { v8::Handle<v8::Context> context = v8::Context::GetEntered(); if (context.IsEmpty()) @@ -1641,6 +1641,15 @@ Frame* V8Proxy::retrieveActiveFrame() } +Frame* V8Proxy::retrieveFrameForCurrentContext() +{ + v8::Handle<v8::Context> context = v8::Context::GetCurrent(); + if (context.IsEmpty()) + return 0; + return retrieveFrame(context); +} + + Frame* V8Proxy::retrieveFrame() { DOMWindow* window = retrieveWindow(); diff --git a/webkit/port/bindings/v8/v8_proxy.h b/webkit/port/bindings/v8/v8_proxy.h index 01b3116..ea32708 100644 --- a/webkit/port/bindings/v8/v8_proxy.h +++ b/webkit/port/bindings/v8/v8_proxy.h @@ -283,10 +283,28 @@ class V8Proxy { // Returns the frame object of the window object associated with // a context. static Frame* retrieveFrame(v8::Handle<v8::Context> context); - // Returns the frame that started JS execution. - // NOTE: cannot declare retrieveActiveFrame as inline function, - // VS complains at linking time. - static Frame* retrieveActiveFrame(); + + + // The two functions below retrieve WebFrame instances relating the currently + // executing JavaScript. Since JavaScript can make function calls across + // frames, though, we need to be more precise. + // + // For example, imagine that a JS function in frame A calls a function in + // frame B, which calls native code, which wants to know what the 'active' + // frame is. + // + // The 'entered context' is the context where execution first entered the + // script engine; the context that is at the bottom of the JS function stack. + // RetrieveFrameForEnteredContext() would return Frame A in our example. + // + // The 'current context' is the context the JS engine is currently inside of; + // the context that is at the top of the JS function stack. + // RetrieveFrameForCurrentContext() would return Frame B in our example. + // + // NOTE: These cannot be declared as inline function, because VS complains at + // linking time. + static Frame* retrieveFrameForEnteredContext(); + static Frame* retrieveFrameForCurrentContext(); // Returns V8 Context of a frame. If none exists, creates // a new context. It is potentially slow and consumes memory. |