Skip to content

Commit

Permalink
Introduced a new policy DefaultBrowserSettingEnabled.
Browse files Browse the repository at this point in the history
When set it either enforces Chrome's registration as default browser,
or prevents the user from seeing the reminder about Chrome not being default
as well as disabled the UI for setting it as default browser. When not set
the old behavior is observed.

BUG=65290
TEST=Manual. Set the policy and the UI should be disabled. If set to true the browser should become default browser immediately.

Review URL: http://codereview.chromium.org/6348021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73280 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
pastarmovj@chromium.org committed Feb 1, 2011
1 parent bbdd9dd commit e450fa6
Show file tree
Hide file tree
Showing 19 changed files with 164 additions and 31 deletions.
10 changes: 3 additions & 7 deletions chrome/app/nibs/Preferences.xib
Original file line number Diff line number Diff line change
Expand Up @@ -2574,19 +2574,15 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">enabled: isDefaultBrowser</string>
<string key="label">enabled: canChangeDefaultBrowser</string>
<reference key="source" ref="192681043"/>
<reference key="destination" ref="1001"/>
<object class="NSNibBindingConnector" key="connector">
<reference key="NSSource" ref="192681043"/>
<reference key="NSDestination" ref="1001"/>
<string key="NSLabel">enabled: isDefaultBrowser</string>
<string key="NSLabel">enabled: canChangeDefaultBrowser</string>
<string key="NSBinding">enabled</string>
<string key="NSKeyPath">isDefaultBrowser</string>
<object class="NSDictionary" key="NSOptions">
<string key="NS.key.0">NSValueTransformerName</string>
<string key="NS.object.0">NSNegateBoolean</string>
</object>
<string key="NSKeyPath">canChangeDefaultBrowser</string>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
Expand Down
16 changes: 16 additions & 0 deletions chrome/app/policy/policy_templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@
},
],
},
{
'name': 'DefaultBrowserSettingEnabled',
'type': 'main',
'supported_on': ['chrome.*:11-'],
'features': {'dynamic_refresh': 1},
'example_value': True,
'caption': '''Set Chrome as Default Browser''',
'desc': '''Configures the default browser checks in <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> and prevents users from changing them.

If you enable this setting, <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> will always check on startup whether it is the default browser and automatically register itself if possible.

If this setting is disabled, <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> will never check if it is the default browser and will disable user controls for setting this option.

If this setting is not set, <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> will allow the user to control whether it is the default browser and whether user notifications should be shown when it isn't.''',
'label': '''Set Chrome as Default Browser''',
},
{
'name': 'ApplicationLocaleValue',
'type': 'string',
Expand Down
16 changes: 16 additions & 0 deletions chrome/browser/browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/safe_browsing/client_side_detection_service.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/sidebar/sidebar_manager.h"
#include "chrome/browser/tab_closeable_state_watcher.h"
#include "chrome/common/chrome_constants.h"
Expand Down Expand Up @@ -566,6 +567,12 @@ void BrowserProcessImpl::Observe(NotificationType type,
plugin_data_remover_->StartRemoving(base::Time());
}
}
} else if (type == NotificationType::PREF_CHANGED) {
std::string* pref = Details<std::string>(details).ptr();
if (*pref == prefs::kDefaultBrowserSettingEnabled) {
if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
ShellIntegration::SetAsDefaultBrowser();
}
} else {
NOTREACHED();
}
Expand Down Expand Up @@ -742,6 +749,15 @@ void BrowserProcessImpl::CreateLocalState() {
print_job_manager_->set_printing_enabled(printing_enabled);
pref_change_registrar_.Add(prefs::kPrintingEnabled,
print_job_manager_.get());

// Initialize the notification for the default browser setting policy.
local_state_->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled,
false);
if (local_state_->IsManagedPreference(prefs::kDefaultBrowserSettingEnabled)) {
if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
ShellIntegration::SetAsDefaultBrowser();
}
pref_change_registrar_.Add(prefs::kDefaultBrowserSettingEnabled, this);
}

void BrowserProcessImpl::CreateIconManager() {
Expand Down
20 changes: 18 additions & 2 deletions chrome/browser/dom_ui/options/browser_options_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/custom_home_pages_table_model.h"
#include "chrome/browser/dom_ui/dom_ui_favicon_source.h"
Expand Down Expand Up @@ -133,6 +134,9 @@ void BrowserOptionsHandler::Initialize() {
make_scoped_refptr(new DOMUIFavIconSource(profile))));

homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL);
default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled,
g_browser_process->local_state(),
this);
UpdateDefaultBrowserState();
UpdateStartupPages();
UpdateSearchEngines();
Expand Down Expand Up @@ -187,6 +191,11 @@ void BrowserOptionsHandler::UpdateDefaultBrowserState() {
}

void BrowserOptionsHandler::BecomeDefaultBrowser(const ListValue* args) {
// If the default browser setting is managed then we should not be able to
// call this function.
if (default_browser_policy_.IsManaged())
return;

UserMetricsRecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"));
#if defined(OS_MACOSX)
if (ShellIntegration::SetAsDefaultBrowser())
Expand Down Expand Up @@ -230,8 +239,9 @@ void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id) {
status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT));

scoped_ptr<Value> can_be_default(Value::CreateBooleanValue(
status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT ||
status_string_id == IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT));
!default_browser_policy_.IsManaged() &&
(status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT ||
status_string_id == IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT)));

dom_ui_->CallJavascriptFunction(
L"BrowserOptions.updateDefaultBrowserState",
Expand Down Expand Up @@ -333,6 +343,12 @@ void BrowserOptionsHandler::OnItemsRemoved(int start, int length) {
OnModelChanged();
}

void BrowserOptionsHandler::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
UpdateDefaultBrowserState();
}

void BrowserOptionsHandler::SetStartupPagesToCurrentPages(
const ListValue* args) {
startup_custom_pages_table_model_->SetToCurrentlyOpenPages();
Expand Down
6 changes: 6 additions & 0 deletions chrome/browser/dom_ui/options/browser_options_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class BrowserOptionsHandler : public OptionsPageUIHandler,
virtual void OnItemsRemoved(int start, int length);

private:
// NotificationObserver implementation.
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);

// Sets the home page to the given string. Called from DOMUI.
void SetHomePage(const ListValue* args);

Expand Down Expand Up @@ -91,6 +96,7 @@ class BrowserOptionsHandler : public OptionsPageUIHandler,
scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;

StringPrefMember homepage_;
BooleanPrefMember default_browser_policy_;

TemplateURLModel* template_url_model_; // Weak.

Expand Down
20 changes: 15 additions & 5 deletions chrome/browser/first_run/first_run.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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.

Expand Down Expand Up @@ -301,10 +301,20 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
}
#endif

if (prefs.GetBool(
installer::master_preferences::kMakeChromeDefaultForUser,
&value) && value) {
ShellIntegration::SetAsDefaultBrowser();
// Even on the first run we only allow for the user choice to take effect if
// no policy has been set by the admin.
if (!g_browser_process->local_state()->IsManagedPreference(
prefs::kDefaultBrowserSettingEnabled)) {
if (prefs.GetBool(
installer::master_preferences::kMakeChromeDefaultForUser,
&value) && value) {
ShellIntegration::SetAsDefaultBrowser();
}
} else {
if (g_browser_process->local_state()->GetBoolean(
prefs::kDefaultBrowserSettingEnabled)) {
ShellIntegration::SetAsDefaultBrowser();
}
}

return false;
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/policy/configuration_policy_pref_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry
prefs::kDisable3DAPIs },
{ Value::TYPE_INTEGER, kPolicyPolicyRefreshRate,
prefs::kPolicyRefreshRate },
{ Value::TYPE_BOOLEAN, kPolicyDefaultBrowserSettingEnabled,
prefs::kDefaultBrowserSettingEnabled },

#if defined(OS_CHROMEOS)
{ Value::TYPE_BOOLEAN, kPolicyChromeOsLockOnIdleSuspend,
Expand Down Expand Up @@ -841,6 +843,8 @@ ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() {
key::kDisable3DAPIs },
{ kPolicyPolicyRefreshRate, Value::TYPE_INTEGER,
key::kPolicyRefreshRate },
{ kPolicyDefaultBrowserSettingEnabled, Value::TYPE_BOOLEAN,
key::kDefaultBrowserSettingEnabled },

#if defined(OS_CHROMEOS)
{ kPolicyChromeOsLockOnIdleSuspend, Value::TYPE_BOOLEAN,
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/policy/managed_prefs_banner_base.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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.

Expand Down Expand Up @@ -67,6 +67,7 @@ void ManagedPrefsBannerBase::Init(PrefService* local_state,
AddUserPref(prefs::kDefaultSearchProviderSuggestURL);
AddUserPref(prefs::kDefaultSearchProviderIconURL);
AddUserPref(prefs::kDefaultSearchProviderEncodings);
AddLocalStatePref(prefs::kDefaultBrowserSettingEnabled);
break;
case OPTIONS_PAGE_CONTENT:
AddUserPref(prefs::kSyncManaged);
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/shell_integration.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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.

Expand All @@ -10,8 +10,10 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"

ShellIntegration::ShortcutInfo::ShortcutInfo()
: create_on_desktop(false),
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/shell_integration.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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.

Expand All @@ -15,6 +15,7 @@
#include "third_party/skia/include/core/SkBitmap.h"

class FilePath;
class PrefService;

#if defined(USE_X11)
namespace base {
Expand Down
14 changes: 14 additions & 0 deletions chrome/browser/ui/browser_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1055,10 +1055,24 @@ void BrowserInit::LaunchWithProfile::CheckDefaultBrowser(Profile* profile) {
// We do not check if we are the default browser if:
// - the user said "don't ask me again" on the infobar earlier.
// - this is the first launch after the first run flow.
// - There is a policy in control of this setting.
if (!profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser) ||
FirstRun::IsChromeFirstRun()) {
return;
}
if (g_browser_process->local_state()->IsManagedPreference(
prefs::kDefaultBrowserSettingEnabled)) {
if (g_browser_process->local_state()->GetBoolean(
prefs::kDefaultBrowserSettingEnabled)) {
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE, NewRunnableFunction(
&ShellIntegration::SetAsDefaultBrowser));
} else {
// TODO(pastarmovj): We can't really do anything meaningful here yet but
// just prevent showing the infobar.
}
return;
}
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE, new CheckDefaultBrowserTask());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class ProfileSyncService;
BooleanPrefMember instantEnabled_;
IBOutlet NSButton* instantCheckbox_;
scoped_nsobject<SearchEngineListModel> searchEngineModel_;
BooleanPrefMember default_browser_policy_;
// Used when creating a new home page url to make the new cell editable.
BOOL pendingSelectForEdit_;
BOOL restoreButtonsEnabled_;
Expand Down
36 changes: 24 additions & 12 deletions chrome/browser/ui/cocoa/options/preferences_window_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ - (void)initBannerStateForPage:(OptionsPage)page;

// KVC getter methods.
- (BOOL)fileHandlerUIEnabled;
- (BOOL)canChangeDefaultBrowser;
@end

namespace PreferencesWindowControllerInternal {
Expand Down Expand Up @@ -831,6 +832,13 @@ - (NSArray*)toolbarSelectableItemIdentifiers:(NSToolbar*)toolbar {
- (void)registerPrefObservers {
if (!prefs_) return;

// During unit tests, there is no local state object, so we fall back to
// the prefs object (where we've explicitly registered this pref so we
// know it's there).
PrefService* local = g_browser_process->local_state();
if (!local)
local = prefs_;

// Basics panel
registrar_.Init(prefs_);
registrar_.Add(prefs::kURLsToRestoreOnStartup, observer_.get());
Expand All @@ -840,6 +848,8 @@ - (void)registerPrefObservers {
homepage_.Init(prefs::kHomePage, prefs_, observer_.get());
showHomeButton_.Init(prefs::kShowHomeButton, prefs_, observer_.get());
instantEnabled_.Init(prefs::kInstantEnabled, prefs_, observer_.get());
default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled,
local, observer_.get());

// Personal Stuff panel
askSavePasswords_.Init(prefs::kPasswordManagerEnabled,
Expand All @@ -858,12 +868,6 @@ - (void)registerPrefObservers {
translateEnabled_.Init(prefs::kEnableTranslate, prefs_, observer_.get());
tabsToLinks_.Init(prefs::kWebkitTabsToLinks, prefs_, observer_.get());

// During unit tests, there is no local state object, so we fall back to
// the prefs object (where we've explicitly registered this pref so we
// know it's there).
PrefService* local = g_browser_process->local_state();
if (!local)
local = prefs_;
metricsReporting_.Init(prefs::kMetricsReportingEnabled,
local, observer_.get());
defaultDownloadLocation_.Init(prefs::kDownloadDefaultDirectory, prefs_,
Expand Down Expand Up @@ -911,7 +915,7 @@ + (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key {
paths = [paths setByAddingObject:@"homepageURL"];
} else if ([key isEqualToString:@"hompageURL"]) {
paths = [paths setByAddingObject:@"newTabPageIsHomePageIndex"];
} else if ([key isEqualToString:@"isDefaultBrowser"]) {
} else if ([key isEqualToString:@"canChangeDefaultBrowser"]) {
paths = [paths setByAddingObject:@"defaultBrowser"];
} else if ([key isEqualToString:@"defaultBrowserTextColor"]) {
paths = [paths setByAddingObject:@"defaultBrowser"];
Expand Down Expand Up @@ -978,6 +982,9 @@ - (void)basicsPrefChanged:(std::string*)prefName {
[self setShowHomeButtonEnabled:!showHomeButton_.IsManaged()];
} else if (*prefName == prefs::kInstantEnabled) {
[self configureInstant];
} else if (*prefName == prefs::kDefaultBrowserSettingEnabled) {
[self willChangeValueForKey:@"defaultBrowser"];
[self didChangeValueForKey:@"defaultBrowser"];
}
}

Expand Down Expand Up @@ -1264,15 +1271,19 @@ - (IBAction)makeDefaultBrowser:(id)sender {
[self didChangeValueForKey:@"defaultBrowser"];
}

// Returns the Chromium default browser state.
- (ShellIntegration::DefaultBrowserState)isDefaultBrowser {
return ShellIntegration::IsDefaultBrowser();
// Returns the Chromium default browser state and whether this is user
// controlled or locked by a policy.
- (BOOL)canChangeDefaultBrowser {
return !default_browser_policy_.IsManaged() &&
ShellIntegration::IsDefaultBrowser() !=
ShellIntegration::IS_DEFAULT_BROWSER;
}

// Returns the text color of the "chromium is your default browser" text (green
// for yes, red for no).
- (NSColor*)defaultBrowserTextColor {
ShellIntegration::DefaultBrowserState state = [self isDefaultBrowser];
ShellIntegration::DefaultBrowserState state =
ShellIntegration::IsDefaultBrowser();
return (state == ShellIntegration::IS_DEFAULT_BROWSER) ?
[NSColor colorWithCalibratedRed:0.0 green:135.0/255.0 blue:0 alpha:1.0] :
[NSColor colorWithCalibratedRed:135.0/255.0 green:0 blue:0 alpha:1.0];
Expand All @@ -1281,7 +1292,8 @@ - (NSColor*)defaultBrowserTextColor {
// Returns the text for the "chromium is your default browser" string dependent
// on if Chromium actually is or not.
- (NSString*)defaultBrowserText {
ShellIntegration::DefaultBrowserState state = [self isDefaultBrowser];
ShellIntegration::DefaultBrowserState state =
ShellIntegration::IsDefaultBrowser();
int stringId;
if (state == ShellIntegration::IS_DEFAULT_BROWSER)
stringId = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
Expand Down
Loading

0 comments on commit e450fa6

Please sign in to comment.