OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/arc_file_tasks.h" | 5 #include "chrome/browser/chromeos/file_manager/arc_file_tasks.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/base64.h" | 13 #include "base/base64.h" |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
19 #include "chrome/browser/chromeos/file_manager/path_util.h" | 19 #include "chrome/browser/chromeos/file_manager/path_util.h" |
20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
21 #include "chrome/common/extensions/api/file_manager_private.h" | 21 #include "chrome/common/extensions/api/file_manager_private.h" |
22 #include "components/arc/arc_bridge_service.h" | 22 #include "components/arc/arc_bridge_service.h" |
23 #include "components/arc/arc_service_manager.h" | 23 #include "components/arc/arc_service_manager.h" |
24 #include "components/arc/common/intent_helper.mojom.h" | 24 #include "components/arc/common/intent_helper.mojom.h" |
25 #include "components/arc/intent_helper/activity_icon_loader.h" | 25 #include "components/arc/intent_helper/activity_icon_loader.h" |
26 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" | 26 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
| 27 #include "components/arc/intent_helper/intent_constants.h" |
27 #include "components/user_manager/user_manager.h" | 28 #include "components/user_manager/user_manager.h" |
28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
29 #include "extensions/browser/entry_info.h" | 30 #include "extensions/browser/entry_info.h" |
30 #include "mojo/public/cpp/bindings/binding.h" | 31 #include "mojo/public/cpp/bindings/binding.h" |
31 #include "net/base/escape.h" | 32 #include "net/base/escape.h" |
32 #include "net/base/filename_util.h" | 33 #include "net/base/filename_util.h" |
33 #include "storage/browser/fileapi/file_system_url.h" | 34 #include "storage/browser/fileapi/file_system_url.h" |
34 #include "url/gurl.h" | 35 #include "url/gurl.h" |
35 | 36 |
36 namespace file_manager { | 37 namespace file_manager { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // Returns the icon loader that wraps the Mojo interface for ARC Intent Helper. | 69 // Returns the icon loader that wraps the Mojo interface for ARC Intent Helper. |
69 scoped_refptr<arc::ActivityIconLoader> GetArcActivityIconLoader() { | 70 scoped_refptr<arc::ActivityIconLoader> GetArcActivityIconLoader() { |
70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
71 | 72 |
72 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); | 73 arc::ArcServiceManager* arc_service_manager = arc::ArcServiceManager::Get(); |
73 if (!arc_service_manager) | 74 if (!arc_service_manager) |
74 return nullptr; | 75 return nullptr; |
75 return arc_service_manager->icon_loader(); | 76 return arc_service_manager->icon_loader(); |
76 } | 77 } |
77 | 78 |
78 std::string ArcActionTypeToString(arc::mojom::ActionType action_type) { | 79 // Converts an Android intent action (see kIntentAction* in |
79 switch (action_type) { | 80 // components/arc/intent_helper/intent_constants.h) to a file task action ID |
80 case arc::mojom::ActionType::VIEW: | 81 // (see chrome/browser/chromeos/file_manager/file_tasks.h). |
81 return "view"; | 82 std::string ArcActionToFileTaskActionId(const std::string& action) { |
82 case arc::mojom::ActionType::SEND: | 83 if (action == arc::kIntentActionView) |
83 return "send"; | 84 return "view"; |
84 case arc::mojom::ActionType::SEND_MULTIPLE: | 85 else if (action == arc::kIntentActionSend) |
85 return "send_multiple"; | 86 return "send"; |
86 } | 87 else if (action == arc::kIntentActionSendMultiple) |
87 NOTREACHED(); | 88 return "send_multiple"; |
| 89 NOTREACHED() << "Unhandled ARC action \"" << action << "\""; |
88 return ""; | 90 return ""; |
89 } | 91 } |
90 | 92 |
91 arc::mojom::ActionType StringToArcActionType(const std::string& str) { | 93 // TODO(derat): Replace this with a FileTaskActionIdToArcAction method once |
92 if (str == "view") | 94 // HandleUrlList has been updated to take a string action rather than an |
| 95 // ArcActionType. |
| 96 arc::mojom::ActionType FileTaskActionIdToArcActionType(const std::string& id) { |
| 97 if (id == "view") |
93 return arc::mojom::ActionType::VIEW; | 98 return arc::mojom::ActionType::VIEW; |
94 if (str == "send") | 99 if (id == "send") |
95 return arc::mojom::ActionType::SEND; | 100 return arc::mojom::ActionType::SEND; |
96 if (str == "send_multiple") | 101 if (id == "send_multiple") |
97 return arc::mojom::ActionType::SEND_MULTIPLE; | 102 return arc::mojom::ActionType::SEND_MULTIPLE; |
98 NOTREACHED(); | 103 NOTREACHED() << "Unhandled file task action ID \"" << id << "\""; |
99 return arc::mojom::ActionType::VIEW; | 104 return arc::mojom::ActionType::VIEW; |
100 } | 105 } |
101 | 106 |
102 std::string ActivityNameToAppId(const std::string& package_name, | 107 std::string ActivityNameToAppId(const std::string& package_name, |
103 const std::string& activity_name) { | 108 const std::string& activity_name) { |
104 return package_name + kAppIdSeparator + activity_name; | 109 return package_name + kAppIdSeparator + activity_name; |
105 } | 110 } |
106 | 111 |
107 arc::mojom::ActivityNamePtr AppIdToActivityName(const std::string& id) { | 112 arc::mojom::ActivityNamePtr AppIdToActivityName(const std::string& id) { |
108 arc::mojom::ActivityNamePtr name = arc::mojom::ActivityName::New(); | 113 arc::mojom::ActivityNamePtr name = arc::mojom::ActivityName::New(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, | 251 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, |
247 const FindTasksCallback& callback, | 252 const FindTasksCallback& callback, |
248 mojo::Array<arc::mojom::IntentHandlerInfoPtr> handlers, | 253 mojo::Array<arc::mojom::IntentHandlerInfoPtr> handlers, |
249 std::unique_ptr<IconUrlMap> icons) { | 254 std::unique_ptr<IconUrlMap> icons) { |
250 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 255 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
251 | 256 |
252 using extensions::api::file_manager_private::Verb; | 257 using extensions::api::file_manager_private::Verb; |
253 for (const arc::mojom::IntentHandlerInfoPtr& handler : handlers) { | 258 for (const arc::mojom::IntentHandlerInfoPtr& handler : handlers) { |
254 std::string name(handler->name); | 259 std::string name(handler->name); |
255 Verb handler_verb = Verb::VERB_NONE; | 260 Verb handler_verb = Verb::VERB_NONE; |
256 if (handler->action_type == arc::mojom::ActionType::SEND || | 261 if (handler->action == arc::kIntentActionSend || |
257 handler->action_type == arc::mojom::ActionType::SEND_MULTIPLE) { | 262 handler->action == arc::kIntentActionSendMultiple) { |
258 handler_verb = Verb::VERB_SHARE_WITH; | 263 handler_verb = Verb::VERB_SHARE_WITH; |
259 } | 264 } |
260 const GURL& icon_url = (*icons)[arc::ActivityIconLoader::ActivityName( | 265 const GURL& icon_url = (*icons)[arc::ActivityIconLoader::ActivityName( |
261 handler->package_name, handler->activity_name)]; | 266 handler->package_name, handler->activity_name)]; |
262 result_list->push_back(FullTaskDescriptor( | 267 result_list->push_back(FullTaskDescriptor( |
263 TaskDescriptor( | 268 TaskDescriptor( |
264 ActivityNameToAppId(handler->package_name, handler->activity_name), | 269 ActivityNameToAppId(handler->package_name, handler->activity_name), |
265 TASK_TYPE_ARC_APP, ArcActionTypeToString(handler->action_type)), | 270 TASK_TYPE_ARC_APP, ArcActionToFileTaskActionId(handler->action)), |
266 name, handler_verb, icon_url, false /* is_default */, | 271 name, handler_verb, icon_url, false /* is_default */, |
267 handler->action_type != arc::mojom::ActionType::VIEW /* is_generic */)); | 272 handler->action != arc::kIntentActionView /* is_generic */)); |
268 } | 273 } |
269 callback.Run(std::move(result_list)); | 274 callback.Run(std::move(result_list)); |
270 } | 275 } |
271 | 276 |
272 } // namespace | 277 } // namespace |
273 | 278 |
274 void FindArcTasks(Profile* profile, | 279 void FindArcTasks(Profile* profile, |
275 const std::vector<extensions::EntryInfo>& entries, | 280 const std::vector<extensions::EntryInfo>& entries, |
276 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, | 281 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list, |
277 const FindTasksCallback& callback) { | 282 const FindTasksCallback& callback) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 return false; | 335 return false; |
331 } | 336 } |
332 | 337 |
333 arc::mojom::UrlWithMimeTypePtr url_with_type = | 338 arc::mojom::UrlWithMimeTypePtr url_with_type = |
334 arc::mojom::UrlWithMimeType::New(); | 339 arc::mojom::UrlWithMimeType::New(); |
335 url_with_type->url = url.spec(); | 340 url_with_type->url = url.spec(); |
336 url_with_type->mime_type = mime_types[i]; | 341 url_with_type->mime_type = mime_types[i]; |
337 urls.push_back(std::move(url_with_type)); | 342 urls.push_back(std::move(url_with_type)); |
338 } | 343 } |
339 | 344 |
340 arc_intent_helper->HandleUrlList(std::move(urls), | 345 arc_intent_helper->HandleUrlList( |
341 AppIdToActivityName(task.app_id), | 346 std::move(urls), AppIdToActivityName(task.app_id), |
342 StringToArcActionType(task.action_id)); | 347 FileTaskActionIdToArcActionType(task.action_id)); |
343 return true; | 348 return true; |
344 } | 349 } |
345 | 350 |
346 } // namespace file_tasks | 351 } // namespace file_tasks |
347 } // namespace file_manager | 352 } // namespace file_manager |
OLD | NEW |