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

Side by Side Diff: chrome/browser/chromeos/extensions/file_handler_util.cc

Issue 12218136: [cros] Remove file manager code for WebIntents file tasks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/extensions/file_handler_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/extensions/file_handler_util.h" 5 #include "chrome/browser/chromeos/extensions/file_handler_util.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/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 using content::ChildProcessSecurityPolicy; 48 using content::ChildProcessSecurityPolicy;
49 using content::SiteInstance; 49 using content::SiteInstance;
50 using content::WebContents; 50 using content::WebContents;
51 using extensions::Extension; 51 using extensions::Extension;
52 using fileapi::FileSystemURL; 52 using fileapi::FileSystemURL;
53 53
54 namespace file_handler_util { 54 namespace file_handler_util {
55 55
56 const char kTaskFile[] = "file"; 56 const char kTaskFile[] = "file";
57 const char kTaskDrive[] = "drive"; 57 const char kTaskDrive[] = "drive";
58 const char kTaskWebIntent[] = "web-intent";
59 const char kTaskApp[] = "app"; 58 const char kTaskApp[] = "app";
60 59
61 namespace { 60 namespace {
62 61
63 // Legacy Drive task extension prefix, used by CrackTaskID. 62 // Legacy Drive task extension prefix, used by CrackTaskID.
64 const char kDriveTaskExtensionPrefix[] = "drive-app:"; 63 const char kDriveTaskExtensionPrefix[] = "drive-app:";
65 const size_t kDriveTaskExtensionPrefixLength = 64 const size_t kDriveTaskExtensionPrefixLength =
66 arraysize(kDriveTaskExtensionPrefix) - 1; 65 arraysize(kDriveTaskExtensionPrefix) - 1;
67 66
68 typedef std::set<const FileBrowserHandler*> FileBrowserHandlerSet; 67 typedef std::set<const FileBrowserHandler*> FileBrowserHandlerSet;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 262
264 int GetReadOnlyPermissions() { 263 int GetReadOnlyPermissions() {
265 return kReadOnlyFilePermissions; 264 return kReadOnlyFilePermissions;
266 } 265 }
267 266
268 std::string MakeTaskID(const std::string& extension_id, 267 std::string MakeTaskID(const std::string& extension_id,
269 const std::string& task_type, 268 const std::string& task_type,
270 const std::string& action_id) { 269 const std::string& action_id) {
271 DCHECK(task_type == kTaskFile || 270 DCHECK(task_type == kTaskFile ||
272 task_type == kTaskDrive || 271 task_type == kTaskDrive ||
273 task_type == kTaskWebIntent ||
274 task_type == kTaskApp); 272 task_type == kTaskApp);
275 return base::StringPrintf("%s|%s|%s", 273 return base::StringPrintf("%s|%s|%s",
276 extension_id.c_str(), 274 extension_id.c_str(),
277 task_type.c_str(), 275 task_type.c_str(),
278 action_id.c_str()); 276 action_id.c_str());
279 } 277 }
280 278
281 // Breaks down task_id that is used between getFileTasks() and executeTask() on 279 // Breaks down task_id that is used between getFileTasks() and executeTask() on
282 // its building blocks. task_id field the following structure: 280 // its building blocks. task_id field the following structure:
283 // <extension-id>|<task-type>|<task-action-id> 281 // <extension-id>|<task-type>|<task-action-id>
(...skipping 30 matching lines...) Expand all
314 if (count != 3) 312 if (count != 3)
315 return false; 313 return false;
316 314
317 if (extension_id) 315 if (extension_id)
318 *extension_id = result[0]; 316 *extension_id = result[0];
319 317
320 if (task_type) { 318 if (task_type) {
321 *task_type = result[1]; 319 *task_type = result[1];
322 DCHECK(*task_type == kTaskFile || 320 DCHECK(*task_type == kTaskFile ||
323 *task_type == kTaskDrive || 321 *task_type == kTaskDrive ||
324 *task_type == kTaskWebIntent ||
325 *task_type == kTaskApp); 322 *task_type == kTaskApp);
326 } 323 }
327 324
328 if (action_id) 325 if (action_id)
329 *action_id = result[2]; 326 *action_id = result[2];
330 327
331 return true; 328 return true;
332 } 329 }
333 330
334 // Find a specific handler in the handler list. 331 // Find a specific handler in the handler list.
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 void SetupHandlerHostFileAccessPermissions( 532 void SetupHandlerHostFileAccessPermissions(
536 const FileDefinitionList& file_list, 533 const FileDefinitionList& file_list,
537 const Extension* extension, 534 const Extension* extension,
538 int handler_pid); 535 int handler_pid);
539 536
540 int32 tab_id_; 537 int32 tab_id_;
541 const std::string action_id_; 538 const std::string action_id_;
542 FileTaskFinishedCallback done_; 539 FileTaskFinishedCallback done_;
543 }; 540 };
544 541
545 class WebIntentTaskExecutor : public FileTaskExecutor {
546 public:
547 // FileTaskExecutor overrides.
548 virtual bool ExecuteAndNotify(const std::vector<FileSystemURL>& file_urls,
549 const FileTaskFinishedCallback& done) OVERRIDE;
550
551 private:
552 // FileTaskExecutor is the only class allowed to create one.
553 friend class FileTaskExecutor;
554
555 WebIntentTaskExecutor(Profile* profile,
556 const GURL& source_url,
557 const std::string& file_browser_id,
558 const std::string& extension_id,
559 const std::string& action_id);
560 virtual ~WebIntentTaskExecutor();
561
562 const std::string extension_id_;
563 const std::string action_id_;
564 };
565
566 class AppTaskExecutor : public FileTaskExecutor { 542 class AppTaskExecutor : public FileTaskExecutor {
567 public: 543 public:
568 // FileTaskExecutor overrides. 544 // FileTaskExecutor overrides.
569 virtual bool ExecuteAndNotify(const std::vector<FileSystemURL>& file_urls, 545 virtual bool ExecuteAndNotify(const std::vector<FileSystemURL>& file_urls,
570 const FileTaskFinishedCallback& done) OVERRIDE; 546 const FileTaskFinishedCallback& done) OVERRIDE;
571 547
572 private: 548 private:
573 // FileTaskExecutor is the only class allowed to create one. 549 // FileTaskExecutor is the only class allowed to create one.
574 friend class FileTaskExecutor; 550 friend class FileTaskExecutor;
575 551
(...skipping 22 matching lines...) Expand all
598 file_browser_id, 574 file_browser_id,
599 tab_id, 575 tab_id,
600 extension_id, 576 extension_id,
601 action_id); 577 action_id);
602 578
603 if (task_type == kTaskDrive) 579 if (task_type == kTaskDrive)
604 return new drive::DriveTaskExecutor(profile, 580 return new drive::DriveTaskExecutor(profile,
605 extension_id, // really app_id 581 extension_id, // really app_id
606 action_id); 582 action_id);
607 583
608 if (task_type == kTaskWebIntent)
609 return new WebIntentTaskExecutor(profile,
610 source_url,
611 file_browser_id,
612 extension_id,
613 action_id);
614
615 if (task_type == kTaskApp) 584 if (task_type == kTaskApp)
616 return new AppTaskExecutor(profile, 585 return new AppTaskExecutor(profile,
617 source_url, 586 source_url,
618 file_browser_id, 587 file_browser_id,
619 extension_id, 588 extension_id,
620 action_id); 589 action_id);
621 590
622 NOTREACHED(); 591 NOTREACHED();
623 return NULL; 592 return NULL;
624 } 593 }
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 for (FileDefinitionList::const_iterator iter = file_list.begin(); 974 for (FileDefinitionList::const_iterator iter = file_list.begin();
1006 iter != file_list.end(); 975 iter != file_list.end();
1007 ++iter) { 976 ++iter) {
1008 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( 977 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile(
1009 handler_pid, 978 handler_pid,
1010 iter->absolute_path, 979 iter->absolute_path,
1011 GetAccessPermissionsForFileBrowserHandler(extension, action_id_)); 980 GetAccessPermissionsForFileBrowserHandler(extension, action_id_));
1012 } 981 }
1013 } 982 }
1014 983
1015 WebIntentTaskExecutor::WebIntentTaskExecutor(
1016 Profile* profile,
1017 const GURL& source_url,
1018 const std::string& file_browser_id,
1019 const std::string& extension_id,
1020 const std::string& action_id)
1021 : FileTaskExecutor(profile, source_url, file_browser_id, extension_id),
1022 action_id_(action_id) {
1023 }
1024
1025 WebIntentTaskExecutor::~WebIntentTaskExecutor() {}
1026
1027 bool WebIntentTaskExecutor::ExecuteAndNotify(
1028 const std::vector<FileSystemURL>& file_urls,
1029 const FileTaskFinishedCallback& done) {
1030 if (!FileBrowserHasAccessPermissionForFiles(file_urls))
1031 return false;
1032
1033 for (size_t i = 0; i != file_urls.size(); ++i) {
1034 extensions::LaunchPlatformAppWithPath(profile(), GetExtension(),
1035 file_urls[i].path());
1036 }
1037
1038 if (!done.is_null())
1039 done.Run(true);
1040
1041 return true;
1042 }
1043
1044 AppTaskExecutor::AppTaskExecutor( 984 AppTaskExecutor::AppTaskExecutor(
1045 Profile* profile, 985 Profile* profile,
1046 const GURL& source_url, 986 const GURL& source_url,
1047 const std::string& file_browser_id, 987 const std::string& file_browser_id,
1048 const std::string& extension_id, 988 const std::string& extension_id,
1049 const std::string& action_id) 989 const std::string& action_id)
1050 : FileTaskExecutor(profile, source_url, file_browser_id, extension_id), 990 : FileTaskExecutor(profile, source_url, file_browser_id, extension_id),
1051 action_id_(action_id) { 991 action_id_(action_id) {
1052 } 992 }
1053 993
1054 AppTaskExecutor::~AppTaskExecutor() {} 994 AppTaskExecutor::~AppTaskExecutor() {}
1055 995
1056 bool AppTaskExecutor::ExecuteAndNotify( 996 bool AppTaskExecutor::ExecuteAndNotify(
1057 const std::vector<FileSystemURL>& file_urls, 997 const std::vector<FileSystemURL>& file_urls,
1058 const FileTaskFinishedCallback& done) { 998 const FileTaskFinishedCallback& done) {
1059 if (!FileBrowserHasAccessPermissionForFiles(file_urls)) 999 if (!FileBrowserHasAccessPermissionForFiles(file_urls))
1060 return false; 1000 return false;
1061 1001
1062 for (size_t i = 0; i != file_urls.size(); ++i) { 1002 for (size_t i = 0; i != file_urls.size(); ++i) {
1063 extensions::LaunchPlatformAppWithFileHandler(profile(), GetExtension(), 1003 extensions::LaunchPlatformAppWithFileHandler(profile(), GetExtension(),
1064 action_id_, file_urls[i].path()); 1004 action_id_, file_urls[i].path());
1065 } 1005 }
1066 1006
1067 if (!done.is_null()) 1007 if (!done.is_null())
1068 done.Run(true); 1008 done.Run(true);
1069 return true; 1009 return true;
1070 } 1010 }
1071 1011
1072 } // namespace file_handler_util 1012 } // namespace file_handler_util
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_handler_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698