Commit 1afc8122 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Cleanup chrome.send in print preview

Move all chrome.send calls to the native layer
Rename native layer functions to match names of messages being sent.

Bug: 717296
Change-Id: Ie69391d107183c4fd0e97339d4014ea89f1181e3
Reviewed-on: https://chromium-review.googlesource.com/575374Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487979}
parent ff8f4d20
......@@ -86,8 +86,7 @@ cr.define('print_preview', function() {
function AppState() {
/**
* Internal representation of application state.
* @type {Object}
* @private
* @private {Object}
*/
this.state_ = {};
this.state_[print_preview.AppStateField.VERSION] = AppState.VERSION_;
......@@ -97,10 +96,15 @@ cr.define('print_preview', function() {
/**
* Whether the app state has been initialized. The app state will ignore all
* writes until it has been initialized.
* @type {boolean}
* @private
* @private {boolean}
*/
this.isInitialized_ = false;
/**
* Native Layer object to use for sending app state to C++ handler.
* @private {!print_preview.NativeLayer}
*/
this.nativeLayer_ = print_preview.NativeLayer.getInstance();
}
/**
......@@ -118,14 +122,6 @@ cr.define('print_preview', function() {
*/
AppState.VERSION_ = 2;
/**
* Name of C++ layer function to persist app state.
* @type {string}
* @const
* @private
*/
AppState.NATIVE_FUNCTION_NAME_ = 'saveAppState';
AppState.prototype = {
/**
* @return {?RecentDestination} The most recent destination,
......@@ -307,8 +303,7 @@ cr.define('print_preview', function() {
* @private
*/
persist_: function() {
chrome.send(
AppState.NATIVE_FUNCTION_NAME_, [JSON.stringify(this.state_)]);
this.nativeLayer_.saveAppState(JSON.stringify(this.state_));
}
};
......
......@@ -8,8 +8,6 @@ cr.define('print_preview', function() {
/**
* A data store that stores destinations and dispatches events when the data
* store changes.
* @param {!print_preview.NativeLayer} nativeLayer Used to fetch local print
* destinations.
* @param {!print_preview.UserInfo} userInfo User information repository.
* @param {!print_preview.AppState} appState Application state.
* @param {!WebUIListenerTracker} listenerTracker Tracker for WebUI listeners
......@@ -17,14 +15,14 @@ cr.define('print_preview', function() {
* @constructor
* @extends {cr.EventTarget}
*/
function DestinationStore(nativeLayer, userInfo, appState, listenerTracker) {
function DestinationStore(userInfo, appState, listenerTracker) {
cr.EventTarget.call(this);
/**
* Used to fetch local print destinations.
* @private {!print_preview.NativeLayer}
*/
this.nativeLayer_ = nativeLayer;
this.nativeLayer_ = print_preview.NativeLayer.getInstance();
/**
* User information repository.
......
......@@ -105,6 +105,9 @@ cr.define('print_preview', function() {
/** @private {number} */
this.maxBucket_ = maxBucket;
/** @private {!print_preview.NativeLayer} */
this.nativeLayer_ = print_preview.NativeLayer.getInstance();
}
MetricsContext.prototype = {
......@@ -114,10 +117,10 @@ cr.define('print_preview', function() {
* @param {number} bucket Value to record.
*/
record: function(bucket) {
chrome.send('metricsHandler:recordInHistogram', [
this.histogram_,
((bucket > this.maxBucket_) ? this.maxBucket_ : bucket), this.maxBucket_
]);
this.nativeLayer_.recordInHistogram(
this.histogram_,
(bucket > this.maxBucket_) ? this.maxBucket_ : bucket,
this.maxBucket_);
}
};
......
......@@ -453,12 +453,20 @@ cr.define('print_preview', function() {
},
/** Requests that the current pending print request be cancelled. */
startCancelPendingPrint: function() {
cancelPendingPrintRequest: function() {
chrome.send('cancelPendingPrintRequest');
},
/**
* Sends the app state to be saved in the sticky settings.
* @param {string} appStateStr JSON string of the app state to persist
*/
saveAppState: function(appStateStr) {
chrome.send('saveAppState', [appStateStr]);
},
/** Shows the system's native printing dialog. */
startShowSystemDialog: function() {
showSystemDialog: function() {
assert(!cr.isWindows);
chrome.send('showSystemDialog');
},
......@@ -470,14 +478,14 @@ cr.define('print_preview', function() {
* @param {boolean} isCancel whether this was called due to the user
* closing the dialog without printing.
*/
startCloseDialog: function(isCancel) {
dialogClose: function(isCancel) {
if (isCancel)
chrome.send('closePrintPreviewDialog');
chrome.send('dialogClose');
},
/** Hide the print preview dialog and allow the native layer to close it. */
startHideDialog: function() {
hidePreview: function() {
chrome.send('hidePreview');
},
......@@ -494,7 +502,7 @@ cr.define('print_preview', function() {
},
/** Navigates the user to the system printer settings interface. */
startManageLocalDestinations: function() {
manageLocalPrinters: function() {
chrome.send('manageLocalPrinters');
},
......@@ -504,12 +512,12 @@ cr.define('print_preview', function() {
* page for (user must be currently logged in, indeed) or {@code null}
* to open this page for the primary user.
*/
startManageCloudDestinations: function(user) {
manageCloudPrinters: function(user) {
chrome.send('manageCloudPrinters', [user || '']);
},
/** Forces browser to open a new tab with the given URL address. */
startForceOpenNewTab: function(url) {
forceOpenNewTab: function(url) {
chrome.send('forceOpenNewTab', [url]);
},
......@@ -518,7 +526,7 @@ cr.define('print_preview', function() {
* option has been set to a particular value and that the change has
* finished modifying the preview area.
*/
previewReadyForTest: function() {
uiLoadedForTest: function() {
chrome.send('UILoadedForTest');
},
......@@ -526,9 +534,28 @@ cr.define('print_preview', function() {
* Notifies the test that the option it tried to change
* had not been changed successfully.
*/
previewFailedForTest: function() {
uiFailedLoadingForTest: function() {
chrome.send('UIFailedLoadingForTest');
}
},
/**
* Notifies the metrics handler to record an action.
* @param {string} action The action to record.
*/
recordAction: function(action) {
chrome.send('metricsHandler:recordAction', [action]);
},
/**
* Notifies the metrics handler to record a histogram value.
* @param {string} histogram The name of the histogram to record
* @param {number} bucket The bucket to record
* @param {number} maxBucket The maximum bucket value in the histogram.
*/
recordInHistogram: function(histogram, bucket, maxBucket) {
chrome.send(
'metricsHandler:recordInHistogram', [histogram, bucket, maxBucket]);
},
};
/**
......
......@@ -56,14 +56,11 @@ cr.define('print_preview', function() {
* currently selected destination.
* @param {!print_preview.PrintTicketStore} printTicketStore Used to get
* information about how the preview should be displayed.
* @param {!print_preview.NativeLayer} nativeLayer Needed to communicate with
* Chromium's preview generation system.
* @param {!print_preview.DocumentInfo} documentInfo Document data model.
* @constructor
* @extends {print_preview.Component}
*/
function PreviewArea(
destinationStore, printTicketStore, nativeLayer, documentInfo) {
function PreviewArea(destinationStore, printTicketStore, documentInfo) {
print_preview.Component.call(this);
// TODO(rltoscano): Understand the dependencies of printTicketStore needed
// here, and add only those here (not the entire print ticket store).
......@@ -87,7 +84,7 @@ cr.define('print_preview', function() {
* @type {!print_preview.NativeLayer}
* @private
*/
this.nativeLayer_ = nativeLayer;
this.nativeLayer_ = print_preview.NativeLayer.getInstance();
/**
* Document data model.
......
......@@ -84,8 +84,7 @@ cr.define('print_preview', function() {
* @private
*/
this.destinationStore_ = new print_preview.DestinationStore(
this.nativeLayer_, this.userInfo_, this.appState_,
this.listenerTracker);
this.userInfo_, this.appState_, this.listenerTracker);
/**
* Data store which holds printer sharing invitations.
......@@ -253,8 +252,7 @@ cr.define('print_preview', function() {
* @private
*/
this.previewArea_ = new print_preview.PreviewArea(
this.destinationStore_, this.printTicketStore_, this.nativeLayer_,
this.documentInfo_);
this.destinationStore_, this.printTicketStore_, this.documentInfo_);
this.addChild(this.previewArea_);
/**
......@@ -533,7 +531,7 @@ cr.define('print_preview', function() {
this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW) {
// Hide the dialog for now. The actual print command will be issued
// when the preview generation is done.
this.nativeLayer_.startHideDialog();
this.nativeLayer_.hidePreview();
}
}
},
......@@ -582,7 +580,7 @@ cr.define('print_preview', function() {
// Local printers resolve when print is ready to start. Hide the
// dialog. Mac "Open in Preview" is treated as a local printer.
var boundHideDialog = function() {
this.nativeLayer_.startHideDialog();
this.nativeLayer_.hidePreview();
}.bind(this);
whenPrintDone.then(boundHideDialog, boundHideDialog);
} else if (!destination.isLocal) {
......@@ -620,7 +618,7 @@ cr.define('print_preview', function() {
close_: function(isCancel) {
this.exitDocument();
this.uiState_ = PrintPreviewUiState_.CLOSING;
this.nativeLayer_.startCloseDialog(isCancel);
this.nativeLayer_.dialogClose(isCancel);
},
/**
......@@ -640,7 +638,7 @@ cr.define('print_preview', function() {
setIsVisible(getRequiredElement('system-dialog-throbber'), true);
this.setIsEnabled_(false);
this.uiState_ = PrintPreviewUiState_.OPENING_NATIVE_PRINT_DIALOG;
this.nativeLayer_.startShowSystemDialog();
this.nativeLayer_.showSystemDialog();
},
/**
......@@ -822,7 +820,7 @@ cr.define('print_preview', function() {
this.isPreviewGenerationInProgress_ = false;
this.printHeader_.isPrintButtonEnabled = true;
if (this.isListeningForManipulateSettings_)
this.nativeLayer_.previewReadyForTest();
this.nativeLayer_.uiLoadedForTest();
this.printIfReady_();
},
......@@ -834,7 +832,7 @@ cr.define('print_preview', function() {
this.isPreviewGenerationInProgress_ = false;
this.printHeader_.isPrintButtonEnabled = false;
if (this.uiState_ == PrintPreviewUiState_.PRINTING)
this.nativeLayer_.startCancelPendingPrint();
this.nativeLayer_.cancelPendingPrintRequest();
},
/**
......@@ -882,7 +880,7 @@ cr.define('print_preview', function() {
*/
onCloudPrintRegisterPromoClick_: function(e) {
var devicesUrl = 'chrome://devices/register?id=' + e.destination.id;
this.nativeLayer_.startForceOpenNewTab(devicesUrl);
this.nativeLayer_.forceOpenNewTab(devicesUrl);
this.destinationStore_.waitForRegister(e.destination.id);
},
......@@ -980,7 +978,7 @@ cr.define('print_preview', function() {
* @private
*/
onManageCloudDestinationsActivated_: function() {
this.nativeLayer_.startManageCloudDestinations(this.userInfo_.activeUser);
this.nativeLayer_.manageCloudPrinters(this.userInfo_.activeUser);
},
/**
......@@ -989,7 +987,7 @@ cr.define('print_preview', function() {
* @private
*/
onManageLocalDestinationsActivated_: function() {
this.nativeLayer_.startManageLocalDestinations();
this.nativeLayer_.manageLocalPrinters();
},
/**
......@@ -1099,7 +1097,7 @@ cr.define('print_preview', function() {
if (this.destinationStore_.selectedDestination &&
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ==
this.destinationStore_.selectedDestination.id) {
this.nativeLayer_.previewReadyForTest();
this.nativeLayer_.uiLoadedForTest();
return;
}
......@@ -1116,7 +1114,7 @@ cr.define('print_preview', function() {
if (pdfDestination)
this.destinationStore_.selectDestination(pdfDestination);
else
this.nativeLayer_.previewFailedForTest();
this.nativeLayer_.uiFailedLoadingForTest();
},
/**
......@@ -1129,7 +1127,7 @@ cr.define('print_preview', function() {
setLayoutSettingsForTest_: function(portrait) {
var combobox = document.querySelector('.layout-settings-select');
if (combobox.value == 'portrait') {
this.nativeLayer_.previewReadyForTest();
this.nativeLayer_.uiLoadedForTest();
} else {
combobox.value = 'landscape';
this.layoutSettings_.onSelectChange_();
......@@ -1146,7 +1144,7 @@ cr.define('print_preview', function() {
setPageRangeForTest_: function(pageRange) {
var textbox = document.querySelector('.page-settings-custom-input');
if (textbox.value == pageRange) {
this.nativeLayer_.previewReadyForTest();
this.nativeLayer_.uiLoadedForTest();
} else {
textbox.value = pageRange;
document.querySelector('.page-settings-custom-radio').click();
......@@ -1163,7 +1161,7 @@ cr.define('print_preview', function() {
setHeadersAndFootersForTest_: function(headersAndFooters) {
var checkbox = document.querySelector('.header-footer-checkbox');
if (headersAndFooters == checkbox.checked)
this.nativeLayer_.previewReadyForTest();
this.nativeLayer_.uiLoadedForTest();
else
checkbox.click();
},
......@@ -1178,7 +1176,7 @@ cr.define('print_preview', function() {
setBackgroundColorsAndImagesForTest_: function(backgroundColorsAndImages) {
var checkbox = document.querySelector('.css-background-checkbox');
if (backgroundColorsAndImages == checkbox.checked)
this.nativeLayer_.previewReadyForTest();
this.nativeLayer_.uiLoadedForTest();
else
checkbox.click();
},
......@@ -1193,12 +1191,12 @@ cr.define('print_preview', function() {
setMarginsForTest_: function(margins) {
var combobox = document.querySelector('.margin-settings-select');
if (margins == combobox.selectedIndex) {
this.nativeLayer_.previewReadyForTest();
this.nativeLayer_.uiLoadedForTest();
} else if (margins >= 0 && margins < combobox.length) {
combobox.selectedIndex = margins;
this.marginSettings_.onSelectChange_();
} else {
this.nativeLayer_.previewFailedForTest();
this.nativeLayer_.uiFailedLoadingForTest();
}
},
......
......@@ -24,44 +24,44 @@ cr.define('print_preview', function() {
/**
* Data store containing the destinations to search through.
* @type {!print_preview.DestinationStore}
* @private
* @private {!print_preview.DestinationStore}
*/
this.destinationStore_ = destinationStore;
/**
* Data store holding printer sharing invitations.
* @type {!print_preview.InvitationStore}
* @private
* @private {!print_preview.InvitationStore}
*/
this.invitationStore_ = invitationStore;
/**
* Event target that contains information about the logged in user.
* @type {!print_preview.UserInfo}
* @private
* @private {!print_preview.UserInfo}
*/
this.userInfo_ = userInfo;
/**
* Instance of native layer used to send metrics to C++ metrics handler.
* @private {!print_preview.NativeLayer}
*/
this.nativeLayer_ = print_preview.NativeLayer.getInstance();
/**
* Currently displayed printer sharing invitation.
* @type {print_preview.Invitation}
* @private
* @private {print_preview.Invitation}
*/
this.invitation_ = null;
/**
* Used to record usage statistics.
* @type {!print_preview.DestinationSearchMetricsContext}
* @private
* @private {!print_preview.DestinationSearchMetricsContext}
*/
this.metrics_ = new print_preview.DestinationSearchMetricsContext();
/**
* Whether or not a UMA histogram for the register promo being shown was
* already recorded.
* @type {boolean}
* @private
* @private {boolean}
*/
this.registerPromoShownMetricRecorded_ = false;
......@@ -81,8 +81,7 @@ cr.define('print_preview', function() {
/**
* Search box used to search through the destination lists.
* @type {!print_preview.SearchBox}
* @private
* @private {!print_preview.SearchBox}
*/
this.searchBox_ = new print_preview.SearchBox(
loadTimeData.getString('searchBoxPlaceholder'));
......@@ -90,16 +89,14 @@ cr.define('print_preview', function() {
/**
* Destination list containing recent destinations.
* @type {!print_preview.DestinationList}
* @private
* @private {!print_preview.DestinationList}
*/
this.recentList_ = new print_preview.RecentDestinationList(this);
this.addChild(this.recentList_);
/**
* Destination list containing local destinations.
* @type {!print_preview.DestinationList}
* @private
* @private {!print_preview.DestinationList}
*/
this.localList_ = new print_preview.DestinationList(
this, loadTimeData.getString('localDestinationsTitle'),
......@@ -110,8 +107,7 @@ cr.define('print_preview', function() {
/**
* Destination list containing cloud destinations.
* @type {!print_preview.DestinationList}
* @private
* @private {!print_preview.DestinationList}
*/
this.cloudList_ = new print_preview.CloudDestinationList(this);
this.addChild(this.cloudList_);
......@@ -155,9 +151,7 @@ cr.define('print_preview', function() {
if (getIsVisible(this.getChildElement('.cloudprint-promo'))) {
this.metrics_.record(
print_preview.Metrics.DestinationSearchBucket.SIGNIN_PROMPT);
chrome.send(
'metricsHandler:recordAction',
['Signin_Impression_FromCloudPrint']);
this.nativeLayer_.recordAction('Signin_Impression_FromCloudPrint');
}
if (this.userInfo_.initialized)
this.onUsersChanged_();
......@@ -189,9 +183,7 @@ cr.define('print_preview', function() {
if (this.getIsVisible()) {
this.metrics_.record(
print_preview.Metrics.DestinationSearchBucket.SIGNIN_PROMPT);
chrome.send(
'metricsHandler:recordAction',
['Signin_Impression_FromCloudPrint']);
this.nativeLayer_.recordAction('Signin_Impression_FromCloudPrint');
}
this.reflowLists_();
},
......
......@@ -10,16 +10,16 @@ cr.define('print_preview', function() {
*/
function NativeLayerStub() {
TestBrowserProxy.call(this, [
'getInitialSettings',
'getPrinters',
'getExtensionPrinters',
'getPreview',
'getPrivetPrinters',
'getPrinterCapabilities',
'print',
'setupPrinter',
'startHideDialog'
]);
'getInitialSettings',
'getPrinters',
'getExtensionPrinters',
'getPreview',
'getPrivetPrinters',
'getPrinterCapabilities',
'hidePreview',
'print',
'setupPrinter',
]);
/**
* @private {!print_preview.NativeInitialSettings} The initial settings
......@@ -153,10 +153,19 @@ cr.define('print_preview', function() {
},
/** @override */
startHideDialog: function () {
this.methodCalled('startHideDialog');
hidePreview: function() {
this.methodCalled('hidePreview');
},
/** @override */
recordAction: function() {},
/** @override */
recordInHistogram: function() {},
/** @override */
saveAppState: function() {},
/**
* @param {!print_preview.NativeInitialSettings} settings The settings
* to return as a response to |getInitialSettings|.
......
......@@ -125,10 +125,11 @@ TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() {
setup(function() {
nativeLayer_ = new print_preview.NativeLayerStub();
print_preview.NativeLayer.setInstance(nativeLayer_);
invitationStore_ = new print_preview.InvitationStore();
destinationStore_ = new print_preview.DestinationStore(
nativeLayer_, new print_preview.UserInfo(),
new print_preview.AppState(), new WebUIListenerTracker());
new print_preview.UserInfo(), new print_preview.AppState(),
new WebUIListenerTracker());
userInfo_ = new print_preview.UserInfo();
destinationSearch_ = new print_preview.DestinationSearch(
......
......@@ -1345,7 +1345,7 @@ cr.define('print_preview_test', function() {
expectEquals(
mediaDefault.height_microns,
printTicketStore.mediaSize.getValue().height_microns);
return nativeLayer.whenCalled('startHideDialog');
return nativeLayer.whenCalled('hidePreview');
});
});
......@@ -1447,7 +1447,7 @@ cr.define('print_preview_test', function() {
*/
function(args) {
expectTrue(args.openPdfInPreview);
return nativeLayer.whenCalled('startHideDialog');
return nativeLayer.whenCalled('hidePreview');
});
});
}
......@@ -1480,7 +1480,7 @@ cr.define('print_preview_test', function() {
*/
function(args) {
expectTrue(args.showSystemDialog);
return nativeLayer.whenCalled('startHideDialog');
return nativeLayer.whenCalled('hidePreview');
});
});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment