| 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 #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h" | 5 #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 const FileBrowserHandler* handler = handler_iter->get(); | 126 const FileBrowserHandler* handler = handler_iter->get(); |
| 127 if (!handler->MatchesURL(lowercase_url)) | 127 if (!handler->MatchesURL(lowercase_url)) |
| 128 continue; | 128 continue; |
| 129 | 129 |
| 130 results.push_back(handler_iter->get()); | 130 results.push_back(handler_iter->get()); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 return results; | 133 return results; |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Finds a file browser handler that matches |extension_id| and |action_id| | |
| 137 // from |handler_list|. Returns a mutable iterator to the handler if | |
| 138 // found. Returns handler_list->end() if not found. | |
| 139 FileBrowserHandlerList::iterator | |
| 140 FindFileBrowserHandlerForExtensionIdAndActionId( | |
| 141 FileBrowserHandlerList* handler_list, | |
| 142 const std::string& extension_id, | |
| 143 const std::string& action_id) { | |
| 144 DCHECK(handler_list); | |
| 145 | |
| 146 FileBrowserHandlerList::iterator iter = handler_list->begin(); | |
| 147 while (iter != handler_list->end() && | |
| 148 !((*iter)->extension_id() == extension_id && | |
| 149 (*iter)->id() == action_id)) { | |
| 150 ++iter; | |
| 151 } | |
| 152 return iter; | |
| 153 } | |
| 154 | |
| 155 // This class is used to execute a file browser handler task. Here's how this | 136 // This class is used to execute a file browser handler task. Here's how this |
| 156 // works: | 137 // works: |
| 157 // | 138 // |
| 158 // 1) Open the "external" file system | 139 // 1) Open the "external" file system |
| 159 // 2) Set up permissions for the target files on the external file system. | 140 // 2) Set up permissions for the target files on the external file system. |
| 160 // 3) Raise onExecute event with the action ID and entries of the target | 141 // 3) Raise onExecute event with the action ID and entries of the target |
| 161 // files. The event will launch the file browser handler if not active. | 142 // files. The event will launch the file browser handler if not active. |
| 162 // 4) In the file browser handler, onExecute event is handled and executes the | 143 // 4) In the file browser handler, onExecute event is handled and executes the |
| 163 // task in JavaScript. | 144 // task in JavaScript. |
| 164 // | 145 // |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 if (ContainsKey(common_handler_set, *itr)) | 518 if (ContainsKey(common_handler_set, *itr)) |
| 538 intersection.push_back(*itr); | 519 intersection.push_back(*itr); |
| 539 } | 520 } |
| 540 | 521 |
| 541 std::swap(common_handlers, intersection); | 522 std::swap(common_handlers, intersection); |
| 542 if (common_handlers.empty()) | 523 if (common_handlers.empty()) |
| 543 return FileBrowserHandlerList(); | 524 return FileBrowserHandlerList(); |
| 544 } | 525 } |
| 545 } | 526 } |
| 546 | 527 |
| 547 // "watch" and "gallery" are defined in the file manager's manifest.json. | |
| 548 FileBrowserHandlerList::iterator watch_iter = | |
| 549 FindFileBrowserHandlerForExtensionIdAndActionId( | |
| 550 &common_handlers, kFileManagerAppId, "watch"); | |
| 551 FileBrowserHandlerList::iterator gallery_iter = | |
| 552 FindFileBrowserHandlerForExtensionIdAndActionId( | |
| 553 &common_handlers, kFileManagerAppId, "gallery"); | |
| 554 if (watch_iter != common_handlers.end() && | |
| 555 gallery_iter != common_handlers.end()) { | |
| 556 // Both "watch" and "gallery" actions are applicable which means that the | |
| 557 // selection is all videos. Showing them both is confusing, so we only keep | |
| 558 // the one that makes more sense ("watch" for single selection, "gallery" | |
| 559 // for multiple selection). | |
| 560 if (file_list.size() == 1) | |
| 561 common_handlers.erase(gallery_iter); | |
| 562 else | |
| 563 common_handlers.erase(watch_iter); | |
| 564 } | |
| 565 | |
| 566 return common_handlers; | 528 return common_handlers; |
| 567 } | 529 } |
| 568 | 530 |
| 569 } // namespace file_browser_handlers | 531 } // namespace file_browser_handlers |
| 570 } // namespace file_manager | 532 } // namespace file_manager |
| OLD | NEW |