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 APP_LAUNCH = { | 8 var APP_LAUNCH = { |
9 // The histogram buckets (keep in sync with extension_constants.h). | 9 // The histogram buckets (keep in sync with extension_constants.h). |
10 NTP_APPS_MAXIMIZED: 0, | 10 NTP_APPS_MAXIMIZED: 0, |
(...skipping 21 matching lines...) Expand all Loading... | |
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 /** | |
43 * If true, the "Create shortcuts" context menu entry will be hidden. | |
44 * @type {boolean} | |
45 */ | |
46 disableCreateAppShortcut: false, | |
tapted
2013/05/30 05:32:24
pretty sure this should be in initialize(), with a
| |
47 | |
42 initialize: function() { | 48 initialize: function() { |
43 var menu = new cr.ui.Menu; | 49 var menu = new cr.ui.Menu; |
44 cr.ui.decorate(menu, cr.ui.Menu); | 50 cr.ui.decorate(menu, cr.ui.Menu); |
45 menu.classList.add('app-context-menu'); | 51 menu.classList.add('app-context-menu'); |
46 this.menu = menu; | 52 this.menu = menu; |
47 | 53 |
48 this.launch_ = this.appendMenuItem_(); | 54 this.launch_ = this.appendMenuItem_(); |
49 this.launch_.addEventListener('activate', this.onLaunch_.bind(this)); | 55 this.launch_.addEventListener('activate', this.onLaunch_.bind(this)); |
50 | 56 |
51 menu.appendChild(cr.ui.MenuItem.createSeparator()); | 57 menu.appendChild(cr.ui.MenuItem.createSeparator()); |
(...skipping 14 matching lines...) Expand all Loading... | |
66 this.options_ = this.appendMenuItem_('appoptions'); | 72 this.options_ = this.appendMenuItem_('appoptions'); |
67 this.details_ = this.appendMenuItem_('appdetails'); | 73 this.details_ = this.appendMenuItem_('appdetails'); |
68 this.uninstall_ = this.appendMenuItem_('appuninstall'); | 74 this.uninstall_ = this.appendMenuItem_('appuninstall'); |
69 this.options_.addEventListener('activate', | 75 this.options_.addEventListener('activate', |
70 this.onShowOptions_.bind(this)); | 76 this.onShowOptions_.bind(this)); |
71 this.details_.addEventListener('activate', | 77 this.details_.addEventListener('activate', |
72 this.onShowDetails_.bind(this)); | 78 this.onShowDetails_.bind(this)); |
73 this.uninstall_.addEventListener('activate', | 79 this.uninstall_.addEventListener('activate', |
74 this.onUninstall_.bind(this)); | 80 this.onUninstall_.bind(this)); |
75 | 81 |
76 if (!(cr.isChromeOS || cr.isMac)) { | 82 if (!cr.isChromeOS) { |
77 this.createShortcutSeparator_ = | 83 this.createShortcutSeparator_ = |
78 menu.appendChild(cr.ui.MenuItem.createSeparator()); | 84 menu.appendChild(cr.ui.MenuItem.createSeparator()); |
79 this.createShortcut_ = this.appendMenuItem_('appcreateshortcut'); | 85 this.createShortcut_ = this.appendMenuItem_('appcreateshortcut'); |
80 this.createShortcut_.addEventListener( | 86 this.createShortcut_.addEventListener( |
81 'activate', this.onCreateShortcut_.bind(this)); | 87 'activate', this.onCreateShortcut_.bind(this)); |
82 } | 88 } |
83 | 89 |
84 document.body.appendChild(menu); | 90 document.body.appendChild(menu); |
85 }, | 91 }, |
86 | 92 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 launchTypeButton.checked = app.appData.launch_type == id; | 139 launchTypeButton.checked = app.appData.launch_type == id; |
134 launchTypeButton.hidden = app.appData.packagedApp; | 140 launchTypeButton.hidden = app.appData.packagedApp; |
135 }); | 141 }); |
136 | 142 |
137 this.launchTypeMenuSeparator_.hidden = app.appData.packagedApp; | 143 this.launchTypeMenuSeparator_.hidden = app.appData.packagedApp; |
138 | 144 |
139 this.options_.disabled = !app.appData.optionsUrl || !app.appData.enabled; | 145 this.options_.disabled = !app.appData.optionsUrl || !app.appData.enabled; |
140 this.details_.disabled = !app.appData.detailsUrl; | 146 this.details_.disabled = !app.appData.detailsUrl; |
141 this.uninstall_.disabled = !app.appData.mayDisable; | 147 this.uninstall_.disabled = !app.appData.mayDisable; |
142 | 148 |
143 if (this.createShortcut_ && cr.isMac) { | 149 if (cr.isMac) { |
144 // On Windows and Linux, these should always be visible. On ChromeOS, | 150 // On Windows and Linux, these should always be visible. On ChromeOS, |
145 // they are never created. On Mac, shortcuts can only be created for | 151 // they are never created. On Mac, shortcuts can only be created for |
146 // new-style packaged apps, so hide the menu item. | 152 // new-style packaged apps, so hide the menu item. |
147 this.createShortcutSeparator_.hidden = this.createShortcut_.hidden = | 153 this.createShortcutSeparator_.hidden = this.createShortcut_.hidden = |
148 !app.appData.packagedApp; | 154 !app.appData.packagedApp || this.disableCreateAppShortcut; |
149 } | 155 } |
150 }, | 156 }, |
151 | 157 |
152 /** | 158 /** |
153 * Handlers for menu item activation. | 159 * Handlers for menu item activation. |
154 * @param {Event} e The activation event. | 160 * @param {Event} e The activation event. |
155 * @private | 161 * @private |
156 */ | 162 */ |
157 onLaunch_: function(e) { | 163 onLaunch_: function(e) { |
158 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]); | 164 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]); |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 this.classList.add('apps-page'); | 548 this.classList.add('apps-page'); |
543 | 549 |
544 this.addEventListener('cardselected', this.onCardSelected_); | 550 this.addEventListener('cardselected', this.onCardSelected_); |
545 | 551 |
546 this.addEventListener('tilePage:tile_added', this.onTileAdded_); | 552 this.addEventListener('tilePage:tile_added', this.onTileAdded_); |
547 | 553 |
548 this.content_.addEventListener('scroll', this.onScroll_.bind(this)); | 554 this.content_.addEventListener('scroll', this.onScroll_.bind(this)); |
549 }, | 555 }, |
550 | 556 |
551 /** | 557 /** |
558 * Disable the "Create shortcut" context menu item. | |
559 */ | |
560 disableCreateAppShortcut: function() { | |
561 AppContextMenu.getInstance().disableCreateAppShortcut = true; | |
562 }, | |
563 | |
564 /** | |
552 * Highlight a newly installed app as it's added to the NTP. | 565 * Highlight a newly installed app as it's added to the NTP. |
553 * @param {Object} appData The data object that describes the app. | 566 * @param {Object} appData The data object that describes the app. |
554 */ | 567 */ |
555 insertAndHighlightApp: function(appData) { | 568 insertAndHighlightApp: function(appData) { |
556 ntp.getCardSlider().selectCardByValue(this); | 569 ntp.getCardSlider().selectCardByValue(this); |
557 this.content_.scrollTop = this.content_.scrollHeight; | 570 this.content_.scrollTop = this.content_.scrollHeight; |
558 this.insertApp(appData, true); | 571 this.insertApp(appData, true); |
559 }, | 572 }, |
560 | 573 |
561 /** | 574 /** |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 function launchAppAfterEnable(appId) { | 762 function launchAppAfterEnable(appId) { |
750 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); | 763 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); |
751 } | 764 } |
752 | 765 |
753 return { | 766 return { |
754 APP_LAUNCH: APP_LAUNCH, | 767 APP_LAUNCH: APP_LAUNCH, |
755 AppsPage: AppsPage, | 768 AppsPage: AppsPage, |
756 launchAppAfterEnable: launchAppAfterEnable, | 769 launchAppAfterEnable: launchAppAfterEnable, |
757 }; | 770 }; |
758 }); | 771 }); |
OLD | NEW |