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 |
109 ExtensionSettings.prototype = { | 40 ExtensionSettings.prototype = { |
110 __proto__: HTMLDivElement.prototype, | |
111 | |
112 /** | 41 /** |
113 * The drag-drop wrapper for installing external Extensions, if available. | 42 * The drag-drop wrapper for installing external Extensions, if available. |
114 * null if external Extension installation is not available. | 43 * null if external Extension installation is not available. |
115 * @type {cr.ui.DragWrapper} | 44 * @type {cr.ui.DragWrapper} |
116 * @private | 45 * @private |
117 */ | 46 */ |
118 dragWrapper_: null, | 47 dragWrapper_: null, |
119 | 48 |
120 /** | 49 /** |
121 * True if drag-drop is both available and currently enabled - it can be | 50 * True if drag-drop is both available and currently enabled - it can be |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 chrome.send('metricsHandler:recordAction', | 104 chrome.send('metricsHandler:recordAction', |
176 ['Options_LoadUnpackedExtension']); | 105 ['Options_LoadUnpackedExtension']); |
177 extensionLoader.loadUnpacked(); | 106 extensionLoader.loadUnpacked(); |
178 }); | 107 }); |
179 $('pack-extension').addEventListener('click', | 108 $('pack-extension').addEventListener('click', |
180 this.handlePackExtension_.bind(this)); | 109 this.handlePackExtension_.bind(this)); |
181 $('update-extensions-now').addEventListener('click', | 110 $('update-extensions-now').addEventListener('click', |
182 this.handleUpdateExtensionNow_.bind(this)); | 111 this.handleUpdateExtensionNow_.bind(this)); |
183 | 112 |
184 if (!loadTimeData.getBoolean('offStoreInstallEnabled')) { | 113 if (!loadTimeData.getBoolean('offStoreInstallEnabled')) { |
185 this.dragWrapper_ = new cr.ui.DragWrapper(document.documentElement, | 114 var dragTarget = document.documentElement; |
186 dragWrapperHandler); | 115 /** @private {extensions.DragAndDropHandler} */ |
187 this.dragEnabled_ = true; | 116 this.dragWrapperHandler_ = |
| 117 new extensions.DragAndDropHandler(true, dragTarget); |
| 118 dragTarget.addEventListener('extension-drag-started', function() { |
| 119 ExtensionSettings.showOverlay($('drop-target-overlay')); |
| 120 }); |
| 121 dragTarget.addEventListener('extension-drag-ended', function() { |
| 122 var overlay = ExtensionSettings.getCurrentOverlay(); |
| 123 if (overlay && overlay.id === 'drop-target-overlay') |
| 124 ExtensionSettings.showOverlay(null); |
| 125 }); |
| 126 this.dragWrapper_ = |
| 127 new cr.ui.DragWrapper(dragTarget, this.dragWrapperHandler_); |
188 } | 128 } |
189 | 129 |
190 extensions.PackExtensionOverlay.getInstance().initializePage(); | 130 extensions.PackExtensionOverlay.getInstance().initializePage(); |
191 | 131 |
192 // Hook up the configure commands link to the overlay. | 132 // Hook up the configure commands link to the overlay. |
193 var link = document.querySelector('.extension-commands-config'); | 133 var link = document.querySelector('.extension-commands-config'); |
194 link.addEventListener('click', | 134 link.addEventListener('click', |
195 this.handleExtensionCommandsConfig_.bind(this)); | 135 this.handleExtensionCommandsConfig_.bind(this)); |
196 | 136 |
197 // Initialize the Commands overlay. | 137 // Initialize the Commands overlay. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 361 |
422 $('overlay').hidden = !node; | 362 $('overlay').hidden = !node; |
423 | 363 |
424 if (node) | 364 if (node) |
425 ExtensionSettings.focusOverlay(); | 365 ExtensionSettings.focusOverlay(); |
426 | 366 |
427 // If drag-drop for external Extension installation is available, enable | 367 // If drag-drop for external Extension installation is available, enable |
428 // drag-drop when there is any overlay showing other than the usual overlay | 368 // drag-drop when there is any overlay showing other than the usual overlay |
429 // shown when drag-drop is started. | 369 // shown when drag-drop is started. |
430 var settings = ExtensionSettings.getInstance(); | 370 var settings = ExtensionSettings.getInstance(); |
431 if (settings.dragWrapper_) | 371 if (settings.dragWrapper_) { |
432 settings.dragEnabled_ = !node || node == $('drop-target-overlay'); | 372 assert(settings.dragWrapperHandler_).dragEnabled = |
| 373 !node || node == $('drop-target-overlay'); |
| 374 } |
433 | 375 |
434 uber.invokeMethodOnParent(node ? 'beginInterceptingEvents' : | 376 uber.invokeMethodOnParent(node ? 'beginInterceptingEvents' : |
435 'stopInterceptingEvents'); | 377 'stopInterceptingEvents'); |
436 }; | 378 }; |
437 | 379 |
438 ExtensionSettings.focusOverlay = function() { | 380 ExtensionSettings.focusOverlay = function() { |
439 var currentlyShowingOverlay = ExtensionSettings.getCurrentOverlay(); | 381 var currentlyShowingOverlay = ExtensionSettings.getCurrentOverlay(); |
440 assert(currentlyShowingOverlay); | 382 assert(currentlyShowingOverlay); |
441 | 383 |
442 if (cr.ui.FocusOutlineManager.forDocument(document).visible) | 384 if (cr.ui.FocusOutlineManager.forDocument(document).visible) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 | 425 |
484 // Export | 426 // Export |
485 return { | 427 return { |
486 ExtensionSettings: ExtensionSettings | 428 ExtensionSettings: ExtensionSettings |
487 }; | 429 }; |
488 }); | 430 }); |
489 | 431 |
490 window.addEventListener('load', function(e) { | 432 window.addEventListener('load', function(e) { |
491 extensions.ExtensionSettings.getInstance().initialize(); | 433 extensions.ExtensionSettings.getInstance().initialize(); |
492 }); | 434 }); |
OLD | NEW |