15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)cr.define('options', function() { 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /** 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Base class for banners that appear at the top of the settings page. 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */ 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) function SettingsBannerBase() {} 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cr.addSingletonGetter(SettingsBannerBase); 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SettingsBannerBase.prototype = { 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /** 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Whether or not the banner has already been dismissed. 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * This is needed because of the surprising ordering of asynchronous 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * JS<->native calls when the settings page is opened with specifying a 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * given sub-page, e.g. chrome://settings/AutomaticSettingsReset. 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * In such a case, AutomaticSettingsResetOverlay's didShowPage(), which 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * calls our dismiss() method, would be called before the native Handlers' 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * InitalizePage() methods have an effect in the JS, which includes calling 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * our show() method. This would mean that the banner would be first 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * dismissed, then shown. We want to prevent this. 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * @type {boolean} 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * @private 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */ 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) hadBeenDismissed_: false, 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /** 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Metric name to send when a show event occurs. 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */ 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) showMetricName_: '', 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /** 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Name of the native callback invoked when the banner is dismised. 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */ 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dismissNativeCallbackName_: '', 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /** 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * DOM element whose visibility is set when setVisibility_ is called. 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */ 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) setVisibilibyDomElement_: null, 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /** 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Called by the native code to show the banner if needed. 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * @private 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */ 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) show_: function() { 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!this.hadBeenDismissed_) { 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome.send('metricsHandler:recordAction', [this.showMetricName_]); 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) this.setVisibility_(true); 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }, 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /** 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Called when the banner should be closed as a result of something taking 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * place on the WebUI page, i.e. when its close button is pressed, or when 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * the confirmation dialog for the profile settings reset feature is opened. 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * @private 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */ 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dismiss_: function() { 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome.send(this.dismissNativeCallbackName_); 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) this.hadBeenDismissed_ = true; 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) this.setVisibility_(false); 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }, 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /** 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Sets whether or not the reset profile settings banner shall be visible. 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * @param {boolean} show Whether or not to show the banner. 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * @private 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */ 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) setVisibility_: function(show) { 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) this.setVisibilibyDomElement_.hidden = !show; 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }, 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Export 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return { 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SettingsBannerBase: SettingsBannerBase 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}); 87