summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpeletskyi <peletskyi@chromium.org>2015-04-08 07:13:00 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-08 14:14:48 +0000
commit86af4462b98b956599232b6c1e89ada0ccbaac45 (patch)
tree7c5019921240c81329d05cc8830e5140b5cff5eb
parent8666f86539a214bb7a981d41a08c462e08a3bda0 (diff)
downloadchromium_src-86af4462b98b956599232b6c1e89ada0ccbaac45.zip
chromium_src-86af4462b98b956599232b6c1e89ada0ccbaac45.tar.gz
chromium_src-86af4462b98b956599232b6c1e89ada0ccbaac45.tar.bz2
If DefaultBrowserSettingEnabled set to false and there is the command line
flag that makes chrome default browser, the flag beats Policy. This is wrong behavior. Thus added the condition that checks policy before set chrome as a default browser. BUG=361527 Review URL: https://codereview.chromium.org/927163002 Cr-Commit-Position: refs/heads/master@{#324224}
-rw-r--r--chrome/browser/chrome_browser_main.cc7
-rw-r--r--chrome/browser/policy/policy_startup_browsertest.cc46
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--chrome/common/chrome_result_codes.h3
4 files changed, 58 insertions, 0 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 5e3d4ef..c250470 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -1176,6 +1176,13 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
#endif // defined(OS_WIN)
if (parsed_command_line().HasSwitch(switches::kMakeDefaultBrowser)) {
+ bool is_managed = g_browser_process->local_state()->IsManagedPreference(
+ prefs::kDefaultBrowserSettingEnabled);
+ if (is_managed && !g_browser_process->local_state()->GetBoolean(
+ prefs::kDefaultBrowserSettingEnabled)) {
+ return static_cast<int>(chrome::RESULT_CODE_ACTION_DISALLOWED_BY_POLICY);
+ }
+
return ShellIntegration::SetAsDefaultBrowser() ?
static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) :
static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED);
diff --git a/chrome/browser/policy/policy_startup_browsertest.cc b/chrome/browser/policy/policy_startup_browsertest.cc
new file mode 100644
index 0000000..bf429d3
--- /dev/null
+++ b/chrome/browser/policy/policy_startup_browsertest.cc
@@ -0,0 +1,46 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Warning: this file will not be compiled for ChromeOS because the test
+// PolicyMakeDefaultBrowserTest is not valid for this platform.
+
+#include "base/command_line.h"
+#include "chrome/common/chrome_result_codes.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "components/policy/core/browser/browser_policy_connector.h"
+#include "components/policy/core/common/mock_configuration_policy_provider.h"
+#include "components/policy/core/common/policy_map.h"
+#include "policy/policy_constants.h"
+
+class PolicyMakeDefaultBrowserTest : public InProcessBrowserTest {
+ protected:
+ PolicyMakeDefaultBrowserTest() : InProcessBrowserTest() {
+ set_expected_exit_code(chrome::RESULT_CODE_ACTION_DISALLOWED_BY_POLICY);
+ }
+
+ void SetUpInProcessBrowserTestFixture() override {
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kMakeDefaultBrowser);
+ EXPECT_CALL(provider_, IsInitializationComplete(testing::_))
+ .WillRepeatedly(testing::Return(true));
+
+ policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
+
+ policy::PolicyMap values;
+ values.Set(policy::key::kDefaultBrowserSettingEnabled,
+ policy::POLICY_LEVEL_MANDATORY,
+ policy::POLICY_SCOPE_MACHINE,
+ new base::FundamentalValue(false),
+ NULL);
+ provider_.UpdateChromePolicy(values);
+ }
+
+ private:
+ policy::MockConfigurationPolicyProvider provider_;
+ DISALLOW_COPY_AND_ASSIGN(PolicyMakeDefaultBrowserTest);
+};
+
+IN_PROC_BROWSER_TEST_F(PolicyMakeDefaultBrowserTest, MakeDefaultDisabled) {
+}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 96201b4..8f3947b 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -762,6 +762,7 @@
'browser/policy/cloud/test_request_interceptor.h',
'browser/policy/policy_browsertest.cc',
'browser/policy/policy_prefs_browsertest.cc',
+ 'browser/policy/policy_startup_browsertest.cc',
'browser/ui/webui/options/certificate_manager_browsertest.cc',
'browser/ui/webui/options/preferences_browsertest.cc',
'browser/ui/webui/options/preferences_browsertest.h',
@@ -2160,6 +2161,7 @@
'../apps/load_and_launch_browsertest.cc',
'browser/printing/cloud_print/test/cloud_print_policy_browsertest.cc',
'browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc',
+ 'browser/policy/policy_startup_browsertest.cc',
# chromeos does not support profile list avatar menu
'browser/profiles/profile_list_desktop_browsertest.cc',
'browser/service_process/service_process_control_browsertest.cc',
diff --git a/chrome/common/chrome_result_codes.h b/chrome/common/chrome_result_codes.h
index c047b46..9f80d9d 100644
--- a/chrome/common/chrome_result_codes.h
+++ b/chrome/common/chrome_result_codes.h
@@ -89,6 +89,9 @@ enum ResultCode {
// (Linux-only).
RESULT_CODE_SXS_MIGRATION_FAILED,
+ // The action is not allowed by a policy.
+ RESULT_CODE_ACTION_DISALLOWED_BY_POLICY,
+
// Last return code (keep this last).
RESULT_CODE_CHROME_LAST_CODE,
};