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

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: cros test fix 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 18 matching lines...) Expand all
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/fileapi/file_system_context.h" 37 #include "webkit/fileapi/file_system_context.h"
38 #include "webkit/fileapi/file_system_mount_point_provider.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 (!url.is_valid())
571 fileapi::FileSystemType type;
572 if (!CrackFileSystemURL(origin_file_url, &file_origin_url, &type,
573 &virtual_path)) {
574 return false; 572 return false;
575 }
576 573
577 if (type != fileapi::kFileSystemTypeExternal) 574 if (!fileapi::IsCrosManagedFileSystemType(url.type()))
578 return false; 575 return false;
579 576
580 fileapi::ExternalFileSystemMountPointProvider* external_provider = 577 fileapi::ExternalFileSystemMountPointProvider* external_provider =
581 file_system_context_->external_provider(); 578 file_system_context_->external_provider();
582 if (!external_provider) 579 if (!external_provider)
583 return false; 580 return false;
584 581
585 if (!external_provider->IsAccessAllowed(file_origin_url, 582 if (!external_provider->IsAccessAllowed(url.origin(),
586 type, 583 url.type(),
587 virtual_path)) { 584 url.virtual_path())) {
588 return false; 585 return false;
589 } 586 }
590 587
591 // Make sure this url really being used by the right caller extension. 588 // Make sure this url really being used by the right caller extension.
592 if (source_url_.GetOrigin() != file_origin_url) { 589 if (source_url_.GetOrigin() != url.origin()) {
593 DidFail(base::PLATFORM_FILE_ERROR_SECURITY); 590 DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
594 return false; 591 return false;
595 } 592 }
596 593
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. 594 // Check if this file system entry exists first.
606 base::PlatformFileInfo file_info; 595 base::PlatformFileInfo file_info;
607 596
608 bool is_gdata_file = gdata::util::IsUnderGDataMountPoint(final_file_path); 597 bool is_gdata_file = url.type() == fileapi::kFileSystemTypeGData;
satorux1 2012/08/20 03:30:23 is_gdata_file -> is_drive_file kFileSystemTypeGDa
kinuko 2012/08/20 08:54:35 Done.
598
599 DCHECK(!is_gdata_file || gdata::util::IsUnderGDataMountPoint(url.path()));
609 600
610 // If the file is under gdata mount point, there is no actual file to be 601 // If the file is under gdata mount point, there is no actual file to be
611 // found on the final_file_path. 602 // found on the url.path().
612 if (!is_gdata_file) { 603 if (!is_gdata_file) {
613 if (!file_util::PathExists(final_file_path) || 604 if (!file_util::PathExists(url.path()) ||
kmadhusu 2012/08/14 18:01:13 nit: url.path() and url.virtual_path() are called
kinuko 2012/08/20 08:54:35 Done.
614 file_util::IsLink(final_file_path) || 605 file_util::IsLink(url.path()) ||
615 !file_util::GetFileInfo(final_file_path, &file_info)) { 606 !file_util::GetFileInfo(url.path(), &file_info)) {
616 return false; 607 return false;
617 } 608 }
618 } 609 }
619 610
620 // Grant access to this particular file to target extension. This will 611 // Grant access to this particular file to target extension. This will
621 // ensure that the target extension can access only this FS entry and 612 // ensure that the target extension can access only this FS entry and
622 // prevent from traversing FS hierarchy upward. 613 // prevent from traversing FS hierarchy upward.
623 external_provider->GrantFileAccessToExtension(handler_extension_->id(), 614 external_provider->GrantFileAccessToExtension(handler_extension_->id(),
624 virtual_path); 615 url.virtual_path());
625 616
626 // Output values. 617 // Output values.
627 GURL target_origin_url(Extension::GetBaseURLFromExtensionId( 618 GURL target_origin_url(Extension::GetBaseURLFromExtensionId(
628 handler_extension_->id())); 619 handler_extension_->id()));
629 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url, 620 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url,
630 fileapi::kFileSystemTypeExternal); 621 fileapi::kFileSystemTypeExternal);
631 file->target_file_url = GURL(base_url.spec() + virtual_path.value()); 622 file->target_file_url = GURL(base_url.spec() + url.virtual_path().value());
632 file->virtual_path = virtual_path; 623 file->virtual_path = url.virtual_path();
633 file->is_directory = file_info.is_directory; 624 file->is_directory = file_info.is_directory;
634 file->absolute_path = final_file_path; 625 file->absolute_path = url.path();
635 return true; 626 return true;
636 } 627 }
637 628
638 ExtensionTaskExecutor* executor_; 629 ExtensionTaskExecutor* executor_;
639 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 630 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
640 // Extension source URL. 631 // Extension source URL.
641 GURL source_url_; 632 GURL source_url_;
642 scoped_refptr<const Extension> handler_extension_; 633 scoped_refptr<const Extension> handler_extension_;
643 int handler_pid_; 634 int handler_pid_;
644 std::string action_id_; 635 std::string action_id_;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 handler_pid, 879 handler_pid,
889 handler_host_permissions_[i].first, 880 handler_host_permissions_[i].first,
890 handler_host_permissions_[i].second); 881 handler_host_permissions_[i].second);
891 } 882 }
892 883
893 // We don't need this anymore. 884 // We don't need this anymore.
894 handler_host_permissions_.clear(); 885 handler_host_permissions_.clear();
895 } 886 }
896 887
897 } // namespace file_handler_util 888 } // namespace file_handler_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698