Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(647)

Side by Side Diff: chrome/browser/resources/options/reset_profile_settings_banner.js

Issue 151003004: Add an automatic settings reset banner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on top of transaction patch. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Note: the native-side handler for this is ResetProfileSettingsHandler. 5 // Note: the native-side handler for this is ResetProfileSettingsHandler.
6 6
7 cr.define('options', function() { 7 cr.define('options', function() {
8 /** @const */ var OptionsPage = options.OptionsPage; 8 /** @const */ var OptionsPage = options.OptionsPage;
9 /** @const */ var SettingsBannerBase = options.SettingsBannerBase;
9 10
10 /** 11 /**
11 * ResetProfileSettingsBanner class 12 * ResetProfileSettingsBanner class
12 * Provides encapsulated handling of the Reset Profile Settings banner. 13 * Provides encapsulated handling of the Reset Profile Settings banner.
13 * @constructor 14 * @constructor
14 */ 15 */
15 function ResetProfileSettingsBanner() {} 16 function ResetProfileSettingsBanner() {}
16 17
17 cr.addSingletonGetter(ResetProfileSettingsBanner); 18 cr.addSingletonGetter(ResetProfileSettingsBanner);
18 19
19 ResetProfileSettingsBanner.prototype = { 20 ResetProfileSettingsBanner.prototype = {
20 /** 21 __proto__: SettingsBannerBase.prototype,
21 * Whether or not the banner has already been dismissed.
22 *
23 * This is needed because of the surprising ordering of asynchronous
24 * JS<->native calls when the settings page is opened with specifying a
25 * given sub-page, e.g. chrome://settings/resetProfileSettings.
26 *
27 * In such a case, ResetProfileSettingsOverlay's didShowPage(), which calls
28 * our dismiss() method, would be called before the native Handlers'
29 * InitalizePage() methods have an effect in the JS, which includes calling
30 * our show() method. This would mean that the banner would be first
31 * dismissed, then shown. We want to prevent this.
32 *
33 * @type {boolean}
34 * @private
35 */
36 hadBeenDismissed_: false,
37 22
38 /** 23 /**
39 * Initializes the banner's event handlers. 24 * Initializes the banner's event handlers.
40 */ 25 */
41 initialize: function() { 26 initialize: function() {
27 this.showMetricName_ = 'AutomaticReset_WebUIBanner_BannerShown';
28
29 this.dismissNativeCallbackName_ =
30 'onDismissedResetProfileSettingsBanner';
31
32 this.setVisibilibyDomElement_ = $('reset-profile-settings-banner');
33
42 $('reset-profile-settings-banner-close').onclick = function(event) { 34 $('reset-profile-settings-banner-close').onclick = function(event) {
43 chrome.send('metricsHandler:recordAction', 35 chrome.send('metricsHandler:recordAction',
44 ['AutomaticReset_WebUIBanner_ManuallyClosed']); 36 ['AutomaticReset_WebUIBanner_ManuallyClosed']);
45 ResetProfileSettingsBanner.dismiss(); 37 ResetProfileSettingsBanner.dismiss();
46 }; 38 };
47 $('reset-profile-settings-banner-activate').onclick = function(event) { 39 $('reset-profile-settings-banner-activate').onclick = function(event) {
48 chrome.send('metricsHandler:recordAction', 40 chrome.send('metricsHandler:recordAction',
49 ['AutomaticReset_WebUIBanner_ResetClicked']); 41 ['AutomaticReset_WebUIBanner_ResetClicked']);
50 OptionsPage.navigateToPage('resetProfileSettings'); 42 OptionsPage.navigateToPage('resetProfileSettings');
51 }; 43 };
52 }, 44 },
53
54 /**
55 * Called by the native code to show the banner if needed.
56 * @private
57 */
58 show_: function() {
59 if (!this.hadBeenDismissed_) {
60 chrome.send('metricsHandler:recordAction',
61 ['AutomaticReset_WebUIBanner_BannerShown']);
62 this.setVisibility_(true);
63 }
64 },
65
66 /**
67 * Called when the banner should be closed as a result of something taking
68 * place on the WebUI page, i.e. when its close button is pressed, or when
69 * the confirmation dialog for the profile settings reset feature is opened.
70 * @private
71 */
72 dismiss_: function() {
73 chrome.send('onDismissedResetProfileSettingsBanner');
74 this.hadBeenDismissed_ = true;
75 this.setVisibility_(false);
76 },
77
78 /**
79 * Sets whether or not the reset profile settings banner shall be visible.
80 * @param {boolean} show Whether or not to show the banner.
81 * @private
82 */
83 setVisibility_: function(show) {
84 $('reset-profile-settings-banner').hidden = !show;
85 }
86 }; 45 };
87 46
88 // Forward public APIs to private implementations. 47 // Forward public APIs to private implementations.
89 [ 48 [
90 'show', 49 'show',
91 'dismiss', 50 'dismiss',
92 ].forEach(function(name) { 51 ].forEach(function(name) {
93 ResetProfileSettingsBanner[name] = function() { 52 ResetProfileSettingsBanner[name] = function() {
94 var instance = ResetProfileSettingsBanner.getInstance(); 53 var instance = ResetProfileSettingsBanner.getInstance();
95 return instance[name + '_'].apply(instance, arguments); 54 return instance[name + '_'].apply(instance, arguments);
96 }; 55 };
97 }); 56 });
98 57
99 // Export 58 // Export
100 return { 59 return {
101 ResetProfileSettingsBanner: ResetProfileSettingsBanner 60 ResetProfileSettingsBanner: ResetProfileSettingsBanner
102 }; 61 };
103 }); 62 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698