From 86af4462b98b956599232b6c1e89ada0ccbaac45 Mon Sep 17 00:00:00 2001 From: peletskyi Date: Wed, 8 Apr 2015 07:13:00 -0700 Subject: 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} --- chrome/browser/chrome_browser_main.cc | 7 ++++ .../browser/policy/policy_startup_browsertest.cc | 46 ++++++++++++++++++++++ chrome/chrome_tests.gypi | 2 + chrome/common/chrome_result_codes.h | 3 ++ 4 files changed, 58 insertions(+) create mode 100644 chrome/browser/policy/policy_startup_browsertest.cc 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(chrome::RESULT_CODE_ACTION_DISALLOWED_BY_POLICY); + } + return ShellIntegration::SetAsDefaultBrowser() ? static_cast(content::RESULT_CODE_NORMAL_EXIT) : static_cast(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, }; -- cgit v1.1