Chromium Code Reviews| 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; | |
|
Finnur
2011/12/05 16:15:16
The underscore in appData_ denotes private, you sh
asargent_no_longer_on_chrome
2011/12/05 17:42:39
Done.
| |
| 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 currentlyDisabled = app.appData_.notifications_disabled; | |
| 172 if (!currentlyDisabled && app.currentBubbleShowing_) { | |
|
Finnur
2011/12/05 16:15:16
same problem here, _ means private.
asargent_no_longer_on_chrome
2011/12/05 17:42:39
Done.
Finnur
2011/12/05 17:50:00
I was referring to currentBubbleShowing_ ...
On
asargent_no_longer_on_chrome
2011/12/05 18:21:05
Oops, fixed. I added a method called removeBubble
| |
| 173 app.currentBubbleShowing_.hide(); | |
| 174 app.currentBubbleShowing_ = null; | |
| 175 } | |
| 176 app.appData_.notifications_disabled = !currentlyDisabled; | |
| 177 chrome.send('setNotificationsDisabled', | |
| 178 [app.appData.id, app.appData_.notifications_disabled]); | |
| 179 }, | |
| 158 onUninstall_: function(e) { | 180 onUninstall_: function(e) { |
| 159 chrome.send('uninstallApp', [this.app_.appData.id]); | 181 chrome.send('uninstallApp', [this.app_.appData.id]); |
| 160 }, | 182 }, |
| 161 onCreateShortcut_: function(e) { | 183 onCreateShortcut_: function(e) { |
| 162 chrome.send('createAppShortcut', [this.app_.appData.id]); | 184 chrome.send('createAppShortcut', [this.app_.appData.id]); |
| 163 }, | 185 }, |
| 164 }; | 186 }; |
| 165 | 187 |
| 166 /** | 188 /** |
| 167 * Creates a new App object. | 189 * 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; | 237 this.appImgContainer_.title = this.appData_.title; |
| 216 } | 238 } |
| 217 | 239 |
| 218 var appSpan = this.appContents_.querySelector('.title'); | 240 var appSpan = this.appContents_.querySelector('.title'); |
| 219 appSpan.textContent = appSpan.title = this.appData_.title; | 241 appSpan.textContent = appSpan.title = this.appData_.title; |
| 220 this.addLaunchClickTarget_(appSpan); | 242 this.addLaunchClickTarget_(appSpan); |
| 221 | 243 |
| 222 var notification = this.appData_.notification; | 244 var notification = this.appData_.notification; |
| 223 var hasNotification = typeof notification != 'undefined' && | 245 var hasNotification = typeof notification != 'undefined' && |
| 224 typeof notification['title'] != 'undefined' && | 246 typeof notification['title'] != 'undefined' && |
| 225 typeof notification['body'] != 'undefined'; | 247 typeof notification['body'] != 'undefined' && |
| 248 !this.appData_.notifications_disabled; | |
| 226 if (hasNotification) | 249 if (hasNotification) |
| 227 this.setupNotification_(notification); | 250 this.setupNotification_(notification); |
| 228 | 251 |
| 229 this.addEventListener('keydown', cr.ui.contextMenuHandler); | 252 this.addEventListener('keydown', cr.ui.contextMenuHandler); |
| 230 this.addEventListener('keyup', cr.ui.contextMenuHandler); | 253 this.addEventListener('keyup', cr.ui.contextMenuHandler); |
| 231 | 254 |
| 232 // This hack is here so that appContents.contextMenu will be the same as | 255 // This hack is here so that appContents.contextMenu will be the same as |
| 233 // this.contextMenu. | 256 // this.contextMenu. |
| 234 var self = this; | 257 var self = this; |
| 235 this.appContents_.__defineGetter__('contextMenu', function() { | 258 this.appContents_.__defineGetter__('contextMenu', function() { |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 784 * Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE | 807 * Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE |
| 785 * histogram. This should only be invoked from the AppLauncherHandler. | 808 * histogram. This should only be invoked from the AppLauncherHandler. |
| 786 * @param {String} appID The ID of the app. | 809 * @param {String} appID The ID of the app. |
| 787 */ | 810 */ |
| 788 function launchAppAfterEnable(appId) { | 811 function launchAppAfterEnable(appId) { |
| 789 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); | 812 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); |
| 790 }; | 813 }; |
| 791 | 814 |
| 792 function appNotificationChanged(id, notification) { | 815 function appNotificationChanged(id, notification) { |
| 793 var app = $(id); | 816 var app = $(id); |
| 794 if (app) // The app might have been uninstalled. | 817 // The app might have been uninstalled, or notifications might be disabled. |
| 818 if (app && !app.appData_.notifications_disabled) | |
| 795 app.setupNotification_(notification); | 819 app.setupNotification_(notification); |
| 796 }; | 820 }; |
| 797 | 821 |
| 798 return { | 822 return { |
| 799 APP_LAUNCH: APP_LAUNCH, | 823 APP_LAUNCH: APP_LAUNCH, |
| 800 appNotificationChanged: appNotificationChanged, | 824 appNotificationChanged: appNotificationChanged, |
| 801 AppsPage: AppsPage, | 825 AppsPage: AppsPage, |
| 802 launchAppAfterEnable: launchAppAfterEnable, | 826 launchAppAfterEnable: launchAppAfterEnable, |
| 803 }; | 827 }; |
| 804 }); | 828 }); |
| 805 | 829 |
| 806 // TODO(estade): update the content handlers to use ntp namespace instead of | 830 // TODO(estade): update the content handlers to use ntp namespace instead of |
| 807 // making these global. | 831 // making these global. |
| 808 var appNotificationChanged = ntp4.appNotificationChanged; | 832 var appNotificationChanged = ntp4.appNotificationChanged; |
| 809 var launchAppAfterEnable = ntp4.launchAppAfterEnable; | 833 var launchAppAfterEnable = ntp4.launchAppAfterEnable; |
| OLD | NEW |