Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1875)

Unified Diff: extensions/renderer/script_injection_manager.cc

Issue 952473002: Add frameId to executeScript/insertCSS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a few nits (review up to comment 16) Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/common/extension_messages.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/script_injection_manager.cc
diff --git a/extensions/renderer/script_injection_manager.cc b/extensions/renderer/script_injection_manager.cc
index 93862dd04bdfe1109bf23c223ccef4cb734ec90e..f20194d620fcf8f9470a9c5f4523ad07517bf2c7 100644
--- a/extensions/renderer/script_injection_manager.cc
+++ b/extensions/renderer/script_injection_manager.cc
@@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
+#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/render_view_observer.h"
@@ -67,6 +68,29 @@ scoped_ptr<ExtensionInjectionHost> GetExtensionInjectionHost(
new ExtensionInjectionHost(extension));
}
+// TODO(robwu): ScriptInjectionManager should use RenderFrame instead of
+// RenderView. Then the browser should direct messages to specific frames and
+// this check becomes redundant (https://crbug.com/460950).
+blink::WebLocalFrame* GetFrameByFrameId(blink::WebFrame* parent_frame,
+ int frame_id) {
+ DCHECK(parent_frame);
+ blink::WebLocalFrame* result = nullptr;
+ for (blink::WebFrame* frame = parent_frame->firstChild(); !result && frame;
+ frame = frame->nextSibling()) {
+ content::RenderFrame* rf = content::RenderFrame::FromWebFrame(frame);
+ if (rf && rf->GetRoutingID() == frame_id) {
+ // TODO(robwu): This does not work with OOPIF. That doesn't really matter
+ // for now, because ScriptInjectionManager is not OOPIF-friendly anyway.
+ // This helper function will be obsolete when this class is converted to
+ // RenderFrame.
+ result = frame->toWebLocalFrame();
+ } else {
+ result = GetFrameByFrameId(frame, frame_id);
+ }
+ }
+ return result;
+}
+
} // namespace
class ScriptInjectionManager::RVOHelper : public content::RenderViewObserver {
@@ -418,16 +442,18 @@ void ScriptInjectionManager::InjectScripts(
void ScriptInjectionManager::HandleExecuteCode(
const ExtensionMsg_ExecuteCode_Params& params,
content::RenderView* render_view) {
+ blink::WebLocalFrame* main_frame =
+ render_view->GetWebView()->mainFrame()->toWebLocalFrame();
+ if (main_frame && params.frame_id > 0)
+ main_frame = GetFrameByFrameId(main_frame, params.frame_id);
// 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(),
params.request_id,
- "No main frame",
+ "Frame not found.",
GURL(std::string()),
base::ListValue()));
return;
« no previous file with comments | « extensions/common/extension_messages.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698