summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/resources/extensions/extensions.css10
-rw-r--r--chrome/browser/resources/extensions/extensions.html2
-rw-r--r--chrome/browser/resources/extensions/extensions.js51
-rw-r--r--chrome/browser/resources/extensions/pack_extension_overlay.css4
-rw-r--r--chrome/browser/resources/extensions/pack_extension_overlay.js62
-rw-r--r--chrome/browser/resources/shared/html/alert_overlay.html12
-rw-r--r--chrome/browser/resources/shared/js/cr/ui/alert_overlay.js82
-rw-r--r--chrome/browser/resources/shared_resources.grd2
-rw-r--r--chrome/browser/ui/webui/options/pack_extension_handler.cc1
9 files changed, 196 insertions, 30 deletions
diff --git a/chrome/browser/resources/extensions/extensions.css b/chrome/browser/resources/extensions/extensions.css
index c0064ab..d4ad5a1 100644
--- a/chrome/browser/resources/extensions/extensions.css
+++ b/chrome/browser/resources/extensions/extensions.css
@@ -134,6 +134,16 @@ html[dir="rtl"] .extension-list-item {
display: inline-block;
}
+/* Overlays */
+
+#overlay {
+ z-index: 5;
+}
+
+#overlay .page:not(.showing) {
+ display: none;
+}
+
/* Trash */
.trash {
diff --git a/chrome/browser/resources/extensions/extensions.html b/chrome/browser/resources/extensions/extensions.html
index b7dc705..4d2a397 100644
--- a/chrome/browser/resources/extensions/extensions.html
+++ b/chrome/browser/resources/extensions/extensions.html
@@ -15,6 +15,7 @@
<script src="chrome://resources/js/local_strings.js"></script>
<script src="chrome://resources/js/util.js"></script>
<script src="chrome://resources/js/cr/ui.js"></script>
+<script src="chrome://resources/js/cr/ui/alert_overlay.js"></script>
<script src="chrome://extensions-frame/extensions.js"></script>
</head>
@@ -23,6 +24,7 @@
<div id="overlay" class="overlay" hidden>
<include src="pack_extension_overlay.html">
+ <include src="../shared/html/alert_overlay.html">
</div>
<div id="extension-settings">
diff --git a/chrome/browser/resources/extensions/extensions.js b/chrome/browser/resources/extensions/extensions.js
index 22ffaf2..78189fc 100644
--- a/chrome/browser/resources/extensions/extensions.js
+++ b/chrome/browser/resources/extensions/extensions.js
@@ -100,8 +100,7 @@ cr.define('extensions', function() {
* @private
*/
handlePackExtension_: function(e) {
- $('overlay').hidden = false;
-
+ ExtensionSettings.showOverlay($('packExtensionOverlay'));
chrome.send('coreOptionsUserMetricsAction', ['Options_PackExtension']);
},
@@ -188,20 +187,40 @@ cr.define('extensions', function() {
// Indicate that warning |message| has occured for pack of |crx_path| and
// |pem_path| files. Ask if user wants override the warning. Send
// |overrideFlags| to repeated 'pack' call to accomplish the override.
- ExtensionSettings.askToOverrideWarning
- = function(message, crx_path, pem_path, overrideFlags) {
- OptionsPage.closeOverlay();
- AlertOverlay.show(
- localStrings.getString('packExtensionWarningTitle'),
- message,
- localStrings.getString('packExtensionProceedAnyway'),
- localStrings.getString('cancel'),
- function() {
- chrome.send('pack', [crx_path, pem_path, overrideFlags]);
- },
- function() {
- OptionsPage.closeOverlay();
- });
+ ExtensionSettings.askToOverrideWarning =
+ function(message, crx_path, pem_path, overrideFlags) {
+ var closeAlert = function() {
+ ExtensionSettings.showOverlay(null);
+ };
+
+ alertOverlay.setValues(
+ localStrings.getString('packExtensionWarningTitle'),
+ message,
+ localStrings.getString('packExtensionProceedAnyway'),
+ localStrings.getString('cancel'),
+ function() {
+ chrome.send('pack', [crx_path, pem_path, overrideFlags]);
+ closeAlert();
+ },
+ closeAlert);
+ ExtensionSettings.showOverlay($('alertOverlay'));
+ }
+
+ /**
+ * Sets the given overlay to show. This hides whatever overlay is currently
+ * showing, if any.
+ * @param {HTMLElement} node The overlay page to show. If falsey, all overlays
+ * are hidden.
+ */
+ ExtensionSettings.showOverlay = function(node) {
+ var currentlyShowingOverlay =
+ document.querySelector('#overlay .page.showing');
+ if (currentlyShowingOverlay)
+ currentlyShowingOverlay.classList.remove('showing');
+
+ if (node)
+ node.classList.add('showing');
+ overlay.hidden = !node;
}
// Export
diff --git a/chrome/browser/resources/extensions/pack_extension_overlay.css b/chrome/browser/resources/extensions/pack_extension_overlay.css
index a9269e1..e19423b 100644
--- a/chrome/browser/resources/extensions/pack_extension_overlay.css
+++ b/chrome/browser/resources/extensions/pack_extension_overlay.css
@@ -2,10 +2,6 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. */
-.overlay {
- z-index: 5;
-}
-
.packExtensionHeading {
width: 520px;
padding-bottom: 5px;
diff --git a/chrome/browser/resources/extensions/pack_extension_overlay.js b/chrome/browser/resources/extensions/pack_extension_overlay.js
index f36383c..18813f6 100644
--- a/chrome/browser/resources/extensions/pack_extension_overlay.js
+++ b/chrome/browser/resources/extensions/pack_extension_overlay.js
@@ -18,14 +18,10 @@ cr.define('extensions', function() {
* Initialize the page.
*/
initializePage: function() {
- $('packExtensionDismiss').onclick = function(event) {
- $('overlay').hidden = true;
- };
- $('packExtensionCommit').onclick = function(event) {
- var extensionPath = $('extensionRootDir').value;
- var privateKeyPath = $('extensionPrivateKey').value;
- chrome.send('pack', [extensionPath, privateKeyPath, 0]);
- };
+ $('packExtensionDismiss').addEventListener('click',
+ this.handleDismiss_.bind(this));
+ $('packExtensionCommit').addEventListener('click',
+ this.handleCommit_.bind(this));
$('browseExtensionDir').addEventListener('click',
this.handleBrowseExtensionDir_.bind(this));
$('browsePrivateKey').addEventListener('click',
@@ -33,6 +29,24 @@ cr.define('extensions', function() {
},
/**
+ * Handles a click on the dismiss button.
+ * @param {Event} e
+ */
+ handleDismiss_: function(e) {
+ ExtensionSettings.showOverlay(null);
+ },
+
+ /**
+ * Handles a click on the pack button.
+ * @param {Event} e
+ */
+ handleCommit_: function(e) {
+ var extensionPath = $('extensionRootDir').value;
+ var privateKeyPath = $('extensionPrivateKey').value;
+ chrome.send('pack', [extensionPath, privateKeyPath, 0]);
+ },
+
+ /**
* Utility function which asks the C++ to show a platform-specific file
* select dialog, and fire |callback| with the |filePath| that resulted.
* |selectType| can be either 'file' or 'folder'. |operation| can be 'load',
@@ -78,8 +92,33 @@ cr.define('extensions', function() {
* @param {String} message The message to show to the user.
*/
PackExtensionOverlay.showSuccessMessage = function(message) {
- alert(message);
- $('overlay').hidden = true;
+ alertOverlay.setValues(
+ localStrings.getString('packExtensionOverlay'),
+ message,
+ localStrings.getString('ok'),
+ '',
+ function() {
+ ExtensionSettings.showOverlay($('packExtensionOverlay'));
+ },
+ null);
+ ExtensionSettings.showOverlay($('alertOverlay'));
+ };
+
+ /**
+ * Post an alert overlay showing |message|, and upon acknowledgement, close
+ * the alert overlay and return to showing the PackExtensionOverlay.
+ */
+ PackExtensionOverlay.showError = function(message) {
+ alertOverlay.setValues(
+ localStrings.getString('packExtensionErrorTitle'),
+ message,
+ localStrings.getString('ok'),
+ '',
+ function() {
+ ExtensionSettings.showOverlay($('packExtensionOverlay'));
+ },
+ null);
+ ExtensionSettings.showOverlay($('alertOverlay'));
};
// Export
@@ -87,3 +126,6 @@ cr.define('extensions', function() {
PackExtensionOverlay: PackExtensionOverlay
};
});
+
+// Update the C++ call so this isn't necessary.
+var PackExtensionOverlay = extensions.PackExtensionOverlay;
diff --git a/chrome/browser/resources/shared/html/alert_overlay.html b/chrome/browser/resources/shared/html/alert_overlay.html
new file mode 100644
index 0000000..df263ea
--- /dev/null
+++ b/chrome/browser/resources/shared/html/alert_overlay.html
@@ -0,0 +1,12 @@
+<div id="alertOverlay" class="page">
+ <h1 id="alertOverlayTitle"></h1>
+ <div class="content-area">
+ <div id="alertOverlayMessage"></div>
+ </div>
+ <div class="action-area">
+ <div class="button-strip">
+ <button id="alertOverlayOk" type="submit"></button>
+ <button id="alertOverlayCancel" type="reset"></button>
+ </div>
+ </div>
+</div>
diff --git a/chrome/browser/resources/shared/js/cr/ui/alert_overlay.js b/chrome/browser/resources/shared/js/cr/ui/alert_overlay.js
new file mode 100644
index 0000000..76ec501
--- /dev/null
+++ b/chrome/browser/resources/shared/js/cr/ui/alert_overlay.js
@@ -0,0 +1,82 @@
+// Copyright (c) 2012 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('alertOverlay', function() {
+ /**
+ * The confirm <button>.
+ * @type {HTMLButtonElement}
+ */
+ var okButton;
+
+ /**
+ * The cancel <button>.
+ * @type {HTMLButtonElement}
+ */
+ var cancelButton;
+
+ function initialize(e) {
+ okButton = $('alertOverlayOk');
+ cancelButton = $('alertOverlayCancel');
+
+ // The callbacks are set to the callbacks provided in show(). Clear them
+ // out when either is clicked.
+ okButton.addEventListener('click', function(e) {
+ assert(okButton.clickCallback);
+
+ okButton.clickCallback(e);
+ okButton.clickCallback = null;
+ cancelButton.clickCallback = null;
+ });
+ cancelButton.addEventListener('click', function(e) {
+ assert(cancelButton.clickCallback);
+
+ cancelButton.clickCallback(e);
+ okButton.clickCallback = null;
+ cancelButton.clickCallback = null;
+ });
+ };
+
+ /**
+ * Updates the alert overlay with the given message, button titles, and
+ * callbacks.
+ * @param {string} title The alert title to display to the user.
+ * @param {string} message The alert message to display to the user.
+ * @param {string=} okTitle The title of the OK button. If undefined or empty,
+ * no button is shown.
+ * @param {string=} cancelTitle The title of the cancel button. If undefined
+ * or empty, no button is shown.
+ * @param {function=} okCallback A function to be called when the user presses
+ * the ok button. Can be undefined if |okTitle| is falsey.
+ * @param {function=} cancelCallback A function to be called when the user
+ * presses the cancel button. Can be undefined if |cancelTitle| is falsey.
+ */
+ function setValues(
+ title, message, okTitle, cancelTitle, okCallback, cancelCallback) {
+ if (typeof title != 'undefined')
+ $('alertOverlayTitle').textContent = title;
+ $('alertOverlayTitle').hidden = typeof title == 'undefined';
+
+ if (typeof message != 'undefined')
+ $('alertOverlayMessage').textContent = message;
+ $('alertOverlayMessage').hidden = typeof message == 'undefined';
+
+ if (okTitle)
+ okButton.textContent = okTitle;
+ okButton.hidden = !okTitle;
+ okButton.clickCallback = okCallback;
+
+ if (cancelTitle)
+ cancelButton.textContent = cancelTitle;
+ cancelButton.hidden = !cancelTitle;
+ cancelButton.clickCallback = cancelCallback;
+ };
+
+ // Export
+ return {
+ initialize: initialize,
+ setValues: setValues
+ };
+});
+
+document.addEventListener('DOMContentLoaded', alertOverlay.initialize);
diff --git a/chrome/browser/resources/shared_resources.grd b/chrome/browser/resources/shared_resources.grd
index 88f0f10..fe7fe6c 100644
--- a/chrome/browser/resources/shared_resources.grd
+++ b/chrome/browser/resources/shared_resources.grd
@@ -82,6 +82,8 @@ without changes to the corresponding grd file. -->
file="shared/js/cr/promise.js" type="BINDATA" />
<include name="IDR_SHARED_JS_CR_UI"
file="shared/js/cr/ui.js" type="BINDATA" />
+ <include name="IDR_SHARED_JS_CR_UI_ALERT_OVERLAY"
+ file="shared/js/cr/ui/alert_overlay.js" type="BINDATA" />
<include name="IDR_SHARED_JS_CR_UI_ARRAY_DATA_MODEL"
file="shared/js/cr/ui/array_data_model.js" type="BINDATA" />
<include name="IDR_SHARED_JS_CR_UI_AUTOCOMPLETE_LIST"
diff --git a/chrome/browser/ui/webui/options/pack_extension_handler.cc b/chrome/browser/ui/webui/options/pack_extension_handler.cc
index 7b39144..3ef768c 100644
--- a/chrome/browser/ui/webui/options/pack_extension_handler.cc
+++ b/chrome/browser/ui/webui/options/pack_extension_handler.cc
@@ -34,6 +34,7 @@ void PackExtensionHandler::GetLocalizedValues(
l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_HEADING));
localized_strings->SetString("packExtensionCommit",
l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_BUTTON));
+ localized_strings->SetString("ok", l10n_util::GetStringUTF16(IDS_OK));
localized_strings->SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL));
localized_strings->SetString("packExtensionRootDir",
l10n_util::GetStringUTF16(