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 <include src="../../../../ui/webui/resources/js/cr/ui/focus_row.js"> | 5 <include src="../../../../ui/webui/resources/js/cr/ui/focus_row.js"> |
6 <include src="../../../../ui/webui/resources/js/cr/ui/focus_grid.js"> | 6 <include src="../../../../ui/webui/resources/js/cr/ui/focus_grid.js"> |
7 <include src="../uber/uber_utils.js"> | 7 <include src="../uber/uber_utils.js"> |
8 <include src="drag_and_drop_handler.js"> | |
8 <include src="extension_code.js"> | 9 <include src="extension_code.js"> |
9 <include src="extension_commands_overlay.js"> | 10 <include src="extension_commands_overlay.js"> |
10 <include src="extension_error_overlay.js"> | 11 <include src="extension_error_overlay.js"> |
11 <include src="extension_focus_manager.js"> | 12 <include src="extension_focus_manager.js"> |
12 <include src="focus_row.js"> | 13 <include src="focus_row.js"> |
13 <include src="extension_list.js"> | 14 <include src="extension_list.js"> |
14 <include src="pack_extension_overlay.js"> | 15 <include src="pack_extension_overlay.js"> |
15 <include src="extension_loader.js"> | 16 <include src="extension_loader.js"> |
16 <include src="extension_options_overlay.js"> | 17 <include src="extension_options_overlay.js"> |
17 | 18 |
18 <if expr="chromeos"> | 19 <if expr="chromeos"> |
19 <include src="chromeos/kiosk_apps.js"> | 20 <include src="chromeos/kiosk_apps.js"> |
20 </if> | 21 </if> |
21 | 22 |
22 // Used for observing function of the backend datasource for this page by | 23 // Used for observing function of the backend datasource for this page by |
23 // tests. | 24 // tests. |
24 var webuiResponded = false; | 25 var webuiResponded = false; |
25 | 26 |
26 cr.define('extensions', function() { | 27 cr.define('extensions', function() { |
27 var ExtensionList = extensions.ExtensionList; | 28 var ExtensionList = extensions.ExtensionList; |
28 | 29 |
29 // Implements the DragWrapper handler interface. | |
30 var dragWrapperHandler = { | |
31 /** @override */ | |
32 shouldAcceptDrag: function(e) { | |
33 // External Extension installation can be disabled globally, e.g. while a | |
34 // different overlay is already showing. | |
35 if (!ExtensionSettings.getInstance().dragEnabled_) | |
36 return false; | |
37 | |
38 // We can't access filenames during the 'dragenter' event, so we have to | |
39 // wait until 'drop' to decide whether to do something with the file or | |
40 // not. | |
41 // See: http://www.w3.org/TR/2011/WD-html5-20110113/dnd.html#concept-dnd-p | |
42 return (e.dataTransfer.types && | |
43 e.dataTransfer.types.indexOf('Files') > -1); | |
44 }, | |
45 /** @override */ | |
46 doDragEnter: function() { | |
47 chrome.send('startDrag'); | |
48 ExtensionSettings.showOverlay($('drop-target-overlay')); | |
49 }, | |
50 /** @override */ | |
51 doDragLeave: function() { | |
52 this.hideDropTargetOverlay_(); | |
53 chrome.send('stopDrag'); | |
54 }, | |
55 /** @override */ | |
56 doDragOver: function(e) { | |
57 e.preventDefault(); | |
58 }, | |
59 /** @override */ | |
60 doDrop: function(e) { | |
61 this.hideDropTargetOverlay_(); | |
62 if (e.dataTransfer.files.length != 1) | |
63 return; | |
64 | |
65 var toSend = null; | |
66 // Files lack a check if they're a directory, but we can find out through | |
67 // its item entry. | |
68 for (var i = 0; i < e.dataTransfer.items.length; ++i) { | |
69 if (e.dataTransfer.items[i].kind == 'file' && | |
70 e.dataTransfer.items[i].webkitGetAsEntry().isDirectory) { | |
71 toSend = 'installDroppedDirectory'; | |
72 break; | |
73 } | |
74 } | |
75 // Only process files that look like extensions. Other files should | |
76 // navigate the browser normally. | |
77 if (!toSend && | |
78 /\.(crx|user\.js|zip)$/i.test(e.dataTransfer.files[0].name)) { | |
79 toSend = 'installDroppedFile'; | |
80 } | |
81 | |
82 if (toSend) { | |
83 e.preventDefault(); | |
84 chrome.send(toSend); | |
85 } | |
86 }, | |
87 | |
88 /** | |
89 * Hide the current overlay if it is the drop target overlay. | |
90 * @private | |
91 */ | |
92 hideDropTargetOverlay_: function() { | |
93 var currentOverlay = ExtensionSettings.getCurrentOverlay(); | |
94 if (currentOverlay && currentOverlay.id === 'drop-target-overlay') | |
95 ExtensionSettings.showOverlay(null); | |
96 } | |
97 }; | |
98 | |
99 /** | 30 /** |
100 * ExtensionSettings class | 31 * ExtensionSettings class |
101 * @class | 32 * @class |
102 * @constructor | 33 * @constructor |
103 * @implements {extensions.ExtensionListDelegate} | 34 * @implements {extensions.ExtensionListDelegate} |
104 */ | 35 */ |
105 function ExtensionSettings() {} | 36 function ExtensionSettings() {} |
106 | 37 |
107 cr.addSingletonGetter(ExtensionSettings); | 38 cr.addSingletonGetter(ExtensionSettings); |
108 | 39 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 chrome.send('metricsHandler:recordAction', | 106 chrome.send('metricsHandler:recordAction', |
176 ['Options_LoadUnpackedExtension']); | 107 ['Options_LoadUnpackedExtension']); |
177 extensionLoader.loadUnpacked(); | 108 extensionLoader.loadUnpacked(); |
178 }); | 109 }); |
179 $('pack-extension').addEventListener('click', | 110 $('pack-extension').addEventListener('click', |
180 this.handlePackExtension_.bind(this)); | 111 this.handlePackExtension_.bind(this)); |
181 $('update-extensions-now').addEventListener('click', | 112 $('update-extensions-now').addEventListener('click', |
182 this.handleUpdateExtensionNow_.bind(this)); | 113 this.handleUpdateExtensionNow_.bind(this)); |
183 | 114 |
184 if (!loadTimeData.getBoolean('offStoreInstallEnabled')) { | 115 if (!loadTimeData.getBoolean('offStoreInstallEnabled')) { |
185 this.dragWrapper_ = new cr.ui.DragWrapper(document.documentElement, | 116 var dragTarget = document.documentElement; |
Dan Beam
2016/07/21 02:29:12
why not just pass |this| as the event target inste
Devlin
2016/07/21 18:11:30
Because line 41, declaring that this inherits HTML
| |
186 dragWrapperHandler); | 117 /** @private {extensions.DragAndDropHandler} */ |
187 this.dragEnabled_ = true; | 118 this.dragWrapperHandler_ = |
119 new extensions.DragAndDropHandler(true, dragTarget); | |
120 dragTarget.addEventListener('extension-drag-started', function() { | |
121 ExtensionSettings.showOverlay($('drop-target-overlay')); | |
122 }); | |
123 dragTarget.addEventListener('extension-drag-ended', function() { | |
124 var overlay = ExtensionSettings.getCurrentOverlay(); | |
125 if (overlay && overlay.id === 'drop-target-overlay') | |
126 ExtensionSettings.showOverlay(null); | |
127 }); | |
128 this.dragWrapper_ = | |
129 new cr.ui.DragWrapper(dragTarget, this.dragWrapperHandler_); | |
188 } | 130 } |
189 | 131 |
190 extensions.PackExtensionOverlay.getInstance().initializePage(); | 132 extensions.PackExtensionOverlay.getInstance().initializePage(); |
191 | 133 |
192 // Hook up the configure commands link to the overlay. | 134 // Hook up the configure commands link to the overlay. |
193 var link = document.querySelector('.extension-commands-config'); | 135 var link = document.querySelector('.extension-commands-config'); |
194 link.addEventListener('click', | 136 link.addEventListener('click', |
195 this.handleExtensionCommandsConfig_.bind(this)); | 137 this.handleExtensionCommandsConfig_.bind(this)); |
196 | 138 |
197 // Initialize the Commands overlay. | 139 // Initialize the Commands overlay. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 | 363 |
422 $('overlay').hidden = !node; | 364 $('overlay').hidden = !node; |
423 | 365 |
424 if (node) | 366 if (node) |
425 ExtensionSettings.focusOverlay(); | 367 ExtensionSettings.focusOverlay(); |
426 | 368 |
427 // If drag-drop for external Extension installation is available, enable | 369 // If drag-drop for external Extension installation is available, enable |
428 // drag-drop when there is any overlay showing other than the usual overlay | 370 // drag-drop when there is any overlay showing other than the usual overlay |
429 // shown when drag-drop is started. | 371 // shown when drag-drop is started. |
430 var settings = ExtensionSettings.getInstance(); | 372 var settings = ExtensionSettings.getInstance(); |
431 if (settings.dragWrapper_) | 373 if (settings.dragWrapper_) { |
432 settings.dragEnabled_ = !node || node == $('drop-target-overlay'); | 374 assert(settings.dragWrapperHandler_).dragEnabled = |
375 !node || node == $('drop-target-overlay'); | |
376 } | |
433 | 377 |
434 uber.invokeMethodOnParent(node ? 'beginInterceptingEvents' : | 378 uber.invokeMethodOnParent(node ? 'beginInterceptingEvents' : |
435 'stopInterceptingEvents'); | 379 'stopInterceptingEvents'); |
436 }; | 380 }; |
437 | 381 |
438 ExtensionSettings.focusOverlay = function() { | 382 ExtensionSettings.focusOverlay = function() { |
439 var currentlyShowingOverlay = ExtensionSettings.getCurrentOverlay(); | 383 var currentlyShowingOverlay = ExtensionSettings.getCurrentOverlay(); |
440 assert(currentlyShowingOverlay); | 384 assert(currentlyShowingOverlay); |
441 | 385 |
442 if (cr.ui.FocusOutlineManager.forDocument(document).visible) | 386 if (cr.ui.FocusOutlineManager.forDocument(document).visible) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 | 427 |
484 // Export | 428 // Export |
485 return { | 429 return { |
486 ExtensionSettings: ExtensionSettings | 430 ExtensionSettings: ExtensionSettings |
487 }; | 431 }; |
488 }); | 432 }); |
489 | 433 |
490 window.addEventListener('load', function(e) { | 434 window.addEventListener('load', function(e) { |
491 extensions.ExtensionSettings.getInstance().initialize(); | 435 extensions.ExtensionSettings.getInstance().initialize(); |
492 }); | 436 }); |
OLD | NEW |