Chromium Code Reviews| Index: chrome/browser/extensions/api/media_gallery/media_gallery_api.cc |
| =================================================================== |
| --- chrome/browser/extensions/api/media_gallery/media_gallery_api.cc (revision 138924) |
| +++ chrome/browser/extensions/api/media_gallery/media_gallery_api.cc (working copy) |
| @@ -6,16 +6,62 @@ |
| #include "chrome/browser/extensions/api/media_gallery/media_gallery_api.h" |
| -#include "base/json/json_writer.h" |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/platform_file.h" |
| #include "base/values.h" |
| +#include "chrome/browser/media_gallery/media_file_system_registry.h" |
| +#include "content/public/browser/child_process_security_policy.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/browser/render_view_host.h" |
| namespace extensions { |
| +using chrome::MediaFileSystemRegistry; |
| +using content::ChildProcessSecurityPolicy; |
| + |
| GetMediaFileSystemsFunction::~GetMediaFileSystemsFunction() {} |
| bool GetMediaFileSystemsFunction::RunImpl() { |
| - // TODO(vandebo) Get the list of galleries. |
| - result_.reset(new ListValue()); |
| + chrome::MediaFileSystemRegistry* media_fs_registry = |
| + MediaFileSystemRegistry::GetInstance(); |
| + const std::vector<MediaFileSystemRegistry::MediaFSIDAndPath> filesystems = |
| + media_fs_registry->GetMediaFileSystems(); |
| + |
| + base::ListValue* list = new base::ListValue(); |
| + for (size_t i = 0; i < filesystems.size(); i++) { |
| + // TODO(thestig) Check permissions to file systems when that capability |
| + // exists. |
| + const MediaFileSystemRegistry::MediaFSIDAndPath& fsid_and_path = |
| + filesystems[i]; |
| + const std::string& fsid = fsid_and_path.first; |
| + const FilePath& path = fsid_and_path.second; |
| + const FilePath::StringType basepath = path.BaseName().value(); |
| +#if defined(OS_WIN) |
| + // We standardize on UTF8 encoding for |basepath|. |
| + const std::string basepath_utf8(base::SysWideToUTF8(basepath); |
| +#elif defined(OS_POSIX) |
| + const std::string basepath_utf8(basepath); |
| +#endif |
| + |
| + base::DictionaryValue* dict_value = new base::DictionaryValue(); |
| + dict_value->SetWithoutPathExpansion( |
| + "fsid", Value::CreateStringValue(fsid)); |
| + dict_value->SetWithoutPathExpansion( |
| + "dirname", Value::CreateStringValue(basepath_utf8)); |
| + list->Append(dict_value); |
| + |
| + ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( |
|
kinuko
2012/05/25 09:30:38
Instead of specifying detailed permissions you can
vandebo (ex-Chrome)
2012/05/29 16:46:07
Should this be GrantReadDirectory or even GrantAcc
Lei Zhang
2012/05/29 23:26:41
Done.
Lei Zhang
2012/05/29 23:26:41
In the current ChildProcessSecurityPolicy implemen
kinuko
2012/05/30 09:45:13
Yup... if my one lands earlier please change these
|
| + render_view_host()->GetProcess()->GetID(), |
| + path, |
| + (base::PLATFORM_FILE_OPEN | |
| + base::PLATFORM_FILE_READ | |
| + base::PLATFORM_FILE_EXCLUSIVE_READ | |
| + base::PLATFORM_FILE_ASYNC)); |
| + } |
| + |
| + result_.reset(list); |
| return true; |
| } |