OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/common/extensions/extension_file_util.h" | 5 #include "chrome/common/extensions/extension_file_util.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/json/json_file_value_serializer.h" | 13 #include "base/json/json_file_value_serializer.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
21 #include "chrome/common/extensions/api/extension_action/action_info.h" | 21 #include "chrome/common/extensions/api/extension_action/action_info.h" |
22 #include "chrome/common/extensions/extension_l10n_util.h" | |
23 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 22 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
24 #include "chrome/common/extensions/manifest_handlers/theme_handler.h" | 23 #include "chrome/common/extensions/manifest_handlers/theme_handler.h" |
25 #include "chrome/common/extensions/message_bundle.h" | |
26 #include "extensions/common/constants.h" | 24 #include "extensions/common/constants.h" |
27 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
28 #include "extensions/common/extension_icon_set.h" | 26 #include "extensions/common/extension_icon_set.h" |
| 27 #include "extensions/common/extension_l10n_util.h" |
29 #include "extensions/common/extension_messages.h" | 28 #include "extensions/common/extension_messages.h" |
30 #include "extensions/common/extension_resource.h" | 29 #include "extensions/common/extension_resource.h" |
31 #include "extensions/common/install_warning.h" | 30 #include "extensions/common/install_warning.h" |
32 #include "extensions/common/manifest.h" | 31 #include "extensions/common/manifest.h" |
33 #include "extensions/common/manifest_constants.h" | 32 #include "extensions/common/manifest_constants.h" |
34 #include "extensions/common/manifest_handler.h" | 33 #include "extensions/common/manifest_handler.h" |
35 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
36 #include "net/base/file_stream.h" | 35 #include "net/base/file_stream.h" |
37 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
38 | 37 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 AddPathsFromIconSet(page_action->default_icon, &image_paths); | 314 AddPathsFromIconSet(page_action->default_icon, &image_paths); |
316 | 315 |
317 const extensions::ActionInfo* browser_action = | 316 const extensions::ActionInfo* browser_action = |
318 extensions::ActionInfo::GetBrowserActionInfo(extension); | 317 extensions::ActionInfo::GetBrowserActionInfo(extension); |
319 if (browser_action && !browser_action->default_icon.empty()) | 318 if (browser_action && !browser_action->default_icon.empty()) |
320 AddPathsFromIconSet(browser_action->default_icon, &image_paths); | 319 AddPathsFromIconSet(browser_action->default_icon, &image_paths); |
321 | 320 |
322 return image_paths; | 321 return image_paths; |
323 } | 322 } |
324 | 323 |
325 extensions::MessageBundle* LoadMessageBundle( | |
326 const base::FilePath& extension_path, | |
327 const std::string& default_locale, | |
328 std::string* error) { | |
329 error->clear(); | |
330 // Load locale information if available. | |
331 base::FilePath locale_path = extension_path.Append(extensions::kLocaleFolder); | |
332 if (!base::PathExists(locale_path)) | |
333 return NULL; | |
334 | |
335 std::set<std::string> locales; | |
336 if (!extension_l10n_util::GetValidLocales(locale_path, &locales, error)) | |
337 return NULL; | |
338 | |
339 if (default_locale.empty() || | |
340 locales.find(default_locale) == locales.end()) { | |
341 *error = l10n_util::GetStringUTF8( | |
342 IDS_EXTENSION_LOCALES_NO_DEFAULT_LOCALE_SPECIFIED); | |
343 return NULL; | |
344 } | |
345 | |
346 extensions::MessageBundle* message_bundle = | |
347 extension_l10n_util::LoadMessageCatalogs( | |
348 locale_path, | |
349 default_locale, | |
350 extension_l10n_util::CurrentLocaleOrDefault(), | |
351 locales, | |
352 error); | |
353 | |
354 return message_bundle; | |
355 } | |
356 | |
357 SubstitutionMap* LoadMessageBundleSubstitutionMap( | |
358 const base::FilePath& extension_path, | |
359 const std::string& extension_id, | |
360 const std::string& default_locale) { | |
361 SubstitutionMap* returnValue = new SubstitutionMap(); | |
362 if (!default_locale.empty()) { | |
363 // Touch disk only if extension is localized. | |
364 std::string error; | |
365 scoped_ptr<extensions::MessageBundle> bundle( | |
366 LoadMessageBundle(extension_path, default_locale, &error)); | |
367 | |
368 if (bundle.get()) | |
369 *returnValue = *bundle->dictionary(); | |
370 } | |
371 | |
372 // Add @@extension_id reserved message here, so it's available to | |
373 // non-localized extensions too. | |
374 returnValue->insert( | |
375 std::make_pair(extensions::MessageBundle::kExtensionIdKey, extension_id)); | |
376 | |
377 return returnValue; | |
378 } | |
379 | |
380 bool CheckForIllegalFilenames(const base::FilePath& extension_path, | 324 bool CheckForIllegalFilenames(const base::FilePath& extension_path, |
381 std::string* error) { | 325 std::string* error) { |
382 // Reserved underscore names. | 326 // Reserved underscore names. |
383 static const base::FilePath::CharType* reserved_names[] = { | 327 static const base::FilePath::CharType* reserved_names[] = { |
384 extensions::kLocaleFolder, | 328 extensions::kLocaleFolder, |
385 extensions::kPlatformSpecificFolder, | 329 extensions::kPlatformSpecificFolder, |
386 FILE_PATH_LITERAL("__MACOSX"), | 330 FILE_PATH_LITERAL("__MACOSX"), |
387 }; | 331 }; |
388 CR_DEFINE_STATIC_LOCAL( | 332 CR_DEFINE_STATIC_LOCAL( |
389 std::set<base::FilePath::StringType>, reserved_underscore_names, | 333 std::set<base::FilePath::StringType>, reserved_underscore_names, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 return base::FilePath(); | 388 return base::FilePath(); |
445 } | 389 } |
446 return temp_path; | 390 return temp_path; |
447 } | 391 } |
448 | 392 |
449 void DeleteFile(const base::FilePath& path, bool recursive) { | 393 void DeleteFile(const base::FilePath& path, bool recursive) { |
450 base::DeleteFile(path, recursive); | 394 base::DeleteFile(path, recursive); |
451 } | 395 } |
452 | 396 |
453 } // namespace extension_file_util | 397 } // namespace extension_file_util |
OLD | NEW |