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('print_preview', function() {
9 * Repository which stores information about the user. Events are dispatched
10 * when the information changes.
12 * @extends {cr.EventTarget}
15 cr.EventTarget.call(this);
18 * Tracker used to keep track of event listeners.
19 * @type {!EventTracker}
22 this.tracker_ = new EventTracker();
25 * Email address of the logged in user or {@code null} if no user is logged
30 this.userEmail_ = null;
34 * Enumeration of event types dispatched by the user info.
37 UserInfo.EventType = {
38 EMIAL_CHANGE: 'print_preview.UserInfo.EMAIL_CHANGE'
41 UserInfo.prototype = {
42 __proto__: cr.EventTarget.prototype,
45 * @return {?string} Email address of the logged in user or {@code null} if
48 getUserEmail: function() {
49 return this.userEmail_;
53 * @param {!cloudprint.CloudPrintInterface} cloudPrintInterface Interface
54 * to Google Cloud Print that the print preview uses.
56 setCloudPrintInterface: function(cloudPrintInterface) {
59 cloudprint.CloudPrintInterface.EventType.SEARCH_DONE,
60 this.onCloudPrintSearchDone_.bind(this));
63 /** Removes all event listeners. */
64 removeEventListeners: function() {
65 this.tracker_.removeAll();
69 * Called when a Google Cloud Print printer search completes. Updates user
71 * @type {Event} event Contains information about the logged in user.
74 onCloudPrintSearchDone_: function(event) {
75 if (event.origin == print_preview.Destination.Origin.COOKIES) {
76 this.userEmail_ = event.email;
77 cr.dispatchSimpleEvent(this, UserInfo.EventType.EMAIL_CHANGE);