Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: chrome/browser/resources/extensions/drag_and_drop_handler.js

Issue 2164693002: [WebUI] ClosureCompile cr.ui.DragWrapper, create a real handler class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove prototypical lies Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('extensions', function() {
6 'use strict';
7
8 /**
9 * @param {boolean} dragEnabled
10 * @param {!EventTarget} target
11 * @constructor
12 * @implements cr.ui.DragWrapperDelegate
13 */
14 function DragAndDropHandler(dragEnabled, target) {
15 this.dragEnabled = dragEnabled;
16 /** @private {!EventTarget} */
17 this.eventTarget_ = target;
18 }
19
20 // TODO(devlin): Un-chrome.send-ify this implementation.
21 DragAndDropHandler.prototype = {
22 /** @type {boolean} */
23 dragEnabled: false,
24
25 /** @override */
26 shouldAcceptDrag: function(e) {
27 // External Extension installation can be disabled globally, e.g. while a
28 // different overlay is already showing.
29 if (!this.dragEnabled)
30 return false;
31
32 // We can't access filenames during the 'dragenter' event, so we have to
33 // wait until 'drop' to decide whether to do something with the file or
34 // not.
35 // See: http://www.w3.org/TR/2011/WD-html5-20110113/dnd.html#concept-dnd-p
36 return !!e.dataTransfer.types &&
37 e.dataTransfer.types.indexOf('Files') > -1;
38 },
39
40 /** @override */
41 doDragEnter: function() {
42 chrome.send('startDrag');
43 this.eventTarget_.dispatchEvent(
44 new CustomEvent('extension-drag-started'));
45 },
46
47 /** @override */
48 doDragLeave: function() {
49 this.fireDragEnded_();
Dan Beam 2016/07/21 23:42:39 i think it's odd to say the drag has ended if this
50 chrome.send('stopDrag');
51 },
52
53 /** @override */
54 doDragOver: function(e) {
55 e.preventDefault();
56 },
57
58 /** @override */
59 doDrop: function(e) {
60 this.fireDragEnded_();
61 if (e.dataTransfer.files.length != 1)
62 return;
63
64 var toSend = '';
65 // Files lack a check if they're a directory, but we can find out through
66 // its item entry.
67 for (var i = 0; i < e.dataTransfer.items.length; ++i) {
68 if (e.dataTransfer.items[i].kind == 'file' &&
69 e.dataTransfer.items[i].webkitGetAsEntry().isDirectory) {
70 toSend = 'installDroppedDirectory';
71 break;
72 }
73 }
74 // Only process files that look like extensions. Other files should
75 // navigate the browser normally.
76 if (!toSend &&
77 /\.(crx|user\.js|zip)$/i.test(e.dataTransfer.files[0].name)) {
78 toSend = 'installDroppedFile';
79 }
80
81 if (toSend) {
82 e.preventDefault();
83 chrome.send(toSend);
84 }
85 },
86
87 /** @private */
88 fireDragEnded_: function() {
89 this.eventTarget_.dispatchEvent(new CustomEvent('extension-drag-ended'));
90 }
91 };
92
93 return {
94 DragAndDropHandler: DragAndDropHandler,
95 };
96 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/extensions/compiled_resources2.gyp ('k') | chrome/browser/resources/extensions/extensions.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698