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