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

Side by Side Diff: chrome/browser/extensions/script_executor.cc

Issue 286003004: Block tabs.executeScript() from executing until user grants permission (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/script_executor.h" 5 #include "chrome/browser/extensions/script_executor.h"
6 6
7 #include "base/bind.h"
7 #include "base/callback.h" 8 #include "base/callback.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/pickle.h" 10 #include "base/pickle.h"
10 #include "chrome/browser/extensions/active_script_controller.h" 11 #include "chrome/browser/extensions/active_script_controller.h"
11 #include "chrome/browser/extensions/tab_helper.h" 12 #include "chrome/browser/extensions/tab_helper.h"
12 #include "content/public/browser/navigation_controller.h" 13 #include "content/public/browser/navigation_controller.h"
13 #include "content/public/browser/navigation_entry.h" 14 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/render_view_host.h" 15 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_observer.h" 17 #include "content/public/browser/web_contents_observer.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 const std::string& code, 120 const std::string& code,
120 ScriptExecutor::FrameScope frame_scope, 121 ScriptExecutor::FrameScope frame_scope,
121 UserScript::RunLocation run_at, 122 UserScript::RunLocation run_at,
122 ScriptExecutor::WorldType world_type, 123 ScriptExecutor::WorldType world_type,
123 ScriptExecutor::ProcessType process_type, 124 ScriptExecutor::ProcessType process_type,
124 const GURL& webview_src, 125 const GURL& webview_src,
125 const GURL& file_url, 126 const GURL& file_url,
126 bool user_gesture, 127 bool user_gesture,
127 ScriptExecutor::ResultType result_type, 128 ScriptExecutor::ResultType result_type,
128 const ExecuteScriptCallback& callback) { 129 const ExecuteScriptCallback& callback) {
129 ActiveScriptController* active_script_controller =
130 ActiveScriptController::GetForWebContents(web_contents_);
131 content::NavigationEntry* visible_entry =
132 web_contents_->GetController().GetVisibleEntry();
133 if (active_script_controller && visible_entry) {
134 // TODO(rdevlin.cronin): Now, this is just a notification. Soon, it should
135 // block until the user gives the OK to execute.
136 active_script_controller->NotifyScriptExecuting(extension_id,
137 visible_entry->GetPageID());
138 }
139
140 ExtensionMsg_ExecuteCode_Params params; 130 ExtensionMsg_ExecuteCode_Params params;
141 params.request_id = next_request_id_++; 131 params.request_id = next_request_id_++;
142 params.extension_id = extension_id; 132 params.extension_id = extension_id;
143 params.is_javascript = (script_type == JAVASCRIPT); 133 params.is_javascript = (script_type == JAVASCRIPT);
144 params.code = code; 134 params.code = code;
145 params.all_frames = (frame_scope == ALL_FRAMES); 135 params.all_frames = (frame_scope == ALL_FRAMES);
146 params.run_at = static_cast<int>(run_at); 136 params.run_at = static_cast<int>(run_at);
147 params.in_main_world = (world_type == MAIN_WORLD); 137 params.in_main_world = (world_type == MAIN_WORLD);
148 params.is_web_view = (process_type == WEB_VIEW_PROCESS); 138 params.is_web_view = (process_type == WEB_VIEW_PROCESS);
149 params.webview_src = webview_src; 139 params.webview_src = webview_src;
150 params.file_url = file_url; 140 params.file_url = file_url;
151 params.wants_result = (result_type == JSON_SERIALIZED_RESULT); 141 params.wants_result = (result_type == JSON_SERIALIZED_RESULT);
152 params.user_gesture = user_gesture; 142 params.user_gesture = user_gesture;
153 143
144 ActiveScriptController* active_script_controller =
145 ActiveScriptController::GetForWebContents(web_contents_);
146 content::NavigationEntry* visible_entry =
147 web_contents_->GetController().GetVisibleEntry();
148 if (active_script_controller && visible_entry) {
149 // The base::Unretained(this) is safe, because this and the
150 // ActiveScriptController are both attached to the TabHelper. Thus, if the
151 // ActiveScriptController is still alive to invoke the callback, this is
152 // alive, too.
153 active_script_controller->GetPermissionForInjection(
154 extension_id,
155 visible_entry->GetPageID(),
156 scoped_ptr<const base::Closure>(new base::Closure(
157 base::Bind(&ScriptExecutor::ExecuteScriptHelper,
158 base::Unretained(this),
159 params,
not at google - send to devlin 2014/05/15 00:12:36 yes, it would make sense to Pass() this.
Devlin 2014/05/15 17:45:59 Done.
160 callback))));
161 } else {
162 ExecuteScriptHelper(params, callback);
163 }
164 }
165
166 void ScriptExecutor::ExecuteScriptHelper(
167 const ExtensionMsg_ExecuteCode_Params& params,
168 const ExecuteScriptCallback& callback) {
154 // Handler handles IPCs and deletes itself on completion. 169 // Handler handles IPCs and deletes itself on completion.
155 new Handler(script_observers_, web_contents_, params, callback); 170 new Handler(script_observers_, web_contents_, params, callback);
156 } 171 }
157 172
158 } // namespace extensions 173 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698