summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-12 00:48:58 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-12 00:48:58 +0000
commit9a7b22e6fb1d115a694616fd5a12bfe6e491664b (patch)
tree505bc1a11530c975bf45588b19aa6c3cfbc36c13
parent08da43b40e557c42b93fe490e91ab44a73d7e0dd (diff)
downloadchromium_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
-rw-r--r--DEPS2
-rw-r--r--chrome/renderer/extensions/bindings_utils.cc6
-rw-r--r--chrome/renderer/extensions/bindings_utils.h4
-rw-r--r--chrome/renderer/extensions/extension_process_bindings.cc6
-rw-r--r--chrome/renderer/extensions/renderer_extension_bindings.cc6
-rw-r--r--chrome/renderer/external_extension.cc2
-rw-r--r--chrome/renderer/loadtimes_extension_bindings.cc2
-rw-r--r--webkit/glue/devtools/debugger_agent_manager.cc2
-rw-r--r--webkit/glue/webdevtoolsclient_impl.cc4
-rw-r--r--webkit/glue/webframe.h18
-rw-r--r--webkit/glue/webframe_impl.cc15
-rw-r--r--webkit/port/bindings/v8/JSXPathNSResolver.cpp2
-rw-r--r--webkit/port/bindings/v8/ScriptController.cpp11
-rw-r--r--webkit/port/bindings/v8/ScriptController.h14
-rw-r--r--webkit/port/bindings/v8/v8_custom.cpp2
-rw-r--r--webkit/port/bindings/v8/v8_proxy.cpp17
-rw-r--r--webkit/port/bindings/v8/v8_proxy.h26
17 files changed, 101 insertions, 38 deletions
diff --git a/DEPS b/DEPS
index 7228d96..c866d54 100644
--- a/DEPS
+++ b/DEPS
@@ -1,7 +1,7 @@
vars = {
"webkit_trunk":
"http://svn.webkit.org/repository/webkit/trunk",
- "webkit_revision": "43511",
+ "webkit_revision": "43512",
}
diff --git a/chrome/renderer/extensions/bindings_utils.cc b/chrome/renderer/extensions/bindings_utils.cc
index ee4688d..097c8d0 100644
--- a/chrome/renderer/extensions/bindings_utils.cc
+++ b/chrome/renderer/extensions/bindings_utils.cc
@@ -7,9 +7,9 @@
#include "chrome/renderer/render_view.h"
#include "webkit/glue/webframe.h"
-RenderView* GetActiveRenderView() {
- WebFrame* webframe = WebFrame::RetrieveActiveFrame();
- DCHECK(webframe) << "GetActiveRenderView called when not in a V8 context.";
+RenderView* GetRenderViewForCurrentContext() {
+ WebFrame* webframe = WebFrame::RetrieveFrameForCurrentContext();
+ DCHECK(webframe) << "RetrieveCurrentFrame called when not in a V8 context.";
if (!webframe)
return NULL;
diff --git a/chrome/renderer/extensions/bindings_utils.h b/chrome/renderer/extensions/bindings_utils.h
index 7f336c3..7596952 100644
--- a/chrome/renderer/extensions/bindings_utils.h
+++ b/chrome/renderer/extensions/bindings_utils.h
@@ -28,8 +28,8 @@ const char* GetStringResource() {
Singleton< StringResourceTemplate<kResourceId> >::get()->resource.c_str();
}
-// Returns the active RenderView, based on which V8 context is active. It is
+// Returns the current RenderView, based on which V8 context is current. It is
// an error to call this when not in a V8 context.
-RenderView* GetActiveRenderView();
+RenderView* GetRenderViewForCurrentContext();
#endif // CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_
diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc
index 1a3614f..032d4570 100644
--- a/chrome/renderer/extensions/extension_process_bindings.cc
+++ b/chrome/renderer/extensions/extension_process_bindings.cc
@@ -69,8 +69,10 @@ class ExtensionImpl : public v8::Extension {
}
static v8::Handle<v8::Value> StartRequest(const v8::Arguments& args) {
- WebFrame* webframe = WebFrame::RetrieveActiveFrame();
- RenderView* renderview = GetActiveRenderView();
+ // Get the current RenderView so that we can send a routed IPC message from
+ // the correct source.
+ WebFrame* webframe = WebFrame::RetrieveFrameForCurrentContext();
+ RenderView* renderview = GetRenderViewForCurrentContext();
if (!webframe || !renderview)
return v8::Undefined();
diff --git a/chrome/renderer/extensions/renderer_extension_bindings.cc b/chrome/renderer/extensions/renderer_extension_bindings.cc
index 4d894a4..86d3d15 100644
--- a/chrome/renderer/extensions/renderer_extension_bindings.cc
+++ b/chrome/renderer/extensions/renderer_extension_bindings.cc
@@ -49,7 +49,9 @@ class ExtensionImpl : public v8::Extension {
// Creates a new messaging channel to the given extension.
static v8::Handle<v8::Value> OpenChannelToExtension(
const v8::Arguments& args) {
- RenderView* renderview = GetActiveRenderView();
+ // Get the current RenderView so that we can send a routed IPC message from
+ // the correct source.
+ RenderView* renderview = GetRenderViewForCurrentContext();
if (!renderview)
return v8::Undefined();
@@ -65,7 +67,7 @@ class ExtensionImpl : public v8::Extension {
// Sends a message along the given channel.
static v8::Handle<v8::Value> PostMessage(const v8::Arguments& args) {
- RenderView* renderview = GetActiveRenderView();
+ RenderView* renderview = GetRenderViewForCurrentContext();
if (!renderview)
return v8::Undefined();
diff --git a/chrome/renderer/external_extension.cc b/chrome/renderer/external_extension.cc
index 378e78e..100f311 100644
--- a/chrome/renderer/external_extension.cc
+++ b/chrome/renderer/external_extension.cc
@@ -35,7 +35,7 @@ class ExternalExtensionWrapper : public v8::Extension {
if (!args.Length())
return v8::Undefined();
- WebFrame* webframe = WebFrame::RetrieveActiveFrame();
+ WebFrame* webframe = WebFrame::RetrieveFrameForEnteredContext();
DCHECK(webframe) << "There should be an active frame since we just got "
"a native function called.";
if (!webframe) return v8::Undefined();
diff --git a/chrome/renderer/loadtimes_extension_bindings.cc b/chrome/renderer/loadtimes_extension_bindings.cc
index 49f2b25..6acbbe6 100644
--- a/chrome/renderer/loadtimes_extension_bindings.cc
+++ b/chrome/renderer/loadtimes_extension_bindings.cc
@@ -55,7 +55,7 @@ class LoadTimesExtensionWrapper : public v8::Extension {
}
static v8::Handle<v8::Value> GetLoadTimes(const v8::Arguments& args) {
- WebFrame* win_frame = WebFrame::RetrieveActiveFrame();
+ WebFrame* win_frame = WebFrame::RetrieveFrameForEnteredContext();
if (win_frame) {
WebDataSource* data_source = win_frame->GetDataSource();
if (data_source) {
diff --git a/webkit/glue/devtools/debugger_agent_manager.cc b/webkit/glue/devtools/debugger_agent_manager.cc
index aa692aa..41461c8 100644
--- a/webkit/glue/devtools/debugger_agent_manager.cc
+++ b/webkit/glue/devtools/debugger_agent_manager.cc
@@ -235,7 +235,7 @@ DebuggerAgentImpl* DebuggerAgentManager::FindAgentForCurrentV8Context() {
}
DCHECK(!attached_agents_->isEmpty());
- WebCore::Frame* frame = WebCore::V8Proxy::retrieveActiveFrame();
+ WebCore::Frame* frame = WebCore::V8Proxy::retrieveFrameForEnteredContext();
if (!frame) {
return NULL;
}
diff --git a/webkit/glue/webdevtoolsclient_impl.cc b/webkit/glue/webdevtoolsclient_impl.cc
index d887022..7de27db 100644
--- a/webkit/glue/webdevtoolsclient_impl.cc
+++ b/webkit/glue/webdevtoolsclient_impl.cc
@@ -197,7 +197,7 @@ v8::Handle<v8::Value> WebDevToolsClientImpl::JsAddSourceToFrame(
return v8::Undefined();
}
- Page* page = V8Proxy::retrieveActiveFrame()->page();
+ Page* page = V8Proxy::retrieveFrameForEnteredContext()->page();
InspectorController* inspectorController = page->inspectorController();
return WebCore::v8Boolean(inspectorController->
addSourceToFrame(mime_type, source_string, node));
@@ -211,7 +211,7 @@ v8::Handle<v8::Value> WebDevToolsClientImpl::JsLoaded(
client->loaded_ = true;
// Grant the devtools page the ability to have source view iframes.
- Page* page = V8Proxy::retrieveActiveFrame()->page();
+ Page* page = V8Proxy::retrieveFrameForEnteredContext()->page();
SecurityOrigin* origin = page->mainFrame()->domWindow()->securityOrigin();
origin->grantUniversalAccess();
diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h
index e1495fa..77d3b27 100644
--- a/webkit/glue/webframe.h
+++ b/webkit/glue/webframe.h
@@ -32,7 +32,23 @@ class WebFrame {
public:
WebFrame() {}
- static WebFrame* 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.
+ static WebFrame* RetrieveFrameForEnteredContext();
+ static WebFrame* RetrieveFrameForCurrentContext();
// Binds a C++ class to a JavaScript property of the window object. This
// should generally be used via CppBoundClass::BindToJavascript() instead of
diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc
index 466fe5f..db177aa 100644
--- a/webkit/glue/webframe_impl.cc
+++ b/webkit/glue/webframe_impl.cc
@@ -341,8 +341,19 @@ class ChromePrintContext : public WebCore::PrintContext {
int WebFrameImpl::live_object_count_ = 0;
// static
-WebFrame* WebFrame::RetrieveActiveFrame() {
- WebCore::Frame* frame = WebCore::ScriptController::retrieveActiveFrame();
+WebFrame* WebFrame::RetrieveFrameForEnteredContext() {
+ WebCore::Frame* frame =
+ WebCore::ScriptController::retrieveFrameForEnteredContext();
+ if (frame)
+ return WebFrameImpl::FromFrame(frame);
+ else
+ return NULL;
+}
+
+// static
+WebFrame* WebFrame::RetrieveFrameForCurrentContext() {
+ WebCore::Frame* frame =
+ WebCore::ScriptController::retrieveFrameForCurrentContext();
if (frame)
return WebFrameImpl::FromFrame(frame);
else
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.