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 = { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 this.launchFullscreen_ = this.appendMenuItem_('applaunchtypefullscreen'); | 56 this.launchFullscreen_ = this.appendMenuItem_('applaunchtypefullscreen'); |
57 | 57 |
58 var self = this; | 58 var self = this; |
59 this.forAllLaunchTypes_(function(launchTypeButton, id) { | 59 this.forAllLaunchTypes_(function(launchTypeButton, id) { |
60 launchTypeButton.addEventListener('activate', | 60 launchTypeButton.addEventListener('activate', |
61 self.onLaunchTypeChanged_.bind(self)); | 61 self.onLaunchTypeChanged_.bind(self)); |
62 }); | 62 }); |
63 | 63 |
64 menu.appendChild(cr.ui.MenuItem.createSeparator()); | 64 menu.appendChild(cr.ui.MenuItem.createSeparator()); |
65 this.options_ = this.appendMenuItem_('appoptions'); | 65 this.options_ = this.appendMenuItem_('appoptions'); |
66 this.disableNotifications_ = | |
67 this.appendMenuItem_('appdisablenotifications'); | |
66 this.uninstall_ = this.appendMenuItem_('appuninstall'); | 68 this.uninstall_ = this.appendMenuItem_('appuninstall'); |
67 this.options_.addEventListener('activate', | 69 this.options_.addEventListener('activate', |
68 this.onShowOptions_.bind(this)); | 70 this.onShowOptions_.bind(this)); |
71 this.disableNotifications_.addEventListener( | |
72 'activate', this.onDisableNotifications_.bind(this)); | |
69 this.uninstall_.addEventListener('activate', | 73 this.uninstall_.addEventListener('activate', |
70 this.onUninstall_.bind(this)); | 74 this.onUninstall_.bind(this)); |
71 | 75 |
72 if (!cr.isMac && !cr.isChromeOS) { | 76 if (!cr.isMac && !cr.isChromeOS) { |
73 menu.appendChild(cr.ui.MenuItem.createSeparator()); | 77 menu.appendChild(cr.ui.MenuItem.createSeparator()); |
74 this.createShortcut_ = this.appendMenuItem_('appcreateshortcut'); | 78 this.createShortcut_ = this.appendMenuItem_('appcreateshortcut'); |
75 this.createShortcut_.addEventListener( | 79 this.createShortcut_.addEventListener( |
76 'activate', this.onCreateShortcut_.bind(this)); | 80 'activate', this.onCreateShortcut_.bind(this)); |
77 } | 81 } |
78 | 82 |
(...skipping 29 matching lines...) Expand all Loading... | |
108 | 112 |
109 for (var i = 0; i < launchTypes.length; ++i) { | 113 for (var i = 0; i < launchTypes.length; ++i) { |
110 if (!launchTypes[i]) | 114 if (!launchTypes[i]) |
111 continue; | 115 continue; |
112 | 116 |
113 f(launchTypes[i], i); | 117 f(launchTypes[i], i); |
114 } | 118 } |
115 }, | 119 }, |
116 | 120 |
117 /** | 121 /** |
118 * Does all the necessary setup to show the menu for the give app. | 122 * Does all the necessary setup to show the menu for the given app. |
119 * @param {App} app The App object that will be showing a context menu. | 123 * @param {App} app The App object that will be showing a context menu. |
120 */ | 124 */ |
121 setupForApp: function(app) { | 125 setupForApp: function(app) { |
122 this.app_ = app; | 126 this.app_ = app; |
123 | 127 |
124 this.launch_.textContent = app.appData.title; | 128 this.launch_.textContent = app.appData.title; |
125 | 129 |
126 this.forAllLaunchTypes_(function(launchTypeButton, id) { | 130 this.forAllLaunchTypes_(function(launchTypeButton, id) { |
127 launchTypeButton.disabled = false; | 131 launchTypeButton.disabled = false; |
128 launchTypeButton.checked = app.appData.launch_type == id; | 132 launchTypeButton.checked = app.appData.launch_type == id; |
129 }); | 133 }); |
130 | 134 |
131 this.options_.disabled = !app.appData.options_url || !app.appData.enabled; | 135 this.options_.disabled = !app.appData.options_url || !app.appData.enabled; |
132 this.uninstall_.disabled = !app.appData.can_uninstall; | 136 this.uninstall_.disabled = !app.appData.can_uninstall; |
137 | |
138 this.disableNotifications_.hidden = true; | |
139 var notificationsDisabled = app.appData.notifications_disabled; | |
140 if (typeof notificationsDisabled != 'undefined') { | |
141 this.disableNotifications_.hidden = false; | |
142 this.disableNotifications_.checked = notificationsDisabled; | |
143 } | |
133 }, | 144 }, |
134 | 145 |
135 /** | 146 /** |
136 * Handlers for menu item activation. | 147 * Handlers for menu item activation. |
137 * @param {Event} e The activation event. | 148 * @param {Event} e The activation event. |
138 * @private | 149 * @private |
139 */ | 150 */ |
140 onLaunch_: function(e) { | 151 onLaunch_: function(e) { |
141 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]); | 152 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]); |
142 }, | 153 }, |
143 onLaunchTypeChanged_: function(e) { | 154 onLaunchTypeChanged_: function(e) { |
144 var pressed = e.currentTarget; | 155 var pressed = e.currentTarget; |
145 var app = this.app_; | 156 var app = this.app_; |
146 this.forAllLaunchTypes_(function(launchTypeButton, id) { | 157 this.forAllLaunchTypes_(function(launchTypeButton, id) { |
147 if (launchTypeButton == pressed) { | 158 if (launchTypeButton == pressed) { |
148 chrome.send('setLaunchType', [app.appId, id]); | 159 chrome.send('setLaunchType', [app.appId, id]); |
149 // Manually update the launch type. We will only get | 160 // Manually update the launch type. We will only get |
150 // appsPrefChangeCallback calls after changes to other NTP instances. | 161 // appsPrefChangeCallback calls after changes to other NTP instances. |
151 app.appData.launch_type = id; | 162 app.appData.launch_type = id; |
152 } | 163 } |
153 }); | 164 }); |
154 }, | 165 }, |
155 onShowOptions_: function(e) { | 166 onShowOptions_: function(e) { |
156 window.location = this.app_.appData.options_url; | 167 window.location = this.app_.appData.options_url; |
157 }, | 168 }, |
169 onDisableNotifications_: function(e) { | |
170 var app = this.app_; | |
171 var disabled = this.disableNotifications_.checked; | |
172 app.removeBubble(); | |
173 app.appData.notifications_disabled = !disabled; | |
Evan Stade
2011/12/05 23:19:32
as it stands, isn't this backwards
asargent_no_longer_on_chrome
2011/12/06 00:14:55
Nope, this event handler toggles the sense of the
Evan Stade
2011/12/06 01:27:08
ah, I think the confusion is about whether checked
| |
174 chrome.send('setNotificationsDisabled', | |
175 [app.appData.id, app.appData.notifications_disabled]); | |
Evan Stade
2011/12/05 23:19:32
nit: s/app.appData.notifications_disabled/disabled
asargent_no_longer_on_chrome
2011/12/06 00:14:55
fixed by refactor
| |
176 }, | |
158 onUninstall_: function(e) { | 177 onUninstall_: function(e) { |
159 chrome.send('uninstallApp', [this.app_.appData.id]); | 178 chrome.send('uninstallApp', [this.app_.appData.id]); |
160 }, | 179 }, |
161 onCreateShortcut_: function(e) { | 180 onCreateShortcut_: function(e) { |
162 chrome.send('createAppShortcut', [this.app_.appData.id]); | 181 chrome.send('createAppShortcut', [this.app_.appData.id]); |
163 }, | 182 }, |
164 }; | 183 }; |
165 | 184 |
166 /** | 185 /** |
167 * Creates a new App object. | 186 * Creates a new App object. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 this.appImgContainer_.title = this.appData_.title; | 234 this.appImgContainer_.title = this.appData_.title; |
216 } | 235 } |
217 | 236 |
218 var appSpan = this.appContents_.querySelector('.title'); | 237 var appSpan = this.appContents_.querySelector('.title'); |
219 appSpan.textContent = appSpan.title = this.appData_.title; | 238 appSpan.textContent = appSpan.title = this.appData_.title; |
220 this.addLaunchClickTarget_(appSpan); | 239 this.addLaunchClickTarget_(appSpan); |
221 | 240 |
222 var notification = this.appData_.notification; | 241 var notification = this.appData_.notification; |
223 var hasNotification = typeof notification != 'undefined' && | 242 var hasNotification = typeof notification != 'undefined' && |
224 typeof notification['title'] != 'undefined' && | 243 typeof notification['title'] != 'undefined' && |
225 typeof notification['body'] != 'undefined'; | 244 typeof notification['body'] != 'undefined' && |
245 !this.appData_.notifications_disabled; | |
226 if (hasNotification) | 246 if (hasNotification) |
227 this.setupNotification_(notification); | 247 this.setupNotification_(notification); |
228 | 248 |
229 this.addEventListener('keydown', cr.ui.contextMenuHandler); | 249 this.addEventListener('keydown', cr.ui.contextMenuHandler); |
230 this.addEventListener('keyup', cr.ui.contextMenuHandler); | 250 this.addEventListener('keyup', cr.ui.contextMenuHandler); |
231 | 251 |
232 // 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 |
233 // this.contextMenu. | 253 // this.contextMenu. |
234 var self = this; | 254 var self = this; |
235 this.appContents_.__defineGetter__('contextMenu', function() { | 255 this.appContents_.__defineGetter__('contextMenu', function() { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 } | 369 } |
350 infoBubble.contentTitle = this.createBubbleNode_(notification, false); | 370 infoBubble.contentTitle = this.createBubbleNode_(notification, false); |
351 infoBubble.content = this.createBubbleNode_(notification, true); | 371 infoBubble.content = this.createBubbleNode_(notification, true); |
352 infoBubble.show(); | 372 infoBubble.show(); |
353 | 373 |
354 this.currentBubbleShowing_ = infoBubble; | 374 this.currentBubbleShowing_ = infoBubble; |
355 } | 375 } |
356 }, | 376 }, |
357 | 377 |
358 /** | 378 /** |
379 * Removes the info bubble if there is one. | |
380 */ | |
381 removeBubble: function() { | |
382 if (this.currentBubbleShowing_) { | |
383 this.currentBubbleShowing_.hide(); | |
384 this.currentBubbleShowing_ = null; | |
385 } | |
386 }, | |
387 | |
388 /** | |
359 * Creates the apps-promo section of the app (should only be called for the | 389 * Creates the apps-promo section of the app (should only be called for the |
360 * webstore app). | 390 * webstore app). |
361 * @private | 391 * @private |
362 */ | 392 */ |
363 createAppsPromoExtras_: function() { | 393 createAppsPromoExtras_: function() { |
364 this.classList.add('webstore'); | 394 this.classList.add('webstore'); |
365 | 395 |
366 this.appsPromoExtras_ = $('apps-promo-extras-template').cloneNode(true); | 396 this.appsPromoExtras_ = $('apps-promo-extras-template').cloneNode(true); |
367 this.appsPromoExtras_.id = ''; | 397 this.appsPromoExtras_.id = ''; |
368 this.appsPromoHeading_ = | 398 this.appsPromoHeading_ = |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
784 * Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE | 814 * Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE |
785 * histogram. This should only be invoked from the AppLauncherHandler. | 815 * histogram. This should only be invoked from the AppLauncherHandler. |
786 * @param {String} appID The ID of the app. | 816 * @param {String} appID The ID of the app. |
787 */ | 817 */ |
788 function launchAppAfterEnable(appId) { | 818 function launchAppAfterEnable(appId) { |
789 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); | 819 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); |
790 }; | 820 }; |
791 | 821 |
792 function appNotificationChanged(id, notification) { | 822 function appNotificationChanged(id, notification) { |
793 var app = $(id); | 823 var app = $(id); |
794 if (app) // The app might have been uninstalled. | 824 // The app might have been uninstalled, or notifications might be disabled. |
825 if (app && !app.appData.notifications_disabled) | |
795 app.setupNotification_(notification); | 826 app.setupNotification_(notification); |
796 }; | 827 }; |
797 | 828 |
798 return { | 829 return { |
799 APP_LAUNCH: APP_LAUNCH, | 830 APP_LAUNCH: APP_LAUNCH, |
800 appNotificationChanged: appNotificationChanged, | 831 appNotificationChanged: appNotificationChanged, |
801 AppsPage: AppsPage, | 832 AppsPage: AppsPage, |
802 launchAppAfterEnable: launchAppAfterEnable, | 833 launchAppAfterEnable: launchAppAfterEnable, |
803 }; | 834 }; |
804 }); | 835 }); |
805 | 836 |
806 // TODO(estade): update the content handlers to use ntp namespace instead of | 837 // TODO(estade): update the content handlers to use ntp namespace instead of |
807 // making these global. | 838 // making these global. |
808 var appNotificationChanged = ntp4.appNotificationChanged; | 839 var appNotificationChanged = ntp4.appNotificationChanged; |
809 var launchAppAfterEnable = ntp4.launchAppAfterEnable; | 840 var launchAppAfterEnable = ntp4.launchAppAfterEnable; |
OLD | NEW |