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

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

Issue 8055036: Revert 103010 - Refactored code to move cloudprint specific code into print_preview_cloud.js. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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/print_preview_cloud.js
===================================================================
--- chrome/browser/resources/print_preview/print_preview_cloud.js (revision 103066)
+++ chrome/browser/resources/print_preview/print_preview_cloud.js (working copy)
@@ -119,11 +119,13 @@
var searchResult = JSON.parse(xhr.responseText);
if (searchResult['success']) {
var printerList = searchResult['printers'];
- addCloudPrinters(printerList, callback);
- return;
+ callback.call(this, printerList);
+ } else {
+ callback.call(this, null);
}
+ } else {
+ callback.call(this, null);
}
- addCloudPrinters(null, callback);
}
/**
@@ -304,8 +306,7 @@
cloud_print_data,
add_callback,
update_caps_callback) {
- var printer = addCloudPrinters([JSON.parse(cloud_print_data)],
- add_callback);
+ var printer = add_callback([JSON.parse(cloud_print_data)]);
if (printer)
update_caps_callback(printer);
}
@@ -349,87 +350,7 @@
printer.cloudPrintOptions.id = id;
}
- /**
- * Test if a particular cloud printer has already been added to the
- * printer dropdown.
- * @param {string} id A unique value to track this printer.
- * @return {boolean} True if |id| has previously been passed to
- * trackCloudPrinterAdded.
- */
- function cloudPrinterAlreadyAdded(id) {
- return addedCloudPrinters[id];
- }
-
- /**
- * Test if a particular printer has already been added to the printers
- * dropdown. Records it if not.
- * @param {string} id A unique value to track this printer.
- * @return {boolean} False if adding this printer would exceed
- * |maxCloudPrinters|.
- */
- function trackCloudPrinterAdded(id) {
- if (Object.keys(addedCloudPrinters).length < maxCloudPrinters) {
- addedCloudPrinters[id] = true;
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Add cloud printers to the list drop down.
- * Called from the cloudprint object on receipt of printer information from
- * the cloud print server.
- * @param {Array} printers Array of printer info objects.
- * @return {Object} The currently selected printer.
- */
- function addCloudPrinters(printers, addDestinationListOptionAtPosition) {
- var isFirstPass = false;
- var printerList = $('printer-list');
-
- if (firstCloudPrintOptionPos == lastCloudPrintOptionPos) {
- isFirstPass = true;
- // Remove empty entry added by setDefaultPrinter.
- if (printerList[0] && printerList[0].textContent == '')
- printerList.remove(0);
- }
- if (printers != null) {
- for (var i = 0; i < printers.length; i++) {
- if (!cloudPrinterAlreadyAdded(printers[i]['id'])) {
- if (!trackCloudPrinterAdded(printers[i]['id'])) {
- break;
- }
- var option = addDestinationListOptionAtPosition(
- lastCloudPrintOptionPos++,
- printers[i]['name'],
- printers[i]['id'],
- printers[i]['name'] == defaultOrLastUsedPrinterName,
- false,
- false);
- cloudprint.setCloudPrint(option,
- printers[i]['name'],
- printers[i]['id']);
- }
- }
- } else {
- if (!cloudPrinterAlreadyAdded(SIGN_IN)) {
- addDestinationListOptionAtPosition(lastCloudPrintOptionPos++,
- localStrings.getString('signIn'),
- SIGN_IN,
- false,
- false,
- false);
- trackCloudPrinterAdded(SIGN_IN);
- }
- }
- var selectedPrinter = printerList.selectedIndex;
- if (selectedPrinter < 0)
- return null;
- return printerList.options[selectedPrinter];
- }
-
return {
- addCloudPrinters: addCloudPrinters,
colorIsDefault: colorIsDefault,
fetchPrinters: fetchPrinters,
getBaseURL: getBaseURL,
« no previous file with comments | « chrome/browser/resources/print_preview/print_preview.js ('k') | chrome/browser/ui/webui/print_preview_data_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698