OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/execute_code_in_tab_function.h" | 5 #include "chrome/browser/extensions/execute_code_in_tab_function.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
12 #include "chrome/browser/extensions/extension_tabs_module.h" | 12 #include "chrome/browser/extensions/extension_tabs_module.h" |
13 #include "chrome/browser/extensions/extension_tabs_module_constants.h" | 13 #include "chrome/browser/extensions/extension_tabs_module_constants.h" |
14 #include "chrome/browser/extensions/file_reader.h" | 14 #include "chrome/browser/extensions/file_reader.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
19 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
20 #include "chrome/common/extensions/extension_error_utils.h" | 20 #include "chrome/common/extensions/extension_error_utils.h" |
21 #include "chrome/common/extensions/extension_file_util.h" | 21 #include "chrome/common/extensions/extension_file_util.h" |
22 #include "chrome/common/extensions/extension_l10n_util.h" | 22 #include "chrome/common/extensions/extension_l10n_util.h" |
23 #include "chrome/common/extensions/extension_message_bundle.h" | 23 #include "chrome/common/extensions/extension_message_bundle.h" |
24 #include "chrome/common/extensions/extension_messages.h" | 24 #include "chrome/common/extensions/extension_messages.h" |
25 #include "chrome/common/extensions/user_script.h" | |
Aaron Boodman
2012/03/03 00:59:10
Since you include the header in the .h file, it is
eaugusti
2012/03/27 00:43:33
Done.
| |
25 #include "content/browser/renderer_host/render_view_host.h" | 26 #include "content/browser/renderer_host/render_view_host.h" |
26 #include "content/browser/renderer_host/render_view_host.h" | 27 #include "content/browser/renderer_host/render_view_host.h" |
27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
28 | 29 |
29 using content::BrowserThread; | 30 using content::BrowserThread; |
30 | 31 |
31 namespace keys = extension_tabs_module_constants; | 32 namespace keys = extension_tabs_module_constants; |
32 | 33 |
33 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() | 34 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() |
34 : execute_tab_id_(-1), | 35 : execute_tab_id_(-1), |
35 all_frames_(false) { | 36 all_frames_(false), |
37 run_at_(UserScript::DOCUMENT_IDLE) { | |
36 } | 38 } |
37 | 39 |
38 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() { | 40 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() { |
39 } | 41 } |
40 | 42 |
41 bool ExecuteCodeInTabFunction::RunImpl() { | 43 bool ExecuteCodeInTabFunction::RunImpl() { |
42 DictionaryValue* script_info; | 44 DictionaryValue* script_info; |
43 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &script_info)); | 45 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &script_info)); |
44 size_t number_of_value = script_info->size(); | 46 size_t number_of_value = script_info->size(); |
45 if (number_of_value == 0) { | 47 if (number_of_value == 0) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 if (!GetExtension()->CanExecuteScriptOnPage( | 91 if (!GetExtension()->CanExecuteScriptOnPage( |
90 contents->web_contents()->GetURL(), NULL, &error_)) { | 92 contents->web_contents()->GetURL(), NULL, &error_)) { |
91 return false; | 93 return false; |
92 } | 94 } |
93 | 95 |
94 if (script_info->HasKey(keys::kAllFramesKey)) { | 96 if (script_info->HasKey(keys::kAllFramesKey)) { |
95 if (!script_info->GetBoolean(keys::kAllFramesKey, &all_frames_)) | 97 if (!script_info->GetBoolean(keys::kAllFramesKey, &all_frames_)) |
96 return false; | 98 return false; |
97 } | 99 } |
98 | 100 |
101 if (script_info->HasKey(keys::kRunAtKey)) { | |
102 std::string run_string; | |
103 if (!script_info->GetString(keys::kRunAtKey, &run_string)) | |
Aaron Boodman
2012/03/03 00:59:10
You can do:
EXTENSION_FUNCTION_VALIDATE(script_in
eaugusti
2012/03/27 00:43:33
Done.
| |
104 return false; | |
105 | |
106 if (run_string == keys::kRunAtNow) | |
107 run_at_ = UserScript::DOCUMENT_NOW; | |
108 else if (run_string == keys::kRunAtDocumentStart) | |
109 run_at_ = UserScript::DOCUMENT_START; | |
110 else if (run_string == keys::kRunAtDocumentEnd) | |
111 run_at_ = UserScript::DOCUMENT_END; | |
112 else if (run_string == keys::kRunAtDocumentIdle) | |
113 run_at_ = UserScript::DOCUMENT_IDLE; | |
114 else | |
115 return false; | |
Aaron Boodman
2012/03/03 00:59:10
same here, this can be EXTENSION_FUNCTION_VALIDATE
eaugusti
2012/03/27 00:43:33
Done.
| |
116 } | |
117 | |
99 std::string code_string; | 118 std::string code_string; |
100 if (script_info->HasKey(keys::kCodeKey)) { | 119 if (script_info->HasKey(keys::kCodeKey)) { |
101 if (!script_info->GetString(keys::kCodeKey, &code_string)) | 120 if (!script_info->GetString(keys::kCodeKey, &code_string)) |
102 return false; | 121 return false; |
103 } | 122 } |
104 | 123 |
105 if (!code_string.empty()) { | 124 if (!code_string.empty()) { |
106 if (!Execute(code_string)) | 125 if (!Execute(code_string)) |
107 return false; | 126 return false; |
108 return true; | 127 return true; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 } else if (function_name != TabsExecuteScriptFunction::function_name()) { | 235 } else if (function_name != TabsExecuteScriptFunction::function_name()) { |
217 DCHECK(false); | 236 DCHECK(false); |
218 } | 237 } |
219 | 238 |
220 ExtensionMsg_ExecuteCode_Params params; | 239 ExtensionMsg_ExecuteCode_Params params; |
221 params.request_id = request_id(); | 240 params.request_id = request_id(); |
222 params.extension_id = extension->id(); | 241 params.extension_id = extension->id(); |
223 params.is_javascript = is_js_code; | 242 params.is_javascript = is_js_code; |
224 params.code = code_string; | 243 params.code = code_string; |
225 params.all_frames = all_frames_; | 244 params.all_frames = all_frames_; |
245 params.run_at = run_at_; | |
226 params.in_main_world = false; | 246 params.in_main_world = false; |
227 contents->web_contents()->GetRenderViewHost()->Send( | 247 contents->web_contents()->GetRenderViewHost()->Send( |
228 new ExtensionMsg_ExecuteCode( | 248 new ExtensionMsg_ExecuteCode( |
229 contents->web_contents()->GetRenderViewHost()->routing_id(), params)); | 249 contents->web_contents()->GetRenderViewHost()->routing_id(), params)); |
230 | 250 |
231 Observe(contents->web_contents()); | 251 Observe(contents->web_contents()); |
232 AddRef(); // balanced in OnExecuteCodeFinished() | 252 AddRef(); // balanced in OnExecuteCodeFinished() |
233 return true; | 253 return true; |
234 } | 254 } |
235 | 255 |
(...skipping 24 matching lines...) Expand all Loading... | |
260 if (!error.empty()) { | 280 if (!error.empty()) { |
261 CHECK(!success); | 281 CHECK(!success); |
262 error_ = error; | 282 error_ = error; |
263 } | 283 } |
264 | 284 |
265 SendResponse(success); | 285 SendResponse(success); |
266 | 286 |
267 Observe(NULL); | 287 Observe(NULL); |
268 Release(); // balanced in Execute() | 288 Release(); // balanced in Execute() |
269 } | 289 } |
OLD | NEW |