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

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

Issue 7552028: Injected CSS localization fix (see bug no.) (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Inserted whitespace. Created 9 years, 4 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) 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"
20 #include "chrome/common/extensions/extension_messages.h" 21 #include "chrome/common/extensions/extension_messages.h"
22 #include "chrome/common/extensions/extension_message_bundle.h"
21 #include "content/browser/renderer_host/render_view_host.h" 23 #include "content/browser/renderer_host/render_view_host.h"
22 #include "content/browser/tab_contents/tab_contents.h" 24 #include "content/browser/tab_contents/tab_contents.h"
23 #include "content/browser/renderer_host/render_view_host.h" 25 #include "content/browser/renderer_host/render_view_host.h"
24 #include "content/common/notification_service.h" 26 #include "content/common/notification_service.h"
25 27
26 namespace keys = extension_tabs_module_constants; 28 namespace keys = extension_tabs_module_constants;
27 29
28 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() 30 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction()
29 : execute_tab_id_(-1), 31 : execute_tab_id_(-1),
30 all_frames_(false) { 32 all_frames_(false) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return false; 156 return false;
155 } 157 }
156 158
157 const Extension* extension = GetExtension(); 159 const Extension* extension = GetExtension();
158 if (!extension) { 160 if (!extension) {
159 SendResponse(false); 161 SendResponse(false);
160 return false; 162 return false;
161 } 163 }
162 164
163 bool is_js_code = true; 165 bool is_js_code = true;
166 std::string code_string_to_execute = code_string;
Nebojša Ćirić 2011/08/10 20:38:57 Why change name here? You could just rename the fu
adriansc 2011/08/10 23:20:53 The code_string gets passed in the binding as a co
164 std::string function_name = name(); 167 std::string function_name = name();
165 if (function_name == TabsInsertCSSFunction::function_name()) { 168 if (function_name == TabsInsertCSSFunction::function_name()) {
166 is_js_code = false; 169 is_js_code = false;
170 // Localize CSS messages.
171 std::string error;
172 const SubstitutionMap localization_messages =
173 extension_file_util::LoadExtensionMessageBundleSubstitutionMap(
174 extension->path(), extension->id(), extension->default_locale());
175 ExtensionMessageBundle::ReplaceMessagesWithExternalDictionary(
176 localization_messages, &code_string_to_execute, &error);
Nebojša Ćirić 2011/08/10 20:38:57 If this code snippet shows up in other places you
adriansc 2011/08/10 23:20:53 Moved to extension_l10n_utils
167 } else if (function_name != TabsExecuteScriptFunction::function_name()) { 177 } else if (function_name != TabsExecuteScriptFunction::function_name()) {
168 DCHECK(false); 178 DCHECK(false);
169 } 179 }
170 180
171 ExtensionMsg_ExecuteCode_Params params; 181 ExtensionMsg_ExecuteCode_Params params;
172 params.request_id = request_id(); 182 params.request_id = request_id();
173 params.extension_id = extension->id(); 183 params.extension_id = extension->id();
174 params.is_javascript = is_js_code; 184 params.is_javascript = is_js_code;
175 params.code = code_string; 185 params.code = code_string_to_execute;
176 params.all_frames = all_frames_; 186 params.all_frames = all_frames_;
177 params.in_main_world = false; 187 params.in_main_world = false;
178 contents->render_view_host()->Send(new ExtensionMsg_ExecuteCode( 188 contents->render_view_host()->Send(new ExtensionMsg_ExecuteCode(
179 contents->render_view_host()->routing_id(), params)); 189 contents->render_view_host()->routing_id(), params));
180 190
181 Observe(contents->tab_contents()); 191 Observe(contents->tab_contents());
182 AddRef(); // balanced in OnExecuteCodeFinished() 192 AddRef(); // balanced in OnExecuteCodeFinished()
183 return true; 193 return true;
184 } 194 }
185 195
(...skipping 24 matching lines...) Expand all
210 if (!error.empty()) { 220 if (!error.empty()) {
211 CHECK(!success); 221 CHECK(!success);
212 error_ = error; 222 error_ = error;
213 } 223 }
214 224
215 SendResponse(success); 225 SendResponse(success);
216 226
217 Observe(NULL); 227 Observe(NULL);
218 Release(); // balanced in Execute() 228 Release(); // balanced in Execute()
219 } 229 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/user_script_master.h » ('j') | chrome/browser/extensions/user_script_master.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698