Commit 4ca4e8e4 authored by Nicolas Ouellet-payeur's avatar Nicolas Ouellet-payeur Committed by Commit Bot

chrome://browser-switch: show error messages

Bug: 887005
Change-Id: Ic5940c15a652c0fceea34f8a1ca493b7707d9236
Reviewed-on: https://chromium-review.googlesource.com/c/1467022
Commit-Queue: Nicolas Ouellet-Payeur <nicolaso@chromium.org>
Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#632013}
parent 3032d1ac
...@@ -4716,13 +4716,22 @@ Keep your key file in a safe place. You will need it to create new versions of y ...@@ -4716,13 +4716,22 @@ Keep your key file in a safe place. You will need it to create new versions of y
</message> </message>
</if> </if>
<!-- about:browser-switch strings --> <!-- chrome://browser-switch strings -->
<if expr="is_win or is_macosx or (is_linux and not is_chromeos)"> <if expr="is_win or is_macosx or (is_linux and not is_chromeos)">
<message name="IDS_ABOUT_BROWSER_SWITCH_TITLE" desc="about:browser-switch page title"> <message name="IDS_ABOUT_BROWSER_SWITCH_TITLE" desc="about:browser-switch page title">
Legacy Browser Support Legacy Browser Support
</message> </message>
<message name="IDS_ABOUT_BROWSER_SWITCH_OPENING" desc="Shown while waiting for an alternative browser to open"> <message name="IDS_ABOUT_BROWSER_SWITCH_OPENING_TITLE" desc="Shown while waiting for an alternative browser to open">
Opening in alternate browser now. Opening in alternative browser now
</message>
<message name="IDS_ABOUT_BROWSER_SWITCH_ERROR_TITLE" desc="Error message shown when we fail to open the alternative browser">
The alternative browser could not be opened
</message>
<message name="IDS_ABOUT_BROWSER_SWITCH_GENERIC_ERROR" desc="Generic error message when we don't know why we failed to open the alternative browser">
<ph name="URL">$1<ex>ftp://example.com/</ex></ph> could not be open in an alternative browser. Please contact your system administrator.
</message>
<message name="IDS_ABOUT_BROWSER_SWITCH_PROTOCOL_ERROR" desc="Specific error message when we failed to open the alternative browser, because the URL is not one of http://, https:// or file://">
Only http, https and file protocols are supported for browser redirects.
</message> </message>
</if> </if>
......
<link rel="import" href="chrome://resources/html/polymer.html"> <link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/html/cr.html"> <link rel="import" href="chrome://resources/html/cr.html">
<link rel="import" href="chrome://resources/html/i18n_behavior.html">
<link rel="import" href="chrome://resources/cr_elements/shared_vars_css.html"> <link rel="import" href="chrome://resources/cr_elements/shared_vars_css.html">
<link rel="import" href="browser_switcher_proxy.html"> <link rel="import" href="browser_switcher_proxy.html">
...@@ -35,8 +36,8 @@ ...@@ -35,8 +36,8 @@
} }
</style> </style>
<h1>$i18n{opening}</h1> <h1>[[computeTitle_(error_)]]</h1>
<p>$i18n{description}</p> <p inner-h-t-m-l="[[computeDescription_(url_, error_)]]"></p>
</template> </template>
<script src="app.js"></script> <script src="app.js"></script>
</dom-module> </dom-module>
...@@ -6,9 +6,17 @@ ...@@ -6,9 +6,17 @@
(function() { (function() {
/** @enum {string} */
const LaunchError = {
GENERIC_ERROR: 'genericError',
PROTOCOL_ERROR: 'protocolError',
};
Polymer({ Polymer({
is: 'browser-switcher-app', is: 'browser-switcher-app',
behaviors: [I18nBehavior],
properties: { properties: {
/** /**
* URL to launch in the alternative browser. * URL to launch in the alternative browser.
...@@ -20,6 +28,15 @@ Polymer({ ...@@ -20,6 +28,15 @@ Polymer({
return (new URLSearchParams(window.location.search)).get('url') || ''; return (new URLSearchParams(window.location.search)).get('url') || '';
}, },
}, },
/**
* Error message, or empty string if no error has occurred (yet).
* @private
*/
error_: {
type: String,
value: '',
},
}, },
/** @override */ /** @override */
...@@ -39,6 +56,7 @@ Polymer({ ...@@ -39,6 +56,7 @@ Polymer({
const anchor = document.createElement('a'); const anchor = document.createElement('a');
anchor.href = this.url_; anchor.href = this.url_;
if (!/^(file|http|https):$/.test(anchor.protocol)) { if (!/^(file|http|https):$/.test(anchor.protocol)) {
this.error_ = LaunchError.PROTOCOL_ERROR;
return; return;
} }
...@@ -46,7 +64,38 @@ Polymer({ ...@@ -46,7 +64,38 @@ Polymer({
// immediately re-trigger LBS. // immediately re-trigger LBS.
history.pushState({}, '', '/?done=true'); history.pushState({}, '', '/?done=true');
proxy.launchAlternativeBrowserAndCloseTab(this.url_); proxy.launchAlternativeBrowserAndCloseTab(this.url_).catch(() => {
this.error_ = LaunchError.GENERIC_ERROR;
});
},
/**
* @return {string}
* @private
*/
computeTitle_: function() {
if (this.error_) {
return this.i18n('errorTitle');
}
return this.i18n('openingTitle');
},
/**
* @return {string}
* @private
*/
computeDescription_: function() {
if (this.error_) {
return this.i18n(this.error_, getUrlHostname(this.url_));
}
return this.i18n('description');
}, },
}); });
function getUrlHostname(url) {
const anchor = document.createElement('a');
anchor.href = url;
// Return entire url if parsing failed (which means the URL is bogus).
return anchor.hostname || url;
}
})(); })();
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
<link rel="stylesheet" href="chrome://resources/css/md_colors.css"> <link rel="stylesheet" href="chrome://resources/css/md_colors.css">
<link rel="stylesheet" href="chrome://resources/css/text_defaults_md.css"> <link rel="stylesheet" href="chrome://resources/css/text_defaults_md.css">
<link rel="import" href="chrome://resources/html/load_time_data.html">
<script src="strings.js"></script>
<link rel="import" href="app.html"> <link rel="import" href="app.html">
</body> </body>
</html> </html>
...@@ -70,7 +70,14 @@ content::WebUIDataSource* CreateBrowserSwitchUIHTMLSource( ...@@ -70,7 +70,14 @@ content::WebUIDataSource* CreateBrowserSwitchUIHTMLSource(
source->AddLocalizedString("description", source->AddLocalizedString("description",
IDS_ABOUT_BROWSER_SWITCH_DESCRIPTION); IDS_ABOUT_BROWSER_SWITCH_DESCRIPTION);
source->AddLocalizedString("opening", IDS_ABOUT_BROWSER_SWITCH_OPENING); source->AddLocalizedString("errorTitle",
IDS_ABOUT_BROWSER_SWITCH_ERROR_TITLE);
source->AddLocalizedString("genericError",
IDS_ABOUT_BROWSER_SWITCH_GENERIC_ERROR);
source->AddLocalizedString("openingTitle",
IDS_ABOUT_BROWSER_SWITCH_OPENING_TITLE);
source->AddLocalizedString("protocolError",
IDS_ABOUT_BROWSER_SWITCH_PROTOCOL_ERROR);
source->AddLocalizedString("title", IDS_ABOUT_BROWSER_SWITCH_TITLE); source->AddLocalizedString("title", IDS_ABOUT_BROWSER_SWITCH_TITLE);
source->AddResourcePath("app.html", IDR_BROWSER_SWITCHER_APP_HTML); source->AddResourcePath("app.html", IDR_BROWSER_SWITCHER_APP_HTML);
...@@ -83,6 +90,7 @@ content::WebUIDataSource* CreateBrowserSwitchUIHTMLSource( ...@@ -83,6 +90,7 @@ content::WebUIDataSource* CreateBrowserSwitchUIHTMLSource(
IDR_BROWSER_SWITCHER_BROWSER_SWITCHER_PROXY_JS); IDR_BROWSER_SWITCHER_BROWSER_SWITCHER_PROXY_JS);
source->SetDefaultResource(IDR_BROWSER_SWITCHER_BROWSER_SWITCH_HTML); source->SetDefaultResource(IDR_BROWSER_SWITCHER_BROWSER_SWITCH_HTML);
source->SetJsonPath("strings.js");
source->UseGzip(); source->UseGzip();
return source; return source;
......
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