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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc

Issue 16316002: extensions: Get rid of RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.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_manager/file_browser_private_a pi.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_a pi.h"
6 6
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 #include <sys/statvfs.h> 8 #include <sys/statvfs.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <utime.h> 10 #include <utime.h>
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 // Returns a task id for the web app with |app_id|. 447 // Returns a task id for the web app with |app_id|.
448 std::string MakeWebAppTaskId(const std::string& app_id) { 448 std::string MakeWebAppTaskId(const std::string& app_id) {
449 // TODO(gspencer): For now, the action id is always "open-with", but we 449 // TODO(gspencer): For now, the action id is always "open-with", but we
450 // could add any actions that the drive app supports. 450 // could add any actions that the drive app supports.
451 return file_handler_util::MakeTaskID( 451 return file_handler_util::MakeTaskID(
452 app_id, file_handler_util::kTaskDrive, "open-with"); 452 app_id, file_handler_util::kTaskDrive, "open-with");
453 } 453 }
454 454
455 } // namespace 455 } // namespace
456 456
457 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher {
458 public:
459 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback(
460 RequestLocalFileSystemFunction* function,
461 scoped_refptr<fileapi::FileSystemContext> file_system_context,
462 int child_id,
463 scoped_refptr<const Extension> extension) {
464 return base::Bind(
465 &LocalFileSystemCallbackDispatcher::DidOpenFileSystem,
466 base::Owned(new LocalFileSystemCallbackDispatcher(
467 function, file_system_context, child_id, extension)));
468 }
469
470 void DidOpenFileSystem(base::PlatformFileError result,
471 const std::string& name,
472 const GURL& root_path) {
473 if (result != base::PLATFORM_FILE_OK) {
474 DidFail(result);
475 return;
476 }
477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
478 // Set up file permission access.
479 if (!SetupFileSystemAccessPermissions()) {
480 DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
481 return;
482 }
483
484 BrowserThread::PostTask(
485 BrowserThread::UI, FROM_HERE,
486 base::Bind(
487 &RequestLocalFileSystemFunction::RespondSuccessOnUIThread,
488 function_,
489 name,
490 root_path));
491 }
492
493 void DidFail(base::PlatformFileError error_code) {
494 BrowserThread::PostTask(
495 BrowserThread::UI, FROM_HERE,
496 base::Bind(
497 &RequestLocalFileSystemFunction::RespondFailedOnUIThread,
498 function_,
499 error_code));
500 }
501
502 private:
503 LocalFileSystemCallbackDispatcher(
504 RequestLocalFileSystemFunction* function,
505 scoped_refptr<fileapi::FileSystemContext> file_system_context,
506 int child_id,
507 scoped_refptr<const Extension> extension)
508 : function_(function),
509 file_system_context_(file_system_context),
510 child_id_(child_id),
511 extension_(extension) {
512 DCHECK(function_);
513 }
514
515 // Grants file system access permissions to file browser component.
516 bool SetupFileSystemAccessPermissions() {
517 if (!extension_.get())
518 return false;
519
520 // Make sure that only component extension can access the entire
521 // local file system.
522 if (extension_->location() != extensions::Manifest::COMPONENT) {
523 NOTREACHED() << "Private method access by non-component extension "
524 << extension_->id();
525 return false;
526 }
527
528 fileapi::ExternalFileSystemMountPointProvider* provider =
529 file_system_context_->external_provider();
530 if (!provider)
531 return false;
532
533 // Grant full access to File API from this component extension.
534 provider->GrantFullAccessToExtension(extension_->id());
535
536 // Grant R/W file permissions to the renderer hosting component
537 // extension for all paths exposed by our local file system provider.
538 std::vector<base::FilePath> root_dirs = provider->GetRootDirectories();
539 for (size_t i = 0; i < root_dirs.size(); ++i) {
540 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile(
541 child_id_, root_dirs[i],
542 file_handler_util::GetReadWritePermissions());
543 }
544 return true;
545 }
546
547 RequestLocalFileSystemFunction* function_;
548 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
549 // Renderer process id.
550 int child_id_;
551 // Extension source URL.
552 scoped_refptr<const Extension> extension_;
553 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher);
554 };
555
556 FileBrowserPrivateAPI::FileBrowserPrivateAPI(Profile* profile) 457 FileBrowserPrivateAPI::FileBrowserPrivateAPI(Profile* profile)
557 : event_router_(new FileManagerEventRouter(profile)) { 458 : event_router_(new FileManagerEventRouter(profile)) {
558 (new FileBrowserHandlerParser)->Register(); 459 (new FileBrowserHandlerParser)->Register();
559 460
560 ExtensionFunctionRegistry* registry = 461 ExtensionFunctionRegistry* registry =
561 ExtensionFunctionRegistry::GetInstance(); 462 ExtensionFunctionRegistry::GetInstance();
562 registry->RegisterFunction<LogoutUserFunction>(); 463 registry->RegisterFunction<LogoutUserFunction>();
563 registry->RegisterFunction<CancelFileDialogFunction>(); 464 registry->RegisterFunction<CancelFileDialogFunction>();
564 registry->RegisterFunction<ExecuteTasksFileBrowserFunction>(); 465 registry->RegisterFunction<ExecuteTasksFileBrowserFunction>();
565 registry->RegisterFunction<SetDefaultTaskFileBrowserFunction>(); 466 registry->RegisterFunction<SetDefaultTaskFileBrowserFunction>();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 508
608 // static 509 // static
609 FileBrowserPrivateAPI* FileBrowserPrivateAPI::Get(Profile* profile) { 510 FileBrowserPrivateAPI* FileBrowserPrivateAPI::Get(Profile* profile) {
610 return FileBrowserPrivateAPIFactory::GetForProfile(profile); 511 return FileBrowserPrivateAPIFactory::GetForProfile(profile);
611 } 512 }
612 513
613 void RequestLocalFileSystemFunction::RequestOnFileThread( 514 void RequestLocalFileSystemFunction::RequestOnFileThread(
614 scoped_refptr<fileapi::FileSystemContext> file_system_context, 515 scoped_refptr<fileapi::FileSystemContext> file_system_context,
615 const GURL& source_url, 516 const GURL& source_url,
616 int child_id) { 517 int child_id) {
518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
519
617 GURL origin_url = source_url.GetOrigin(); 520 GURL origin_url = source_url.GetOrigin();
618 file_system_context->OpenFileSystem( 521 file_system_context->OpenFileSystem(
619 origin_url, fileapi::kFileSystemTypeExternal, 522 origin_url,
523 fileapi::kFileSystemTypeExternal,
620 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, 524 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT,
621 LocalFileSystemCallbackDispatcher::CreateCallback( 525 base::Bind(&RequestLocalFileSystemFunction::DidOpenFileSystem,
526 this,
527 file_system_context,
528 child_id,
529 GetExtension()));
530 }
531
532 void RequestLocalFileSystemFunction::DidOpenFileSystem(
533 scoped_refptr<fileapi::FileSystemContext> file_system_context,
534 int child_id,
535 scoped_refptr<const extensions::Extension> extension,
536 base::PlatformFileError result,
537 const std::string& name,
538 const GURL& root_path) {
539 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
540
541 if (result != base::PLATFORM_FILE_OK) {
542 DidFail(result);
543 return;
544 }
545 // Set up file permission access.
546 if (!SetupFileSystemAccessPermissions(file_system_context,
547 child_id,
548 extension)) {
549 DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
550 return;
551 }
552
553 BrowserThread::PostTask(
554 BrowserThread::UI, FROM_HERE,
555 base::Bind(
556 &RequestLocalFileSystemFunction::RespondSuccessOnUIThread,
622 this, 557 this,
623 file_system_context, 558 name,
624 child_id, 559 root_path));
625 GetExtension())); 560 }
561
562 void RequestLocalFileSystemFunction::DidFail(
563 base::PlatformFileError error_code) {
564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
565
566 BrowserThread::PostTask(
567 BrowserThread::UI, FROM_HERE,
568 base::Bind(
569 &RequestLocalFileSystemFunction::RespondFailedOnUIThread,
570 this,
571 error_code));
572 }
573
574 bool RequestLocalFileSystemFunction::SetupFileSystemAccessPermissions(
575 scoped_refptr<fileapi::FileSystemContext> file_system_context,
576 int child_id,
577 scoped_refptr<const extensions::Extension> extension) {
578 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
579
580 if (!extension.get())
581 return false;
582
583 // Make sure that only component extension can access the entire
584 // local file system.
585 if (extension_->location() != extensions::Manifest::COMPONENT) {
586 NOTREACHED() << "Private method access by non-component extension "
587 << extension->id();
588 return false;
589 }
590
591 fileapi::ExternalFileSystemMountPointProvider* provider =
592 file_system_context->external_provider();
593 if (!provider)
594 return false;
595
596 // Grant full access to File API from this component extension.
597 provider->GrantFullAccessToExtension(extension_->id());
598
599 // Grant R/W file permissions to the renderer hosting component
600 // extension for all paths exposed by our local file system provider.
601 std::vector<base::FilePath> root_dirs = provider->GetRootDirectories();
602 for (size_t i = 0; i < root_dirs.size(); ++i) {
603 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile(
604 child_id, root_dirs[i],
605 file_handler_util::GetReadWritePermissions());
606 }
607 return true;
626 } 608 }
627 609
628 bool LogoutUserFunction::RunImpl() { 610 bool LogoutUserFunction::RunImpl() {
hashimoto 2013/06/03 06:05:29 nit: In file_browser_private_api.cc, LogoutUserFun
satorux1 2013/06/03 07:10:46 Done.
629 chrome::AttemptUserExit(); 611 chrome::AttemptUserExit();
630 return true; 612 return true;
631 } 613 }
632 614
633 bool RequestLocalFileSystemFunction::RunImpl() { 615 bool RequestLocalFileSystemFunction::RunImpl() {
634 if (!dispatcher() || !render_view_host() || !render_view_host()->GetProcess()) 616 if (!dispatcher() || !render_view_host() || !render_view_host()->GetProcess())
635 return false; 617 return false;
636 618
637 set_log_on_completion(true); 619 set_log_on_completion(true);
638 620
(...skipping 2548 matching lines...) Expand 10 before | Expand all | Expand 10 after
3187 OpenNewWindowFunction::OpenNewWindowFunction() {} 3169 OpenNewWindowFunction::OpenNewWindowFunction() {}
3188 3170
3189 OpenNewWindowFunction::~OpenNewWindowFunction() {} 3171 OpenNewWindowFunction::~OpenNewWindowFunction() {}
3190 3172
3191 bool OpenNewWindowFunction::RunImpl() { 3173 bool OpenNewWindowFunction::RunImpl() {
3192 std::string url; 3174 std::string url;
3193 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); 3175 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url));
3194 file_manager_util::OpenNewWindow(profile_, GURL(url)); 3176 file_manager_util::OpenNewWindow(profile_, GURL(url));
3195 return true; 3177 return true;
3196 } 3178 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698