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

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

Issue 12578008: Move CrxFile, FileReader, ExtensionResource to src/extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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) 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/common/extensions/extension_l10n_util.h" 5 #include "chrome/common/extensions/extension_l10n_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/file_util.h" 12 #include "base/file_util.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/memory/linked_ptr.h" 15 #include "base/memory/linked_ptr.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/extensions/extension_manifest_constants.h" 18 #include "chrome/common/extensions/extension_manifest_constants.h"
20 #include "chrome/common/extensions/extension_file_util.h" 19 #include "chrome/common/extensions/extension_file_util.h"
21 #include "chrome/common/extensions/message_bundle.h" 20 #include "chrome/common/extensions/message_bundle.h"
22 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
22 #include "extensions/common/constants.h"
23 #include "third_party/icu/public/common/unicode/uloc.h" 23 #include "third_party/icu/public/common/unicode/uloc.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 25
26 namespace errors = extension_manifest_errors; 26 namespace errors = extension_manifest_errors;
27 namespace keys = extension_manifest_keys; 27 namespace keys = extension_manifest_keys;
28 28
29 static std::string& GetProcessLocale() { 29 static std::string& GetProcessLocale() {
30 CR_DEFINE_STATIC_LOCAL(std::string, locale, ()); 30 CR_DEFINE_STATIC_LOCAL(std::string, locale, ());
31 return locale; 31 return locale;
32 } 32 }
33 33
34 namespace extension_l10n_util { 34 namespace extension_l10n_util {
35 35
36 void SetProcessLocale(const std::string& locale) { 36 void SetProcessLocale(const std::string& locale) {
37 GetProcessLocale() = locale; 37 GetProcessLocale() = locale;
38 } 38 }
39 39
40 std::string GetDefaultLocaleFromManifest(const DictionaryValue& manifest, 40 std::string GetDefaultLocaleFromManifest(const DictionaryValue& manifest,
41 std::string* error) { 41 std::string* error) {
42 std::string default_locale; 42 std::string default_locale;
43 if (manifest.GetString(keys::kDefaultLocale, &default_locale)) 43 if (manifest.GetString(keys::kDefaultLocale, &default_locale))
44 return default_locale; 44 return default_locale;
45 45
46 *error = errors::kInvalidDefaultLocale; 46 *error = errors::kInvalidDefaultLocale;
47 return ""; 47 return "";
48 48
49 } 49 }
50 50
51 bool ShouldRelocalizeManifest(const extensions::ExtensionInfo& info) { 51 bool ShouldRelocalizeManifest(DictionaryValue* const manifest) {
Jeffrey Yasskin 2013/03/22 20:26:50 I think you want const DictionaryValue* here, sinc
Yoyo Zhou 2013/03/22 21:33:32 Done.
52 DictionaryValue* manifest = info.extension_manifest.get();
53 if (!manifest) 52 if (!manifest)
54 return false; 53 return false;
55 54
56 if (!manifest->HasKey(keys::kDefaultLocale)) 55 if (!manifest->HasKey(keys::kDefaultLocale))
57 return false; 56 return false;
58 57
59 std::string manifest_current_locale; 58 std::string manifest_current_locale;
60 manifest->GetString(keys::kCurrentLocale, &manifest_current_locale); 59 manifest->GetString(keys::kCurrentLocale, &manifest_current_locale);
61 return manifest_current_locale != CurrentLocaleOrDefault(); 60 return manifest_current_locale != CurrentLocaleOrDefault();
62 } 61 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 return true; 200 return true;
202 if (chrome_locales.find(locale_name) == chrome_locales.end()) { 201 if (chrome_locales.find(locale_name) == chrome_locales.end()) {
203 // Warn if there is an extension locale that's not in the Chrome list, 202 // Warn if there is an extension locale that's not in the Chrome list,
204 // but don't fail. 203 // but don't fail.
205 DLOG(WARNING) << base::StringPrintf("Supplied locale %s is not supported.", 204 DLOG(WARNING) << base::StringPrintf("Supplied locale %s is not supported.",
206 locale_name.c_str()); 205 locale_name.c_str());
207 return true; 206 return true;
208 } 207 }
209 // Check if messages file is actually present (but don't check content). 208 // Check if messages file is actually present (but don't check content).
210 if (file_util::PathExists( 209 if (file_util::PathExists(
211 locale_folder.Append(extensions::Extension::kMessagesFilename))) { 210 locale_folder.Append(extensions::kMessagesFilename))) {
212 valid_locales->insert(locale_name); 211 valid_locales->insert(locale_name);
213 } else { 212 } else {
214 *error = base::StringPrintf("Catalog file is missing for locale %s.", 213 *error = base::StringPrintf("Catalog file is missing for locale %s.",
215 locale_name.c_str()); 214 locale_name.c_str());
216 return false; 215 return false;
217 } 216 }
218 217
219 return true; 218 return true;
220 } 219 }
221 220
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 282 }
284 283
285 // Loads contents of the messages file for given locale. If file is not found, 284 // Loads contents of the messages file for given locale. If file is not found,
286 // or there was parsing error we return NULL and set |error|. 285 // or there was parsing error we return NULL and set |error|.
287 // Caller owns the returned object. 286 // Caller owns the returned object.
288 static DictionaryValue* LoadMessageFile(const base::FilePath& locale_path, 287 static DictionaryValue* LoadMessageFile(const base::FilePath& locale_path,
289 const std::string& locale, 288 const std::string& locale,
290 std::string* error) { 289 std::string* error) {
291 std::string extension_locale = locale; 290 std::string extension_locale = locale;
292 base::FilePath file = locale_path.AppendASCII(extension_locale) 291 base::FilePath file = locale_path.AppendASCII(extension_locale)
293 .Append(extensions::Extension::kMessagesFilename); 292 .Append(extensions::kMessagesFilename);
294 JSONFileValueSerializer messages_serializer(file); 293 JSONFileValueSerializer messages_serializer(file);
295 Value *dictionary = messages_serializer.Deserialize(NULL, error); 294 Value *dictionary = messages_serializer.Deserialize(NULL, error);
296 if (!dictionary && error->empty()) { 295 if (!dictionary && error->empty()) {
297 // JSONFileValueSerializer just returns NULL if file cannot be found. It 296 // JSONFileValueSerializer just returns NULL if file cannot be found. It
298 // doesn't set the error, so we have to do it. 297 // doesn't set the error, so we have to do it.
299 *error = base::StringPrintf("Catalog file is missing for locale %s.", 298 *error = base::StringPrintf("Catalog file is missing for locale %s.",
300 extension_locale.c_str()); 299 extension_locale.c_str());
301 } 300 }
302 301
303 return static_cast<DictionaryValue*>(dictionary); 302 return static_cast<DictionaryValue*>(dictionary);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 ScopedLocaleForTest::ScopedLocaleForTest(const std::string& locale) 361 ScopedLocaleForTest::ScopedLocaleForTest(const std::string& locale)
363 : locale_(extension_l10n_util::CurrentLocaleOrDefault()) { 362 : locale_(extension_l10n_util::CurrentLocaleOrDefault()) {
364 extension_l10n_util::SetProcessLocale(locale); 363 extension_l10n_util::SetProcessLocale(locale);
365 } 364 }
366 365
367 ScopedLocaleForTest::~ScopedLocaleForTest() { 366 ScopedLocaleForTest::~ScopedLocaleForTest() {
368 extension_l10n_util::SetProcessLocale(locale_); 367 extension_l10n_util::SetProcessLocale(locale_);
369 } 368 }
370 369
371 } // namespace extension_l10n_util 370 } // namespace extension_l10n_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698