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

Side by Side Diff: ui/file_manager/file_manager/foreground/js/ui/suggest_apps_dialog.js

Issue 1058873004: Revert of Add button to add new FSP services to Files app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 * SuggestAppsDialog contains a list box to select an app to be opened the file 6 * SuggestAppsDialog contains a list box to select an app to be opened the file
7 * with. This dialog should be used as action picker for file operations. 7 * with. This dialog should be used as action picker for file operations.
8 */ 8 */
9 9
10 /** 10 /**
11 * The width of the widget (in pixel). 11 * The width of the widget (in pixel).
12 * @type {number} 12 * @type {number}
13 * @const 13 * @const
14 */ 14 */
15 var WEBVIEW_WIDTH = 735; 15 var WEBVIEW_WIDTH = 735;
16 /** 16 /**
17 * The height of the widget (in pixel). 17 * The height of the widget (in pixel).
18 * @type {number} 18 * @type {number}
19 * @const 19 * @const
20 */ 20 */
21 var WEBVIEW_HEIGHT = 480; 21 var WEBVIEW_HEIGHT = 480;
22 22
23 /** 23 /**
24 * The URL of the widget showing suggested apps. 24 * The URL of the widget.
25 * @type {string} 25 * @type {string}
26 * @const 26 * @const
27 */ 27 */
28 var CWS_WIDGET_URL = 28 var CWS_WIDGET_URL =
29 'https://clients5.google.com/webstore/wall/cros-widget-container'; 29 'https://clients5.google.com/webstore/wall/cros-widget-container';
30
31 /** 30 /**
32 * The origin of the widget. 31 * The origin of the widget.
33 * @type {string} 32 * @type {string}
34 * @const 33 * @const
35 */ 34 */
36 var CWS_WIDGET_ORIGIN = 'https://clients5.google.com'; 35 var CWS_WIDGET_ORIGIN = 'https://clients5.google.com';
37 36
38 /** 37 /**
39 * Creates dialog in DOM tree. 38 * Creates dialog in DOM tree.
40 * 39 *
(...skipping 15 matching lines...) Expand all
56 55
57 var spinnerLayer = this.document_.createElement('div'); 56 var spinnerLayer = this.document_.createElement('div');
58 spinnerLayer.className = 'spinner-layer'; 57 spinnerLayer.className = 'spinner-layer';
59 this.webviewContainer_.appendChild(spinnerLayer); 58 this.webviewContainer_.appendChild(spinnerLayer);
60 59
61 this.buttons_ = this.document_.createElement('div'); 60 this.buttons_ = this.document_.createElement('div');
62 this.buttons_.id = 'buttons'; 61 this.buttons_.id = 'buttons';
63 this.frame_.appendChild(this.buttons_); 62 this.frame_.appendChild(this.buttons_);
64 63
65 this.webstoreButton_ = this.document_.createElement('div'); 64 this.webstoreButton_ = this.document_.createElement('div');
66 this.webstoreButton_.hidden = true;
67 this.webstoreButton_.id = 'webstore-button'; 65 this.webstoreButton_.id = 'webstore-button';
68 this.webstoreButton_.innerHTML = str('SUGGEST_DIALOG_LINK_TO_WEBSTORE'); 66 this.webstoreButton_.innerHTML = str('SUGGEST_DIALOG_LINK_TO_WEBSTORE');
69 this.webstoreButton_.addEventListener( 67 this.webstoreButton_.addEventListener(
70 'click', this.onWebstoreLinkClicked_.bind(this)); 68 'click', this.onWebstoreLinkClicked_.bind(this));
71 this.buttons_.appendChild(this.webstoreButton_); 69 this.buttons_.appendChild(this.webstoreButton_);
72 70
73 this.initialFocusElement_ = this.webviewContainer_; 71 this.initialFocusElement_ = this.webviewContainer_;
74 72
75 this.webview_ = null; 73 this.webview_ = null;
76 this.accessToken_ = null; 74 this.accessToken_ = null;
77 this.widgetUrl_ = state.overrideCwsContainerUrlForTest || CWS_WIDGET_URL; 75 this.widgetUrl_ =
78 this.widgetOrigin_ = state.overrideCwsContainerOriginForTest || 76 state.overrideCwsContainerUrlForTest || CWS_WIDGET_URL;
79 CWS_WIDGET_ORIGIN; 77 this.widgetOrigin_ =
78 state.overrideCwsContainerOriginForTest || CWS_WIDGET_ORIGIN;
80 79
81 this.options_ = null; 80 this.extension_ = null;
81 this.mime_ = null;
82 this.installingItemId_ = null; 82 this.installingItemId_ = null;
83 this.state_ = SuggestAppsDialog.State.UNINITIALIZED; 83 this.state_ = SuggestAppsDialog.State.UNINITIALIZED;
84 84
85 this.initializationTask_ = new AsyncUtil.Group(); 85 this.initializationTask_ = new AsyncUtil.Group();
86 this.initializationTask_.add(this.retrieveAuthorizeToken_.bind(this)); 86 this.initializationTask_.add(this.retrieveAuthorizeToken_.bind(this));
87 this.initializationTask_.run(); 87 this.initializationTask_.run();
88 } 88 }
89 89
90 SuggestAppsDialog.prototype = { 90 SuggestAppsDialog.prototype = {
91 __proto__: FileManagerDialogBase.prototype 91 __proto__: FileManagerDialogBase.prototype
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 /** 169 /**
170 * Dummy function for SuggestAppsDialog.show() not to be called unintentionally. 170 * Dummy function for SuggestAppsDialog.show() not to be called unintentionally.
171 */ 171 */
172 SuggestAppsDialog.prototype.show = function() { 172 SuggestAppsDialog.prototype.show = function() {
173 console.error('SuggestAppsDialog.show() shouldn\'t be called directly.'); 173 console.error('SuggestAppsDialog.show() shouldn\'t be called directly.');
174 }; 174 };
175 175
176 /** 176 /**
177 * Shows suggest-apps dialog by file extension and mime. 177 * Shows suggest-apps dialog by file extension and mime.
178 * 178 *
179 * @param {string} extension Extension of the file with a trailing dot. 179 * @param {string} extension Extension of the file.
180 * @param {string} mime Mime of the file. 180 * @param {string} mime Mime of the file.
181 * @param {function(boolean)} onDialogClosed Called when the dialog is closed. 181 * @param {function(boolean)} onDialogClosed Called when the dialog is closed.
182 * The argument is the result of installation: true if an app is installed, 182 * The argument is the result of installation: true if an app is installed,
183 * false otherwise. 183 * false otherwise.
184 */ 184 */
185 SuggestAppsDialog.prototype.showByExtensionAndMime = 185 SuggestAppsDialog.prototype.showByExtensionAndMime =
186 function(extension, mime, onDialogClosed) { 186 function(extension, mime, onDialogClosed) {
187 assert(extension && extension[0] === '.'); 187 this.text_.hidden = true;
188 this.showInternal_( 188 this.dialogText_ = '';
189 { 189 this.showInternal_(null, extension, mime, onDialogClosed);
190 file_extension: extension.substr(1),
191 mime_type: mime
192 },
193 str('SUGGEST_DIALOG_TITLE'),
194 FileTasks.createWebStoreLink(extension, mime),
195 onDialogClosed);
196 };
197
198 /**
199 * Shows suggest-apps dialog for FSP API
200 * @param {function(boolean)} onDialogClosed Called when the dialog is closed.
201 * The argument is the result of installation: true if an app is installed,
202 * false otherwise.
203 */
204 SuggestAppsDialog.prototype.showProviders = function(onDialogClosed) {
205 this.showInternal_(
206 {
207 file_system_provider: true
208 },
209 str('SUGGEST_DIALOG_FOR_PROVIDERS_TITLE'),
210 null /* webStoreUrl */,
211 onDialogClosed);
212 }; 190 };
213 191
214 /** 192 /**
215 * Internal method to show a dialog. This should be called only from 'Suggest. 193 * Internal method to show a dialog. This should be called only from 'Suggest.
216 * appDialog.showXxxx()' functions. 194 * appDialog.showXxxx()' functions.
217 * 195 *
218 * @param {!Object<string, *>} options Map of options for the dialog. 196 * @param {?string} filename Filename (without extension) of the file.
219 * @param {string} title Title of the dialog. 197 * @param {?string} extension Extension of the file.
220 * @param {?string} webStoreUrl Url for more results. Null if not supported. 198 * @param {?string} mime Mime of the file.
221 * @param {function(boolean)} onDialogClosed Called when the dialog is closed. 199 * @param {function(boolean)} onDialogClosed Called when the dialog is closed.
222 * The argument is the result of installation: true if an app is installed, 200 * The argument is the result of installation: true if an app is installed,
223 * false otherwise. 201 * false otherwise.
224 * @private 202 * @private
225 */ 203 */
226 SuggestAppsDialog.prototype.showInternal_ = 204 SuggestAppsDialog.prototype.showInternal_ =
227 function(options, title, webStoreUrl, onDialogClosed) { 205 function(filename, extension, mime, onDialogClosed) {
228 if (this.state_ != SuggestAppsDialog.State.UNINITIALIZED) { 206 if (this.state_ != SuggestAppsDialog.State.UNINITIALIZED) {
229 console.error('Invalid state.'); 207 console.error('Invalid state.');
230 return; 208 return;
231 } 209 }
232 210
233 this.text_.hidden = true; 211 this.extension_ = extension;
234 this.webstoreButton_.hidden = (webStoreUrl === null); 212 this.mimeType_ = mime;
235 this.dialogText_ = '';
236
237 this.webStoreUrl_ = webStoreUrl;
238 this.options_ = options;
239 this.onDialogClosed_ = onDialogClosed; 213 this.onDialogClosed_ = onDialogClosed;
240 this.state_ = SuggestAppsDialog.State.INITIALIZING; 214 this.state_ = SuggestAppsDialog.State.INITIALIZING;
241 215
242 SuggestAppsDialog.Metrics.recordShowDialog(); 216 SuggestAppsDialog.Metrics.recordShowDialog();
243 SuggestAppsDialog.Metrics.startLoad(); 217 SuggestAppsDialog.Metrics.startLoad();
244 218
245 // Makes it sure that the initialization is completed. 219 // Makes it sure that the initialization is completed.
246 this.initializationTask_.run(function() { 220 this.initializationTask_.run(function() {
247 if (!this.accessToken_) { 221 if (!this.accessToken_) {
248 this.state_ = SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING; 222 this.state_ = SuggestAppsDialog.State.INITIALIZE_FAILED_CLOSING;
249 this.onHide_(); 223 this.onHide_();
250 return; 224 return;
251 } 225 }
252 226
227 var title = str('SUGGEST_DIALOG_TITLE');
253 var show = this.dialogText_ ? 228 var show = this.dialogText_ ?
254 FileManagerDialogBase.prototype.showTitleAndTextDialog.call( 229 FileManagerDialogBase.prototype.showTitleAndTextDialog.call(
255 this, title, this.dialogText_) : 230 this, title, this.dialogText_) :
256 FileManagerDialogBase.prototype.showTitleOnlyDialog.call( 231 FileManagerDialogBase.prototype.showTitleOnlyDialog.call(
257 this, title); 232 this, title);
258 if (!show) { 233 if (!show) {
259 console.error('SuggestAppsDialog can\'t be shown'); 234 console.error('SuggestAppsDialog can\'t be shown');
260 this.state_ = SuggestAppsDialog.State.UNINITIALIZED; 235 this.state_ = SuggestAppsDialog.State.UNINITIALIZED;
261 this.onHide_(); 236 this.onHide_();
262 return; 237 return;
(...skipping 14 matching lines...) Expand all
277 event.window.discard(); 252 event.window.discard();
278 util.visitURL(event.targetUrl); 253 util.visitURL(event.targetUrl);
279 event.preventDefault(); 254 event.preventDefault();
280 }); 255 });
281 this.webviewContainer_.appendChild(this.webview_); 256 this.webviewContainer_.appendChild(this.webview_);
282 257
283 this.frame_.classList.add('show-spinner'); 258 this.frame_.classList.add('show-spinner');
284 259
285 this.webviewClient_ = new CWSContainerClient( 260 this.webviewClient_ = new CWSContainerClient(
286 this.webview_, 261 this.webview_,
287 WEBVIEW_WIDTH, 262 extension, mime, filename,
288 WEBVIEW_HEIGHT, 263 WEBVIEW_WIDTH, WEBVIEW_HEIGHT,
289 this.widgetUrl_, 264 this.widgetUrl_, this.widgetOrigin_);
290 this.widgetOrigin_,
291 this.options_);
292 this.webviewClient_.addEventListener(CWSContainerClient.Events.LOADED, 265 this.webviewClient_.addEventListener(CWSContainerClient.Events.LOADED,
293 this.onWidgetLoaded_.bind(this)); 266 this.onWidgetLoaded_.bind(this));
294 this.webviewClient_.addEventListener(CWSContainerClient.Events.LOAD_FAILED, 267 this.webviewClient_.addEventListener(CWSContainerClient.Events.LOAD_FAILED,
295 this.onWidgetLoadFailed_.bind(this)); 268 this.onWidgetLoadFailed_.bind(this));
296 this.webviewClient_.addEventListener( 269 this.webviewClient_.addEventListener(
297 CWSContainerClient.Events.REQUEST_INSTALL, 270 CWSContainerClient.Events.REQUEST_INSTALL,
298 this.onInstallRequest_.bind(this)); 271 this.onInstallRequest_.bind(this));
299 this.webviewClient_.load(); 272 this.webviewClient_.load();
300 }.bind(this)); 273 }.bind(this));
301 }; 274 };
302 275
303 /** 276 /**
304 * Called when the 'See more...' link is clicked to be navigated to Webstore. 277 * Called when the 'See more...' link is clicked to be navigated to Webstore.
305 * @param {Event} e Event. 278 * @param {Event} e Event.
306 * @private 279 * @private
307 */ 280 */
308 SuggestAppsDialog.prototype.onWebstoreLinkClicked_ = function(e) { 281 SuggestAppsDialog.prototype.onWebstoreLinkClicked_ = function(e) {
309 if (!this.webStoreUrl_) 282 var webStoreUrl =
310 return; 283 FileTasks.createWebStoreLink(this.extension_, this.mimeType_);
311 util.visitURL(this.webStoreUrl_); 284 util.visitURL(webStoreUrl);
312 this.state_ = SuggestAppsDialog.State.OPENING_WEBSTORE_CLOSING; 285 this.state_ = SuggestAppsDialog.State.OPENING_WEBSTORE_CLOSING;
313 this.hide(); 286 this.hide();
314 }; 287 };
315 288
316 /** 289 /**
317 * Called when the widget is loaded successfully. 290 * Called when the widget is loaded successfully.
318 * @param {Event} event Event. 291 * @param {Event} event Event.
319 * @private 292 * @private
320 */ 293 */
321 SuggestAppsDialog.prototype.onWidgetLoaded_ = function(event) { 294 SuggestAppsDialog.prototype.onWidgetLoaded_ = function(event) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 console.error('Invalid state.'); 420 console.error('Invalid state.');
448 } 421 }
449 422
450 if (this.webviewClient_) { 423 if (this.webviewClient_) {
451 this.webviewClient_.dispose(); 424 this.webviewClient_.dispose();
452 this.webviewClient_ = null; 425 this.webviewClient_ = null;
453 } 426 }
454 427
455 this.webviewContainer_.removeChild(this.webview_); 428 this.webviewContainer_.removeChild(this.webview_);
456 this.webview_ = null; 429 this.webview_ = null;
457 this.webStoreUrl_ = null; 430 this.extension_ = null;
458 this.options_ = null; 431 this.mime_ = null;
459 432
460 FileManagerDialogBase.prototype.hide.call( 433 FileManagerDialogBase.prototype.hide.call(
461 this, 434 this,
462 this.onHide_.bind(this, opt_originalOnHide)); 435 this.onHide_.bind(this, opt_originalOnHide));
463 }; 436 };
464 437
465 /** 438 /**
466 * @param {Function=} opt_originalOnHide Original onHide function passed to 439 * @param {Function=} opt_originalOnHide Original onHide function passed to
467 * SuggestAppsDialog.hide(). 440 * SuggestAppsDialog.hide().
468 * @private 441 * @private
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 metrics.recordUserAction('SuggestApps.ShowDialog'); 543 metrics.recordUserAction('SuggestApps.ShowDialog');
571 }; 544 };
572 545
573 SuggestAppsDialog.Metrics.startLoad = function() { 546 SuggestAppsDialog.Metrics.startLoad = function() {
574 metrics.startInterval('SuggestApps.LoadTime'); 547 metrics.startInterval('SuggestApps.LoadTime');
575 }; 548 };
576 549
577 SuggestAppsDialog.Metrics.finishLoad = function() { 550 SuggestAppsDialog.Metrics.finishLoad = function() {
578 metrics.recordInterval('SuggestApps.LoadTime'); 551 metrics.recordInterval('SuggestApps.LoadTime');
579 }; 552 };
OLDNEW
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/ui/directory_tree.js ('k') | ui/file_manager/file_manager/main.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698