Chromium Code Reviews| 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_device_manager.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" | |
| 11 | 18 |
| 12 namespace extensions { | 19 namespace extensions { |
| 13 | 20 |
| 21 using chrome::MediaDeviceManager; | |
| 22 using content::ChildProcessSecurityPolicy; | |
| 23 | |
| 14 GetMediaFileSystemsFunction::~GetMediaFileSystemsFunction() {} | 24 GetMediaFileSystemsFunction::~GetMediaFileSystemsFunction() {} |
| 15 | 25 |
| 16 bool GetMediaFileSystemsFunction::RunImpl() { | 26 bool GetMediaFileSystemsFunction::RunImpl() { |
| 17 // TODO(vandebo) Get the list of galleries. | 27 scoped_ptr<std::vector<MediaDeviceManager::MediaFSIDAndPath> > filesystems; |
| 18 result_.reset(new ListValue()); | 28 chrome::MediaDeviceManager* media_device_manager = |
| 29 MediaDeviceManager::GetInstance(); | |
| 30 filesystems.reset(media_device_manager->GetMediaFileSystems()); | |
| 31 | |
| 32 base::ListValue* list = new base::ListValue(); | |
| 33 | |
| 34 for (size_t i = 0; i < filesystems->size(); i++) { | |
|
vandebo (ex-Chrome)
2012/05/23 00:50:46
nit: Can you add a TODO here about checking securi
Lei Zhang
2012/05/23 03:12:49
Done.
| |
| 35 const MediaDeviceManager::MediaFSIDAndPath& fsid_and_path = | |
| 36 (*filesystems)[i]; | |
| 37 const std::string& fsid = fsid_and_path.first; | |
| 38 const FilePath& path = fsid_and_path.second; | |
| 39 const FilePath::StringType basepath = path.BaseName().value(); | |
| 40 #if defined(OS_WIN) | |
| 41 // We standardize on UTF8 encoding for |basepath|. | |
| 42 const std::string basepath_utf8(base::SysWideToUTF8(basepath); | |
| 43 #elif defined(OS_POSIX) | |
| 44 const std::string basepath_utf8(basepath); | |
| 45 #endif | |
| 46 | |
| 47 base::DictionaryValue* dict_value = new base::DictionaryValue(); | |
| 48 dict_value->SetWithoutPathExpansion( | |
| 49 "fsid", Value::CreateStringValue(fsid)); | |
| 50 dict_value->SetWithoutPathExpansion( | |
| 51 "dirname", Value::CreateStringValue(basepath_utf8)); | |
| 52 list->Append(dict_value); | |
| 53 | |
| 54 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( | |
| 55 render_view_host()->GetProcess()->GetID(), | |
| 56 path, | |
| 57 (base::PLATFORM_FILE_OPEN | | |
| 58 base::PLATFORM_FILE_READ | | |
| 59 base::PLATFORM_FILE_EXCLUSIVE_READ | | |
| 60 base::PLATFORM_FILE_ASYNC)); | |
| 61 } | |
| 62 | |
| 63 result_.reset(list); | |
| 19 return true; | 64 return true; |
| 20 } | 65 } |
| 21 | 66 |
| 22 OpenMediaGalleryManagerFunction::~OpenMediaGalleryManagerFunction() {} | 67 OpenMediaGalleryManagerFunction::~OpenMediaGalleryManagerFunction() {} |
| 23 | 68 |
| 24 bool OpenMediaGalleryManagerFunction::RunImpl() { | 69 bool OpenMediaGalleryManagerFunction::RunImpl() { |
| 25 // TODO(vandebo) Open the Media Gallery Manager UI. | 70 // TODO(vandebo) Open the Media Gallery Manager UI. |
| 26 result_.reset(Value::CreateNullValue()); | 71 result_.reset(Value::CreateNullValue()); |
| 27 return true; | 72 return true; |
| 28 } | 73 } |
| 29 | 74 |
| 30 AssembleMediaFileFunction::~AssembleMediaFileFunction() {} | 75 AssembleMediaFileFunction::~AssembleMediaFileFunction() {} |
| 31 | 76 |
| 32 bool AssembleMediaFileFunction::RunImpl() { | 77 bool AssembleMediaFileFunction::RunImpl() { |
| 33 // TODO(vandebo) Update the metadata and return the new file. | 78 // TODO(vandebo) Update the metadata and return the new file. |
| 34 result_.reset(Value::CreateNullValue()); | 79 result_.reset(Value::CreateNullValue()); |
| 35 return true; | 80 return true; |
| 36 } | 81 } |
| 37 | 82 |
| 38 } // namespace extensions | 83 } // namespace extensions |
| OLD | NEW |