| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/script_executor.h" | 5 #include "extensions/browser/script_executor.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
| 11 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
| 14 #include "extensions/browser/extension_registry.h" | 14 #include "extensions/browser/extension_registry.h" |
| 15 #include "extensions/browser/script_execution_observer.h" | 15 #include "extensions/browser/script_execution_observer.h" |
| 16 #include "extensions/common/extension_messages.h" | 16 #include "extensions/common/extension_messages.h" |
| 17 #include "extensions/common/host_id.h" |
| 17 #include "ipc/ipc_message.h" | 18 #include "ipc/ipc_message.h" |
| 18 #include "ipc/ipc_message_macros.h" | 19 #include "ipc/ipc_message_macros.h" |
| 19 | 20 |
| 20 namespace base { | 21 namespace base { |
| 21 class ListValue; | 22 class ListValue; |
| 22 } // namespace base | 23 } // namespace base |
| 23 | 24 |
| 24 namespace extensions { | 25 namespace extensions { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 116 |
| 116 void ScriptExecutor::ExecuteScript(const std::string& extension_id, | 117 void ScriptExecutor::ExecuteScript(const std::string& extension_id, |
| 117 ScriptExecutor::ScriptType script_type, | 118 ScriptExecutor::ScriptType script_type, |
| 118 const std::string& code, | 119 const std::string& code, |
| 119 ScriptExecutor::FrameScope frame_scope, | 120 ScriptExecutor::FrameScope frame_scope, |
| 120 ScriptExecutor::MatchAboutBlank about_blank, | 121 ScriptExecutor::MatchAboutBlank about_blank, |
| 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, |
| 126 int instance_id, |
| 125 const GURL& file_url, | 127 const GURL& file_url, |
| 126 bool user_gesture, | 128 bool user_gesture, |
| 127 ScriptExecutor::ResultType result_type, | 129 ScriptExecutor::ResultType result_type, |
| 128 const ExecuteScriptCallback& callback) { | 130 const ExecuteScriptCallback& callback) { |
| 129 // Don't execute if the extension has been unloaded. | 131 // Don't execute if the extension has been unloaded. |
| 130 const Extension* extension = | 132 const Extension* extension = |
| 131 ExtensionRegistry::Get(web_contents_->GetBrowserContext()) | 133 ExtensionRegistry::Get(web_contents_->GetBrowserContext()) |
| 132 ->enabled_extensions().GetByID(extension_id); | 134 ->enabled_extensions().GetByID(extension_id); |
| 133 if (!extension) | 135 if (!extension) |
| 134 return; | 136 return; |
| 135 | 137 |
| 136 ExtensionMsg_ExecuteCode_Params params; | 138 ExtensionMsg_ExecuteCode_Params params; |
| 137 params.request_id = next_request_id_++; | 139 params.request_id = next_request_id_++; |
| 138 params.extension_id = extension_id; | 140 params.extension_id = extension_id; |
| 139 params.is_javascript = (script_type == JAVASCRIPT); | 141 params.is_javascript = (script_type == JAVASCRIPT); |
| 140 params.code = code; | 142 params.code = code; |
| 141 params.all_frames = (frame_scope == ALL_FRAMES); | 143 params.all_frames = (frame_scope == ALL_FRAMES); |
| 142 params.match_about_blank = (about_blank == MATCH_ABOUT_BLANK); | 144 params.match_about_blank = (about_blank == MATCH_ABOUT_BLANK); |
| 143 params.run_at = static_cast<int>(run_at); | 145 params.run_at = static_cast<int>(run_at); |
| 144 params.in_main_world = (world_type == MAIN_WORLD); | 146 params.in_main_world = (world_type == MAIN_WORLD); |
| 145 params.is_web_view = (process_type == WEB_VIEW_PROCESS); | 147 params.is_web_view = (process_type == WEB_VIEW_PROCESS); |
| 148 params.instance_id = params.is_web_view ? instance_id : |
| 149 Host::kDefaultInstanceId; |
| 146 params.webview_src = webview_src; | 150 params.webview_src = webview_src; |
| 147 params.file_url = file_url; | 151 params.file_url = file_url; |
| 148 params.wants_result = (result_type == JSON_SERIALIZED_RESULT); | 152 params.wants_result = (result_type == JSON_SERIALIZED_RESULT); |
| 149 params.user_gesture = user_gesture; | 153 params.user_gesture = user_gesture; |
| 150 | 154 |
| 151 // Handler handles IPCs and deletes itself on completion. | 155 // Handler handles IPCs and deletes itself on completion. |
| 152 new Handler(script_observers_, web_contents_, params, callback); | 156 new Handler(script_observers_, web_contents_, params, callback); |
| 153 } | 157 } |
| 154 | 158 |
| 155 } // namespace extensions | 159 } // namespace extensions |
| OLD | NEW |