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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_(); |
49 this.launch_.addEventListener('activate', this.onLaunch_.bind(this)); | 49 this.launch_.addEventListener('activate', this.onLaunch_.bind(this)); |
50 | 50 |
51 menu.appendChild(cr.ui.MenuItem.createSeparator()); | 51 menu.appendChild(cr.ui.MenuItem.createSeparator()); |
52 if (loadTimeData.getBoolean('enableNewBookmarkApps')) | 52 this.launchRegularTab_ = this.appendMenuItem_('applaunchtyperegular'); |
53 this.launchRegularTab_ = this.appendMenuItem_('applaunchtypetab'); | |
54 else | |
55 this.launchRegularTab_ = this.appendMenuItem_('applaunchtyperegular'); | |
56 this.launchPinnedTab_ = this.appendMenuItem_('applaunchtypepinned'); | 53 this.launchPinnedTab_ = this.appendMenuItem_('applaunchtypepinned'); |
57 if (loadTimeData.getBoolean('enableNewBookmarkApps') || !cr.isMac) | 54 if (loadTimeData.getBoolean('enableNewBookmarkApps') || !cr.isMac) |
58 this.launchNewWindow_ = this.appendMenuItem_('applaunchtypewindow'); | 55 this.launchNewWindow_ = this.appendMenuItem_('applaunchtypewindow'); |
59 this.launchFullscreen_ = this.appendMenuItem_('applaunchtypefullscreen'); | 56 this.launchFullscreen_ = this.appendMenuItem_('applaunchtypefullscreen'); |
60 | 57 |
61 var self = this; | 58 var self = this; |
62 this.forAllLaunchTypes_(function(launchTypeButton, id) { | 59 this.forAllLaunchTypes_(function(launchTypeButton, id) { |
63 launchTypeButton.addEventListener('activate', | 60 launchTypeButton.addEventListener('activate', |
64 self.onLaunchTypeChanged_.bind(self)); | 61 self.onLaunchTypeChanged_.bind(self)); |
65 }); | 62 }); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 121 |
125 /** | 122 /** |
126 * Does all the necessary setup to show the menu for the given app. | 123 * Does all the necessary setup to show the menu for the given app. |
127 * @param {App} app The App object that will be showing a context menu. | 124 * @param {App} app The App object that will be showing a context menu. |
128 */ | 125 */ |
129 setupForApp: function(app) { | 126 setupForApp: function(app) { |
130 this.app_ = app; | 127 this.app_ = app; |
131 | 128 |
132 this.launch_.textContent = app.appData.title; | 129 this.launch_.textContent = app.appData.title; |
133 | 130 |
134 var launchTypeRegularTab = this.launchRegularTab_; | 131 var launchTypeWindow = this.launchNewWindow_; |
135 this.forAllLaunchTypes_(function(launchTypeButton, id) { | 132 this.forAllLaunchTypes_(function(launchTypeButton, id) { |
136 launchTypeButton.disabled = false; | 133 launchTypeButton.disabled = false; |
137 launchTypeButton.checked = app.appData.launch_type == id; | 134 launchTypeButton.checked = app.appData.launch_type == id; |
138 // If bookmark apps are enabled, only show the "Open as tab" button. | 135 // If bookmark apps are enabled, only show the "Open as window" button. |
139 launchTypeButton.hidden = app.appData.packagedApp || | 136 launchTypeButton.hidden = app.appData.packagedApp || |
140 (loadTimeData.getBoolean('enableNewBookmarkApps') && | 137 (loadTimeData.getBoolean('enableNewBookmarkApps') && |
141 launchTypeButton != launchTypeRegularTab); | 138 launchTypeButton != launchTypeWindow); |
142 }); | 139 }); |
143 | 140 |
144 this.launchTypeMenuSeparator_.hidden = app.appData.packagedApp; | 141 this.launchTypeMenuSeparator_.hidden = app.appData.packagedApp; |
145 | 142 |
146 this.options_.disabled = !app.appData.optionsUrl || !app.appData.enabled; | 143 this.options_.disabled = !app.appData.optionsUrl || !app.appData.enabled; |
147 this.details_.disabled = !app.appData.detailsUrl; | 144 this.details_.disabled = !app.appData.detailsUrl; |
148 this.uninstall_.disabled = !app.appData.mayDisable; | 145 this.uninstall_.disabled = !app.appData.mayDisable; |
149 | 146 |
150 if (cr.isMac) { | 147 if (cr.isMac) { |
151 // On Windows and Linux, these should always be visible. On ChromeOS, | 148 // On Windows and Linux, these should always be visible. On ChromeOS, |
(...skipping 12 matching lines...) Expand all Loading... |
164 onLaunch_: function(e) { | 161 onLaunch_: function(e) { |
165 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]); | 162 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]); |
166 }, | 163 }, |
167 onLaunchTypeChanged_: function(e) { | 164 onLaunchTypeChanged_: function(e) { |
168 var pressed = e.currentTarget; | 165 var pressed = e.currentTarget; |
169 var app = this.app_; | 166 var app = this.app_; |
170 var targetLaunchType = pressed; | 167 var targetLaunchType = pressed; |
171 // When bookmark apps are enabled, hosted apps can only toggle between | 168 // When bookmark apps are enabled, hosted apps can only toggle between |
172 // open as window and open as tab. | 169 // open as window and open as tab. |
173 if (loadTimeData.getBoolean('enableNewBookmarkApps')) { | 170 if (loadTimeData.getBoolean('enableNewBookmarkApps')) { |
174 targetLaunchType = this.launchRegularTab_.checked ? | 171 targetLaunchType = this.launchNewWindow_.checked ? |
175 this.launchNewWindow_ : this.launchRegularTab_; | 172 this.launchRegularTab_ : this.launchNewWindow_; |
176 } | 173 } |
177 this.forAllLaunchTypes_(function(launchTypeButton, id) { | 174 this.forAllLaunchTypes_(function(launchTypeButton, id) { |
178 if (launchTypeButton == targetLaunchType) { | 175 if (launchTypeButton == targetLaunchType) { |
179 chrome.send('setLaunchType', [app.appId, id]); | 176 chrome.send('setLaunchType', [app.appId, id]); |
180 // Manually update the launch type. We will only get | 177 // Manually update the launch type. We will only get |
181 // appsPrefChangeCallback calls after changes to other NTP instances. | 178 // appsPrefChangeCallback calls after changes to other NTP instances. |
182 app.appData.launch_type = id; | 179 app.appData.launch_type = id; |
183 } | 180 } |
184 }); | 181 }); |
185 }, | 182 }, |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 function launchAppAfterEnable(appId) { | 767 function launchAppAfterEnable(appId) { |
771 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); | 768 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); |
772 } | 769 } |
773 | 770 |
774 return { | 771 return { |
775 APP_LAUNCH: APP_LAUNCH, | 772 APP_LAUNCH: APP_LAUNCH, |
776 AppsPage: AppsPage, | 773 AppsPage: AppsPage, |
777 launchAppAfterEnable: launchAppAfterEnable, | 774 launchAppAfterEnable: launchAppAfterEnable, |
778 }; | 775 }; |
779 }); | 776 }); |
OLD | NEW |