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

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

Issue 671011: All platforms don't support same locales at the same time. Make locale check ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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
« no previous file with comments | « no previous file | chrome/common/extensions/extension_l10n_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 return message_bundle; 401 return message_bundle;
402 } 402 }
403 403
404 static bool ValidateLocaleInfo(const Extension& extension, std::string* error) { 404 static bool ValidateLocaleInfo(const Extension& extension, std::string* error) {
405 // default_locale and _locales have to be both present or both missing. 405 // default_locale and _locales have to be both present or both missing.
406 const FilePath path = extension.path().Append(Extension::kLocaleFolder); 406 const FilePath path = extension.path().Append(Extension::kLocaleFolder);
407 bool path_exists = file_util::PathExists(path); 407 bool path_exists = file_util::PathExists(path);
408 std::string default_locale = extension.default_locale(); 408 std::string default_locale = extension.default_locale();
409 409
410 // If both default locale and _locales folder are empty, skip verification. 410 // If both default locale and _locales folder are empty, skip verification.
411 if (!default_locale.empty() || path_exists) { 411 if (default_locale.empty() && !path_exists)
412 if (default_locale.empty() && path_exists) { 412 return true;
413 *error = errors::kLocalesNoDefaultLocaleSpecified; 413
414 return false; 414 if (default_locale.empty() && path_exists) {
415 } else if (!default_locale.empty() && !path_exists) { 415 *error = errors::kLocalesNoDefaultLocaleSpecified;
416 *error = errors::kLocalesTreeMissing; 416 return false;
417 } else if (!default_locale.empty() && !path_exists) {
418 *error = errors::kLocalesTreeMissing;
419 return false;
420 }
421
422 // Treat all folders under _locales as valid locales.
423 file_util::FileEnumerator locales(path,
424 false,
425 file_util::FileEnumerator::DIRECTORIES);
426
427 std::set<std::string> all_locales;
428 extension_l10n_util::GetAllLocales(&all_locales);
429 const FilePath default_locale_path = path.AppendASCII(default_locale);
430 bool has_default_locale_message_file = false;
431
432 FilePath locale_path;
433 while (!(locale_path = locales.Next()).empty()) {
434 if (extension_l10n_util::ShouldSkipValidation(path, locale_path,
435 all_locales))
436 continue;
437
438 FilePath messages_path =
439 locale_path.Append(Extension::kMessagesFilename);
440
441 if (!file_util::PathExists(messages_path)) {
442 *error = StringPrintf(
443 "%s %s", errors::kLocalesMessagesFileMissing,
444 WideToUTF8(messages_path.ToWStringHack()).c_str());
417 return false; 445 return false;
418 } 446 }
419 447
420 // Treat all folders under _locales as valid locales. 448 if (locale_path == default_locale_path)
421 file_util::FileEnumerator locales(path, 449 has_default_locale_message_file = true;
422 false, 450 }
423 file_util::FileEnumerator::DIRECTORIES);
424 451
425 FilePath locale_path = locales.Next(); 452 // Only message file for default locale has to exist.
426 if (locale_path.empty()) { 453 if (!has_default_locale_message_file) {
427 *error = errors::kLocalesTreeMissing; 454 *error = errors::kLocalesNoDefaultMessages;
428 return false; 455 return false;
429 }
430
431 const FilePath default_locale_path = path.AppendASCII(default_locale);
432 bool has_default_locale_message_file = false;
433 do {
434 // Skip any strings with '.'. This happens sometimes, for example with
435 // '.svn' directories.
436 FilePath relative_path;
437 if (!extension.path().AppendRelativePath(locale_path, &relative_path))
438 NOTREACHED();
439 std::wstring subdir(relative_path.ToWStringHack());
440 if (std::find(subdir.begin(), subdir.end(), L'.') != subdir.end())
441 continue;
442
443 FilePath messages_path =
444 locale_path.Append(Extension::kMessagesFilename);
445
446 if (!file_util::PathExists(messages_path)) {
447 *error = StringPrintf(
448 "%s %s", errors::kLocalesMessagesFileMissing,
449 WideToUTF8(messages_path.ToWStringHack()).c_str());
450 return false;
451 }
452
453 if (locale_path == default_locale_path)
454 has_default_locale_message_file = true;
455 } while (!(locale_path = locales.Next()).empty());
456
457 // Only message file for default locale has to exist.
458 if (!has_default_locale_message_file) {
459 *error = errors::kLocalesNoDefaultMessages;
460 return false;
461 }
462 } 456 }
463 457
464 return true; 458 return true;
465 } 459 }
466 460
467 bool CheckForIllegalFilenames(const FilePath& extension_path, 461 bool CheckForIllegalFilenames(const FilePath& extension_path,
468 std::string* error) { 462 std::string* error) {
469 // Reserved underscore names. 463 // Reserved underscore names.
470 static const FilePath::CharType* reserved_names[] = { 464 static const FilePath::CharType* reserved_names[] = {
471 Extension::kLocaleFolder, 465 Extension::kLocaleFolder,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); 506 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
513 507
514 #if defined(OS_POSIX) 508 #if defined(OS_POSIX)
515 return FilePath(file_path); 509 return FilePath(file_path);
516 #elif defined(OS_WIN) 510 #elif defined(OS_WIN)
517 return FilePath(UTF8ToWide(file_path)); 511 return FilePath(UTF8ToWide(file_path));
518 #endif 512 #endif
519 } 513 }
520 514
521 } // namespace extension_file_util 515 } // namespace extension_file_util
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/extension_l10n_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698