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

Side by Side Diff: chrome/browser/extensions/user_script_master.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, 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
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/user_script_master.h" 5 #include "chrome/browser/extensions/user_script_master.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/pickle.h" 14 #include "base/pickle.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "base/version.h" 18 #include "base/version.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/common/extensions/extension.h" 22 #include "chrome/common/extensions/extension.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_message_bundle.h"
25 #include "chrome/common/extensions/extension_resource.h" 24 #include "chrome/common/extensions/extension_resource.h"
26 #include "chrome/common/extensions/extension_set.h" 25 #include "chrome/common/extensions/extension_set.h"
26 #include "chrome/common/extensions/message_bundle.h"
27 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/render_process_host.h" 28 #include "content/public/browser/render_process_host.h"
29 29
30 using content::BrowserThread; 30 using content::BrowserThread;
31 31
32 namespace extensions { 32 namespace extensions {
33 33
34 // Helper function to parse greasesmonkey headers 34 // Helper function to parse greasesmonkey headers
35 static bool GetDeclarationValue(const base::StringPiece& line, 35 static bool GetDeclarationValue(const base::StringPiece& line,
36 const base::StringPiece& prefix, 36 const base::StringPiece& prefix,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 return false; 189 return false;
190 } 190 }
191 if (!file_util::ReadFileToString(path, &content)) { 191 if (!file_util::ReadFileToString(path, &content)) {
192 LOG(WARNING) << "Failed to load user script file: " << path.value(); 192 LOG(WARNING) << "Failed to load user script file: " << path.value();
193 return false; 193 return false;
194 } 194 }
195 195
196 // Localize the content. 196 // Localize the content.
197 if (localization_messages) { 197 if (localization_messages) {
198 std::string error; 198 std::string error;
199 ExtensionMessageBundle::ReplaceMessagesWithExternalDictionary( 199 MessageBundle::ReplaceMessagesWithExternalDictionary(
200 *localization_messages, &content, &error); 200 *localization_messages, &content, &error);
201 if (!error.empty()) { 201 if (!error.empty()) {
202 LOG(WARNING) << "Failed to replace messages in script: " << error; 202 LOG(WARNING) << "Failed to replace messages in script: " << error;
203 } 203 }
204 } 204 }
205 205
206 // Remove BOM from the content. 206 // Remove BOM from the content.
207 std::string::size_type index = content.find(kUtf8ByteOrderMark); 207 std::string::size_type index = content.find(kUtf8ByteOrderMark);
208 if (index == 0) { 208 if (index == 0) {
209 script_file->set_content(content.substr(strlen(kUtf8ByteOrderMark))); 209 script_file->set_content(content.substr(strlen(kUtf8ByteOrderMark)));
(...skipping 22 matching lines...) Expand all
232 } 232 }
233 } 233 }
234 } 234 }
235 235
236 SubstitutionMap* UserScriptMaster::ScriptReloader::GetLocalizationMessages( 236 SubstitutionMap* UserScriptMaster::ScriptReloader::GetLocalizationMessages(
237 std::string extension_id) { 237 std::string extension_id) {
238 if (extensions_info_.find(extension_id) == extensions_info_.end()) { 238 if (extensions_info_.find(extension_id) == extensions_info_.end()) {
239 return NULL; 239 return NULL;
240 } 240 }
241 241
242 return extension_file_util::LoadExtensionMessageBundleSubstitutionMap( 242 return extension_file_util::LoadMessageBundleSubstitutionMap(
243 extensions_info_[extension_id].first, 243 extensions_info_[extension_id].first,
244 extension_id, 244 extension_id,
245 extensions_info_[extension_id].second); 245 extensions_info_[extension_id].second);
246 } 246 }
247 247
248 // Pickle user scripts and return pointer to the shared memory. 248 // Pickle user scripts and return pointer to the shared memory.
249 static base::SharedMemory* Serialize(const UserScriptList& scripts) { 249 static base::SharedMemory* Serialize(const UserScriptList& scripts) {
250 Pickle pickle; 250 Pickle pickle;
251 pickle.WriteUInt64(scripts.size()); 251 pickle.WriteUInt64(scripts.size());
252 for (size_t i = 0; i < scripts.size(); i++) { 252 for (size_t i = 0; i < scripts.size(); i++) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 434
435 base::SharedMemoryHandle handle_for_process; 435 base::SharedMemoryHandle handle_for_process;
436 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) 436 if (!shared_memory->ShareToProcess(handle, &handle_for_process))
437 return; // This can legitimately fail if the renderer asserts at startup. 437 return; // This can legitimately fail if the renderer asserts at startup.
438 438
439 if (base::SharedMemory::IsHandleValid(handle_for_process)) 439 if (base::SharedMemory::IsHandleValid(handle_for_process))
440 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); 440 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process));
441 } 441 }
442 442
443 } // namespace extensions 443 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/test_extension_system.cc ('k') | chrome/browser/renderer_host/chrome_render_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698