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

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

Issue 10787002: Moved ExtensionMessage* into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest master for cq Created 8 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/api/tabs/execute_code_in_tab_function.h" 5 #include "chrome/browser/extensions/api/tabs/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/api/tabs/tabs.h" 10 #include "chrome/browser/extensions/api/tabs/tabs.h"
11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
12 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_tab_util.h" 13 #include "chrome/browser/extensions/extension_tab_util.h"
14 #include "chrome/browser/extensions/tab_helper.h" 14 #include "chrome/browser/extensions/tab_helper.h"
15 #include "chrome/browser/extensions/file_reader.h" 15 #include "chrome/browser/extensions/file_reader.h"
16 #include "chrome/browser/extensions/script_executor.h" 16 #include "chrome/browser/extensions/script_executor.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents.h" 19 #include "chrome/browser/ui/tab_contents/tab_contents.h"
20 #include "chrome/common/extensions/extension.h" 20 #include "chrome/common/extensions/extension.h"
21 #include "chrome/common/extensions/extension_constants.h" 21 #include "chrome/common/extensions/extension_constants.h"
22 #include "chrome/common/extensions/extension_error_utils.h" 22 #include "chrome/common/extensions/extension_error_utils.h"
23 #include "chrome/common/extensions/extension_file_util.h" 23 #include "chrome/common/extensions/extension_file_util.h"
24 #include "chrome/common/extensions/extension_l10n_util.h" 24 #include "chrome/common/extensions/extension_l10n_util.h"
25 #include "chrome/common/extensions/extension_manifest_constants.h" 25 #include "chrome/common/extensions/extension_manifest_constants.h"
26 #include "chrome/common/extensions/extension_message_bundle.h"
27 #include "chrome/common/extensions/extension_messages.h" 26 #include "chrome/common/extensions/extension_messages.h"
27 #include "chrome/common/extensions/message_bundle.h"
28 #include "content/public/browser/render_view_host.h" 28 #include "content/public/browser/render_view_host.h"
29 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
30 30
31 using content::BrowserThread; 31 using content::BrowserThread;
32 using extensions::ScriptExecutor; 32 using extensions::ScriptExecutor;
33 33
34 namespace keys = extensions::tabs_constants; 34 namespace keys = extensions::tabs_constants;
35 35
36 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() 36 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction()
37 : execute_tab_id_(-1), 37 : execute_tab_id_(-1),
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 165
166 void ExecuteCodeInTabFunction::DidLoadFile(bool success, 166 void ExecuteCodeInTabFunction::DidLoadFile(bool success,
167 const std::string& data) { 167 const std::string& data) {
168 std::string function_name = name(); 168 std::string function_name = name();
169 const extensions::Extension* extension = GetExtension(); 169 const extensions::Extension* extension = GetExtension();
170 170
171 // Check if the file is CSS and needs localization. 171 // Check if the file is CSS and needs localization.
172 if (success && 172 if (success &&
173 function_name == TabsInsertCSSFunction::function_name() && 173 function_name == TabsInsertCSSFunction::function_name() &&
174 extension != NULL && 174 extension != NULL &&
175 data.find(ExtensionMessageBundle::kMessageBegin) != std::string::npos) { 175 data.find(
176 extensions::MessageBundle::kMessageBegin) != std::string::npos) {
176 BrowserThread::PostTask( 177 BrowserThread::PostTask(
177 BrowserThread::FILE, FROM_HERE, 178 BrowserThread::FILE, FROM_HERE,
178 base::Bind(&ExecuteCodeInTabFunction::LocalizeCSS, this, 179 base::Bind(&ExecuteCodeInTabFunction::LocalizeCSS, this,
179 data, 180 data,
180 extension->id(), 181 extension->id(),
181 extension->path(), 182 extension->path(),
182 extension->default_locale())); 183 extension->default_locale()));
183 } else { 184 } else {
184 DidLoadAndLocalizeFile(success, data); 185 DidLoadAndLocalizeFile(success, data);
185 } 186 }
186 } 187 }
187 188
188 void ExecuteCodeInTabFunction::LocalizeCSS( 189 void ExecuteCodeInTabFunction::LocalizeCSS(
189 const std::string& data, 190 const std::string& data,
190 const std::string& extension_id, 191 const std::string& extension_id,
191 const FilePath& extension_path, 192 const FilePath& extension_path,
192 const std::string& extension_default_locale) { 193 const std::string& extension_default_locale) {
193 scoped_ptr<SubstitutionMap> localization_messages( 194 scoped_ptr<SubstitutionMap> localization_messages(
194 extension_file_util::LoadExtensionMessageBundleSubstitutionMap( 195 extension_file_util::LoadMessageBundleSubstitutionMap(
195 extension_path, extension_id, extension_default_locale)); 196 extension_path, extension_id, extension_default_locale));
196 197
197 // We need to do message replacement on the data, so it has to be mutable. 198 // We need to do message replacement on the data, so it has to be mutable.
198 std::string css_data = data; 199 std::string css_data = data;
199 std::string error; 200 std::string error;
200 ExtensionMessageBundle::ReplaceMessagesWithExternalDictionary( 201 extensions::MessageBundle::ReplaceMessagesWithExternalDictionary(
201 *localization_messages, &css_data, &error); 202 *localization_messages, &css_data, &error);
202 203
203 // Call back DidLoadAndLocalizeFile on the UI thread. The success parameter 204 // Call back DidLoadAndLocalizeFile on the UI thread. The success parameter
204 // is always true, because if loading had failed, we wouldn't have had 205 // is always true, because if loading had failed, we wouldn't have had
205 // anything to localize. 206 // anything to localize.
206 BrowserThread::PostTask( 207 BrowserThread::PostTask(
207 BrowserThread::UI, FROM_HERE, 208 BrowserThread::UI, FROM_HERE,
208 base::Bind(&ExecuteCodeInTabFunction::DidLoadAndLocalizeFile, this, 209 base::Bind(&ExecuteCodeInTabFunction::DidLoadAndLocalizeFile, this,
209 true, css_data)); 210 true, css_data));
210 } 211 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 contents->extension_tab_helper()->script_executor()->ExecuteScript( 255 contents->extension_tab_helper()->script_executor()->ExecuteScript(
255 extension->id(), 256 extension->id(),
256 script_type, 257 script_type,
257 code_string, 258 code_string,
258 all_frames_ ? ScriptExecutor::ALL_FRAMES : ScriptExecutor::TOP_FRAME, 259 all_frames_ ? ScriptExecutor::ALL_FRAMES : ScriptExecutor::TOP_FRAME,
259 run_at_, 260 run_at_,
260 ScriptExecutor::ISOLATED_WORLD, 261 ScriptExecutor::ISOLATED_WORLD,
261 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); 262 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this));
262 return true; 263 return true;
263 } 264 }
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/extensions/extension_message_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698