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

Unified Diff: chrome/browser/resources/print_preview.js

Issue 6903083: PrintPreview:[MAC & WIN] Added code to show the native printer management dialog. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Addressed review comments. Created 9 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/print_preview.js
diff --git a/chrome/browser/resources/print_preview.js b/chrome/browser/resources/print_preview.js
index b281892b2c25406be57646c2d00fbda4fdba4bcc..6c517c9dbf1d0024e0ed4736340d9f31657f26fa 100644
--- a/chrome/browser/resources/print_preview.js
+++ b/chrome/browser/resources/print_preview.js
@@ -26,6 +26,9 @@ var previouslySelectedLayout = null;
// needed.
var timerId;
+// Store the last selected printer index.
+var lastSelectedPrinterIndex = 0;
+
/**
* Window onload handler, sets up the page and starts print preview by getting
* the printer list.
@@ -96,11 +99,17 @@ function updateControlsWithSelectedPrinterCapabilities() {
if (printerName == localStrings.getString('printToPDF')) {
updateWithPrinterCapabilities({'disableColorOption': true,
'setColorAsDefault': true});
+ } else if (printerName == localStrings.getString('managePrinters')) {
+ printerList.selectedIndex = lastSelectedPrinterIndex;
+ chrome.send('managePrinters');
+ return;
} else {
// This message will call back to 'updateWithPrinterCapabilities'
// function.
chrome.send('getPrinterCapabilities', [printerName]);
}
+
+ lastSelectedPrinterIndex = selectedPrinter;
}
/**
@@ -328,18 +337,15 @@ function requestPrintPreview() {
*/
function setPrinters(printers, defaultPrinterIndex) {
var printerList = $('printer-list');
- for (var i = 0; i < printers.length; ++i) {
- var option = document.createElement('option');
- option.textContent = printers[i];
- printerList.add(option);
- if (i == defaultPrinterIndex)
- option.selected = true;
- }
+ for (var i = 0; i < printers.length; ++i)
+ addDestinationListOption(printers[i], i == defaultPrinterIndex);
// Adding option for saving PDF to disk.
- var option = document.createElement('option');
- option.textContent = localStrings.getString('printToPDF');
- printerList.add(option);
+ addDestinationListOption(localStrings.getString('printToPDF'), false);
+
+ // Add an option to manage printers.
+ addDestinationListOption(localStrings.getString('managePrinters'), false);
+
printerList.disabled = false;
updateControlsWithSelectedPrinterCapabilities();
@@ -349,6 +355,19 @@ function setPrinters(printers, defaultPrinterIndex) {
}
/**
+ * Adds an option to the printer destination list.
+ * @param {String} optionText specifies the option text content.
+ * @param {boolean} is_default is true if the option needs to be selected.
+ */
+function addDestinationListOption(optionText, is_default) {
+ var option = document.createElement('option');
+ option.textContent = optionText;
+ $('printer-list').add(option);
+ if (is_default)
+ option.selected = true;
+}
+
+/**
* Sets the color mode for the PDF plugin.
* Called from PrintPreviewHandler::ProcessColorSetting().
* @param {boolean} color is true if the PDF plugin should display in color.

Powered by Google App Engine
This is Rietveld 408576698