summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordcheng <dcheng@chromium.org>2014-09-23 21:30:56 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-24 04:31:08 +0000
commit2e44917894a92a0d6fb0e56e3220811f811d1c8e (patch)
treec1ab6fa48ba41d9f2d27a11907105f618c0bbf20
parent5e4a92f923982405e20195e9de9f675c41e0748c (diff)
downloadchromium_src-2e44917894a92a0d6fb0e56e3220811f811d1c8e.zip
chromium_src-2e44917894a92a0d6fb0e56e3220811f811d1c8e.tar.gz
chromium_src-2e44917894a92a0d6fb0e56e3220811f811d1c8e.tar.bz2
Change ScriptInjection to work with WebLocalFrames.
This is to help unblock some of the Blink work to move local frame only APIs off WebFrame. Strictly speaking, all that was required to unblock this bug was to manually coerce the WebFrame to a WebLocalFrame for the call to setIsolatedWorldHumanReadableName. However, it never makes sense to inject script on a remote frame, so I've updated ScriptInjection to just work with local frames where possible. Code that uses ScriptInjection now does the type coercion at the class boundary. As extensions code is gradually updated to understand out-of-process iframes, these manual type coercions should disappear. BUG=416659 Review URL: https://codereview.chromium.org/594043002 Cr-Commit-Position: refs/heads/master@{#296345}
-rw-r--r--extensions/renderer/script_injection.cc14
-rw-r--r--extensions/renderer/script_injection.h12
-rw-r--r--extensions/renderer/script_injection_manager.cc10
-rw-r--r--extensions/renderer/user_script_set.cc4
4 files changed, 25 insertions, 15 deletions
diff --git a/extensions/renderer/script_injection.cc b/extensions/renderer/script_injection.cc
index 2a68720..ea588fe 100644
--- a/extensions/renderer/script_injection.cc
+++ b/extensions/renderer/script_injection.cc
@@ -21,7 +21,7 @@
#include "extensions/renderer/extensions_renderer_client.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/web/WebDocument.h"
-#include "third_party/WebKit/public/web/WebFrame.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebScopedUserGesture.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
@@ -59,7 +59,7 @@ void AppendAllChildFrames(blink::WebFrame* parent_frame,
// |frame|. If no isolated world has been created for that extension,
// one will be created and initialized.
int GetIsolatedWorldIdForExtension(const Extension* extension,
- blink::WebFrame* frame) {
+ blink::WebLocalFrame* frame) {
static int g_next_isolated_world_id =
ExtensionsRendererClient::Get()->GetLowestIsolatedWorldId();
@@ -114,7 +114,7 @@ void ScriptInjection::RemoveIsolatedWorld(const std::string& extension_id) {
ScriptInjection::ScriptInjection(
scoped_ptr<ScriptInjector> injector,
- blink::WebFrame* web_frame,
+ blink::WebLocalFrame* web_frame,
const std::string& extension_id,
UserScript::RunLocation run_location,
int tab_id)
@@ -223,7 +223,9 @@ void ScriptInjection::Inject(const Extension* extension,
for (std::vector<blink::WebFrame*>::iterator iter = frame_vector.begin();
iter != frame_vector.end();
++iter) {
- blink::WebFrame* frame = *iter;
+ // TODO(dcheng): Unfortunately, the code as written won't work in an OOPI
+ // world. This is just a temporary hack to make things compile.
+ blink::WebLocalFrame* frame = (*iter)->toWebLocalFrame();
// We recheck access here in the renderer for extra safety against races
// with navigation, but different frames can have different URLs, and the
@@ -251,7 +253,7 @@ void ScriptInjection::Inject(const Extension* extension,
}
void ScriptInjection::InjectJs(const Extension* extension,
- blink::WebFrame* frame,
+ blink::WebLocalFrame* frame,
base::ListValue* execution_results) {
std::vector<blink::WebScriptSource> sources =
injector_->GetJsSources(run_location_);
@@ -307,7 +309,7 @@ void ScriptInjection::InjectJs(const Extension* extension,
}
}
-void ScriptInjection::InjectCss(blink::WebFrame* frame) {
+void ScriptInjection::InjectCss(blink::WebLocalFrame* frame) {
std::vector<std::string> css_sources =
injector_->GetCssSources(run_location_);
for (std::vector<std::string>::const_iterator iter = css_sources.begin();
diff --git a/extensions/renderer/script_injection.h b/extensions/renderer/script_injection.h
index 42ecdbd..d7edd66 100644
--- a/extensions/renderer/script_injection.h
+++ b/extensions/renderer/script_injection.h
@@ -11,7 +11,7 @@
#include "extensions/renderer/script_injector.h"
namespace blink {
-class WebFrame;
+class WebLocalFrame;
}
namespace extensions {
@@ -29,7 +29,7 @@ class ScriptInjection {
static void RemoveIsolatedWorld(const std::string& extension_id);
ScriptInjection(scoped_ptr<ScriptInjector> injector,
- blink::WebFrame* web_frame,
+ blink::WebLocalFrame* web_frame,
const std::string& extension_id,
UserScript::RunLocation run_location,
int tab_id);
@@ -50,7 +50,7 @@ class ScriptInjection {
ScriptsRunInfo* scripts_run_info);
// Accessors.
- blink::WebFrame* web_frame() const { return web_frame_; }
+ blink::WebLocalFrame* web_frame() const { return web_frame_; }
const std::string& extension_id() const { return extension_id_; }
int64 request_id() const { return request_id_; }
@@ -64,11 +64,11 @@ class ScriptInjection {
// Inject any JS scripts into the |frame|, optionally populating
// |execution_results|.
void InjectJs(const Extension* extension,
- blink::WebFrame* frame,
+ blink::WebLocalFrame* frame,
base::ListValue* execution_results);
// Inject any CSS source into the |frame|.
- void InjectCss(blink::WebFrame* frame);
+ void InjectCss(blink::WebLocalFrame* frame);
// Notify that we will not inject, and mark it as acknowledged.
void NotifyWillNotInject(ScriptInjector::InjectFailureReason reason);
@@ -77,7 +77,7 @@ class ScriptInjection {
scoped_ptr<ScriptInjector> injector_;
// The (main) WebFrame into which this should inject the script.
- blink::WebFrame* web_frame_;
+ blink::WebLocalFrame* web_frame_;
// The id of the associated extension.
std::string extension_id_;
diff --git a/extensions/renderer/script_injection_manager.cc b/extensions/renderer/script_injection_manager.cc
index 14f2767..abd7d80 100644
--- a/extensions/renderer/script_injection_manager.cc
+++ b/extensions/renderer/script_injection_manager.cc
@@ -321,7 +321,11 @@ void ScriptInjectionManager::InjectScripts(
void ScriptInjectionManager::HandleExecuteCode(
const ExtensionMsg_ExecuteCode_Params& params,
content::RenderView* render_view) {
- blink::WebFrame* main_frame = render_view->GetWebView()->mainFrame();
+ // TODO(dcheng): Not sure how this can happen today. In an OOPI world, it
+ // would indicate a logic error--the browser must direct this request to the
+ // right renderer process to begin with.
+ blink::WebLocalFrame* main_frame =
+ render_view->GetWebView()->mainFrame()->toWebLocalFrame();
if (!main_frame) {
render_view->Send(
new ExtensionHostMsg_ExecuteCodeFinished(render_view->GetRoutingID(),
@@ -357,10 +361,12 @@ void ScriptInjectionManager::HandleExecuteDeclarativeScript(
int script_id,
const GURL& url) {
const Extension* extension = extensions_->GetByID(extension_id);
+ // TODO(dcheng): This function signature should really be a WebLocalFrame,
+ // rather than trying to coerce it here.
scoped_ptr<ScriptInjection> injection =
user_script_set_manager_->GetInjectionForDeclarativeScript(
script_id,
- web_frame,
+ web_frame->toWebLocalFrame(),
tab_id,
url,
extension);
diff --git a/extensions/renderer/user_script_set.cc b/extensions/renderer/user_script_set.cc
index 92608bd..87f91fc 100644
--- a/extensions/renderer/user_script_set.cc
+++ b/extensions/renderer/user_script_set.cc
@@ -171,6 +171,8 @@ scoped_ptr<ScriptInjection> UserScriptSet::GetDeclarativeScriptInjection(
return scoped_ptr<ScriptInjection>();
}
+// TODO(dcheng): Scripts can't be injected on a remote frame, so this function
+// signature needs to be updated.
scoped_ptr<ScriptInjection> UserScriptSet::GetInjectionForScript(
UserScript* script,
blink::WebFrame* web_frame,
@@ -208,7 +210,7 @@ scoped_ptr<ScriptInjection> UserScriptSet::GetInjectionForScript(
if (inject_css || inject_js) {
injection.reset(new ScriptInjection(
injector.Pass(),
- web_frame,
+ web_frame->toWebLocalFrame(),
extension->id(),
run_location,
tab_id));