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 /** | 5 /** |
6 * Provides drive search results to chrome launcher. | 6 * Provides drive search results to chrome launcher. |
7 * @constructor | 7 * @constructor |
8 * @struct | 8 * @struct |
9 */ | 9 */ |
10 function LauncherSearch() { | 10 function LauncherSearch() { |
(...skipping 16 matching lines...) Expand all Loading... | |
27 /** | 27 /** |
28 * @private {function(string, string, number)} | 28 * @private {function(string, string, number)} |
29 */ | 29 */ |
30 this.onQueryStartedBound_ = this.onQueryStarted_.bind(this); | 30 this.onQueryStartedBound_ = this.onQueryStarted_.bind(this); |
31 | 31 |
32 /** | 32 /** |
33 * @private {function(string)} | 33 * @private {function(string)} |
34 */ | 34 */ |
35 this.onQueryEndedBound_ = this.onQueryEnded_.bind(this); | 35 this.onQueryEndedBound_ = this.onQueryEnded_.bind(this); |
36 | 36 |
37 /** | |
38 * @private {function(string)} | |
39 */ | |
40 this.onOpenResultBound_ = this.onOpenResult_.bind(this); | |
41 | |
37 // This feature is disabled when drive is disabled. | 42 // This feature is disabled when drive is disabled. |
38 chrome.fileManagerPrivate.onPreferencesChanged.addListener( | 43 chrome.fileManagerPrivate.onPreferencesChanged.addListener( |
39 this.onPreferencesChanged_.bind(this)); | 44 this.onPreferencesChanged_.bind(this)); |
40 this.onPreferencesChanged_(); | 45 this.onPreferencesChanged_(); |
41 } | 46 } |
42 | 47 |
43 /** | 48 /** |
44 * Handles onPreferencesChanged event. | 49 * Handles onPreferencesChanged event. |
45 */ | 50 */ |
46 LauncherSearch.prototype.onPreferencesChanged_ = function() { | 51 LauncherSearch.prototype.onPreferencesChanged_ = function() { |
(...skipping 15 matching lines...) Expand all Loading... | |
62 // If this.enabled_ === isDriveEnabled, we don't need to change anything here. | 67 // If this.enabled_ === isDriveEnabled, we don't need to change anything here. |
63 if (this.enabled_ === isDriveEnabled) | 68 if (this.enabled_ === isDriveEnabled) |
64 return; | 69 return; |
65 | 70 |
66 // Remove event listeners if it's already enabled. | 71 // Remove event listeners if it's already enabled. |
67 if (this.enabled_) { | 72 if (this.enabled_) { |
68 chrome.launcherSearchProvider.onQueryStarted.removeListener( | 73 chrome.launcherSearchProvider.onQueryStarted.removeListener( |
69 this.onQueryStartedBound_); | 74 this.onQueryStartedBound_); |
70 chrome.launcherSearchProvider.onQueryEnded.removeListener( | 75 chrome.launcherSearchProvider.onQueryEnded.removeListener( |
71 this.onQueryEndedBound_); | 76 this.onQueryEndedBound_); |
77 chrome.launcherSearchProvider.onOpenResult.removeListener( | |
78 this.onOpenResultBound_); | |
72 } | 79 } |
73 | 80 |
74 // Set queryId_ to null to prevent that on-going search returns search | 81 // Set queryId_ to null to prevent that on-going search returns search |
75 // results. | 82 // results. |
76 this.queryId_ = null; | 83 this.queryId_ = null; |
77 | 84 |
78 // Add event listeners when drive is enabled. | 85 // Add event listeners when drive is enabled. |
79 if (isDriveEnabled) { | 86 if (isDriveEnabled) { |
80 this.enabled_ = true; | 87 this.enabled_ = true; |
81 chrome.launcherSearchProvider.onQueryStarted.addListener( | 88 chrome.launcherSearchProvider.onQueryStarted.addListener( |
82 this.onQueryStartedBound_); | 89 this.onQueryStartedBound_); |
83 chrome.launcherSearchProvider.onQueryEnded.addListener( | 90 chrome.launcherSearchProvider.onQueryEnded.addListener( |
84 this.onQueryEndedBound_); | 91 this.onQueryEndedBound_); |
85 // TODO(yawano): Adds listener to onOpenResult when it becomes available. | 92 chrome.launcherSearchProvider.onOpenResult.addListener( |
93 this.onOpenResultBound_); | |
86 } else { | 94 } else { |
87 this.enabled_ = false; | 95 this.enabled_ = false; |
88 } | 96 } |
89 }; | 97 }; |
90 | 98 |
91 /** | 99 /** |
92 * Handles onQueryStarted event. | 100 * Handles onQueryStarted event. |
93 * @param {string} queryId | 101 * @param {string} queryId |
94 * @param {string} query | 102 * @param {string} query |
95 * @param {number} limit | 103 * @param {number} limit |
(...skipping 28 matching lines...) Expand all Loading... | |
124 }.bind(this)); | 132 }.bind(this)); |
125 }; | 133 }; |
126 | 134 |
127 /** | 135 /** |
128 * Handles onQueryEnded event. | 136 * Handles onQueryEnded event. |
129 * @param {string} queryId | 137 * @param {string} queryId |
130 */ | 138 */ |
131 LauncherSearch.prototype.onQueryEnded_ = function(queryId) { | 139 LauncherSearch.prototype.onQueryEnded_ = function(queryId) { |
132 this.queryId_ = null; | 140 this.queryId_ = null; |
133 }; | 141 }; |
142 | |
143 /** | |
144 * Handles onOpenResult event. | |
145 * @param {string} itemId | |
146 */ | |
147 LauncherSearch.prototype.onOpenResult_ = function(itemId) { | |
148 util.urlToEntry(itemId).then(function(entry) { | |
149 if (entry.isDirectory) { | |
150 // If it's directory, open the directory with file manager. | |
151 launchFileManager( | |
152 { currentDirectoryURL: entry.toURL() }, | |
153 /* App ID */ undefined, | |
fukino
2015/04/21 08:52:47
nit: We usually add inline comment like this.
unde
yawano
2015/04/21 08:58:45
Done.
| |
154 LaunchType.FOCUS_SAME_OR_CREATE); | |
155 } else { | |
156 // If the file is not directory, try to execute default task. | |
157 chrome.fileManagerPrivate.getFileTasks([entry.toURL()], function(tasks) { | |
158 // Select default task. | |
159 var default_task = null; | |
fukino
2015/04/21 08:52:47
nit: in JavaScript, variableNamesLikeThis
yawano
2015/04/21 08:58:45
Done.
| |
160 for (var i = 0; i < tasks.length; i++) { | |
161 var task = tasks[i]; | |
162 if (task.isDefault) { | |
163 default_task = task; | |
164 break; | |
165 } | |
166 } | |
167 | |
168 if (default_task) { | |
169 // Execute default task. | |
170 chrome.fileManagerPrivate.executeTask( | |
171 default_task.taskId, | |
172 [entry.toURL()], | |
173 function(result) { | |
174 if (result === 'opened' || result === 'message_sent') | |
175 return; | |
176 this.openFileManagerWithSelectionURL_(entry.toURL()); | |
177 }.bind(this)); | |
178 } else { | |
179 // If there is no default task for the url, open a file manager with | |
180 // selecting it. | |
181 // TODO(yawano): Add fallback to view-in-browser as file_tasks.js do. | |
182 this.openFileManagerWithSelectionURL_(entry.toURL()); | |
183 } | |
184 }.bind(this)); | |
185 } | |
186 }.bind(this)); | |
187 }; | |
188 | |
189 /** | |
190 * Opens file manager with selecting a specified url. | |
191 * @param {string} selectionURL A url to be selected. | |
fukino
2015/04/21 08:52:47
nit: @private
yawano
2015/04/21 08:58:45
Done.
| |
192 */ | |
193 LauncherSearch.prototype.openFileManagerWithSelectionURL_ = function( | |
194 selectionURL) { | |
195 launchFileManager( | |
196 { selectionURL: selectionURL }, | |
197 /* App ID */ undefined, | |
fukino
2015/04/21 08:52:47
ditto
yawano
2015/04/21 08:58:45
Done.
| |
198 LaunchType.FOCUS_SAME_OR_CREATE); | |
199 }; | |
OLD | NEW |