| OLD | NEW |
| 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/extensions/extension_file_browser_private_api.h" | 5 #include "chrome/browser/extensions/extension_file_browser_private_api.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "webkit/fileapi/file_system_mount_point_provider.h" | 47 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 48 #include "webkit/fileapi/file_system_operation_context.h" | 48 #include "webkit/fileapi/file_system_operation_context.h" |
| 49 #include "webkit/fileapi/file_system_types.h" | 49 #include "webkit/fileapi/file_system_types.h" |
| 50 #include "webkit/fileapi/file_system_util.h" | 50 #include "webkit/fileapi/file_system_util.h" |
| 51 | 51 |
| 52 #ifdef OS_CHROMEOS | 52 #ifdef OS_CHROMEOS |
| 53 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" | 53 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" |
| 54 #endif | 54 #endif |
| 55 | 55 |
| 56 using chromeos::disks::DiskMountManager; | 56 using chromeos::disks::DiskMountManager; |
| 57 using content::BrowserContext; |
| 57 using content::BrowserThread; | 58 using content::BrowserThread; |
| 58 using content::ChildProcessSecurityPolicy; | 59 using content::ChildProcessSecurityPolicy; |
| 59 using content::SiteInstance; | 60 using content::SiteInstance; |
| 60 using content::WebContents; | 61 using content::WebContents; |
| 61 | 62 |
| 62 namespace { | 63 namespace { |
| 63 | 64 |
| 64 // Error messages. | 65 // Error messages. |
| 65 const char kFileError[] = "File error %d"; | 66 const char kFileError[] = "File error %d"; |
| 66 const char kInvalidFileUrl[] = "Invalid file URL"; | 67 const char kInvalidFileUrl[] = "Invalid file URL"; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 383 |
| 383 // Make sure that only component extension can access the entire | 384 // Make sure that only component extension can access the entire |
| 384 // local file system. | 385 // local file system. |
| 385 if (extension_->location() != Extension::COMPONENT) { | 386 if (extension_->location() != Extension::COMPONENT) { |
| 386 NOTREACHED() << "Private method access by non-component extension " | 387 NOTREACHED() << "Private method access by non-component extension " |
| 387 << extension_->id(); | 388 << extension_->id(); |
| 388 return false; | 389 return false; |
| 389 } | 390 } |
| 390 | 391 |
| 391 fileapi::ExternalFileSystemMountPointProvider* provider = | 392 fileapi::ExternalFileSystemMountPointProvider* provider = |
| 392 profile_->GetFileSystemContext()->external_provider(); | 393 BrowserContext::GetFileSystemContext(profile_)->external_provider(); |
| 393 if (!provider) | 394 if (!provider) |
| 394 return false; | 395 return false; |
| 395 | 396 |
| 396 // Grant full access to File API from this component extension. | 397 // Grant full access to File API from this component extension. |
| 397 provider->GrantFullAccessToExtension(extension_->id()); | 398 provider->GrantFullAccessToExtension(extension_->id()); |
| 398 | 399 |
| 399 // Grant R/W file permissions to the renderer hosting component | 400 // Grant R/W file permissions to the renderer hosting component |
| 400 // extension for all paths exposed by our local file system provider. | 401 // extension for all paths exposed by our local file system provider. |
| 401 std::vector<FilePath> root_dirs = provider->GetRootDirectories(); | 402 std::vector<FilePath> root_dirs = provider->GetRootDirectories(); |
| 402 for (std::vector<FilePath>::iterator iter = root_dirs.begin(); | 403 for (std::vector<FilePath>::iterator iter = root_dirs.begin(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 413 // Renderer process id. | 414 // Renderer process id. |
| 414 int child_id_; | 415 int child_id_; |
| 415 // Extension source URL. | 416 // Extension source URL. |
| 416 scoped_refptr<const Extension> extension_; | 417 scoped_refptr<const Extension> extension_; |
| 417 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher); | 418 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher); |
| 418 }; | 419 }; |
| 419 | 420 |
| 420 void RequestLocalFileSystemFunction::RequestOnFileThread( | 421 void RequestLocalFileSystemFunction::RequestOnFileThread( |
| 421 const GURL& source_url, int child_id) { | 422 const GURL& source_url, int child_id) { |
| 422 GURL origin_url = source_url.GetOrigin(); | 423 GURL origin_url = source_url.GetOrigin(); |
| 423 profile()->GetFileSystemContext()->OpenFileSystem( | 424 BrowserContext::GetFileSystemContext(profile())->OpenFileSystem( |
| 424 origin_url, fileapi::kFileSystemTypeExternal, false, // create | 425 origin_url, fileapi::kFileSystemTypeExternal, false, // create |
| 425 LocalFileSystemCallbackDispatcher::CreateCallback( | 426 LocalFileSystemCallbackDispatcher::CreateCallback( |
| 426 this, | 427 this, |
| 427 profile(), | 428 profile(), |
| 428 child_id, | 429 child_id, |
| 429 GetExtension())); | 430 GetExtension())); |
| 430 } | 431 } |
| 431 | 432 |
| 432 bool RequestLocalFileSystemFunction::RunImpl() { | 433 bool RequestLocalFileSystemFunction::RunImpl() { |
| 433 if (!dispatcher() || !render_view_host() || !render_view_host()->process()) | 434 if (!dispatcher() || !render_view_host() || !render_view_host()->process()) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 const GURL& file_url, FilePath* local_path, FilePath* virtual_path) { | 467 const GURL& file_url, FilePath* local_path, FilePath* virtual_path) { |
| 467 GURL file_origin_url; | 468 GURL file_origin_url; |
| 468 fileapi::FileSystemType type; | 469 fileapi::FileSystemType type; |
| 469 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, | 470 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, |
| 470 virtual_path)) { | 471 virtual_path)) { |
| 471 return false; | 472 return false; |
| 472 } | 473 } |
| 473 if (type != fileapi::kFileSystemTypeExternal) | 474 if (type != fileapi::kFileSystemTypeExternal) |
| 474 return false; | 475 return false; |
| 475 | 476 |
| 476 FilePath root_path = profile_->GetFileSystemContext()->external_provider()-> | 477 FilePath root_path = BrowserContext::GetFileSystemContext(profile_)-> |
| 477 GetFileSystemRootPathOnFileThread( | 478 external_provider()->GetFileSystemRootPathOnFileThread( |
| 478 file_origin_url, | 479 file_origin_url, |
| 479 fileapi::kFileSystemTypeExternal, | 480 fileapi::kFileSystemTypeExternal, |
| 480 *virtual_path, | 481 *virtual_path, |
| 481 false); | 482 false); |
| 482 if (root_path == FilePath()) | 483 if (root_path == FilePath()) |
| 483 return false; | 484 return false; |
| 484 | 485 |
| 485 *local_path = root_path.Append(*virtual_path); | 486 *local_path = root_path.Append(*virtual_path); |
| 486 return true; | 487 return true; |
| 487 } | 488 } |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 fileapi::FileSystemType type; | 738 fileapi::FileSystemType type; |
| 738 if (!CrackFileSystemURL(origin_file_url, &file_origin_url, &type, | 739 if (!CrackFileSystemURL(origin_file_url, &file_origin_url, &type, |
| 739 &virtual_path)) { | 740 &virtual_path)) { |
| 740 return false; | 741 return false; |
| 741 } | 742 } |
| 742 | 743 |
| 743 if (type != fileapi::kFileSystemTypeExternal) | 744 if (type != fileapi::kFileSystemTypeExternal) |
| 744 return false; | 745 return false; |
| 745 | 746 |
| 746 fileapi::ExternalFileSystemMountPointProvider* external_provider = | 747 fileapi::ExternalFileSystemMountPointProvider* external_provider = |
| 747 profile_->GetFileSystemContext()->external_provider(); | 748 BrowserContext::GetFileSystemContext(profile_)->external_provider(); |
| 748 if (!external_provider) | 749 if (!external_provider) |
| 749 return false; | 750 return false; |
| 750 | 751 |
| 751 if (!external_provider->IsAccessAllowed(file_origin_url, | 752 if (!external_provider->IsAccessAllowed(file_origin_url, |
| 752 type, | 753 type, |
| 753 virtual_path)) { | 754 virtual_path)) { |
| 754 return false; | 755 return false; |
| 755 } | 756 } |
| 756 | 757 |
| 757 // Make sure this url really being used by the right caller extension. | 758 // Make sure this url really being used by the right caller extension. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 file_urls)); | 865 file_urls)); |
| 865 result_.reset(new base::FundamentalValue(true)); | 866 result_.reset(new base::FundamentalValue(true)); |
| 866 return true; | 867 return true; |
| 867 } | 868 } |
| 868 | 869 |
| 869 void ExecuteTasksFileBrowserFunction::RequestFileEntryOnFileThread( | 870 void ExecuteTasksFileBrowserFunction::RequestFileEntryOnFileThread( |
| 870 const GURL& source_url, const std::string& task_id, | 871 const GURL& source_url, const std::string& task_id, |
| 871 const std::vector<GURL>& file_urls) { | 872 const std::vector<GURL>& file_urls) { |
| 872 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 873 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 873 GURL origin_url = source_url.GetOrigin(); | 874 GURL origin_url = source_url.GetOrigin(); |
| 874 profile()->GetFileSystemContext()->OpenFileSystem( | 875 BrowserContext::GetFileSystemContext(profile())->OpenFileSystem( |
| 875 origin_url, fileapi::kFileSystemTypeExternal, false, // create | 876 origin_url, fileapi::kFileSystemTypeExternal, false, // create |
| 876 ExecuteTasksFileSystemCallbackDispatcher::CreateCallback( | 877 ExecuteTasksFileSystemCallbackDispatcher::CreateCallback( |
| 877 this, | 878 this, |
| 878 profile(), | 879 profile(), |
| 879 render_view_host()->process()->GetID(), | 880 render_view_host()->process()->GetID(), |
| 880 source_url, | 881 source_url, |
| 881 GetExtension(), | 882 GetExtension(), |
| 882 task_id, | 883 task_id, |
| 883 file_urls)); | 884 file_urls)); |
| 884 } | 885 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 // thread. | 999 // thread. |
| 999 void FileBrowserFunction::GetLocalPathsOnFileThread( | 1000 void FileBrowserFunction::GetLocalPathsOnFileThread( |
| 1000 const UrlList& file_urls, | 1001 const UrlList& file_urls, |
| 1001 GetLocalPathsCallback callback) { | 1002 GetLocalPathsCallback callback) { |
| 1002 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1003 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 1003 FilePathList selected_files; | 1004 FilePathList selected_files; |
| 1004 | 1005 |
| 1005 // FilePath(virtual_path) doesn't work on win, so limit this to ChromeOS. | 1006 // FilePath(virtual_path) doesn't work on win, so limit this to ChromeOS. |
| 1006 #if defined(OS_CHROMEOS) | 1007 #if defined(OS_CHROMEOS) |
| 1007 fileapi::ExternalFileSystemMountPointProvider* provider = | 1008 fileapi::ExternalFileSystemMountPointProvider* provider = |
| 1008 profile_->GetFileSystemContext()->external_provider(); | 1009 BrowserContext::GetFileSystemContext(profile_)->external_provider(); |
| 1009 if (!provider) { | 1010 if (!provider) { |
| 1010 LOG(WARNING) << "External provider is not available"; | 1011 LOG(WARNING) << "External provider is not available"; |
| 1011 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1012 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 1012 base::Bind(callback, selected_files)); | 1013 base::Bind(callback, selected_files)); |
| 1013 return; | 1014 return; |
| 1014 } | 1015 } |
| 1015 | 1016 |
| 1016 GURL origin_url = source_url().GetOrigin(); | 1017 GURL origin_url = source_url().GetOrigin(); |
| 1017 size_t len = file_urls.size(); | 1018 size_t len = file_urls.size(); |
| 1018 selected_files.reserve(len); | 1019 selected_files.reserve(len); |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 SET_STRING(IDS_FILE_BROWSER, ENQUEUE); | 1699 SET_STRING(IDS_FILE_BROWSER, ENQUEUE); |
| 1699 #undef SET_STRING | 1700 #undef SET_STRING |
| 1700 | 1701 |
| 1701 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); | 1702 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); |
| 1702 | 1703 |
| 1703 dict->SetString("PLAY_MEDIA", | 1704 dict->SetString("PLAY_MEDIA", |
| 1704 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); | 1705 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); |
| 1705 | 1706 |
| 1706 return true; | 1707 return true; |
| 1707 } | 1708 } |
| OLD | NEW |