Commit b18a04f5 authored by dschuyler's avatar dschuyler Committed by Commit bot

[MD settings] display message about secondary install in default browser settings

This CL reworks the 'default browser' messages displayed in different
situations. The error icon has been removed to match the specs. A browser proxy
and unit tests have been added.

BUG=623328
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2317693003
Cr-Commit-Position: refs/heads/master@{#417327}
parent aac49f47
......@@ -41,15 +41,12 @@
<message name="IDS_SETTINGS_DEFAULT_BROWSER_MAKE_DEFAULT" desc="Default browser checkbox label">
Make Chromium the default browser
</message>
<message name="IDS_SETTINGS_DEFAULT_BROWSER_UNKNOWN" desc="The text displayed when Chrome cannot determine or set the default browser">
<message name="IDS_SETTINGS_DEFAULT_BROWSER_ERROR" desc="The text displayed when Chrome cannot determine or set the default browser">
Chromium cannot determine or set the default browser.
</message>
<message name="IDS_SETTINGS_DEFAULT_BROWSER_SECONDARY" desc="The text displayed when Chromium is installed in side-by-side mode, which does not support setting as the default browser.">
This is a secondary installation of Chromium, and cannot be made your default browser.
</message>
<message name="IDS_SETTINGS_DEFAULT_BROWSER_ERROR" desc="The text displayed when Chromium is unable to become the default browser after the user requests that it became the default browser. This is a general error message.">
Chromium was not able to become the default browser.
</message>
</if>
<!-- Privacy Page -->
......
......@@ -41,15 +41,12 @@
<message name="IDS_SETTINGS_DEFAULT_BROWSER_MAKE_DEFAULT" desc="Default browser checkbox label">
Make Google Chrome the default browser
</message>
<message name="IDS_SETTINGS_DEFAULT_BROWSER_UNKNOWN" desc="The text displayed when Chrome cannot determine or set the default browser">
<message name="IDS_SETTINGS_DEFAULT_BROWSER_ERROR" desc="The text displayed when Chrome cannot determine or set the default browser">
Google Chrome cannot determine or set the default browser.
</message>
<message name="IDS_SETTINGS_DEFAULT_BROWSER_SECONDARY" desc="The text displayed when Chrome is installed in side-by-side mode, which does not support setting as the default browser.">
This is a secondary installation of Google Chrome, and cannot be made your default browser.
</message>
<message name="IDS_SETTINGS_DEFAULT_BROWSER_ERROR" desc="The text displayed when Chrome is unable to become the default browser after the user requests that it became the default browser. This is a general error message.">
Google Chrome was not able to become the default browser.
</message>
</if>
<!-- Privacy Page -->
......
......@@ -3,11 +3,19 @@
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'default_browser_browser_proxy',
'dependencies': [
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:cr',
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{
'target_name': 'default_browser_page',
'dependencies': [
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:cr',
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:load_time_data',
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:web_ui_listener_behavior',
'default_browser_browser_proxy',
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
......
<link rel="import" href="chrome://resources/html/cr.html">
<script src="/default_browser_page/default_browser_browser_proxy.js"></script>
// Copyright 2016 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.
/**
* @fileoverview A helper object used from the "Default Browser" section
* to interact with the browser.
*/
/**
* @typedef {{
* canBeDefault: boolean,
* isDefault: boolean,
* isDisabledByPolicy: boolean,
* isUnknownError: boolean,
* }};
*/
var DefaultBrowserInfo;
cr.define('settings', function() {
/** @interface */
function DefaultBrowserBrowserProxy() {}
DefaultBrowserBrowserProxy.prototype = {
/**
* Get the initial DefaultBrowserInfo and begin sending updates to
* 'settings.updateDefaultBrowserState'.
* @return {!Promise<DefaultBrowserInfo>}
*/
requestDefaultBrowserState: function() {},
/*
* Try to set the current browser as the default browser. The new status of
* the settings will be sent to 'settings.updateDefaultBrowserState'.
*/
setAsDefaultBrowser: function() {},
};
/**
* @constructor
* @implements {settings.DefaultBrowserBrowserProxy}
*/
function DefaultBrowserBrowserProxyImpl() {}
cr.addSingletonGetter(DefaultBrowserBrowserProxyImpl);
DefaultBrowserBrowserProxyImpl.prototype = {
/** @override */
requestDefaultBrowserState: function() {
return cr.sendWithPromise(
'SettingsDefaultBrowser.requestDefaultBrowserState');
},
/** @override */
setAsDefaultBrowser: function() {
chrome.send('SettingsDefaultBrowser.setAsDefaultBrowser');
},
};
return {
DefaultBrowserBrowserProxy: DefaultBrowserBrowserProxy,
DefaultBrowserBrowserProxyImpl: DefaultBrowserBrowserProxyImpl,
};
});
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
<link rel="import" href="chrome://resources/html/web_ui_listener_behavior.html">
<link rel="import" href="/default_browser_page/default_browser_browser_proxy.html">
<link rel="import" href="/icons.html">
<link rel="import" href="/settings_shared_css.html">
<dom-module id="settings-default-browser-page">
<template>
<style include="settings-shared">
.error-icon {
color: var(--settings-error-color);
.solo-secondary {
@apply(--settings-secondary);
margin: 0;
}
</style>
<div class="settings-box first two-line">
<template is="dom-if" if="[[showButton_]]">
<div class="start" on-tap="onSetDefaultBrowserTap_" actionable>
<div>$i18n{defaultBrowser}</div>
<template is="dom-if" if="[[maySetDefaultBrowser_]]">
<div class="settings-box first two-line" on-tap="onSetDefaultBrowserTap_"
actionable>
<div>
<div id="canBeDefaultBrowser">$i18n{defaultBrowser}</div>
<div class="secondary">$i18n{defaultBrowserMakeDefault}</div>
</div>
<template is="dom-if" if="[[showError_]]">
<iron-icon icon="settings:error" class="error-icon"
title="$i18n{unableToSetDefaultBrowser}"></iron-icon>
</template>
</template>
<template is="dom-if" if="[[!showButton_]]">
<div class="secondary">[[message_]]</div>
</template>
</div>
</div>
</template>
<template is="dom-if" if="[[!maySetDefaultBrowser_]]">
<div class="settings-box first">
<div class="solo-secondary" hidden$="[[!isDefault_]]" id="isDefault">
$i18n{defaultBrowserDefault}
</div>
<div class="solo-secondary" hidden$="[[!isSecondaryInstall_]]"
id="isSecondaryInstall">
$i18n{defaultBrowserSecondary}
</div>
<div class="solo-secondary" hidden$="[[!isUnknownError_]]"
id="isUnknownError">
$i18n{defaultBrowserError}
</div>
</div>
</template>
</template>
<script src="default_browser_page.js"></script>
</dom-module>
......@@ -10,76 +10,61 @@
Polymer({
is: 'settings-default-browser-page',
behaviors: [WebUIListenerBehavior],
properties: {
/**
* A message about whether Chrome is the default browser.
*/
message_: {
type: String,
},
/** @private */
isDefault_: Boolean,
/**
* Indicates if the next updateDefaultBrowserState_ invocation is following
* a call to SettingsDefaultBrowser.setAsDefaultBrowser().
*/
startedSetAsDefault_: {
type: Boolean,
value: false,
},
/** @private */
isSecondaryInstall_: Boolean,
/**
* Show or hide an error indicator showing whether SetAsDefault succeeded.
*/
showError_: {
type: Boolean,
value: false,
},
/** @private */
isUnknownError_: Boolean,
/**
* Only show the SetAsDefault button if we have permission to set it.
*/
showButton_: {
type: Boolean,
},
/** @private */
maySetDefaultBrowser_: Boolean,
},
/** @private {settings.DefaultBrowserBrowserProxy} */
browserProxy_: null,
/** @override */
created: function() {
this.browserProxy_ = settings.DefaultBrowserBrowserProxyImpl.getInstance();
},
ready: function() {
var self = this;
cr.define('Settings', function() {
return {
updateDefaultBrowserState: function() {
return self.updateDefaultBrowserState_.apply(self, arguments);
},
};
});
chrome.send('SettingsDefaultBrowser.requestDefaultBrowserState');
this.addWebUIListener('settings.updateDefaultBrowserState',
this.updateDefaultBrowserState_.bind(this));
this.browserProxy_.requestDefaultBrowserState().then(
this.updateDefaultBrowserState_.bind(this));
},
/**
* @param {boolean} isDefault Whether Chrome is currently the user's default
* browser.
* @param {boolean} canBeDefault Whether Chrome can be the default browser on
* this system.
* @param {!DefaultBrowserInfo} defaultBrowserState
* @private
*/
updateDefaultBrowserState_: function(isDefault, canBeDefault) {
if (this.startedSetAsDefault_ && !isDefault) {
this.startedSetAsDefault_ = false;
this.showError_ = true;
} else {
this.showError_ = false;
}
updateDefaultBrowserState_: function(defaultBrowserState) {
this.isDefault_ = false;
this.isSecondaryInstall_ = false;
this.isUnknownError_ = false;
this.maySetDefaultBrowser_ = false;
this.showButton_ = !isDefault && canBeDefault;
if (!this.showButton_) {
this.message_ = loadTimeData.getString(
canBeDefault ? 'defaultBrowserDefault' : 'defaultBrowserUnknown');
}
if (defaultBrowserState.isDefault)
this.isDefault_ = true;
else if (!defaultBrowserState.canBeDefault)
this.isSecondaryInstall_ = true;
else if (!defaultBrowserState.isDisabledByPolicy &&
!defaultBrowserState.isUnknownError)
this.maySetDefaultBrowser_ = true;
else
this.isUnknownError_ = true;
},
/** @private */
onSetDefaultBrowserTap_: function() {
this.startedSetAsDefault_ = true;
chrome.send('SettingsDefaultBrowser.setAsDefaultBrowser');
this.browserProxy_.setAsDefaultBrowser();
},
});
......@@ -374,6 +374,12 @@
file="site_settings/cookie_tree_node.js"
type="chrome_html" />
<if expr="not chromeos">
<structure name="IDR_SETTINGS_DEFAULT_BROWSER_BROWSER_PROXY_HTML"
file="default_browser_page/default_browser_browser_proxy.html"
type="chrome_html" />
<structure name="IDR_SETTINGS_DEFAULT_BROWSER_BROWSER_PROXY_JS"
file="default_browser_page/default_browser_browser_proxy.js"
type="chrome_html" />
<structure name="IDR_SETTINGS_DEFAULT_BROWSER_PAGE_HTML"
file="default_browser_page/default_browser_page.html"
type="chrome_html"
......
......@@ -464,9 +464,8 @@ void AddDefaultBrowserStrings(content::WebUIDataSource* html_source) {
{"defaultBrowser", IDS_SETTINGS_DEFAULT_BROWSER},
{"defaultBrowserDefault", IDS_SETTINGS_DEFAULT_BROWSER_DEFAULT},
{"defaultBrowserMakeDefault", IDS_SETTINGS_DEFAULT_BROWSER_MAKE_DEFAULT},
{"defaultBrowserUnknown", IDS_SETTINGS_DEFAULT_BROWSER_UNKNOWN},
{"defaultBrowserError", IDS_SETTINGS_DEFAULT_BROWSER_ERROR},
{"defaultBrowserSecondary", IDS_SETTINGS_DEFAULT_BROWSER_SECONDARY},
{"unableToSetDefaultBrowser", IDS_SETTINGS_DEFAULT_BROWSER_ERROR},
};
AddLocalizedStringsBulk(html_source, localized_strings,
arraysize(localized_strings));
......@@ -1151,7 +1150,7 @@ void AddSearchInSettingsStrings(content::WebUIDataSource* html_source) {
LocalizedString localized_strings[] = {
{"searchPrompt", IDS_SETTINGS_SEARCH_PROMPT},
{"searchNoResults", IDS_SETTINGS_SEARCH_NO_RESULTS},
// TODO(dpapad); IDS_DOWNLOAD_CLEAR_SEARCH and IDS_MD_HISTORY_CLEAR_SEARCH
// TODO(dpapad): IDS_DOWNLOAD_CLEAR_SEARCH and IDS_MD_HISTORY_CLEAR_SEARCH
// are identical, merge them to one and re-use here.
{"clearSearch", IDS_DOWNLOAD_CLEAR_SEARCH},
};
......
......@@ -88,14 +88,16 @@ void DefaultBrowserHandler::OnDefaultBrowserWorkerFinished(
chrome::ResetDefaultBrowserPrompt(Profile::FromWebUI(web_ui()));
}
base::FundamentalValue is_default(state == shell_integration::IS_DEFAULT);
base::FundamentalValue can_be_default(
state != shell_integration::UNKNOWN_DEFAULT &&
!DefaultBrowserIsDisabledByPolicy() &&
base::DictionaryValue dict;
dict.SetBoolean("isDefault", state == shell_integration::IS_DEFAULT);
dict.SetBoolean("canBeDefault",
shell_integration::CanSetAsDefaultBrowser());
dict.SetBoolean("isUnknownError",
state == shell_integration::UNKNOWN_DEFAULT);
dict.SetBoolean("isDisabledByPolicy", DefaultBrowserIsDisabledByPolicy());
CallJavascriptFunction("Settings.updateDefaultBrowserState", is_default,
can_be_default);
CallJavascriptFunction("cr.webUIListenerCallback",
base::StringValue("settings.updateDefaultBrowserState"), dict);
}
} // namespace settings
......@@ -340,6 +340,34 @@ TEST_F('CrSettingsAppearancePageTest', 'AppearancePage', function() {
mocha.run();
});
GEN('#if !defined(OS_CHROMEOS)');
/**
* Test fixture for chrome/browser/resources/settings/default_browser_page/.
* @constructor
* @extends {CrSettingsBrowserTest}
*/
function CrSettingsDefaultBrowserTest() {}
CrSettingsDefaultBrowserTest.prototype = {
__proto__: CrSettingsBrowserTest.prototype,
/** @override */
browsePreload:
'chrome://md-settings/default_browser_page/default_browser_page.html',
/** @override */
extraLibraries: CrSettingsBrowserTest.prototype.extraLibraries.concat([
'test_browser_proxy.js',
'default_browser_browsertest.js',
]),
};
TEST_F('CrSettingsDefaultBrowserTest', 'DefaultBrowserPage', function() {
settings_default_browser.registerTests();
mocha.run();
});
GEN('#endif');
/**
* Test fixture for chrome/browser/resources/settings/search_page/.
* @constructor
......
// Copyright 2016 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.
cr.define('settings_default_browser', function() {
/**
* A test version of DefaultBrowserBrowserProxy. Provides helper methods
* for allowing tests to know when a method was called, as well as
* specifying mock responses.
*
* @constructor
* @implements {settings.DefaultBrowserBrowserProxy}
* @extends {settings.TestBrowserProxy}
*/
var TestDefaultBrowserBrowserProxy = function() {
settings.TestBrowserProxy.call(this, [
'requestDefaultBrowserState',
'setAsDefaultBrowser',
]);
/** @private {!DefaultBrowserInfo} */
this.defaultBrowserInfo_ = {
canBeDefault: true,
isDefault: false,
isDisabledByPolicy: false,
isUnknownError: false
};
};
TestDefaultBrowserBrowserProxy.prototype = {
__proto__: settings.TestBrowserProxy.prototype,
/** @override */
requestDefaultBrowserState: function() {
this.methodCalled('requestDefaultBrowserState');
return Promise.resolve(this.defaultBrowserInfo_);
},
/** @override */
setAsDefaultBrowser: function() {
this.methodCalled('setAsDefaultBrowser');
},
/**
* Sets the response to be returned by |requestDefaultBrowserState|.
* @param {!DefaultBrowserInfo} info Fake info for testing.
*/
setDefaultBrowserInfo: function(info) {
this.defaultBrowserInfo_ = info;
},
}
function registerDefaultBrowserPageTests() {
suite('DefaultBrowserPageTest', function() {
var page = null;
/** @type {?settings.TestDefaultBrowserBrowserProxy} */
var browserProxy = null;
setup(function() {
browserProxy = new TestDefaultBrowserBrowserProxy();
settings.DefaultBrowserBrowserProxyImpl.instance_ = browserProxy;
return initPage();
});
teardown(function() {
page.remove();
page = null;
});
/** @return {!Promise} */
function initPage() {
browserProxy.reset();
PolymerTest.clearBody();
page = document.createElement('settings-default-browser-page');
document.body.appendChild(page);
return browserProxy.whenCalled('requestDefaultBrowserState');
}
test('default-browser-test-can-be-default', function(done) {
browserProxy.setDefaultBrowserInfo({
canBeDefault: true,
isDefault: false,
isDisabledByPolicy: false,
isUnknownError: false
});
return initPage().then(function() {
assertFalse(page.isDefault_);
assertFalse(page.isSecondaryInstall_);
assertFalse(page.isUnknownError_);
assertTrue(page.maySetDefaultBrowser_);
done();
});
});
test('default-browser-test-is-default', function(done) {
assertTrue(!!page);
browserProxy.setDefaultBrowserInfo({
canBeDefault: true,
isDefault: true,
isDisabledByPolicy: false,
isUnknownError: false
});
return initPage().then(function() {
assertTrue(page.isDefault_);
assertFalse(page.isSecondaryInstall_);
assertFalse(page.isUnknownError_);
assertFalse(page.maySetDefaultBrowser_);
done();
});
});
test('default-browser-test-is-secondary-install', function(done) {
browserProxy.setDefaultBrowserInfo({
canBeDefault: false,
isDefault: false,
isDisabledByPolicy: false,
isUnknownError: false
});
return initPage().then(function() {
assertFalse(page.isDefault_);
assertTrue(page.isSecondaryInstall_);
assertFalse(page.isUnknownError_);
assertFalse(page.maySetDefaultBrowser_);
done();
});
});
test('default-browser-test-is-disabled-by-policy', function(done) {
browserProxy.setDefaultBrowserInfo({
canBeDefault: true,
isDefault: false,
isDisabledByPolicy: true,
isUnknownError: false
});
return initPage().then(function() {
assertFalse(page.isDefault_);
assertFalse(page.isSecondaryInstall_);
assertTrue(page.isUnknownError_);
assertFalse(page.maySetDefaultBrowser_);
done();
});
});
test('default-browser-test-is-unknown-error', function(done) {
browserProxy.setDefaultBrowserInfo({
canBeDefault: true,
isDefault: false,
isDisabledByPolicy: false,
isUnknownError: true
});
return initPage().then(function() {
assertFalse(page.isDefault_);
assertFalse(page.isSecondaryInstall_);
assertTrue(page.isUnknownError_);
assertFalse(page.maySetDefaultBrowser_);
done();
});
});
});
}
return {
registerTests: function() {
registerDefaultBrowserPageTests();
},
};
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment