| 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 // Implements the Chrome Extensions Media Galleries API. | 5 // Implements the Chrome Extensions Media Galleries API. |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/media_gallery/media_gallery_api.h" | 7 #include "chrome/browser/extensions/api/media_gallery/media_gallery_api.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 | 24 |
| 25 using chrome::MediaFileSystemRegistry; | 25 using chrome::MediaFileSystemRegistry; |
| 26 using content::ChildProcessSecurityPolicy; | 26 using content::ChildProcessSecurityPolicy; |
| 27 | 27 |
| 28 GetMediaFileSystemsFunction::~GetMediaFileSystemsFunction() {} | 28 GetMediaFileSystemsFunction::~GetMediaFileSystemsFunction() {} |
| 29 | 29 |
| 30 bool GetMediaFileSystemsFunction::RunImpl() { | 30 bool GetMediaFileSystemsFunction::RunImpl() { |
| 31 const content::RenderProcessHost* rph = render_view_host()->GetProcess(); |
| 31 chrome::MediaFileSystemRegistry* media_fs_registry = | 32 chrome::MediaFileSystemRegistry* media_fs_registry = |
| 32 MediaFileSystemRegistry::GetInstance(); | 33 MediaFileSystemRegistry::GetInstance(); |
| 33 const std::vector<MediaFileSystemRegistry::MediaFSIDAndPath> filesystems = | 34 const std::vector<MediaFileSystemRegistry::MediaFSIDAndPath> filesystems = |
| 34 media_fs_registry->GetMediaFileSystems(); | 35 media_fs_registry->GetMediaFileSystems(rph); |
| 35 | 36 |
| 37 const int child_id = rph->GetID(); |
| 36 base::ListValue* list = new base::ListValue(); | 38 base::ListValue* list = new base::ListValue(); |
| 37 for (size_t i = 0; i < filesystems.size(); i++) { | 39 for (size_t i = 0; i < filesystems.size(); i++) { |
| 38 // TODO(thestig) Check permissions to file systems when that capability | 40 // TODO(thestig) Check permissions to file systems when that capability |
| 39 // exists. | 41 // exists. |
| 40 const MediaFileSystemRegistry::MediaFSIDAndPath& fsid_and_path = | 42 const MediaFileSystemRegistry::MediaFSIDAndPath& fsid_and_path = |
| 41 filesystems[i]; | 43 filesystems[i]; |
| 42 const std::string& fsid = fsid_and_path.first; | 44 const std::string& fsid = fsid_and_path.first; |
| 43 const FilePath& path = fsid_and_path.second; | 45 const FilePath& path = fsid_and_path.second; |
| 44 const FilePath::StringType basepath = path.BaseName().value(); | 46 const FilePath::StringType basepath = path.BaseName().value(); |
| 45 #if defined(OS_WIN) | 47 #if defined(OS_WIN) |
| 46 // We standardize on UTF8 encoding for |basepath|. | 48 // We standardize on UTF8 encoding for |basepath|. |
| 47 const std::string basepath_utf8(base::SysWideToUTF8(basepath)); | 49 const std::string basepath_utf8(base::SysWideToUTF8(basepath)); |
| 48 #elif defined(OS_POSIX) | 50 #elif defined(OS_POSIX) |
| 49 const std::string basepath_utf8(basepath); | 51 const std::string basepath_utf8(basepath); |
| 50 #endif | 52 #endif |
| 51 | 53 |
| 52 base::DictionaryValue* dict_value = new base::DictionaryValue(); | 54 base::DictionaryValue* dict_value = new base::DictionaryValue(); |
| 53 dict_value->SetWithoutPathExpansion( | 55 dict_value->SetWithoutPathExpansion( |
| 54 "fsid", Value::CreateStringValue(fsid)); | 56 "fsid", Value::CreateStringValue(fsid)); |
| 55 dict_value->SetWithoutPathExpansion( | 57 dict_value->SetWithoutPathExpansion( |
| 56 "dirname", Value::CreateStringValue(basepath_utf8)); | 58 "dirname", Value::CreateStringValue(basepath_utf8)); |
| 57 list->Append(dict_value); | 59 list->Append(dict_value); |
| 58 | 60 |
| 59 const int child_id = render_view_host()->GetProcess()->GetID(); | |
| 60 content::ChildProcessSecurityPolicy* policy = | 61 content::ChildProcessSecurityPolicy* policy = |
| 61 ChildProcessSecurityPolicy::GetInstance(); | 62 ChildProcessSecurityPolicy::GetInstance(); |
| 62 if (!policy->CanReadFile(child_id, path)) { | 63 if (!policy->CanReadFile(child_id, path)) { |
| 63 policy->GrantReadFile(child_id, path); | 64 policy->GrantReadFile(child_id, path); |
| 64 } | 65 } |
| 65 policy->GrantReadFileSystem(child_id, fsid); | 66 policy->GrantReadFileSystem(child_id, fsid); |
| 66 } | 67 } |
| 67 | 68 |
| 68 result_.reset(list); | 69 result_.reset(list); |
| 69 return true; | 70 return true; |
| 70 } | 71 } |
| 71 | 72 |
| 72 OpenMediaGalleryManagerFunction::~OpenMediaGalleryManagerFunction() {} | 73 OpenMediaGalleryManagerFunction::~OpenMediaGalleryManagerFunction() {} |
| 73 | 74 |
| 74 bool OpenMediaGalleryManagerFunction::RunImpl() { | 75 bool OpenMediaGalleryManagerFunction::RunImpl() { |
| 75 // TODO(vandebo) Open the Media Gallery Manager UI. | 76 // TODO(vandebo) Open the Media Gallery Manager UI. |
| 76 result_.reset(Value::CreateNullValue()); | 77 result_.reset(Value::CreateNullValue()); |
| 77 return true; | 78 return true; |
| 78 } | 79 } |
| 79 | 80 |
| 80 AssembleMediaFileFunction::~AssembleMediaFileFunction() {} | 81 AssembleMediaFileFunction::~AssembleMediaFileFunction() {} |
| 81 | 82 |
| 82 bool AssembleMediaFileFunction::RunImpl() { | 83 bool AssembleMediaFileFunction::RunImpl() { |
| 83 // TODO(vandebo) Update the metadata and return the new file. | 84 // TODO(vandebo) Update the metadata and return the new file. |
| 84 result_.reset(Value::CreateNullValue()); | 85 result_.reset(Value::CreateNullValue()); |
| 85 return true; | 86 return true; |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace extensions | 89 } // namespace extensions |
| OLD | NEW |