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

Side by Side Diff: chrome/browser/resources/md_bookmarks/command_manager.js

Issue 2945513002: MD Bookmarks: Add a confirmation dialog before opening many tabs (Closed)
Patch Set: Rebase Created 3 years, 6 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 * @fileoverview Element which shows context menus and handles keyboard 6 * @fileoverview Element which shows context menus and handles keyboard
7 * shortcuts. 7 * shortcuts.
8 */ 8 */
9 cr.define('bookmarks', function() { 9 cr.define('bookmarks', function() {
10 10
(...skipping 19 matching lines...) Expand all
30 Command.OPEN_INCOGNITO, 30 Command.OPEN_INCOGNITO,
31 ]; 31 ];
32 }, 32 },
33 }, 33 },
34 34
35 /** @private {Set<string>} */ 35 /** @private {Set<string>} */
36 menuIds_: Object, 36 menuIds_: Object,
37 37
38 /** @private */ 38 /** @private */
39 globalCanEdit_: Boolean, 39 globalCanEdit_: Boolean,
40
41 /** @private */
42 confirmOpenString_: String,
40 }, 43 },
41 44
45 /** @private {?Function} */
46 confirmOpenCallback_: null,
47
42 attached: function() { 48 attached: function() {
43 assert(CommandManager.instance_ == null); 49 assert(CommandManager.instance_ == null);
44 CommandManager.instance_ = this; 50 CommandManager.instance_ = this;
45 51
46 this.watch('globalCanEdit_', function(state) { 52 this.watch('globalCanEdit_', function(state) {
47 return state.prefs.canEdit; 53 return state.prefs.canEdit;
48 }); 54 });
49 this.updateFromStore(); 55 this.updateFromStore();
50 56
51 /** @private {function(!Event)} */ 57 /** @private {function(!Event)} */
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 currentId = assert(nodes[currentId].parentId); 314 currentId = assert(nodes[currentId].parentId);
309 if (itemIds.has(currentId)) 315 if (itemIds.has(currentId))
310 return; 316 return;
311 } 317 }
312 minimizedSet.add(itemId); 318 minimizedSet.add(itemId);
313 }); 319 });
314 return minimizedSet; 320 return minimizedSet;
315 }, 321 },
316 322
317 /** 323 /**
324 * Open the given |urls| in response to a |command|. May show a confirmation
325 * dialog before opening large numbers of URLs.
318 * @param {!Array<string>} urls 326 * @param {!Array<string>} urls
319 * @param {Command} command 327 * @param {Command} command
320 * @private 328 * @private
321 */ 329 */
322 openUrls_: function(urls, command) { 330 openUrls_: function(urls, command) {
323 assert( 331 assert(
324 command == Command.OPEN || command == Command.OPEN_NEW_TAB || 332 command == Command.OPEN || command == Command.OPEN_NEW_TAB ||
325 command == Command.OPEN_NEW_WINDOW || 333 command == Command.OPEN_NEW_WINDOW ||
326 command == Command.OPEN_INCOGNITO); 334 command == Command.OPEN_INCOGNITO);
327 335
328 if (urls.length == 0) 336 if (urls.length == 0)
329 return; 337 return;
330 338
331 var incognito = command == Command.OPEN_INCOGNITO; 339 var callback = function() {
calamity 2017/06/22 05:15:33 nit: openUrls?
tsergeant 2017/06/22 07:47:31 Changed it to openUrlsCallback, since I didn't rea
332 if (command == Command.OPEN_NEW_WINDOW || incognito) { 340 var incognito = command == Command.OPEN_INCOGNITO;
333 chrome.windows.create({url: urls, incognito: incognito}); 341 if (command == Command.OPEN_NEW_WINDOW || incognito) {
334 } else { 342 chrome.windows.create({url: urls, incognito: incognito});
335 if (command == Command.OPEN) 343 } else {
336 chrome.tabs.create({url: urls.shift(), active: true}); 344 if (command == Command.OPEN)
337 urls.forEach(function(url) { 345 chrome.tabs.create({url: urls.shift(), active: true});
338 chrome.tabs.create({url: url, active: false}); 346 urls.forEach(function(url) {
339 }); 347 chrome.tabs.create({url: url, active: false});
348 });
349 }
350 };
351
352 if (urls.length <= OPEN_CONFIRMATION_LIMIT) {
353 callback();
354 return;
340 } 355 }
356
357 this.confirmOpenString_ =
calamity 2017/06/22 05:15:33 Is this worth making a property? Can we just get t
tsergeant 2017/06/22 07:47:31 Done.
358 loadTimeData.getStringF('openDialogBody', urls.length);
359 this.confirmOpenCallback_ = callback;
360
361 this.$.openDialog.get().showModal();
341 }, 362 },
342 363
343 /** 364 /**
344 * Returns all URLs in the given set of nodes and their immediate children. 365 * Returns all URLs in the given set of nodes and their immediate children.
345 * Note that these will be ordered by insertion order into the |itemIds| 366 * Note that these will be ordered by insertion order into the |itemIds|
346 * set, and that it is possible to duplicate a URL by passing in both the 367 * set, and that it is possible to duplicate a URL by passing in both the
347 * parent ID and child ID. 368 * parent ID and child ID.
348 * @param {!Set<string>} itemIds 369 * @param {!Set<string>} itemIds
349 * @return {!Array<string>} 370 * @return {!Array<string>}
350 * @private 371 * @private
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 * @param {Event} e 454 * @param {Event} e
434 * @private 455 * @private
435 */ 456 */
436 onMenuMousedown_: function(e) { 457 onMenuMousedown_: function(e) {
437 if (e.path[0] != this.$.dropdown) 458 if (e.path[0] != this.$.dropdown)
438 return; 459 return;
439 460
440 this.closeCommandMenu(); 461 this.closeCommandMenu();
441 }, 462 },
442 463
464 /** @private */
465 onOpenCancelTap_: function() {
466 this.$.openDialog.get().cancel();
467 },
468
469 /** @private */
470 onOpenConfirmTap_: function() {
471 this.confirmOpenCallback_();
472 this.$.openDialog.get().close();
473 },
474
443 /** 475 /**
444 * @param {Command} command 476 * @param {Command} command
445 * @return {string} 477 * @return {string}
446 * @private 478 * @private
447 */ 479 */
448 getCommandLabel_: function(command) { 480 getCommandLabel_: function(command) {
449 var multipleNodes = this.menuIds_.size > 1 || 481 var multipleNodes = this.menuIds_.size > 1 ||
450 this.containsMatchingNode_(this.menuIds_, function(node) { 482 this.containsMatchingNode_(this.menuIds_, function(node) {
451 return !node.url; 483 return !node.url;
452 }); 484 });
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 528
497 /** @return {!bookmarks.CommandManager} */ 529 /** @return {!bookmarks.CommandManager} */
498 CommandManager.getInstance = function() { 530 CommandManager.getInstance = function() {
499 return assert(CommandManager.instance_); 531 return assert(CommandManager.instance_);
500 }; 532 };
501 533
502 return { 534 return {
503 CommandManager: CommandManager, 535 CommandManager: CommandManager,
504 }; 536 };
505 }); 537 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698