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 /** | 5 /** |
6 * This object encapsulates everything related to tasks execution. | 6 * This object encapsulates everything related to tasks execution. |
7 * @param {FileManager} fileManager FileManager instance. | 7 * @param {FileManager} fileManager FileManager instance. |
8 * @param {Array.<string>} urls List of file urls. | 8 * @param {Array.<string>} urls List of file urls. |
9 */ | 9 */ |
10 function FileTasks(fileManager, urls) { | 10 function FileTasks(fileManager, urls) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 /** | 46 /** |
47 * Processes internal tasks. | 47 * Processes internal tasks. |
48 * @param {Array.<Object>} tasks The tasks. | 48 * @param {Array.<Object>} tasks The tasks. |
49 * @private | 49 * @private |
50 */ | 50 */ |
51 FileTasks.prototype.processTasks_ = function(tasks) { | 51 FileTasks.prototype.processTasks_ = function(tasks) { |
52 this.tasks_ = []; | 52 this.tasks_ = []; |
53 var id = this.fileManager_.getExtensionId(); | 53 var id = this.fileManager_.getExtensionId(); |
54 | 54 |
55 // TODO(kaznacheev): Teach menu items to use HiDPI assets. | |
56 function getFileTypeIcon(type) { | |
57 return chrome.extension.getURL( | |
58 'images/files/file_types/' + type + '.png'); | |
59 } | |
60 | |
61 for (var i = 0; i < tasks.length; i++) { | 55 for (var i = 0; i < tasks.length; i++) { |
62 var task = tasks[i]; | 56 var task = tasks[i]; |
63 | 57 |
64 // Tweak images, titles of internal tasks. | 58 // Tweak images, titles of internal tasks. |
65 var task_parts = task.taskId.split('|'); | 59 var task_parts = task.taskId.split('|'); |
66 if (task_parts[0] == id) { | 60 if (task_parts[0] == id) { |
67 if (task_parts[1] == 'play') { | 61 if (task_parts[1] == 'play') { |
68 // TODO(serya): This hack needed until task.iconUrl is working | 62 // TODO(serya): This hack needed until task.iconUrl is working |
69 // (see GetFileTasksFileBrowserFunction::RunImpl). | 63 // (see GetFileTasksFileBrowserFunction::RunImpl). |
70 task.iconUrl = getFileTypeIcon('audio'); | 64 task.iconType = 'audio'; |
71 task.title = loadTimeData.getString('ACTION_LISTEN'); | 65 task.title = loadTimeData.getString('ACTION_LISTEN'); |
72 } else if (task_parts[1] == 'mount-archive') { | 66 } else if (task_parts[1] == 'mount-archive') { |
73 task.iconUrl = getFileTypeIcon('archive'); | 67 task.iconType = 'archive'; |
74 task.title = loadTimeData.getString('MOUNT_ARCHIVE'); | 68 task.title = loadTimeData.getString('MOUNT_ARCHIVE'); |
75 } else if (task_parts[1] == 'gallery') { | 69 } else if (task_parts[1] == 'gallery') { |
76 task.iconUrl = getFileTypeIcon('image'); | 70 task.iconType = 'image'; |
77 task.title = loadTimeData.getString('ACTION_OPEN'); | 71 task.title = loadTimeData.getString('ACTION_OPEN'); |
78 } else if (task_parts[1] == 'watch') { | 72 } else if (task_parts[1] == 'watch') { |
79 task.iconUrl = getFileTypeIcon('video'); | 73 task.iconType = 'video'; |
80 task.title = loadTimeData.getString('ACTION_WATCH'); | 74 task.title = loadTimeData.getString('ACTION_WATCH'); |
81 } else if (task_parts[1] == 'open-hosted') { | 75 } else if (task_parts[1] == 'open-hosted') { |
82 if (this.urls_.length > 1) | 76 if (this.urls_.length > 1) |
83 task.iconUrl = getFileTypeIcon('generic'); | 77 task.iconType = 'generic'; |
84 else // Use specific icon. | 78 else // Use specific icon. |
85 task.iconUrl = getFileTypeIcon(FileType.getIcon(this.urls_[0])); | 79 task.iconType = FileType.getIcon(this.urls_[0]); |
86 task.title = loadTimeData.getString('ACTION_OPEN'); | 80 task.title = loadTimeData.getString('ACTION_OPEN'); |
87 } else if (task_parts[1] == 'view-pdf') { | 81 } else if (task_parts[1] == 'view-pdf') { |
88 // Do not render this task if disabled. | 82 // Do not render this task if disabled. |
89 if (!loadTimeData.getBoolean('PDF_VIEW_ENABLED')) | 83 if (!loadTimeData.getBoolean('PDF_VIEW_ENABLED')) |
90 continue; | 84 continue; |
91 task.iconUrl = getFileTypeIcon('pdf'); | 85 task.iconType = 'pdf'; |
92 task.title = loadTimeData.getString('ACTION_VIEW'); | 86 task.title = loadTimeData.getString('ACTION_VIEW'); |
93 } else if (task_parts[1] == 'view-in-browser') { | 87 } else if (task_parts[1] == 'view-in-browser') { |
94 task.iconUrl = getFileTypeIcon('generic'); | 88 task.iconType = 'generic'; |
95 task.title = loadTimeData.getString('ACTION_VIEW'); | 89 task.title = loadTimeData.getString('ACTION_VIEW'); |
96 } else if (task_parts[1] == 'install-crx') { | 90 } else if (task_parts[1] == 'install-crx') { |
97 task.iconUrl = getFileTypeIcon('generic'); | 91 task.iconType = 'generic'; |
98 task.title = loadTimeData.getString('INSTALL_CRX'); | 92 task.title = loadTimeData.getString('INSTALL_CRX'); |
99 } | 93 } |
100 } | 94 } |
101 | 95 |
102 this.tasks_.push(task); | 96 this.tasks_.push(task); |
103 if (this.defaultTask_ == null) { | 97 if (this.defaultTask_ == null) { |
104 this.defaultTask_ = task; | 98 this.defaultTask_ = task; |
105 } | 99 } |
106 } | 100 } |
107 }; | 101 }; |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 }; | 462 }; |
469 | 463 |
470 /** | 464 /** |
471 * Creates combobutton item based on task. | 465 * Creates combobutton item based on task. |
472 * @param {Object} task Task to convert. | 466 * @param {Object} task Task to convert. |
473 * @param {string=} opt_title Title. | 467 * @param {string=} opt_title Title. |
474 * @return {Object} Item appendable to combobutton drop-down list. | 468 * @return {Object} Item appendable to combobutton drop-down list. |
475 * @private | 469 * @private |
476 */ | 470 */ |
477 FileTasks.prototype.createCombobuttonItem_ = function(task, opt_title) { | 471 FileTasks.prototype.createCombobuttonItem_ = function(task, opt_title) { |
478 return { label: opt_title || task.title, iconUrl: task.iconUrl, task: task }; | 472 return { |
| 473 label: opt_title || task.title, |
| 474 iconUrl: task.iconUrl, |
| 475 iconType: task.iconType, |
| 476 task: task |
| 477 }; |
479 }; | 478 }; |
480 | 479 |
481 | 480 |
482 /** | 481 /** |
483 * Decorates a FileTasks method, so it will be actually executed after the tasks | 482 * Decorates a FileTasks method, so it will be actually executed after the tasks |
484 * are available. | 483 * are available. |
485 * This decorator expects an implementation called |method + '_'|. | 484 * This decorator expects an implementation called |method + '_'|. |
486 * @param {string} method The method name. | 485 * @param {string} method The method name. |
487 */ | 486 */ |
488 FileTasks.decorate = function(method) { | 487 FileTasks.decorate = function(method) { |
489 var privateMethod = method + '_'; | 488 var privateMethod = method + '_'; |
490 FileTasks.prototype[method] = function() { | 489 FileTasks.prototype[method] = function() { |
491 if (this.tasks_) { | 490 if (this.tasks_) { |
492 this[privateMethod].apply(this, arguments); | 491 this[privateMethod].apply(this, arguments); |
493 } else { | 492 } else { |
494 this.pendingInvocations_.push([privateMethod, arguments]); | 493 this.pendingInvocations_.push([privateMethod, arguments]); |
495 } | 494 } |
496 return this; | 495 return this; |
497 }; | 496 }; |
498 }; | 497 }; |
499 | 498 |
500 FileTasks.decorate('display'); | 499 FileTasks.decorate('display'); |
501 FileTasks.decorate('updateMenuItem'); | 500 FileTasks.decorate('updateMenuItem'); |
502 FileTasks.decorate('execute'); | 501 FileTasks.decorate('execute'); |
503 FileTasks.decorate('executeDefault'); | 502 FileTasks.decorate('executeDefault'); |
504 FileTasks.decorate('getExternals'); | 503 FileTasks.decorate('getExternals'); |
505 | 504 |
OLD | NEW |