OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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('extensions', function() { | 5 cr.define('extensions', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * @constructor | |
10 * @implements {extensions.ErrorPageDelegate} | 9 * @implements {extensions.ErrorPageDelegate} |
11 * @implements {extensions.ItemDelegate} | 10 * @implements {extensions.ItemDelegate} |
12 * @implements {extensions.LoadErrorDelegate} | 11 * @implements {extensions.LoadErrorDelegate} |
13 * @implements {extensions.PackDialogDelegate} | 12 * @implements {extensions.PackDialogDelegate} |
14 * @implements {extensions.ToolbarDelegate} | 13 * @implements {extensions.ToolbarDelegate} |
15 */ | 14 */ |
16 function Service() {} | 15 class Service { |
| 16 constructor() { |
| 17 /** @private {boolean} */ |
| 18 this.isDeleting_ = false; |
17 | 19 |
18 Service.prototype = { | 20 /** @private {extensions.Manager} */ |
19 /** @private {boolean} */ | 21 this.manager_; |
20 isDeleting_: false, | 22 |
| 23 /** @private {Array<chrome.developerPrivate.ExtensionInfo>} */ |
| 24 this.extensions_; |
| 25 } |
21 | 26 |
22 /** @param {extensions.Manager} manager */ | 27 /** @param {extensions.Manager} manager */ |
23 managerReady: function(manager) { | 28 managerReady(manager) { |
24 /** @private {extensions.Manager} */ | |
25 this.manager_ = manager; | 29 this.manager_ = manager; |
26 this.manager_.toolbar.setDelegate(this); | 30 this.manager_.toolbar.setDelegate(this); |
27 this.manager_.set('itemDelegate', this); | 31 this.manager_.set('itemDelegate', this); |
28 this.manager_.packDialog.set('delegate', this); | 32 this.manager_.packDialog.set('delegate', this); |
29 this.manager_.loadError.set('delegate', this); | 33 this.manager_.loadError.set('delegate', this); |
30 this.manager_.errorPage.delegate = this; | 34 this.manager_.errorPage.delegate = this; |
31 var keyboardShortcuts = this.manager_.keyboardShortcuts; | 35 var keyboardShortcuts = this.manager_.keyboardShortcuts; |
32 keyboardShortcuts.addEventListener( | 36 keyboardShortcuts.addEventListener( |
33 'shortcut-updated', this.onExtensionCommandUpdated_.bind(this)); | 37 'shortcut-updated', this.onExtensionCommandUpdated_.bind(this)); |
34 keyboardShortcuts.addEventListener( | 38 keyboardShortcuts.addEventListener( |
35 'shortcut-capture-started', | 39 'shortcut-capture-started', |
36 this.onShortcutCaptureChanged_.bind(this, true)); | 40 this.onShortcutCaptureChanged_.bind(this, true)); |
37 keyboardShortcuts.addEventListener( | 41 keyboardShortcuts.addEventListener( |
38 'shortcut-capture-ended', | 42 'shortcut-capture-ended', |
39 this.onShortcutCaptureChanged_.bind(this, false)); | 43 this.onShortcutCaptureChanged_.bind(this, false)); |
40 chrome.developerPrivate.onProfileStateChanged.addListener( | 44 chrome.developerPrivate.onProfileStateChanged.addListener( |
41 this.onProfileStateChanged_.bind(this)); | 45 this.onProfileStateChanged_.bind(this)); |
42 chrome.developerPrivate.onItemStateChanged.addListener( | 46 chrome.developerPrivate.onItemStateChanged.addListener( |
43 this.onItemStateChanged_.bind(this)); | 47 this.onItemStateChanged_.bind(this)); |
44 chrome.developerPrivate.getExtensionsInfo( | 48 chrome.developerPrivate.getExtensionsInfo( |
45 {includeDisabled: true, includeTerminated: true}, | 49 {includeDisabled: true, includeTerminated: true}, |
46 function(extensions) { | 50 function(extensions) { |
47 /** @private {Array<chrome.developerPrivate.ExtensionInfo>} */ | |
48 this.extensions_ = extensions; | 51 this.extensions_ = extensions; |
49 for (let extension of extensions) | 52 for (let extension of extensions) |
50 this.manager_.addItem(extension); | 53 this.manager_.addItem(extension); |
51 | 54 |
52 this.manager_.initPage(); | 55 this.manager_.initPage(); |
53 }.bind(this)); | 56 }.bind(this)); |
54 chrome.developerPrivate.getProfileConfiguration( | 57 chrome.developerPrivate.getProfileConfiguration( |
55 this.onProfileStateChanged_.bind(this)); | 58 this.onProfileStateChanged_.bind(this)); |
56 }, | 59 } |
57 | 60 |
58 /** | 61 /** |
59 * @param {chrome.developerPrivate.ProfileInfo} profileInfo | 62 * @param {chrome.developerPrivate.ProfileInfo} profileInfo |
60 * @private | 63 * @private |
61 */ | 64 */ |
62 onProfileStateChanged_: function(profileInfo) { | 65 onProfileStateChanged_(profileInfo) { |
63 this.manager_.set('inDevMode', profileInfo.inDeveloperMode); | 66 this.manager_.set('inDevMode', profileInfo.inDeveloperMode); |
64 }, | 67 } |
65 | 68 |
66 /** | 69 /** |
67 * @param {chrome.developerPrivate.EventData} eventData | 70 * @param {chrome.developerPrivate.EventData} eventData |
68 * @private | 71 * @private |
69 */ | 72 */ |
70 onItemStateChanged_: function(eventData) { | 73 onItemStateChanged_(eventData) { |
71 var currentIndex = this.extensions_.findIndex(function(extension) { | 74 var currentIndex = this.extensions_.findIndex(function(extension) { |
72 return extension.id == eventData.item_id; | 75 return extension.id == eventData.item_id; |
73 }); | 76 }); |
74 | 77 |
75 var EventType = chrome.developerPrivate.EventType; | 78 var EventType = chrome.developerPrivate.EventType; |
76 switch (eventData.event_type) { | 79 switch (eventData.event_type) { |
77 case EventType.VIEW_REGISTERED: | 80 case EventType.VIEW_REGISTERED: |
78 case EventType.VIEW_UNREGISTERED: | 81 case EventType.VIEW_UNREGISTERED: |
79 case EventType.INSTALLED: | 82 case EventType.INSTALLED: |
80 case EventType.LOADED: | 83 case EventType.LOADED: |
(...skipping 15 matching lines...) Expand all Loading... |
96 this.manager_.addItem(eventData.extensionInfo); | 99 this.manager_.addItem(eventData.extensionInfo); |
97 } | 100 } |
98 break; | 101 break; |
99 case EventType.UNINSTALLED: | 102 case EventType.UNINSTALLED: |
100 this.manager_.removeItem(this.extensions_[currentIndex]); | 103 this.manager_.removeItem(this.extensions_[currentIndex]); |
101 this.extensions_.splice(currentIndex, 1); | 104 this.extensions_.splice(currentIndex, 1); |
102 break; | 105 break; |
103 default: | 106 default: |
104 assertNotReached(); | 107 assertNotReached(); |
105 } | 108 } |
106 }, | 109 } |
107 | 110 |
108 /** | 111 /** |
109 * Opens a file browser dialog for the user to select a file (or directory). | 112 * Opens a file browser dialog for the user to select a file (or directory). |
110 * @param {chrome.developerPrivate.SelectType} selectType | 113 * @param {chrome.developerPrivate.SelectType} selectType |
111 * @param {chrome.developerPrivate.FileType} fileType | 114 * @param {chrome.developerPrivate.FileType} fileType |
112 * @return {Promise<string>} The promise to be resolved with the selected | 115 * @return {Promise<string>} The promise to be resolved with the selected |
113 * path. | 116 * path. |
114 */ | 117 */ |
115 chooseFilePath_: function(selectType, fileType) { | 118 chooseFilePath_(selectType, fileType) { |
116 return new Promise(function(resolve, reject) { | 119 return new Promise(function(resolve, reject) { |
117 chrome.developerPrivate.choosePath( | 120 chrome.developerPrivate.choosePath( |
118 selectType, fileType, function(path) { | 121 selectType, fileType, function(path) { |
119 if (chrome.runtime.lastError && | 122 if (chrome.runtime.lastError && |
120 chrome.runtime.lastError != 'File selection was canceled.') { | 123 chrome.runtime.lastError != 'File selection was canceled.') { |
121 reject(chrome.runtime.lastError); | 124 reject(chrome.runtime.lastError); |
122 } else { | 125 } else { |
123 resolve(path || ''); | 126 resolve(path || ''); |
124 } | 127 } |
125 }); | 128 }); |
126 }); | 129 }); |
127 }, | 130 } |
128 | 131 |
129 /** | 132 /** |
130 * Updates an extension command. | 133 * Updates an extension command. |
131 * @param {!CustomEvent} e | 134 * @param {!CustomEvent} e |
132 * @private | 135 * @private |
133 */ | 136 */ |
134 onExtensionCommandUpdated_: function(e) { | 137 onExtensionCommandUpdated_(e) { |
135 chrome.developerPrivate.updateExtensionCommand({ | 138 chrome.developerPrivate.updateExtensionCommand({ |
136 extensionId: e.detail.item, | 139 extensionId: e.detail.item, |
137 commandName: e.detail.commandName, | 140 commandName: e.detail.commandName, |
138 keybinding: e.detail.keybinding, | 141 keybinding: e.detail.keybinding, |
139 }); | 142 }); |
140 }, | 143 } |
141 | 144 |
142 /** | 145 /** |
143 * Called when shortcut capturing changes in order to suspend or re-enable | 146 * Called when shortcut capturing changes in order to suspend or re-enable |
144 * global shortcut handling. This is important so that the shortcuts aren't | 147 * global shortcut handling. This is important so that the shortcuts aren't |
145 * processed normally as the user types them. | 148 * processed normally as the user types them. |
146 * TODO(devlin): From very brief experimentation, it looks like preventing | 149 * TODO(devlin): From very brief experimentation, it looks like preventing |
147 * the default handling on the event also does this. Investigate more in the | 150 * the default handling on the event also does this. Investigate more in the |
148 * future. | 151 * future. |
149 * @param {boolean} isCapturing | 152 * @param {boolean} isCapturing |
150 * @param {!CustomEvent} e | 153 * @param {!CustomEvent} e |
151 * @private | 154 * @private |
152 */ | 155 */ |
153 onShortcutCaptureChanged_: function(isCapturing, e) { | 156 onShortcutCaptureChanged_(isCapturing, e) { |
154 chrome.developerPrivate.setShortcutHandlingSuspended(isCapturing); | 157 chrome.developerPrivate.setShortcutHandlingSuspended(isCapturing); |
155 }, | 158 } |
156 | 159 |
157 /** | 160 /** |
158 * Attempts to load an unpacked extension, optionally as another attempt at | 161 * Attempts to load an unpacked extension, optionally as another attempt at |
159 * a previously-specified load. | 162 * a previously-specified load. |
160 * @param {string=} opt_retryGuid | 163 * @param {string=} opt_retryGuid |
161 * @private | 164 * @private |
162 */ | 165 */ |
163 loadUnpackedHelper_: function(opt_retryGuid) { | 166 loadUnpackedHelper_(opt_retryGuid) { |
164 chrome.developerPrivate.loadUnpacked( | 167 chrome.developerPrivate.loadUnpacked( |
165 {failQuietly: true, populateError: true, retryGuid: opt_retryGuid}, | 168 {failQuietly: true, populateError: true, retryGuid: opt_retryGuid}, |
166 (loadError) => { | 169 (loadError) => { |
167 if (chrome.runtime.lastError && | 170 if (chrome.runtime.lastError && |
168 chrome.runtime.lastError.message != | 171 chrome.runtime.lastError.message != |
169 'File selection was canceled.') { | 172 'File selection was canceled.') { |
170 throw new Error(chrome.runtime.lastError.message); | 173 throw new Error(chrome.runtime.lastError.message); |
171 } | 174 } |
172 if (loadError) { | 175 if (loadError) { |
173 this.manager_.loadError.loadError = loadError; | 176 this.manager_.loadError.loadError = loadError; |
174 this.manager_.loadError.show(); | 177 this.manager_.loadError.show(); |
175 } | 178 } |
176 }); | 179 }); |
177 }, | 180 } |
178 | 181 |
179 /** @override */ | 182 /** @override */ |
180 deleteItem: function(id) { | 183 deleteItem(id) { |
181 if (this.isDeleting_) | 184 if (this.isDeleting_) |
182 return; | 185 return; |
183 this.isDeleting_ = true; | 186 this.isDeleting_ = true; |
184 chrome.management.uninstall(id, {showConfirmDialog: true}, function() { | 187 chrome.management.uninstall(id, {showConfirmDialog: true}, function() { |
185 // The "last error" was almost certainly the user canceling the dialog. | 188 // The "last error" was almost certainly the user canceling the dialog. |
186 // Do nothing. We only check it so we don't get noisy logs. | 189 // Do nothing. We only check it so we don't get noisy logs. |
187 /** @suppress {suspiciousCode} */ | 190 /** @suppress {suspiciousCode} */ |
188 chrome.runtime.lastError; | 191 chrome.runtime.lastError; |
189 this.isDeleting_ = false; | 192 this.isDeleting_ = false; |
190 }.bind(this)); | 193 }.bind(this)); |
191 }, | 194 } |
192 | 195 |
193 /** @override */ | 196 /** @override */ |
194 setItemEnabled: function(id, isEnabled) { | 197 setItemEnabled(id, isEnabled) { |
195 chrome.management.setEnabled(id, isEnabled); | 198 chrome.management.setEnabled(id, isEnabled); |
196 }, | 199 } |
197 | 200 |
198 /** @override */ | 201 /** @override */ |
199 setItemAllowedIncognito: function(id, isAllowedIncognito) { | 202 setItemAllowedIncognito(id, isAllowedIncognito) { |
200 chrome.developerPrivate.updateExtensionConfiguration({ | 203 chrome.developerPrivate.updateExtensionConfiguration({ |
201 extensionId: id, | 204 extensionId: id, |
202 incognitoAccess: isAllowedIncognito, | 205 incognitoAccess: isAllowedIncognito, |
203 }); | 206 }); |
204 }, | 207 } |
205 | 208 |
206 /** @override */ | 209 /** @override */ |
207 setItemAllowedOnFileUrls: function(id, isAllowedOnFileUrls) { | 210 setItemAllowedOnFileUrls(id, isAllowedOnFileUrls) { |
208 chrome.developerPrivate.updateExtensionConfiguration({ | 211 chrome.developerPrivate.updateExtensionConfiguration({ |
209 extensionId: id, | 212 extensionId: id, |
210 fileAccess: isAllowedOnFileUrls, | 213 fileAccess: isAllowedOnFileUrls, |
211 }); | 214 }); |
212 }, | 215 } |
213 | 216 |
214 /** @override */ | 217 /** @override */ |
215 setItemAllowedOnAllSites: function(id, isAllowedOnAllSites) { | 218 setItemAllowedOnAllSites(id, isAllowedOnAllSites) { |
216 chrome.developerPrivate.updateExtensionConfiguration({ | 219 chrome.developerPrivate.updateExtensionConfiguration({ |
217 extensionId: id, | 220 extensionId: id, |
218 runOnAllUrls: isAllowedOnAllSites, | 221 runOnAllUrls: isAllowedOnAllSites, |
219 }); | 222 }); |
220 }, | 223 } |
221 | 224 |
222 /** @override */ | 225 /** @override */ |
223 setItemCollectsErrors: function(id, collectsErrors) { | 226 setItemCollectsErrors(id, collectsErrors) { |
224 chrome.developerPrivate.updateExtensionConfiguration({ | 227 chrome.developerPrivate.updateExtensionConfiguration({ |
225 extensionId: id, | 228 extensionId: id, |
226 errorCollection: collectsErrors, | 229 errorCollection: collectsErrors, |
227 }); | 230 }); |
228 }, | 231 } |
229 | 232 |
230 /** @override */ | 233 /** @override */ |
231 inspectItemView: function(id, view) { | 234 inspectItemView(id, view) { |
232 chrome.developerPrivate.openDevTools({ | 235 chrome.developerPrivate.openDevTools({ |
233 extensionId: id, | 236 extensionId: id, |
234 renderProcessId: view.renderProcessId, | 237 renderProcessId: view.renderProcessId, |
235 renderViewId: view.renderViewId, | 238 renderViewId: view.renderViewId, |
236 incognito: view.incognito, | 239 incognito: view.incognito, |
237 }); | 240 }); |
238 }, | 241 } |
239 | 242 |
240 /** @override */ | 243 /** @override */ |
241 reloadItem: function(id) { | 244 reloadItem(id) { |
242 chrome.developerPrivate.reload(id, {failQuietly: false}); | 245 chrome.developerPrivate.reload(id, {failQuietly: false}); |
243 }, | 246 } |
244 | 247 |
245 /** @override */ | 248 /** @override */ |
246 repairItem: function(id) { | 249 repairItem(id) { |
247 chrome.developerPrivate.repairExtension(id); | 250 chrome.developerPrivate.repairExtension(id); |
248 }, | 251 } |
249 | 252 |
250 /** @override */ | 253 /** @override */ |
251 showItemOptionsPage: function(id) { | 254 showItemOptionsPage(id) { |
252 var extension = this.extensions_.find(function(e) { | 255 var extension = this.extensions_.find(function(e) { |
253 return e.id == id; | 256 return e.id == id; |
254 }); | 257 }); |
255 assert(extension && extension.optionsPage); | 258 assert(extension && extension.optionsPage); |
256 if (extension.optionsPage.openInTab) { | 259 if (extension.optionsPage.openInTab) { |
257 chrome.developerPrivate.showOptions(id); | 260 chrome.developerPrivate.showOptions(id); |
258 } else { | 261 } else { |
259 this.manager_.changePage( | 262 this.manager_.changePage( |
260 {page: Page.DETAILS, subpage: Dialog.OPTIONS, extensionId: id}); | 263 {page: Page.DETAILS, subpage: Dialog.OPTIONS, extensionId: id}); |
261 } | 264 } |
262 }, | 265 } |
263 | 266 |
264 /** @override */ | 267 /** @override */ |
265 setProfileInDevMode: function(inDevMode) { | 268 setProfileInDevMode(inDevMode) { |
266 chrome.developerPrivate.updateProfileConfiguration( | 269 chrome.developerPrivate.updateProfileConfiguration( |
267 {inDeveloperMode: inDevMode}); | 270 {inDeveloperMode: inDevMode}); |
268 }, | 271 } |
269 | 272 |
270 /** @override */ | 273 /** @override */ |
271 loadUnpacked: function() { | 274 loadUnpacked() { |
272 this.loadUnpackedHelper_(); | 275 this.loadUnpackedHelper_(); |
273 }, | 276 } |
274 | 277 |
275 /** @override */ | 278 /** @override */ |
276 retryLoadUnpacked: function(retryGuid) { | 279 retryLoadUnpacked(retryGuid) { |
277 this.loadUnpackedHelper_(retryGuid); | 280 this.loadUnpackedHelper_(retryGuid); |
278 }, | 281 } |
279 | 282 |
280 /** @override */ | 283 /** @override */ |
281 choosePackRootDirectory: function() { | 284 choosePackRootDirectory() { |
282 return this.chooseFilePath_( | 285 return this.chooseFilePath_( |
283 chrome.developerPrivate.SelectType.FOLDER, | 286 chrome.developerPrivate.SelectType.FOLDER, |
284 chrome.developerPrivate.FileType.LOAD); | 287 chrome.developerPrivate.FileType.LOAD); |
285 }, | 288 } |
286 | 289 |
287 /** @override */ | 290 /** @override */ |
288 choosePrivateKeyPath: function() { | 291 choosePrivateKeyPath() { |
289 return this.chooseFilePath_( | 292 return this.chooseFilePath_( |
290 chrome.developerPrivate.SelectType.FILE, | 293 chrome.developerPrivate.SelectType.FILE, |
291 chrome.developerPrivate.FileType.PEM); | 294 chrome.developerPrivate.FileType.PEM); |
292 }, | 295 } |
293 | 296 |
294 /** @override */ | 297 /** @override */ |
295 packExtension: function(rootPath, keyPath) { | 298 packExtension(rootPath, keyPath) { |
296 chrome.developerPrivate.packDirectory(rootPath, keyPath); | 299 chrome.developerPrivate.packDirectory(rootPath, keyPath); |
297 }, | 300 } |
298 | 301 |
299 /** @override */ | 302 /** @override */ |
300 updateAllExtensions: function() { | 303 updateAllExtensions() { |
301 chrome.developerPrivate.autoUpdate(); | 304 chrome.developerPrivate.autoUpdate(); |
302 }, | 305 } |
303 | 306 |
304 /** @override */ | 307 /** @override */ |
305 deleteErrors: function(extensionId, errorIds, type) { | 308 deleteErrors(extensionId, errorIds, type) { |
306 chrome.developerPrivate.deleteExtensionErrors({ | 309 chrome.developerPrivate.deleteExtensionErrors({ |
307 extensionId: extensionId, | 310 extensionId: extensionId, |
308 errorIds: errorIds, | 311 errorIds: errorIds, |
309 type: type, | 312 type: type, |
310 }); | 313 }); |
311 }, | 314 } |
312 | 315 |
313 /** @override */ | 316 /** @override */ |
314 requestFileSource: function(args) { | 317 requestFileSource(args) { |
315 return new Promise(function(resolve, reject) { | 318 return new Promise(function(resolve, reject) { |
316 chrome.developerPrivate.requestFileSource(args, function(code) { | 319 chrome.developerPrivate.requestFileSource(args, function(code) { |
317 resolve(code); | 320 resolve(code); |
318 }); | 321 }); |
319 }); | 322 }); |
320 }, | 323 } |
321 }; | 324 } |
322 | 325 |
323 cr.addSingletonGetter(Service); | 326 cr.addSingletonGetter(Service); |
324 | 327 |
325 return {Service: Service}; | 328 return {Service: Service}; |
326 }); | 329 }); |
OLD | NEW |