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

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

Issue 10823273: Integrate external mount points to IsolatedContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove too strict DCHECK Created 8 years, 4 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
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 16 matching lines...) Expand all
27 #include "chrome/browser/ui/browser_finder.h" 27 #include "chrome/browser/ui/browser_finder.h"
28 #include "chrome/browser/ui/browser_tabstrip.h" 28 #include "chrome/browser/ui/browser_tabstrip.h"
29 #include "chrome/common/extensions/file_browser_handler.h" 29 #include "chrome/common/extensions/file_browser_handler.h"
30 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
31 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/child_process_security_policy.h" 32 #include "content/public/browser/child_process_security_policy.h"
33 #include "content/public/browser/render_process_host.h" 33 #include "content/public/browser/render_process_host.h"
34 #include "content/public/browser/site_instance.h" 34 #include "content/public/browser/site_instance.h"
35 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
36 #include "net/base/escape.h" 36 #include "net/base/escape.h"
37 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h"
37 #include "webkit/fileapi/file_system_context.h" 38 #include "webkit/fileapi/file_system_context.h"
38 #include "webkit/fileapi/file_system_mount_point_provider.h" 39 #include "webkit/fileapi/file_system_url.h"
39 #include "webkit/fileapi/file_system_util.h" 40 #include "webkit/fileapi/file_system_util.h"
40 41
41 using content::BrowserContext; 42 using content::BrowserContext;
42 using content::BrowserThread; 43 using content::BrowserThread;
43 using content::ChildProcessSecurityPolicy; 44 using content::ChildProcessSecurityPolicy;
44 using content::SiteInstance; 45 using content::SiteInstance;
45 using content::WebContents; 46 using content::WebContents;
46 using extensions::Extension; 47 using extensions::Extension;
47 48
48 namespace file_handler_util { 49 namespace file_handler_util {
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 // Checks legitimacy of file url and grants file RO access permissions from 560 // Checks legitimacy of file url and grants file RO access permissions from
560 // handler (target) extension and its renderer process. 561 // handler (target) extension and its renderer process.
561 bool SetupFileAccessPermissions(const GURL& origin_file_url, 562 bool SetupFileAccessPermissions(const GURL& origin_file_url,
562 FileDefinition* file) { 563 FileDefinition* file) {
563 if (!handler_extension_.get()) 564 if (!handler_extension_.get())
564 return false; 565 return false;
565 566
566 if (handler_pid_ == 0) 567 if (handler_pid_ == 0)
567 return false; 568 return false;
568 569
569 GURL file_origin_url; 570 fileapi::FileSystemURL url(origin_file_url);
570 FilePath virtual_path; 571 if (!chromeos::CrosMountPointProvider::CanHandleURL(url))
571 fileapi::FileSystemType type;
572 if (!CrackFileSystemURL(origin_file_url, &file_origin_url, &type,
573 &virtual_path)) {
574 return false;
575 }
576
577 if (type != fileapi::kFileSystemTypeExternal)
578 return false; 572 return false;
579 573
580 fileapi::ExternalFileSystemMountPointProvider* external_provider = 574 fileapi::ExternalFileSystemMountPointProvider* external_provider =
581 file_system_context_->external_provider(); 575 file_system_context_->external_provider();
582 if (!external_provider) 576 if (!external_provider)
583 return false; 577 return false;
584 578
585 if (!external_provider->IsAccessAllowed(file_origin_url, 579 if (!external_provider->IsAccessAllowed(url.origin(),
586 type, 580 url.type(),
587 virtual_path)) { 581 url.virtual_path())) {
588 return false; 582 return false;
589 } 583 }
590 584
591 // Make sure this url really being used by the right caller extension. 585 // Make sure this url really being used by the right caller extension.
592 if (source_url_.GetOrigin() != file_origin_url) { 586 if (source_url_.GetOrigin() != url.origin()) {
593 DidFail(base::PLATFORM_FILE_ERROR_SECURITY); 587 DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
594 return false; 588 return false;
595 } 589 }
596 590
597 FilePath root_path =
598 external_provider->GetFileSystemRootPathOnFileThread(
599 file_origin_url,
600 fileapi::kFileSystemTypeExternal,
601 virtual_path,
602 false); // create
603 FilePath final_file_path = root_path.Append(virtual_path);
604
605 // Check if this file system entry exists first. 591 // Check if this file system entry exists first.
606 base::PlatformFileInfo file_info; 592 base::PlatformFileInfo file_info;
607 593
608 bool is_gdata_file = gdata::util::IsUnderGDataMountPoint(final_file_path); 594 FilePath local_path = url.path();
595 FilePath virtual_path = url.virtual_path();
596
597 bool is_drive_file = url.type() == fileapi::kFileSystemTypeDrive;
598 DCHECK(!is_drive_file || gdata::util::IsUnderGDataMountPoint(local_path));
609 599
610 // If the file is under gdata mount point, there is no actual file to be 600 // If the file is under gdata mount point, there is no actual file to be
611 // found on the final_file_path. 601 // found on the url.path().
612 if (!is_gdata_file) { 602 if (!is_drive_file) {
613 if (!file_util::PathExists(final_file_path) || 603 if (!file_util::PathExists(local_path) ||
614 file_util::IsLink(final_file_path) || 604 file_util::IsLink(local_path) ||
615 !file_util::GetFileInfo(final_file_path, &file_info)) { 605 !file_util::GetFileInfo(local_path, &file_info)) {
616 return false; 606 return false;
617 } 607 }
618 } 608 }
619 609
620 // Grant access to this particular file to target extension. This will 610 // Grant access to this particular file to target extension. This will
621 // ensure that the target extension can access only this FS entry and 611 // ensure that the target extension can access only this FS entry and
622 // prevent from traversing FS hierarchy upward. 612 // prevent from traversing FS hierarchy upward.
623 external_provider->GrantFileAccessToExtension(handler_extension_->id(), 613 external_provider->GrantFileAccessToExtension(handler_extension_->id(),
624 virtual_path); 614 virtual_path);
625 615
626 // Output values. 616 // Output values.
627 GURL target_origin_url(Extension::GetBaseURLFromExtensionId( 617 GURL target_origin_url(Extension::GetBaseURLFromExtensionId(
628 handler_extension_->id())); 618 handler_extension_->id()));
629 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url, 619 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url,
630 fileapi::kFileSystemTypeExternal); 620 fileapi::kFileSystemTypeExternal);
631 file->target_file_url = GURL(base_url.spec() + virtual_path.value()); 621 file->target_file_url = GURL(base_url.spec() + virtual_path.value());
632 file->virtual_path = virtual_path; 622 file->virtual_path = virtual_path;
633 file->is_directory = file_info.is_directory; 623 file->is_directory = file_info.is_directory;
634 file->absolute_path = final_file_path; 624 file->absolute_path = local_path;
635 return true; 625 return true;
636 } 626 }
637 627
638 ExtensionTaskExecutor* executor_; 628 ExtensionTaskExecutor* executor_;
639 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 629 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
640 // Extension source URL. 630 // Extension source URL.
641 GURL source_url_; 631 GURL source_url_;
642 scoped_refptr<const Extension> handler_extension_; 632 scoped_refptr<const Extension> handler_extension_;
643 int handler_pid_; 633 int handler_pid_;
644 std::string action_id_; 634 std::string action_id_;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 handler_pid, 878 handler_pid,
889 handler_host_permissions_[i].first, 879 handler_host_permissions_[i].first,
890 handler_host_permissions_[i].second); 880 handler_host_permissions_[i].second);
891 } 881 }
892 882
893 // We don't need this anymore. 883 // We don't need this anymore.
894 handler_host_permissions_.clear(); 884 handler_host_permissions_.clear();
895 } 885 }
896 886
897 } // namespace file_handler_util 887 } // namespace file_handler_util
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_browser_private_api.cc ('k') | chrome/browser/chromeos/gdata/drive_task_executor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698