summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-27 23:29:49 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-27 23:29:49 +0000
commitc10cf58384d2808c13808fee0352573bb6069781 (patch)
treeeff79c3f08085544694d5f573364f182526c238d /chrome
parent48abb0046f935690ea83d0290dc6ff0a60d99b27 (diff)
downloadchromium_src-c10cf58384d2808c13808fee0352573bb6069781.zip
chromium_src-c10cf58384d2808c13808fee0352573bb6069781.tar.gz
chromium_src-c10cf58384d2808c13808fee0352573bb6069781.tar.bz2
Fix bug where many extensions don't install due to sandbox.
FWIW, I tracked down why our tests didn't find this. We do have coverage for the code path that was getting executed, but the sandbox is disabled in our browser tests, so it did not expose this issue. BUG=25865 TEST=Install any extension that has a content script or icons (test/data/extensions/good.crx is one example). Go to chrome://extensions/. You should see the extension successfully installed. Review URL: http://codereview.chromium.org/337041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/extension_file_util.cc2
-rw-r--r--chrome/browser/utility_process_host.cc6
-rwxr-xr-xchrome/chrome.gyp6
-rw-r--r--chrome/common/extensions/extension.cc2
-rw-r--r--chrome/common/extensions/extension_l10n_util.cc (renamed from chrome/browser/extensions/extension_l10n_util.cc)21
-rw-r--r--chrome/common/extensions/extension_l10n_util.h (renamed from chrome/browser/extensions/extension_l10n_util.h)11
-rw-r--r--chrome/common/extensions/extension_l10n_util_unittest.cc (renamed from chrome/browser/extensions/extension_l10n_util_unittest.cc)3
-rw-r--r--chrome/common/extensions/extension_resource.cc2
-rw-r--r--chrome/common/extensions/extension_resource_unittest.cc2
-rw-r--r--chrome/utility/utility_main.cc7
10 files changed, 45 insertions, 17 deletions
diff --git a/chrome/browser/extensions/extension_file_util.cc b/chrome/browser/extensions/extension_file_util.cc
index 6372f71..5b1e16c 100644
--- a/chrome/browser/extensions/extension_file_util.cc
+++ b/chrome/browser/extensions/extension_file_util.cc
@@ -10,8 +10,8 @@
#include "base/scoped_temp_dir.h"
#include "base/string_util.h"
#include "chrome/browser/extensions/extension_prefs.h"
-#include "chrome/browser/extensions/extension_l10n_util.h"
#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/extension_l10n_util.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/json_value_serializer.h"
#include "net/base/file_stream.h"
diff --git a/chrome/browser/utility_process_host.cc b/chrome/browser/utility_process_host.cc
index 0e44688..95729b0 100644
--- a/chrome/browser/utility_process_host.cc
+++ b/chrome/browser/utility_process_host.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/utility_process_host.h"
+#include "app/app_switches.h"
+#include "app/l10n_util.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/message_loop.h"
@@ -89,6 +91,10 @@ bool UtilityProcessHost::StartProcess(const FilePath& exposed_dir) {
switches::kUtilityProcess);
cmd_line.AppendSwitchWithValue(switches::kProcessChannelID,
ASCIIToWide(channel_id()));
+ // Pass on the browser locale.
+ std::string locale = l10n_util::GetApplicationLocale(L"");
+ cmd_line.AppendSwitchWithValue(switches::kLang, ASCIIToWide(locale));
+
SetCrashReporterCommandLine(&cmd_line);
base::ProcessHandle process;
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 8d0bb7e..736d860 100755
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -535,6 +535,8 @@
'common/extensions/extension_error_utils.h',
'common/extensions/extension_action.cc',
'common/extensions/extension_action.h',
+ 'common/extensions/extension_l10n_util.cc',
+ 'common/extensions/extension_l10n_util.h',
'common/extensions/extension_message_bundle.cc',
'common/extensions/extension_message_bundle.h',
'common/extensions/extension_resource.cc',
@@ -1323,8 +1325,6 @@
'browser/extensions/extension_host.h',
'browser/extensions/extension_install_ui.cc',
'browser/extensions/extension_install_ui.h',
- 'browser/extensions/extension_l10n_util.cc',
- 'browser/extensions/extension_l10n_util.h',
'browser/extensions/extension_message_service.cc',
'browser/extensions/extension_message_service.h',
'browser/extensions/extension_browser_event_router.cc',
@@ -4494,7 +4494,6 @@
'browser/download/save_package_unittest.cc',
'browser/encoding_menu_controller_unittest.cc',
'browser/extensions/extension_file_util_unittest.cc',
- 'browser/extensions/extension_l10n_util_unittest.cc',
'browser/extensions/extension_messages_unittest.cc',
'browser/extensions/extension_process_manager_unittest.cc',
'browser/extensions/extension_ui_unittest.cc',
@@ -4621,6 +4620,7 @@
'common/extensions/extension_resource_unittest.cc',
'common/extensions/extension_unittest.cc',
'common/extensions/extension_action_unittest.cc',
+ 'common/extensions/extension_l10n_util_unittest.cc',
'common/extensions/extension_message_bundle_unittest.cc',
'common/extensions/update_manifest_unittest.cc',
'common/extensions/url_pattern_unittest.cc',
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index c7207c1..db05c4b 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -13,11 +13,11 @@
#include "base/stl_util-inl.h"
#include "base/third_party/nss/blapi.h"
#include "base/third_party/nss/sha256.h"
-#include "chrome/browser/extensions/extension_l10n_util.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_error_reporter.h"
#include "chrome/common/extensions/extension_error_utils.h"
+#include "chrome/common/extensions/extension_l10n_util.h"
#include "chrome/common/extensions/user_script.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/url_constants.h"
diff --git a/chrome/browser/extensions/extension_l10n_util.cc b/chrome/common/extensions/extension_l10n_util.cc
index 1ac93ff..8ff7ec6 100644
--- a/chrome/browser/extensions/extension_l10n_util.cc
+++ b/chrome/common/extensions/extension_l10n_util.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/extensions/extension_l10n_util.h"
+#include "chrome/common/extensions/extension_l10n_util.h"
#include <set>
#include <string>
@@ -21,8 +21,17 @@
namespace errors = extension_manifest_errors;
namespace keys = extension_manifest_keys;
+static std::string* GetProcessLocale() {
+ static std::string locale;
+ return &locale;
+}
+
namespace extension_l10n_util {
+void SetProcessLocale(const std::string& locale) {
+ *(GetProcessLocale()) = locale;
+}
+
std::string GetDefaultLocaleFromManifest(const DictionaryValue& manifest,
std::string* error) {
std::string default_locale;
@@ -75,7 +84,7 @@ void GetParentLocales(const std::string& current_locale,
const int kNameCapacity = 256;
char parent[kNameCapacity];
- strncpy(parent, locale.c_str(), kNameCapacity);
+ base::strlcpy(parent, locale.c_str(), kNameCapacity);
parent_locales->push_back(parent);
UErrorCode err = U_ZERO_ERROR;
while (uloc_getParent(parent, parent, kNameCapacity, &err) > 0) {
@@ -187,10 +196,12 @@ void GetL10nRelativePaths(const FilePath& relative_resource_path,
std::vector<FilePath>* l10n_paths) {
DCHECK(NULL != l10n_paths);
+ std::string* current_locale = GetProcessLocale();
+ if (current_locale->empty())
+ *current_locale = l10n_util::GetApplicationLocale(L"");
+
std::vector<std::string> locales;
- static const std::string current_locale =
- l10n_util::GetApplicationLocale(L"");
- GetParentLocales(current_locale, &locales);
+ GetParentLocales(*current_locale, &locales);
FilePath locale_relative_path;
for (size_t i = 0; i < locales.size(); ++i) {
diff --git a/chrome/browser/extensions/extension_l10n_util.h b/chrome/common/extensions/extension_l10n_util.h
index 07be73e..87ad43f 100644
--- a/chrome/browser/extensions/extension_l10n_util.h
+++ b/chrome/common/extensions/extension_l10n_util.h
@@ -4,8 +4,8 @@
//
// This file declares extension specific l10n utils.
-#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_L10N_UTIL_H_
-#define CHROME_BROWSER_EXTENSIONS_EXTENSION_L10N_UTIL_H_
+#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_L10N_UTIL_H_
+#define CHROME_COMMON_EXTENSIONS_EXTENSION_L10N_UTIL_H_
#include <set>
#include <string>
@@ -18,6 +18,11 @@ class FilePath;
namespace extension_l10n_util {
+// Set the locale for this process to a fixed value, rather than using the
+// normal file-based lookup mechanisms. This is used to set the locale inside
+// the sandboxed utility process, where file reading is not allowed.
+void SetProcessLocale(const std::string& locale);
+
// Returns default locale in form "en-US" or "sr" or empty string if
// "default_locale" section was not defined in the manifest.json file.
std::string GetDefaultLocaleFromManifest(const DictionaryValue& manifest,
@@ -74,4 +79,4 @@ void GetL10nRelativePaths(const FilePath& relative_resource_path,
} // namespace extension_l10n_util
-#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_L10N_UTIL_H_
+#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_L10N_UTIL_H_
diff --git a/chrome/browser/extensions/extension_l10n_util_unittest.cc b/chrome/common/extensions/extension_l10n_util_unittest.cc
index 7e7ce27..d6e5ad3 100644
--- a/chrome/browser/extensions/extension_l10n_util_unittest.cc
+++ b/chrome/common/extensions/extension_l10n_util_unittest.cc
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/extensions/extension_l10n_util.h"
-
#include "app/l10n_util.h"
#include "base/file_path.h"
#include "base/file_util.h"
@@ -14,6 +12,7 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/common/extensions/extension_l10n_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
diff --git a/chrome/common/extensions/extension_resource.cc b/chrome/common/extensions/extension_resource.cc
index e92a8d0..7b2a833 100644
--- a/chrome/common/extensions/extension_resource.cc
+++ b/chrome/common/extensions/extension_resource.cc
@@ -7,7 +7,7 @@
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/string_util.h"
-#include "chrome/browser/extensions/extension_l10n_util.h"
+#include "chrome/common/extensions/extension_l10n_util.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
diff --git a/chrome/common/extensions/extension_resource_unittest.cc b/chrome/common/extensions/extension_resource_unittest.cc
index 6954408..f467e47 100644
--- a/chrome/common/extensions/extension_resource_unittest.cc
+++ b/chrome/common/extensions/extension_resource_unittest.cc
@@ -8,9 +8,9 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/scoped_temp_dir.h"
-#include "chrome/browser/extensions/extension_l10n_util.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/extension_l10n_util.h"
#include "chrome/common/extensions/extension_resource.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/chrome/utility/utility_main.cc b/chrome/utility/utility_main.cc
index bb669a7..b2eaa46 100644
--- a/chrome/utility/utility_main.cc
+++ b/chrome/utility/utility_main.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "app/app_switches.h"
#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/string_util.h"
@@ -9,6 +10,7 @@
#include "chrome/common/child_process.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/extension_l10n_util.h"
#include "chrome/common/logging_chrome.h"
#include "chrome/common/main_function_params.h"
#include "chrome/utility/utility_thread.h"
@@ -39,6 +41,11 @@ int UtilityMain(const MainFunctionParams& parameters) {
target_services->LowerToken();
#endif
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ std::string lang = command_line->GetSwitchValueASCII(switches::kLang);
+ if (!lang.empty())
+ extension_l10n_util::SetProcessLocale(lang);
+
MessageLoop::current()->Run();
return 0;