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

Side by Side Diff: chrome/browser/resources/chromeos/login/oobe-screen.js

Issue 1179323005: Polymer upgraded to 1.0 in login flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@polymer_pre_migration
Patch Set: Comments addressed. Created 5 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 Polymer('oobe-screen', (function() { 5 cr.define('login', function() {
6 /** @const */ var CALLBACK_USER_ACTED = 'userActed'; 6 /** @const */ var CALLBACK_USER_ACTED = 'userActed';
7 7
8 function doNothing() {}; 8 var OobeScreenBehavior = {
9 properties: {
10 /**
11 * Internal storage of |this.context|. Short name has been choosen for
12 * reason: such name doesn't take much space in HTML data bindings, which
13 * are used very often.
14 * C binded to the native part of the context, that means that all the
15 * changes in the native part appear in C automatically. Reverse is not
16 * true, you should use:
17 * this.context.set(...);
18 * this.context.commitContextChanges();
19 * to send updates to the native part.
20 * TODO(dzhioev): make binding two-way.
21 */
22 C: Object,
9 23
10 return { 24 name: String
25 },
26
11 /** 27 /**
12 * The login.Screen which is hosting |this|. 28 * The login.Screen which is hosting |this|.
13 */ 29 */
14 screen_: null, 30 screen_: null,
15 31
16 /** 32 /**
17 * Dictionary of context observers that are methods of |this| bound to 33 * Dictionary of context observers that are methods of |this| bound to
18 * |this|. 34 * |this|.
19 */ 35 */
20 contextObservers_: null, 36 contextObservers_: null,
21 37
22 /** 38 /**
23 * login.ScreenContext used for sharing data with native backend. 39 * login.ScreenContext used for sharing data with native backend.
24 */ 40 */
25 context: null, 41 context: null,
26 42
27 /** 43 /**
28 * Internal storage of |this.context|. Short name has been choosen for
29 * reason: such name doesn't take much space in HTML data bindings, which
30 * are used very often.
31 * C binded to the native part of the context, that means that all the
32 * changes in the native part appear in C automatically. Reverse is not
33 * true, you should use:
34 * this.context.set(...);
35 * this.context.commitContextChanges();
36 * to send updates to the native part.
37 * TODO(dzhioev): make binding two-way.
38 */
39 C: null,
40
41 /**
42 * Called when the screen is being registered. 44 * Called when the screen is being registered.
43 */ 45 */
44 initialize: doNothing, 46 initialize: function() {},
45 47
46 ready: function() { 48 ready: function() {
47 if (this.decorate_) { 49 if (this.decorate_) {
48 this.initialize(); 50 this.initialize();
49 } else { 51 } else {
50 this.ready_ = true; 52 this.ready_ = true;
51 } 53 }
52 }, 54 },
53 55
54 userActed: function(_, _, source) { 56 userActed: function(e) {
55 this.send(CALLBACK_USER_ACTED, source.getAttribute('action')); 57 this.send(CALLBACK_USER_ACTED,
58 e.detail.sourceEvent.target.getAttribute('action'));
56 }, 59 },
57 60
58 i18n: function(args) { 61 i18n: function(args) {
59 if (!(args instanceof Array)) 62 if (!(args instanceof Array))
60 args = [args]; 63 args = [args];
61 args[0] = 'login_' + this.name + '_' + args[0]; 64 args[0] = 'login_' + this.name + '_' + args[0];
62 return loadTimeData.getStringF.apply(loadTimeData, args); 65 return loadTimeData.getStringF.apply(loadTimeData, args);
63 }, 66 },
64 67
65 /** 68 /**
66 * Called by login.Screen when the screen is beeing registered. 69 * Called by login.Screen when the screen is beeing registered.
67 */ 70 */
68 decorate: function(screen) { 71 decorate: function(screen) {
69 this.screen_ = screen; 72 this.screen_ = screen;
70 this.context = screen.screenContext_; 73 this.context = screen.screenContext_;
71 this.C = this.context.storage_; 74 this.C = this.context.storage_;
72 this.contextObservers_ = {}; 75 this.contextObservers_ = {};
73 var self = this; 76 var self = this;
74 if (this.ready_) { 77 if (this.ready_) {
75 this.initialize(); 78 this.initialize();
76 } else { 79 } else {
77 this.decorate_ = true; 80 this.decorate_ = true;
78 } 81 }
79 }, 82 },
80 83
81 /** 84 /**
85 * Should be called for every context field which is used in Polymer
86 * declarative data bindings (e.g. {{C.fieldName}}).
87 */
88 registerBoundContextField: function(fieldName) {
89 this.addContextObserver(fieldName, this.onContextFieldChanged_);
90 },
91
92 onContextFieldChanged_: function(_, _, fieldName) {
93 this.notifyPath('C.' + fieldName, this.C[fieldName]);
94 },
95
96 /**
82 * @final 97 * @final
83 */ 98 */
84 send: function() { 99 send: function() {
85 return this.sendImpl_.apply(this, arguments); 100 return this.sendImpl_.apply(this, arguments);
86 }, 101 },
87 102
88 /** 103 /**
89 * @final 104 * @final
90 */ 105 */
91 addContextObserver: function() { 106 addContextObserver: function() {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 * name. Otherwise returns empty string. 219 * name. Otherwise returns empty string.
205 * @private 220 * @private
206 */ 221 */
207 getPropertyNameOf_: function(value) { 222 getPropertyNameOf_: function(value) {
208 for (var key in this) 223 for (var key in this)
209 if (this[key] === value) 224 if (this[key] === value)
210 return key; 225 return key;
211 return ''; 226 return '';
212 } 227 }
213 }; 228 };
214 })());
215 229
230 return {
231 OobeScreenBehavior: OobeScreenBehavior
232 };
233 });
234
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698