Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 cr.define('ntp', function() { | 5 cr.define('ntp', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 var Tile = ntp.Tile; | 8 var Tile = ntp.Tile; |
| 9 var TilePage = ntp.TilePage; | 9 var TilePage = ntp.TilePage; |
| 10 var APP_LAUNCH = ntp.APP_LAUNCH; | 10 var APP_LAUNCH = ntp.APP_LAUNCH; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 } | 113 } |
| 114 }, | 114 }, |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * Does all the necessary setup to show the menu for the given app. | 117 * Does all the necessary setup to show the menu for the given app. |
| 118 * @param {App} app The App object that will be showing a context menu. | 118 * @param {App} app The App object that will be showing a context menu. |
| 119 */ | 119 */ |
| 120 setupForApp: function(app) { | 120 setupForApp: function(app) { |
| 121 this.app_ = app; | 121 this.app_ = app; |
| 122 | 122 |
| 123 this.launch_.textContent = app.appData.title; | 123 this.launch_.textContent = app.data.title; |
| 124 | 124 |
| 125 this.forAllLaunchTypes_(function(launchTypeButton, id) { | 125 this.forAllLaunchTypes_(function(launchTypeButton, id) { |
| 126 launchTypeButton.disabled = false; | 126 launchTypeButton.disabled = false; |
| 127 launchTypeButton.checked = app.appData.launch_type == id; | 127 launchTypeButton.checked = app.data.launch_type == id; |
| 128 }); | 128 }); |
| 129 | 129 |
| 130 this.options_.disabled = !app.appData.optionsUrl || !app.appData.enabled; | 130 this.options_.disabled = !app.data.optionsUrl || !app.data.enabled; |
| 131 this.details_.disabled = !app.appData.detailsUrl; | 131 this.details_.disabled = !app.data.detailsUrl; |
| 132 this.uninstall_.disabled = !app.appData.mayDisable; | 132 this.uninstall_.disabled = !app.data.mayDisable; |
| 133 | 133 |
| 134 this.disableNotifications_.hidden = true; | 134 this.disableNotifications_.hidden = true; |
| 135 var notificationsDisabled = app.appData.notifications_disabled; | 135 var notificationsDisabled = app.data.notifications_disabled; |
| 136 if (typeof notificationsDisabled != 'undefined') { | 136 if (typeof notificationsDisabled != 'undefined') { |
| 137 this.disableNotifications_.hidden = false; | 137 this.disableNotifications_.hidden = false; |
| 138 this.disableNotifications_.checked = notificationsDisabled; | 138 this.disableNotifications_.checked = notificationsDisabled; |
| 139 } | 139 } |
| 140 }, | 140 }, |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * Handlers for menu item activation. | 143 * Handlers for menu item activation. |
| 144 * @param {Event} e The activation event. | 144 * @param {Event} e The activation event. |
| 145 * @private | 145 * @private |
| 146 */ | 146 */ |
| 147 onLaunch_: function(e) { | 147 onLaunch_: function(e) { |
| 148 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]); | 148 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]); |
| 149 }, | 149 }, |
| 150 onLaunchTypeChanged_: function(e) { | 150 onLaunchTypeChanged_: function(e) { |
| 151 var pressed = e.currentTarget; | 151 var pressed = e.currentTarget; |
| 152 var app = this.app_; | 152 var app = this.app_; |
| 153 this.forAllLaunchTypes_(function(launchTypeButton, id) { | 153 this.forAllLaunchTypes_(function(launchTypeButton, id) { |
| 154 if (launchTypeButton == pressed) { | 154 if (launchTypeButton == pressed) { |
| 155 chrome.send('setLaunchType', [app.appId, id]); | 155 chrome.send('setLaunchType', [app.appId, id]); |
| 156 // Manually update the launch type. We will only get | 156 // Manually update the launch type. We will only get |
| 157 // appsPrefChangeCallback calls after changes to other NTP instances. | 157 // appsPrefChangeCallback calls after changes to other NTP instances. |
| 158 app.appData.launch_type = id; | 158 app.data.launch_type = id; |
| 159 } | 159 } |
| 160 }); | 160 }); |
| 161 }, | 161 }, |
| 162 onShowOptions_: function(e) { | 162 onShowOptions_: function(e) { |
| 163 window.location = this.app_.appData.optionsUrl; | 163 window.location = this.app_.data.optionsUrl; |
| 164 }, | 164 }, |
| 165 onShowDetails_: function(e) { | 165 onShowDetails_: function(e) { |
| 166 var url = this.app_.appData.detailsUrl; | 166 var url = this.app_.data.detailsUrl; |
| 167 url = appendParam(url, 'utm_source', 'chrome-ntp-launcher'); | 167 url = appendParam(url, 'utm_source', 'chrome-ntp-launcher'); |
| 168 window.location = url; | 168 window.location = url; |
| 169 }, | 169 }, |
| 170 onDisableNotifications_: function(e) { | 170 onDisableNotifications_: function(e) { |
| 171 var app = this.app_; | 171 var app = this.app_; |
| 172 app.removeBubble(); | 172 app.removeBubble(); |
| 173 // Toggle the current disable setting. | 173 // Toggle the current disable setting. |
| 174 var newSetting = !this.disableNotifications_.checked; | 174 var newSetting = !this.disableNotifications_.checked; |
| 175 app.appData.notifications_disabled = newSetting; | 175 app.data.notifications_disabled = newSetting; |
| 176 chrome.send('setNotificationsDisabled', [app.appData.id, newSetting]); | 176 chrome.send('setNotificationsDisabled', [app.data.id, newSetting]); |
| 177 }, | 177 }, |
| 178 onUninstall_: function(e) { | 178 onUninstall_: function(e) { |
| 179 var tileCell = this.app_.tileCell; | 179 chrome.send('uninstallApp', [this.app_.data.id]); |
| 180 tileCell.tilePage.setTileRepositioningState(tileCell.index, true); | |
|
Dan Beam
2012/12/05 18:34:05
does this no longer apply?
pedro (no code reviews)
2012/12/05 19:41:34
No, this was misplaced. This will be called before
| |
| 181 chrome.send('uninstallApp', [this.app_.appData.id]); | |
| 182 }, | 180 }, |
| 183 onCreateShortcut_: function(e) { | 181 onCreateShortcut_: function(e) { |
| 184 chrome.send('createAppShortcut', [this.app_.appData.id]); | 182 chrome.send('createAppShortcut', [this.app_.data.id]); |
| 185 }, | 183 }, |
| 186 }; | 184 }; |
| 187 | 185 |
| 188 /** | 186 /** |
| 189 * Creates a new App object. | 187 * Creates a new App object. |
| 190 * @param {Object} appData The data object that describes the app. | |
| 191 * @constructor | 188 * @constructor |
| 192 * @extends {HTMLDivElement} | 189 * @extends {HTMLDivElement} |
| 193 */ | 190 */ |
| 194 function App(appData) { | 191 function App() { |
|
Dan Beam
2012/12/05 18:34:05
what's the point of an app with no data?
pedro (no code reviews)
2012/12/05 19:41:34
I'm reusing the new Tile/TilePage logic, and the T
| |
| 195 var el = cr.doc.createElement('div'); | 192 var el = cr.doc.createElement('div'); |
| 196 el.__proto__ = App.prototype; | 193 el.__proto__ = App.prototype; |
| 197 el.initialize(appData); | |
| 198 | 194 |
| 199 return el; | 195 return el; |
| 200 } | 196 } |
| 201 | 197 |
| 202 App.prototype = Tile.subclass({ | 198 App.prototype = Tile.subclass({ |
| 203 __proto__: HTMLDivElement.prototype, | 199 __proto__: HTMLDivElement.prototype, |
| 204 | 200 |
| 205 /** | 201 /** |
| 206 * Initialize the app object. | 202 * Initialize the app object. |
| 207 * @param {Object} appData The data object that describes the app. | 203 * @param {Object} data The data object that describes the app. |
| 208 */ | 204 */ |
| 209 initialize: function(appData) { | 205 initialize: function(data) { |
|
Dan Beam
2012/12/05 18:34:05
where do you remember |data| in this.data?
pedro (no code reviews)
2012/12/05 19:41:34
set data will store this value and call initialize
| |
| 210 this.className = 'app focusable'; | 206 this.className = 'app focusable'; |
| 211 | 207 |
| 212 Tile.prototype.initialize.apply(this, arguments); | 208 Tile.prototype.initialize.apply(this, arguments); |
| 213 | 209 |
| 214 this.appData = appData; | 210 assert(this.data_.id, 'Got an app without an ID'); |
|
Dan Beam
2012/12/05 18:34:05
^ I'm confused, why did you remove this?
pedro (no code reviews)
2012/12/05 19:41:34
The initialize is now being called when the App da
| |
| 215 assert(this.appData_.id, 'Got an app without an ID'); | 211 this.id = this.data_.id; |
| 216 this.id = this.appData_.id; | |
| 217 this.setAttribute('role', 'menuitem'); | 212 this.setAttribute('role', 'menuitem'); |
| 218 | 213 |
| 219 if (!this.appData_.icon_big_exists && this.appData_.icon_small_exists) | 214 if (!this.data_.icon_big_exists && this.data_.icon_small_exists) |
| 220 this.useSmallIcon_ = true; | 215 this.useSmallIcon_ = true; |
| 221 | 216 |
| 222 this.appContents_ = this.useSmallIcon_ ? | 217 this.appContents_ = this.useSmallIcon_ ? |
| 223 $('app-small-icon-template').cloneNode(true) : | 218 $('app-small-icon-template').cloneNode(true) : |
| 224 $('app-large-icon-template').cloneNode(true); | 219 $('app-large-icon-template').cloneNode(true); |
| 225 this.appContents_.id = ''; | 220 this.appContents_.id = ''; |
| 226 this.appendChild(this.appContents_); | 221 this.appendChild(this.appContents_); |
| 227 | 222 |
| 228 this.appImgContainer_ = this.querySelector('.app-img-container'); | 223 this.appImgContainer_ = this.querySelector('.app-img-container'); |
| 229 this.appImg_ = this.appImgContainer_.querySelector('img'); | 224 this.appImg_ = this.appImgContainer_.querySelector('img'); |
| 230 this.setIcon(); | 225 this.setIcon(); |
| 231 | 226 |
| 232 if (this.useSmallIcon_) { | 227 if (this.useSmallIcon_) { |
| 233 this.imgDiv_ = this.querySelector('.app-icon-div'); | 228 this.imgDiv_ = this.querySelector('.app-icon-div'); |
| 234 this.addLaunchClickTarget_(this.imgDiv_); | 229 this.addLaunchClickTarget_(this.imgDiv_); |
| 235 this.imgDiv_.title = this.appData_.title; | 230 this.imgDiv_.title = this.data_.title; |
| 236 chrome.send('getAppIconDominantColor', [this.id]); | 231 chrome.send('getAppIconDominantColor', [this.id]); |
| 237 } else { | 232 } else { |
| 238 this.addLaunchClickTarget_(this.appImgContainer_); | 233 this.addLaunchClickTarget_(this.appImgContainer_); |
| 239 this.appImgContainer_.title = this.appData_.title; | 234 this.appImgContainer_.title = this.data_.title; |
| 240 } | 235 } |
| 241 | 236 |
| 242 var appSpan = this.appContents_.querySelector('.title'); | 237 var appSpan = this.appContents_.querySelector('.title'); |
| 243 appSpan.textContent = appSpan.title = this.appData_.title; | 238 appSpan.textContent = appSpan.title = this.data_.title; |
| 244 this.addLaunchClickTarget_(appSpan); | 239 this.addLaunchClickTarget_(appSpan); |
| 245 | 240 |
| 246 var notification = this.appData_.notification; | 241 var notification = this.data_.notification; |
| 247 var hasNotification = typeof notification != 'undefined' && | 242 var hasNotification = typeof notification != 'undefined' && |
| 248 typeof notification['title'] != 'undefined' && | 243 typeof notification['title'] != 'undefined' && |
| 249 typeof notification['body'] != 'undefined' && | 244 typeof notification['body'] != 'undefined' && |
| 250 !this.appData_.notifications_disabled; | 245 !this.data_.notifications_disabled; |
| 251 if (hasNotification) | 246 if (hasNotification) |
| 252 this.setupNotification_(notification); | 247 this.setupNotification_(notification); |
| 253 | 248 |
| 254 this.addEventListener('keydown', cr.ui.contextMenuHandler); | 249 this.addEventListener('keydown', cr.ui.contextMenuHandler); |
| 255 this.addEventListener('keyup', cr.ui.contextMenuHandler); | 250 this.addEventListener('keyup', cr.ui.contextMenuHandler); |
| 256 | 251 |
| 257 // This hack is here so that appContents.contextMenu will be the same as | 252 // This hack is here so that appContents.contextMenu will be the same as |
| 258 // this.contextMenu. | 253 // this.contextMenu. |
| 259 var self = this; | 254 var self = this; |
| 260 this.appContents_.__defineGetter__('contextMenu', function() { | 255 this.appContents_.__defineGetter__('contextMenu', function() { |
| 261 return self.contextMenu; | 256 return self.contextMenu; |
| 262 }); | 257 }); |
| 263 this.appContents_.addEventListener('contextmenu', | 258 this.appContents_.addEventListener('contextmenu', |
| 264 cr.ui.contextMenuHandler); | 259 cr.ui.contextMenuHandler); |
| 265 | 260 |
| 266 this.addEventListener('mousedown', this.onMousedown_, true); | 261 this.addEventListener('mousedown', this.onMousedown_, true); |
| 267 this.addEventListener('keydown', this.onKeydown_); | 262 this.addEventListener('keydown', this.onKeydown_); |
| 268 this.addEventListener('keyup', this.onKeyup_); | 263 this.addEventListener('keyup', this.onKeyup_); |
| 264 | |
| 265 this.isInitialized_ = true; | |
| 269 }, | 266 }, |
| 270 | 267 |
| 271 /** | 268 /** |
| 272 * Sets the color of the favicon dominant color bar. | 269 * Sets the color of the favicon dominant color bar. |
| 273 * @param {string} color The css-parsable value for the color. | 270 * @param {string} color The css-parsable value for the color. |
| 274 */ | 271 */ |
| 275 set stripeColor(color) { | 272 set stripeColor(color) { |
| 276 this.querySelector('.color-stripe').style.backgroundColor = color; | 273 this.querySelector('.color-stripe').style.backgroundColor = color; |
| 277 }, | 274 }, |
| 278 | 275 |
| 279 /** | 276 /** |
| 280 * Removes the app tile from the page. Should be called after the app has | 277 * Removes the app tile from the page. Should be called after the app has |
| 281 * been uninstalled. | 278 * been uninstalled. |
| 282 */ | 279 */ |
| 283 remove: function(opt_animate) { | 280 remove: function(opt_animate) { |
| 284 // Unset the ID immediately, because the app is already gone. But leave | 281 // Unset the ID immediately, because the app is already gone. But leave |
| 285 // the tile on the page as it animates out. | 282 // the tile on the page as it animates out. |
| 286 this.id = ''; | 283 this.id = ''; |
| 287 this.tileCell.doRemove(opt_animate); | 284 this.tileCell.doRemove(opt_animate); |
| 288 }, | 285 }, |
| 289 | 286 |
| 290 /** | 287 /** |
| 291 * Set the URL of the icon from |appData_|. This won't actually show the | 288 * Set the URL of the icon from |data_|. This won't actually show the |
|
Dan Beam
2012/12/05 18:34:05
nit: |this.data_|, IMO
pedro (no code reviews)
2012/12/05 19:41:34
Done.
| |
| 292 * icon until loadIcon() is called (for performance reasons; we don't want | 289 * icon until loadIcon() is called (for performance reasons; we don't want |
| 293 * to load icons until we have to). | 290 * to load icons until we have to). |
| 294 */ | 291 */ |
| 295 setIcon: function() { | 292 setIcon: function() { |
| 296 var src = this.useSmallIcon_ ? this.appData_.icon_small : | 293 var src = this.useSmallIcon_ ? this.data_.icon_small : |
| 297 this.appData_.icon_big; | 294 this.data_.icon_big; |
| 298 if (!this.appData_.enabled || | 295 if (!this.data_.enabled || |
| 299 (!this.appData_.offlineEnabled && !navigator.onLine)) { | 296 (!this.data_.offlineEnabled && !navigator.onLine)) { |
| 300 src += '?grayscale=true'; | 297 src += '?grayscale=true'; |
| 301 } | 298 } |
| 302 | 299 |
| 303 this.appImgSrc_ = src; | 300 this.appImgSrc_ = src; |
| 304 this.classList.add('icon-loading'); | 301 this.classList.add('icon-loading'); |
| 305 }, | 302 }, |
| 306 | 303 |
| 307 /** | 304 /** |
| 308 * Shows the icon for the app. That is, it causes chrome to load the app | 305 * Shows the icon for the app. That is, it causes chrome to load the app |
| 309 * icon resource. | 306 * icon resource. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 * @param {Object} notification The notification to show in the bubble. | 349 * @param {Object} notification The notification to show in the bubble. |
| 353 * @private | 350 * @private |
| 354 */ | 351 */ |
| 355 setupNotification_: function(notification) { | 352 setupNotification_: function(notification) { |
| 356 if (notification) { | 353 if (notification) { |
| 357 var infoBubble; | 354 var infoBubble; |
| 358 if (!this.currentBubbleShowing_) { | 355 if (!this.currentBubbleShowing_) { |
| 359 // Create a new bubble. | 356 // Create a new bubble. |
| 360 infoBubble = new cr.ui.ExpandableBubble; | 357 infoBubble = new cr.ui.ExpandableBubble; |
| 361 infoBubble.anchorNode = this; | 358 infoBubble.anchorNode = this; |
| 362 infoBubble.appId = this.appData_.id; | 359 infoBubble.appId = this.data_.id; |
| 363 infoBubble.handleCloseEvent = function() { | 360 infoBubble.handleCloseEvent = function() { |
| 364 chrome.send('closeNotification', [this.appId]); | 361 chrome.send('closeNotification', [this.appId]); |
| 365 infoBubble.hide(); | 362 infoBubble.hide(); |
| 366 }; | 363 }; |
| 367 } else { | 364 } else { |
| 368 // Reuse the old bubble instead of popping up a new bubble over | 365 // Reuse the old bubble instead of popping up a new bubble over |
| 369 // the old one. | 366 // the old one. |
| 370 infoBubble = this.currentBubbleShowing_; | 367 infoBubble = this.currentBubbleShowing_; |
| 371 infoBubble.collapseBubble_(); | 368 infoBubble.collapseBubble_(); |
| 372 } | 369 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 388 this.currentBubbleShowing_ = null; | 385 this.currentBubbleShowing_ = null; |
| 389 } | 386 } |
| 390 }, | 387 }, |
| 391 | 388 |
| 392 /** | 389 /** |
| 393 * Invoked when an app is clicked. | 390 * Invoked when an app is clicked. |
| 394 * @param {Event} e The click event. | 391 * @param {Event} e The click event. |
| 395 * @private | 392 * @private |
| 396 */ | 393 */ |
| 397 onClick_: function(e) { | 394 onClick_: function(e) { |
| 398 var url = !this.appData_.is_webstore ? '' : | 395 var url = !this.data_.is_webstore ? '' : |
| 399 appendParam(this.appData_.url, | 396 appendParam(this.data_.url, |
| 400 'utm_source', | 397 'utm_source', |
| 401 'chrome-ntp-icon'); | 398 'chrome-ntp-icon'); |
| 402 | 399 |
| 403 chrome.send('launchApp', | 400 chrome.send('launchApp', |
| 404 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, url, | 401 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, url, |
| 405 e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); | 402 e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); |
| 406 | 403 |
| 407 // Don't allow the click to trigger a link or anything | 404 // Don't allow the click to trigger a link or anything |
| 408 e.preventDefault(); | 405 e.preventDefault(); |
| 409 }, | 406 }, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 } else { | 474 } else { |
| 478 this.appContents_.classList.remove('suppress-active'); | 475 this.appContents_.classList.remove('suppress-active'); |
| 479 } | 476 } |
| 480 | 477 |
| 481 // This class is here so we don't show the focus state for apps that | 478 // This class is here so we don't show the focus state for apps that |
| 482 // gain keyboard focus via mouse clicking. | 479 // gain keyboard focus via mouse clicking. |
| 483 this.classList.add('click-focus'); | 480 this.classList.add('click-focus'); |
| 484 }, | 481 }, |
| 485 | 482 |
| 486 /** | 483 /** |
| 487 * Change the appData and update the appearance of the app. | 484 * Change the data and update the appearance of the app. |
| 488 * @param {Object} appData The new data object that describes the app. | 485 * @param {Object} data The new data object that describes the app. |
| 489 */ | 486 */ |
| 490 replaceAppData: function(appData) { | 487 replaceAppData: function(data) { |
|
Dan Beam
2012/12/05 18:34:05
what's the point of this when `set data` exists?
pedro (no code reviews)
2012/12/05 19:41:34
I don't know, I'm not the author of this code, I'm
| |
| 491 this.appData_ = appData; | 488 this.data_ = data; |
| 492 this.setIcon(); | 489 this.setIcon(); |
| 493 this.loadIcon(); | 490 this.loadIcon(); |
| 494 }, | 491 }, |
| 495 | 492 |
| 496 /** | 493 /** |
| 497 * The data and preferences for this app. | 494 * The data and preferences for this app. |
| 498 * @type {Object} | 495 * @type {Object} |
| 499 */ | 496 */ |
| 500 set appData(data) { | 497 set data(data) { |
| 501 this.appData_ = data; | 498 Object.getOwnPropertyDescriptor(Tile.prototype, 'data').set.apply(this, |
| 499 arguments); | |
| 500 | |
| 501 if (!this.isInitialized_) | |
| 502 this.initialize(data); | |
| 502 }, | 503 }, |
| 503 get appData() { | 504 get data() { |
| 504 return this.appData_; | 505 return this.data_; |
| 505 }, | 506 }, |
| 506 | 507 |
| 507 get appId() { | 508 get appId() { |
| 508 return this.appData_.id; | 509 return this.data_.id; |
| 509 }, | 510 }, |
| 510 | 511 |
| 511 /** | 512 /** |
| 512 * Returns a pointer to the context menu for this app. All apps share the | 513 * Returns a pointer to the context menu for this app. All apps share the |
| 513 * singleton AppContextMenu. This function is called by the | 514 * singleton AppContextMenu. This function is called by the |
| 514 * ContextMenuHandler in response to the 'contextmenu' event. | 515 * ContextMenuHandler in response to the 'contextmenu' event. |
| 515 * @type {cr.ui.Menu} | 516 * @type {cr.ui.Menu} |
| 516 */ | 517 */ |
| 517 get contextMenu() { | 518 get contextMenu() { |
| 518 var menu = AppContextMenu.getInstance(); | 519 var menu = AppContextMenu.getInstance(); |
| 519 menu.setupForApp(this); | 520 menu.setupForApp(this); |
| 520 return menu.menu; | 521 return menu.menu; |
| 521 }, | 522 }, |
| 522 | 523 |
| 523 /** | 524 /** |
| 524 * Returns whether this element can be 'removed' from chrome (i.e. whether | 525 * Returns whether this element can be 'removed' from chrome (i.e. whether |
| 525 * the user can drag it onto the trash and expect something to happen). | 526 * the user can drag it onto the trash and expect something to happen). |
| 526 * @return {boolean} True if the app can be uninstalled. | 527 * @return {boolean} True if the app can be uninstalled. |
| 527 */ | 528 */ |
| 528 canBeRemoved: function() { | 529 canBeRemoved: function() { |
| 529 return this.appData_.mayDisable; | 530 return this.data_.mayDisable; |
| 530 }, | 531 }, |
| 531 | 532 |
| 532 /** | 533 /** |
| 533 * Uninstalls the app after it's been dropped on the trash. | 534 * Uninstalls the app after it's been dropped on the trash. |
| 534 */ | 535 */ |
| 535 removeFromChrome: function() { | 536 removeFromChrome: function() { |
| 536 chrome.send('uninstallApp', [this.appData_.id, true]); | 537 chrome.send('uninstallApp', [this.data_.id, true]); |
| 537 this.tile.tilePage.removeTile(this.tile, true); | 538 this.tile.tilePage.removeTile(this.tile, true); |
| 538 if (this.currentBubbleShowing_) | 539 if (this.currentBubbleShowing_) |
| 539 this.currentBubbleShowing_.hide(); | 540 this.currentBubbleShowing_.hide(); |
| 540 }, | 541 }, |
| 541 | 542 |
| 542 /** | 543 /** |
| 543 * Called when a drag is starting on the tile. Updates dataTransfer with | 544 * Called when a drag is starting on the tile. Updates dataTransfer with |
| 544 * data for this tile. | 545 * data for this tile. |
| 545 */ | 546 */ |
| 546 setDragData: function(dataTransfer) { | 547 setDragData: function(dataTransfer) { |
| 547 dataTransfer.setData('Text', this.appData_.title); | 548 dataTransfer.setData('Text', this.data_.title); |
| 548 dataTransfer.setData('URL', this.appData_.url); | 549 dataTransfer.setData('URL', this.data_.url); |
| 549 }, | 550 }, |
| 550 }); | 551 }); |
| 551 | 552 |
| 552 /** | 553 /** |
| 553 * Creates a new AppsPage object. | 554 * Creates a new AppsPage object. |
| 554 * @constructor | 555 * @constructor |
| 555 * @extends {TilePage} | 556 * @extends {TilePage} |
| 556 */ | 557 */ |
| 557 function AppsPage() { | 558 function AppsPage() { |
| 558 var el = new TilePage(); | 559 var el = new TilePage(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 // view. | 597 // view. |
| 597 this.addEventListener('carddeselected', this.onCardDeselected_); | 598 this.addEventListener('carddeselected', this.onCardDeselected_); |
| 598 this.addEventListener('cardSlider:card_change_ended', | 599 this.addEventListener('cardSlider:card_change_ended', |
| 599 this.onCardChangeEnded_); | 600 this.onCardChangeEnded_); |
| 600 | 601 |
| 601 this.addEventListener('tilePage:tile_added', this.onTileAdded_); | 602 this.addEventListener('tilePage:tile_added', this.onTileAdded_); |
| 602 }, | 603 }, |
| 603 | 604 |
| 604 /** | 605 /** |
| 605 * Highlight a newly installed app as it's added to the NTP. | 606 * Highlight a newly installed app as it's added to the NTP. |
| 606 * @param {Object} appData The data object that describes the app. | 607 * @param {Object} data The data object that describes the app. |
| 607 */ | 608 */ |
| 608 insertAndHighlightApp: function(appData) { | 609 insertAndHighlightApp: function(data) { |
| 609 ntp.getCardSlider().selectCardByValue(this); | 610 ntp.getCardSlider().selectCardByValue(this); |
| 610 this.insertApp(appData, true); | 611 this.insertApp(data, true); |
| 611 }, | 612 }, |
| 612 | 613 |
| 613 /** | 614 /** |
| 614 * Inserts an App into the TilePage, preserving the alphabetical order. | 615 * Inserts an App into the TilePage, preserving the alphabetical order. |
| 615 * @param {Object} appData The data that describes the app. | 616 * @param {Object} data The data that describes the app. |
| 616 * @param {boolean} animate Whether to animate the insertion. | 617 * @param {boolean} animate Whether to animate the insertion. |
| 617 */ | 618 */ |
| 618 insertApp: function(appData, animate) { | 619 insertApp: function(data, animate) { |
| 619 var index = this.tiles_.length; | 620 var index = this.tiles_.length; |
| 620 for (var i = 0; i < this.tiles_.length; i++) { | 621 for (var i = 0; i < this.tiles_.length; i++) { |
| 621 if (appData.title.toLocaleLowerCase() < | 622 if (data.title.toLocaleLowerCase() < |
| 622 this.tiles_[i].appData.title.toLocaleLowerCase()) { | 623 this.tiles_[i].data.title.toLocaleLowerCase()) { |
| 623 index = i; | 624 index = i; |
| 624 break; | 625 break; |
| 625 } | 626 } |
| 626 } | 627 } |
| 627 | 628 |
| 628 var app = new App(appData); | 629 var app = new App(); |
| 630 app.data = data; | |
| 629 this.addTileAt(app, index); | 631 this.addTileAt(app, index); |
| 630 this.renderGrid_(); | 632 this.renderGrid_(); |
| 631 }, | 633 }, |
| 632 | 634 |
| 633 /** | 635 /** |
| 634 * Handler for 'cardselected' event, fired when |this| is selected. The | 636 * Handler for 'cardselected' event, fired when |this| is selected. The |
| 635 * first time this is called, we load all the app icons. | 637 * first time this is called, we load all the app icons. |
| 636 * @private | 638 * @private |
| 637 */ | 639 */ |
| 638 onCardSelected_: function(e) { | 640 onCardSelected_: function(e) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 827 * histogram. This should only be invoked from the AppLauncherHandler. | 829 * histogram. This should only be invoked from the AppLauncherHandler. |
| 828 * @param {String} appID The ID of the app. | 830 * @param {String} appID The ID of the app. |
| 829 */ | 831 */ |
| 830 function launchAppAfterEnable(appId) { | 832 function launchAppAfterEnable(appId) { |
| 831 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); | 833 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); |
| 832 } | 834 } |
| 833 | 835 |
| 834 function appNotificationChanged(id, notification) { | 836 function appNotificationChanged(id, notification) { |
| 835 var app = $(id); | 837 var app = $(id); |
| 836 // The app might have been uninstalled, or notifications might be disabled. | 838 // The app might have been uninstalled, or notifications might be disabled. |
| 837 if (app && !app.appData.notifications_disabled) | 839 if (app && !app.data.notifications_disabled) |
| 838 app.setupNotification_(notification); | 840 app.setupNotification_(notification); |
| 839 } | 841 } |
| 840 | 842 |
| 841 return { | 843 return { |
| 842 appNotificationChanged: appNotificationChanged, | 844 appNotificationChanged: appNotificationChanged, |
| 843 AppsPage: AppsPage, | 845 AppsPage: AppsPage, |
| 844 launchAppAfterEnable: launchAppAfterEnable, | 846 launchAppAfterEnable: launchAppAfterEnable, |
| 845 }; | 847 }; |
| 846 }); | 848 }); |
| OLD | NEW |