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 @@ ...@@ -41,15 +41,12 @@
<message name="IDS_SETTINGS_DEFAULT_BROWSER_MAKE_DEFAULT" desc="Default browser checkbox label"> <message name="IDS_SETTINGS_DEFAULT_BROWSER_MAKE_DEFAULT" desc="Default browser checkbox label">
Make Chromium the default browser Make Chromium the default browser
</message> </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. Chromium cannot determine or set the default browser.
</message> </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."> <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. This is a secondary installation of Chromium, and cannot be made your default browser.
</message> </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> </if>
<!-- Privacy Page --> <!-- Privacy Page -->
......
...@@ -41,15 +41,12 @@ ...@@ -41,15 +41,12 @@
<message name="IDS_SETTINGS_DEFAULT_BROWSER_MAKE_DEFAULT" desc="Default browser checkbox label"> <message name="IDS_SETTINGS_DEFAULT_BROWSER_MAKE_DEFAULT" desc="Default browser checkbox label">
Make Google Chrome the default browser Make Google Chrome the default browser
</message> </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. Google Chrome cannot determine or set the default browser.
</message> </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."> <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. This is a secondary installation of Google Chrome, and cannot be made your default browser.
</message> </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> </if>
<!-- Privacy Page --> <!-- Privacy Page -->
......
...@@ -3,11 +3,19 @@ ...@@ -3,11 +3,19 @@
# found in the LICENSE file. # found in the LICENSE file.
{ {
'targets': [ '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', 'target_name': 'default_browser_page',
'dependencies': [ 'dependencies': [
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:cr', '<(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'], '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/html/polymer.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html"> <link rel="import" href="chrome://resources/html/web_ui_listener_behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html"> <link rel="import" href="/default_browser_page/default_browser_browser_proxy.html">
<link rel="import" href="/icons.html"> <link rel="import" href="/icons.html">
<link rel="import" href="/settings_shared_css.html"> <link rel="import" href="/settings_shared_css.html">
<dom-module id="settings-default-browser-page"> <dom-module id="settings-default-browser-page">
<template> <template>
<style include="settings-shared"> <style include="settings-shared">
.error-icon { .solo-secondary {
color: var(--settings-error-color); @apply(--settings-secondary);
margin: 0;
} }
</style> </style>
<div class="settings-box first two-line"> <template is="dom-if" if="[[maySetDefaultBrowser_]]">
<template is="dom-if" if="[[showButton_]]"> <div class="settings-box first two-line" on-tap="onSetDefaultBrowserTap_"
<div class="start" on-tap="onSetDefaultBrowserTap_" actionable> actionable>
<div>$i18n{defaultBrowser}</div> <div>
<div id="canBeDefaultBrowser">$i18n{defaultBrowser}</div>
<div class="secondary">$i18n{defaultBrowserMakeDefault}</div> <div class="secondary">$i18n{defaultBrowserMakeDefault}</div>
</div> </div>
<template is="dom-if" if="[[showError_]]"> </div>
<iron-icon icon="settings:error" class="error-icon" </template>
title="$i18n{unableToSetDefaultBrowser}"></iron-icon> <template is="dom-if" if="[[!maySetDefaultBrowser_]]">
</template> <div class="settings-box first">
</template> <div class="solo-secondary" hidden$="[[!isDefault_]]" id="isDefault">
<template is="dom-if" if="[[!showButton_]]"> $i18n{defaultBrowserDefault}
<div class="secondary">[[message_]]</div> </div>
</template> <div class="solo-secondary" hidden$="[[!isSecondaryInstall_]]"
</div> id="isSecondaryInstall">
$i18n{defaultBrowserSecondary}
</div>
<div class="solo-secondary" hidden$="[[!isUnknownError_]]"
id="isUnknownError">
$i18n{defaultBrowserError}
</div>
</div>
</template>
</template> </template>
<script src="default_browser_page.js"></script> <script src="default_browser_page.js"></script>
</dom-module> </dom-module>
...@@ -10,76 +10,61 @@ ...@@ -10,76 +10,61 @@
Polymer({ Polymer({
is: 'settings-default-browser-page', is: 'settings-default-browser-page',
behaviors: [WebUIListenerBehavior],
properties: { properties: {
/** /** @private */
* A message about whether Chrome is the default browser. isDefault_: Boolean,
*/
message_: {
type: String,
},
/** /** @private */
* Indicates if the next updateDefaultBrowserState_ invocation is following isSecondaryInstall_: Boolean,
* a call to SettingsDefaultBrowser.setAsDefaultBrowser().
*/
startedSetAsDefault_: {
type: Boolean,
value: false,
},
/** /** @private */
* Show or hide an error indicator showing whether SetAsDefault succeeded. isUnknownError_: Boolean,
*/
showError_: {
type: Boolean,
value: false,
},
/** /** @private */
* Only show the SetAsDefault button if we have permission to set it. maySetDefaultBrowser_: Boolean,
*/ },
showButton_: {
type: Boolean, /** @private {settings.DefaultBrowserBrowserProxy} */
}, browserProxy_: null,
/** @override */
created: function() {
this.browserProxy_ = settings.DefaultBrowserBrowserProxyImpl.getInstance();
}, },
ready: function() { ready: function() {
var self = this; this.addWebUIListener('settings.updateDefaultBrowserState',
cr.define('Settings', function() { this.updateDefaultBrowserState_.bind(this));
return {
updateDefaultBrowserState: function() { this.browserProxy_.requestDefaultBrowserState().then(
return self.updateDefaultBrowserState_.apply(self, arguments); this.updateDefaultBrowserState_.bind(this));
},
};
});
chrome.send('SettingsDefaultBrowser.requestDefaultBrowserState');
}, },
/** /**
* @param {boolean} isDefault Whether Chrome is currently the user's default * @param {!DefaultBrowserInfo} defaultBrowserState
* browser.
* @param {boolean} canBeDefault Whether Chrome can be the default browser on
* this system.
* @private * @private
*/ */
updateDefaultBrowserState_: function(isDefault, canBeDefault) { updateDefaultBrowserState_: function(defaultBrowserState) {
if (this.startedSetAsDefault_ && !isDefault) { this.isDefault_ = false;
this.startedSetAsDefault_ = false; this.isSecondaryInstall_ = false;
this.showError_ = true; this.isUnknownError_ = false;
} else { this.maySetDefaultBrowser_ = false;
this.showError_ = false;
}
this.showButton_ = !isDefault && canBeDefault; if (defaultBrowserState.isDefault)
if (!this.showButton_) { this.isDefault_ = true;
this.message_ = loadTimeData.getString( else if (!defaultBrowserState.canBeDefault)
canBeDefault ? 'defaultBrowserDefault' : 'defaultBrowserUnknown'); this.isSecondaryInstall_ = true;
} else if (!defaultBrowserState.isDisabledByPolicy &&
!defaultBrowserState.isUnknownError)
this.maySetDefaultBrowser_ = true;
else
this.isUnknownError_ = true;
}, },
/** @private */ /** @private */
onSetDefaultBrowserTap_: function() { onSetDefaultBrowserTap_: function() {
this.startedSetAsDefault_ = true; this.browserProxy_.setAsDefaultBrowser();
chrome.send('SettingsDefaultBrowser.setAsDefaultBrowser');
}, },
}); });
...@@ -374,6 +374,12 @@ ...@@ -374,6 +374,12 @@
file="site_settings/cookie_tree_node.js" file="site_settings/cookie_tree_node.js"
type="chrome_html" /> type="chrome_html" />
<if expr="not chromeos"> <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" <structure name="IDR_SETTINGS_DEFAULT_BROWSER_PAGE_HTML"
file="default_browser_page/default_browser_page.html" file="default_browser_page/default_browser_page.html"
type="chrome_html" type="chrome_html"
......
...@@ -464,9 +464,8 @@ void AddDefaultBrowserStrings(content::WebUIDataSource* html_source) { ...@@ -464,9 +464,8 @@ void AddDefaultBrowserStrings(content::WebUIDataSource* html_source) {
{"defaultBrowser", IDS_SETTINGS_DEFAULT_BROWSER}, {"defaultBrowser", IDS_SETTINGS_DEFAULT_BROWSER},
{"defaultBrowserDefault", IDS_SETTINGS_DEFAULT_BROWSER_DEFAULT}, {"defaultBrowserDefault", IDS_SETTINGS_DEFAULT_BROWSER_DEFAULT},
{"defaultBrowserMakeDefault", IDS_SETTINGS_DEFAULT_BROWSER_MAKE_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}, {"defaultBrowserSecondary", IDS_SETTINGS_DEFAULT_BROWSER_SECONDARY},
{"unableToSetDefaultBrowser", IDS_SETTINGS_DEFAULT_BROWSER_ERROR},
}; };
AddLocalizedStringsBulk(html_source, localized_strings, AddLocalizedStringsBulk(html_source, localized_strings,
arraysize(localized_strings)); arraysize(localized_strings));
...@@ -1151,7 +1150,7 @@ void AddSearchInSettingsStrings(content::WebUIDataSource* html_source) { ...@@ -1151,7 +1150,7 @@ void AddSearchInSettingsStrings(content::WebUIDataSource* html_source) {
LocalizedString localized_strings[] = { LocalizedString localized_strings[] = {
{"searchPrompt", IDS_SETTINGS_SEARCH_PROMPT}, {"searchPrompt", IDS_SETTINGS_SEARCH_PROMPT},
{"searchNoResults", IDS_SETTINGS_SEARCH_NO_RESULTS}, {"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. // are identical, merge them to one and re-use here.
{"clearSearch", IDS_DOWNLOAD_CLEAR_SEARCH}, {"clearSearch", IDS_DOWNLOAD_CLEAR_SEARCH},
}; };
......
...@@ -88,14 +88,16 @@ void DefaultBrowserHandler::OnDefaultBrowserWorkerFinished( ...@@ -88,14 +88,16 @@ void DefaultBrowserHandler::OnDefaultBrowserWorkerFinished(
chrome::ResetDefaultBrowserPrompt(Profile::FromWebUI(web_ui())); chrome::ResetDefaultBrowserPrompt(Profile::FromWebUI(web_ui()));
} }
base::FundamentalValue is_default(state == shell_integration::IS_DEFAULT); base::DictionaryValue dict;
base::FundamentalValue can_be_default( dict.SetBoolean("isDefault", state == shell_integration::IS_DEFAULT);
state != shell_integration::UNKNOWN_DEFAULT && dict.SetBoolean("canBeDefault",
!DefaultBrowserIsDisabledByPolicy() &&
shell_integration::CanSetAsDefaultBrowser()); shell_integration::CanSetAsDefaultBrowser());
dict.SetBoolean("isUnknownError",
state == shell_integration::UNKNOWN_DEFAULT);
dict.SetBoolean("isDisabledByPolicy", DefaultBrowserIsDisabledByPolicy());
CallJavascriptFunction("Settings.updateDefaultBrowserState", is_default, CallJavascriptFunction("cr.webUIListenerCallback",
can_be_default); base::StringValue("settings.updateDefaultBrowserState"), dict);
} }
} // namespace settings } // namespace settings
...@@ -340,6 +340,34 @@ TEST_F('CrSettingsAppearancePageTest', 'AppearancePage', function() { ...@@ -340,6 +340,34 @@ TEST_F('CrSettingsAppearancePageTest', 'AppearancePage', function() {
mocha.run(); 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/. * Test fixture for chrome/browser/resources/settings/search_page/.
* @constructor * @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