cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / browser / resources / options / alert_overlay.js
blob2206517d08003057a039a9f15fb00e092222e16a
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 cr.define('options', function() {
6 var Page = cr.ui.pageManager.Page;
7 var PageManager = cr.ui.pageManager.PageManager;
9 /**
10 * AlertOverlay class
11 * Encapsulated handling of a generic alert.
12 * @constructor
13 * @extends {cr.ui.pageManager.Page}
15 function AlertOverlay() {
16 Page.call(this, 'alertOverlay', '', 'alertOverlay');
19 cr.addSingletonGetter(AlertOverlay);
21 AlertOverlay.prototype = {
22 // Inherit AlertOverlay from Page.
23 __proto__: Page.prototype,
25 /**
26 * Whether the page can be shown. Used to make sure the page is only
27 * shown via AlertOverlay.Show(), and not via the address bar.
28 * @private
30 canShow_: false,
32 /** @override */
33 initializePage: function() {
34 Page.prototype.initializePage.call(this);
36 // AlertOverlay is special in that it is not tied to one page or overlay.
37 this.alwaysOnTop = true;
39 var self = this;
40 $('alertOverlayOk').onclick = function(event) {
41 self.handleOK_();
44 $('alertOverlayCancel').onclick = function(event) {
45 self.handleCancel_();
49 /**
50 * Handle the 'ok' button. Clear the overlay and call the ok callback if
51 * available.
52 * @private
54 handleOK_: function() {
55 PageManager.closeOverlay();
56 if (this.okCallback != undefined) {
57 this.okCallback.call();
61 /**
62 * Handle the 'cancel' button. Clear the overlay and call the cancel
63 * callback if available.
64 * @private
66 handleCancel_: function() {
67 PageManager.closeOverlay();
68 if (this.cancelCallback != undefined) {
69 this.cancelCallback.call();
73 /**
74 * The page is getting hidden. Don't let it be shown again.
75 * @override
77 willHidePage: function() {
78 this.canShow_ = false;
81 /** @override */
82 canShowPage: function() {
83 return this.canShow_;
87 /**
88 * Show an alert overlay with the given message, button titles, and
89 * callbacks.
90 * @param {string} title The alert title to display to the user.
91 * @param {string} message The alert message to display to the user.
92 * @param {string} okTitle The title of the OK button. If undefined or empty,
93 * no button is shown.
94 * @param {string} cancelTitle The title of the cancel button. If undefined or
95 * empty, no button is shown.
96 * @param {function()} okCallback A function to be called when the user
97 * presses the ok button. The alert window will be closed automatically.
98 * Can be undefined.
99 * @param {function()} cancelCallback A function to be called when the user
100 * presses the cancel button. The alert window will be closed
101 * automatically. Can be undefined.
103 AlertOverlay.show = function(
104 title, message, okTitle, cancelTitle, okCallback, cancelCallback) {
105 if (title != undefined) {
106 $('alertOverlayTitle').textContent = title;
107 $('alertOverlayTitle').style.display = 'block';
108 } else {
109 $('alertOverlayTitle').style.display = 'none';
112 if (message != undefined) {
113 $('alertOverlayMessage').textContent = message;
114 $('alertOverlayMessage').style.display = 'block';
115 } else {
116 $('alertOverlayMessage').style.display = 'none';
119 if (okTitle != undefined && okTitle != '') {
120 $('alertOverlayOk').textContent = okTitle;
121 $('alertOverlayOk').style.display = 'block';
122 } else {
123 $('alertOverlayOk').style.display = 'none';
126 if (cancelTitle != undefined && cancelTitle != '') {
127 $('alertOverlayCancel').textContent = cancelTitle;
128 $('alertOverlayCancel').style.display = 'inline';
129 } else {
130 $('alertOverlayCancel').style.display = 'none';
133 var alertOverlay = AlertOverlay.getInstance();
134 alertOverlay.okCallback = okCallback;
135 alertOverlay.cancelCallback = cancelCallback;
136 alertOverlay.canShow_ = true;
138 // Intentionally don't show the URL in the location bar as we don't want
139 // people trying to navigate here by hand.
140 PageManager.showPageByName('alertOverlay', false);
143 // Export
144 return {
145 AlertOverlay: AlertOverlay