| Index: chrome/browser/extensions/script_executor.cc
|
| diff --git a/chrome/browser/extensions/script_executor.cc b/chrome/browser/extensions/script_executor.cc
|
| index b7711cbc541e1452992eca8978b9dd8225f9e7ad..31715e0ddcdf72ed81adc917931d15902eaef9ac 100644
|
| --- a/chrome/browser/extensions/script_executor.cc
|
| +++ b/chrome/browser/extensions/script_executor.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "chrome/browser/extensions/script_executor.h"
|
|
|
| +#include "base/bind.h"
|
| #include "base/callback.h"
|
| #include "base/logging.h"
|
| #include "base/pickle.h"
|
| @@ -126,33 +127,47 @@ void ScriptExecutor::ExecuteScript(const std::string& extension_id,
|
| bool user_gesture,
|
| ScriptExecutor::ResultType result_type,
|
| const ExecuteScriptCallback& callback) {
|
| + scoped_ptr<ExtensionMsg_ExecuteCode_Params> params(
|
| + new ExtensionMsg_ExecuteCode_Params());
|
| + params->request_id = next_request_id_++;
|
| + params->extension_id = extension_id;
|
| + params->is_javascript = (script_type == JAVASCRIPT);
|
| + params->code = code;
|
| + params->all_frames = (frame_scope == ALL_FRAMES);
|
| + params->run_at = static_cast<int>(run_at);
|
| + params->in_main_world = (world_type == MAIN_WORLD);
|
| + params->is_web_view = (process_type == WEB_VIEW_PROCESS);
|
| + params->webview_src = webview_src;
|
| + params->file_url = file_url;
|
| + params->wants_result = (result_type == JSON_SERIALIZED_RESULT);
|
| + params->user_gesture = user_gesture;
|
| +
|
| ActiveScriptController* active_script_controller =
|
| ActiveScriptController::GetForWebContents(web_contents_);
|
| content::NavigationEntry* visible_entry =
|
| web_contents_->GetController().GetVisibleEntry();
|
| if (active_script_controller && visible_entry) {
|
| - // TODO(rdevlin.cronin): Now, this is just a notification. Soon, it should
|
| - // block until the user gives the OK to execute.
|
| - active_script_controller->NotifyScriptExecuting(extension_id,
|
| - visible_entry->GetPageID());
|
| + // The base::Unretained(this) is safe, because this and the
|
| + // ActiveScriptController are both attached to the TabHelper. Thus, if the
|
| + // ActiveScriptController is still alive to invoke the callback, this is
|
| + // alive, too.
|
| + active_script_controller->InjectScriptIfHasPermission(
|
| + extension_id,
|
| + visible_entry->GetPageID(),
|
| + base::Closure(base::Bind(&ScriptExecutor::ExecuteScriptHelper,
|
| + base::Unretained(this),
|
| + base::Passed(params.Pass()),
|
| + callback)));
|
| + } else {
|
| + ExecuteScriptHelper(params.Pass(), callback);
|
| }
|
| +}
|
|
|
| - ExtensionMsg_ExecuteCode_Params params;
|
| - params.request_id = next_request_id_++;
|
| - params.extension_id = extension_id;
|
| - params.is_javascript = (script_type == JAVASCRIPT);
|
| - params.code = code;
|
| - params.all_frames = (frame_scope == ALL_FRAMES);
|
| - params.run_at = static_cast<int>(run_at);
|
| - params.in_main_world = (world_type == MAIN_WORLD);
|
| - params.is_web_view = (process_type == WEB_VIEW_PROCESS);
|
| - params.webview_src = webview_src;
|
| - params.file_url = file_url;
|
| - params.wants_result = (result_type == JSON_SERIALIZED_RESULT);
|
| - params.user_gesture = user_gesture;
|
| -
|
| +void ScriptExecutor::ExecuteScriptHelper(
|
| + scoped_ptr<ExtensionMsg_ExecuteCode_Params> params,
|
| + const ExecuteScriptCallback& callback) {
|
| // Handler handles IPCs and deletes itself on completion.
|
| - new Handler(script_observers_, web_contents_, params, callback);
|
| + new Handler(script_observers_, web_contents_, *params, callback);
|
| }
|
|
|
| } // namespace extensions
|
|
|