OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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('ntp4', function() { | 5 cr.define('ntp4', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 var localStrings = new LocalStrings; | 8 var localStrings = new LocalStrings; |
9 | 9 |
10 var APP_LAUNCH = { | 10 var APP_LAUNCH = { |
11 // The histogram buckets (keep in sync with extension_constants.h). | 11 // The histogram buckets (keep in sync with extension_constants.h). |
12 NTP_APPS_MAXIMIZED: 0, | 12 NTP_APPS_MAXIMIZED: 0, |
13 NTP_APPS_COLLAPSED: 1, | 13 NTP_APPS_COLLAPSED: 1, |
14 NTP_APPS_MENU: 2, | 14 NTP_APPS_MENU: 2, |
15 NTP_MOST_VISITED: 3, | 15 NTP_MOST_VISITED: 3, |
16 NTP_RECENTLY_CLOSED: 4, | 16 NTP_RECENTLY_CLOSED: 4, |
17 NTP_APP_RE_ENABLE: 16 | 17 NTP_APP_RE_ENABLE: 16 |
18 }; | 18 }; |
19 | 19 |
20 // Histogram buckets for UMA tracking of where a DnD drop came from. | 20 // Histogram buckets for UMA tracking of where a DnD drop came from. |
21 var DRAG_SOURCE = { | 21 var DRAG_SOURCE = { |
22 SAME_APPS_PANE: 0, | 22 SAME_APPS_PANE: 0, |
23 OTHER_APPS_PANE: 1, | 23 OTHER_APPS_PANE: 1, |
24 MOST_VISITED_PANE: 2, | 24 MOST_VISITED_PANE: 2, |
25 BOOKMARKS_PANE: 3, | 25 BOOKMARKS_PANE: 3, |
26 OUTSIDE_NTP: 4 | 26 OUTSIDE_NTP: 4 |
27 }; | 27 } |
Evan Stade
2011/12/02 00:53:24
vat is thees
Dan Beam
2011/12/02 01:25:11
Done. (meant to only remove ; from after function
| |
28 var DRAG_SOURCE_LIMIT = DRAG_SOURCE.OUTSIDE_NTP + 1; | 28 var DRAG_SOURCE_LIMIT = DRAG_SOURCE.OUTSIDE_NTP + 1; |
29 | 29 |
30 /** | 30 /** |
31 * App context menu. The class is designed to be used as a singleton with | 31 * App context menu. The class is designed to be used as a singleton with |
32 * the app that is currently showing a context menu stored in this.app_. | 32 * the app that is currently showing a context menu stored in this.app_. |
33 * @constructor | 33 * @constructor |
34 */ | 34 */ |
35 function AppContextMenu() { | 35 function AppContextMenu() { |
36 this.__proto__ = AppContextMenu.prototype; | 36 this.__proto__ = AppContextMenu.prototype; |
37 this.initialize(); | 37 this.initialize(); |
38 }; | 38 } |
39 cr.addSingletonGetter(AppContextMenu); | 39 cr.addSingletonGetter(AppContextMenu); |
40 | 40 |
41 AppContextMenu.prototype = { | 41 AppContextMenu.prototype = { |
42 initialize: function() { | 42 initialize: function() { |
43 var menu = new cr.ui.Menu; | 43 var menu = new cr.ui.Menu; |
44 cr.ui.decorate(menu, cr.ui.Menu); | 44 cr.ui.decorate(menu, cr.ui.Menu); |
45 menu.classList.add('app-context-menu'); | 45 menu.classList.add('app-context-menu'); |
46 this.menu = menu; | 46 this.menu = menu; |
47 | 47 |
48 this.launch_ = this.appendMenuItem_(); | 48 this.launch_ = this.appendMenuItem_(); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 | 248 |
249 /** | 249 /** |
250 * Sets the color of the favicon dominant color bar. | 250 * Sets the color of the favicon dominant color bar. |
251 * @param {string} color The css-parsable value for the color. | 251 * @param {string} color The css-parsable value for the color. |
252 */ | 252 */ |
253 set stripeColor(color) { | 253 set stripeColor(color) { |
254 this.querySelector('.color-stripe').style.backgroundColor = color; | 254 this.querySelector('.color-stripe').style.backgroundColor = color; |
255 }, | 255 }, |
256 | 256 |
257 /** | 257 /** |
258 * Removes the app tile from the page. Should be called after the app has | |
259 * been uninstalled. | |
260 */ | |
261 remove: function() { | |
262 // Unset the ID immediately, because the app is already gone. But leave | |
263 // the tile on the page as it animates out. | |
264 this.id = ''; | |
265 this.tile.doRemove(); | |
266 }, | |
267 | |
268 /** | |
269 * Set the URL of the icon from |appData_|. This won't actually show the | 258 * Set the URL of the icon from |appData_|. This won't actually show the |
270 * icon until loadIcon() is called (for performance reasons; we don't want | 259 * icon until loadIcon() is called (for performance reasons; we don't want |
271 * to load icons until we have to). | 260 * to load icons until we have to). |
272 */ | 261 */ |
273 setIcon: function() { | 262 setIcon: function() { |
274 var src = this.useSmallIcon_ ? this.appData_.icon_small : | 263 var src = this.useSmallIcon_ ? this.appData_.icon_small : |
275 this.appData_.icon_big; | 264 this.appData_.icon_big; |
276 if (!this.appData_.enabled || | 265 if (!this.appData_.enabled || |
277 (!this.appData_.offline_enabled && !navigator.onLine)) { | 266 (!this.appData_.offline_enabled && !navigator.onLine)) { |
278 src += '?grayscale=true'; | 267 src += '?grayscale=true'; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 */ | 541 */ |
553 canBeRemoved: function() { | 542 canBeRemoved: function() { |
554 return this.appData_.can_uninstall; | 543 return this.appData_.can_uninstall; |
555 }, | 544 }, |
556 | 545 |
557 /** | 546 /** |
558 * Uninstalls the app after it's been dropped on the trash. | 547 * Uninstalls the app after it's been dropped on the trash. |
559 */ | 548 */ |
560 removeFromChrome: function() { | 549 removeFromChrome: function() { |
561 chrome.send('uninstallApp', [this.appData_.id, true]); | 550 chrome.send('uninstallApp', [this.appData_.id, true]); |
562 this.tile.tilePage.removeTile(this.tile, true); | 551 this.tile.remove(true); |
563 | |
564 if (this.currentBubbleShowing_) | 552 if (this.currentBubbleShowing_) |
565 currentBubbleShowing_.hide(); | 553 currentBubbleShowing_.hide(); |
566 }, | 554 }, |
567 | 555 |
568 /** | 556 /** |
569 * Called when a drag is starting on the tile. Updates dataTransfer with | 557 * Called when a drag is starting on the tile. Updates dataTransfer with |
570 * data for this tile. | 558 * data for this tile. |
571 */ | 559 */ |
572 setDragData: function(dataTransfer) { | 560 setDragData: function(dataTransfer) { |
573 dataTransfer.setData('Text', this.appData_.title); | 561 dataTransfer.setData('Text', this.appData_.title); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
781 store.setAppsPromoData(data); | 769 store.setAppsPromoData(data); |
782 }; | 770 }; |
783 | 771 |
784 /** | 772 /** |
785 * Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE | 773 * Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE |
786 * histogram. This should only be invoked from the AppLauncherHandler. | 774 * histogram. This should only be invoked from the AppLauncherHandler. |
787 * @param {String} appID The ID of the app. | 775 * @param {String} appID The ID of the app. |
788 */ | 776 */ |
789 function launchAppAfterEnable(appId) { | 777 function launchAppAfterEnable(appId) { |
790 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); | 778 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); |
791 }; | 779 } |
792 | 780 |
793 function appNotificationChanged(id, notification) { | 781 function appNotificationChanged(id, notification) { |
794 var app = $(id); | 782 var app = $(id); |
795 if (app) // The app might have been uninstalled. | 783 if (app) // The app might have been uninstalled. |
796 app.setupNotification_(notification); | 784 app.setupNotification_(notification); |
797 }; | 785 } |
798 | 786 |
799 return { | 787 return { |
800 APP_LAUNCH: APP_LAUNCH, | 788 APP_LAUNCH: APP_LAUNCH, |
801 appNotificationChanged: appNotificationChanged, | 789 appNotificationChanged: appNotificationChanged, |
802 AppsPage: AppsPage, | 790 AppsPage: AppsPage, |
803 launchAppAfterEnable: launchAppAfterEnable, | 791 launchAppAfterEnable: launchAppAfterEnable, |
804 }; | 792 }; |
805 }); | 793 }); |
806 | 794 |
807 // TODO(estade): update the content handlers to use ntp namespace instead of | 795 // TODO(estade): update the content handlers to use ntp namespace instead of |
808 // making these global. | 796 // making these global. |
809 var appNotificationChanged = ntp4.appNotificationChanged; | 797 var appNotificationChanged = ntp4.appNotificationChanged; |
810 var launchAppAfterEnable = ntp4.launchAppAfterEnable; | 798 var launchAppAfterEnable = ntp4.launchAppAfterEnable; |
OLD | NEW |