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

Side by Side Diff: chrome/common/extensions/extension_file_util.cc

Issue 7552028: Injected CSS localization fix (see bug no.) (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Cleaned up old unused function. 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/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/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/scoped_temp_dir.h" 14 #include "base/scoped_temp_dir.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/threading/thread_restrictions.h" 16 #include "base/threading/thread_restrictions.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_action.h" 20 #include "chrome/common/extensions/extension_action.h"
21 #include "chrome/common/extensions/extension_constants.h" 21 #include "chrome/common/extensions/extension_constants.h"
22 #include "chrome/common/extensions/extension_l10n_util.h" 22 #include "chrome/common/extensions/extension_l10n_util.h"
23 #include "chrome/common/extensions/extension_messages.h"
24 #include "chrome/common/extensions/extension_message_bundle.h"
23 #include "chrome/common/extensions/extension_resource.h" 25 #include "chrome/common/extensions/extension_resource.h"
24 #include "chrome/common/extensions/extension_sidebar_defaults.h" 26 #include "chrome/common/extensions/extension_sidebar_defaults.h"
25 #include "content/common/json_value_serializer.h" 27 #include "content/common/json_value_serializer.h"
26 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
27 #include "net/base/escape.h" 29 #include "net/base/escape.h"
28 #include "net/base/file_stream.h" 30 #include "net/base/file_stream.h"
29 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
30 32
31 namespace errors = extension_manifest_errors; 33 namespace errors = extension_manifest_errors;
32 34
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 extension_l10n_util::LoadMessageCatalogs( 395 extension_l10n_util::LoadMessageCatalogs(
394 locale_path, 396 locale_path,
395 default_locale, 397 default_locale,
396 extension_l10n_util::CurrentLocaleOrDefault(), 398 extension_l10n_util::CurrentLocaleOrDefault(),
397 locales, 399 locales,
398 error); 400 error);
399 401
400 return message_bundle; 402 return message_bundle;
401 } 403 }
402 404
405 SubstitutionMap* LoadExtensionMessageBundleSubstitutionMap(
406 const FilePath& extension_path,
407 const std::string& extension_id,
408 const std::string& default_locale) {
409 SubstitutionMap* returnValue = new SubstitutionMap();
410 if (!default_locale.empty()) {
411 // Touch disk only if extension is localized.
412 std::string error;
413 scoped_ptr<ExtensionMessageBundle> bundle(
414 LoadExtensionMessageBundle(extension_path, default_locale, &error));
415
416 if (bundle.get())
417 *returnValue = *bundle->dictionary();
418 }
419
420 // Add @@extension_id reserved message here, so it's available to
421 // non-localized extensions too.
422 returnValue->insert(
423 std::make_pair(ExtensionMessageBundle::kExtensionIdKey, extension_id));
424
425 return returnValue;
426 }
427
403 static bool ValidateLocaleInfo(const Extension& extension, std::string* error) { 428 static bool ValidateLocaleInfo(const Extension& extension, std::string* error) {
404 // default_locale and _locales have to be both present or both missing. 429 // default_locale and _locales have to be both present or both missing.
405 const FilePath path = extension.path().Append(Extension::kLocaleFolder); 430 const FilePath path = extension.path().Append(Extension::kLocaleFolder);
406 bool path_exists = file_util::PathExists(path); 431 bool path_exists = file_util::PathExists(path);
407 std::string default_locale = extension.default_locale(); 432 std::string default_locale = extension.default_locale();
408 433
409 // If both default locale and _locales folder are empty, skip verification. 434 // If both default locale and _locales folder are empty, skip verification.
410 if (default_locale.empty() && !path_exists) 435 if (default_locale.empty() && !path_exists)
411 return true; 436 return true;
412 437
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 return temp_path; 639 return temp_path;
615 640
616 return FilePath(); 641 return FilePath();
617 } 642 }
618 643
619 void DeleteFile(const FilePath& path, bool recursive) { 644 void DeleteFile(const FilePath& path, bool recursive) {
620 file_util::Delete(path, recursive); 645 file_util::Delete(path, recursive);
621 } 646 }
622 647
623 } // namespace extension_file_util 648 } // namespace extension_file_util
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_file_util.h ('k') | chrome/common/extensions/extension_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698