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/callback.h" | 7 #include "base/callback.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_tabs_module.h" | 11 #include "chrome/browser/extensions/extension_tabs_module.h" |
12 #include "chrome/browser/extensions/extension_tabs_module_constants.h" | 12 #include "chrome/browser/extensions/extension_tabs_module_constants.h" |
13 #include "chrome/browser/extensions/file_reader.h" | 13 #include "chrome/browser/extensions/file_reader.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
17 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
18 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
19 #include "chrome/common/extensions/extension_error_utils.h" | 19 #include "chrome/common/extensions/extension_error_utils.h" |
20 #include "chrome/common/extensions/extension_file_util.h" | |
21 #include "chrome/common/extensions/extension_l10n_util.h" | |
20 #include "chrome/common/extensions/extension_messages.h" | 22 #include "chrome/common/extensions/extension_messages.h" |
23 #include "chrome/common/extensions/extension_message_bundle.h" | |
21 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
22 #include "content/browser/tab_contents/tab_contents.h" | 25 #include "content/browser/tab_contents/tab_contents.h" |
23 #include "content/browser/renderer_host/render_view_host.h" | 26 #include "content/browser/renderer_host/render_view_host.h" |
24 #include "content/common/notification_service.h" | 27 #include "content/common/notification_service.h" |
25 | 28 |
26 namespace keys = extension_tabs_module_constants; | 29 namespace keys = extension_tabs_module_constants; |
27 | 30 |
28 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() | 31 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() |
29 : execute_tab_id_(-1), | 32 : execute_tab_id_(-1), |
30 all_frames_(false) { | 33 all_frames_(false) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 return false; | 157 return false; |
155 } | 158 } |
156 | 159 |
157 const Extension* extension = GetExtension(); | 160 const Extension* extension = GetExtension(); |
158 if (!extension) { | 161 if (!extension) { |
159 SendResponse(false); | 162 SendResponse(false); |
160 return false; | 163 return false; |
161 } | 164 } |
162 | 165 |
163 bool is_js_code = true; | 166 bool is_js_code = true; |
167 // We need to do message replacement on code_string, so it must be mutable. | |
168 std::string code_string_to_execute = code_string; | |
164 std::string function_name = name(); | 169 std::string function_name = name(); |
165 if (function_name == TabsInsertCSSFunction::function_name()) { | 170 if (function_name == TabsInsertCSSFunction::function_name()) { |
166 is_js_code = false; | 171 is_js_code = false; |
172 extension_l10n_util::LocalizeCSSScript(extension, code_string_to_execute); | |
Mihai Parparita -not on Chrome
2011/08/11 01:58:34
I don't think you want to do this when you're pass
Mihai Parparita -not on Chrome
2011/08/11 01:58:34
LocalizeCSSScript ends up doing file IO (to load t
adriansc
2011/08/11 21:25:08
I moved the localization logic to the file thread
adriansc
2011/08/11 21:25:08
Done. Localization is only called in DidLoadFile n
| |
167 } else if (function_name != TabsExecuteScriptFunction::function_name()) { | 173 } else if (function_name != TabsExecuteScriptFunction::function_name()) { |
168 DCHECK(false); | 174 DCHECK(false); |
169 } | 175 } |
170 | 176 |
171 ExtensionMsg_ExecuteCode_Params params; | 177 ExtensionMsg_ExecuteCode_Params params; |
172 params.request_id = request_id(); | 178 params.request_id = request_id(); |
173 params.extension_id = extension->id(); | 179 params.extension_id = extension->id(); |
174 params.is_javascript = is_js_code; | 180 params.is_javascript = is_js_code; |
175 params.code = code_string; | 181 params.code = code_string_to_execute; |
176 params.all_frames = all_frames_; | 182 params.all_frames = all_frames_; |
177 params.in_main_world = false; | 183 params.in_main_world = false; |
178 contents->render_view_host()->Send(new ExtensionMsg_ExecuteCode( | 184 contents->render_view_host()->Send(new ExtensionMsg_ExecuteCode( |
179 contents->render_view_host()->routing_id(), params)); | 185 contents->render_view_host()->routing_id(), params)); |
180 | 186 |
181 Observe(contents->tab_contents()); | 187 Observe(contents->tab_contents()); |
182 AddRef(); // balanced in OnExecuteCodeFinished() | 188 AddRef(); // balanced in OnExecuteCodeFinished() |
183 return true; | 189 return true; |
184 } | 190 } |
185 | 191 |
(...skipping 24 matching lines...) Expand all Loading... | |
210 if (!error.empty()) { | 216 if (!error.empty()) { |
211 CHECK(!success); | 217 CHECK(!success); |
212 error_ = error; | 218 error_ = error; |
213 } | 219 } |
214 | 220 |
215 SendResponse(success); | 221 SendResponse(success); |
216 | 222 |
217 Observe(NULL); | 223 Observe(NULL); |
218 Release(); // balanced in Execute() | 224 Release(); // balanced in Execute() |
219 } | 225 } |
OLD | NEW |