Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Implements the Chrome Extensions Media Galleries API. | |
| 6 | |
| 7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" | |
| 8 | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/platform_file.h" | |
| 13 #include "base/values.h" | |
| 14 #include "chrome/browser/media_gallery/media_file_system_registry.h" | |
| 15 #include "chrome/common/extensions/api/experimental_media_galleries.h" | |
| 16 #include "content/public/browser/child_process_security_policy.h" | |
| 17 #include "content/public/browser/render_process_host.h" | |
| 18 #include "content/public/browser/render_view_host.h" | |
| 19 | |
| 20 #if defined(OS_WIN) | |
| 21 #include "base/sys_string_conversions.h" | |
| 22 #endif | |
| 23 | |
| 24 namespace extensions { | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 const char kInvalidInteractivity[] = "Unknown value for interactivity."; | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 using chrome::MediaFileSystemRegistry; | |
| 33 using content::ChildProcessSecurityPolicy; | |
| 34 | |
| 35 namespace MediaGalleries = extensions::api::experimental_media_galleries; | |
| 36 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; | |
| 37 | |
| 38 MediaGalleriesGetMediaFileSystemsFunction:: | |
| 39 ~MediaGalleriesGetMediaFileSystemsFunction() {} | |
| 40 | |
| 41 bool MediaGalleriesGetMediaFileSystemsFunction::RunImpl() { | |
| 42 scoped_ptr<GetMediaFileSystems::Params> params( | |
| 43 GetMediaFileSystems::Params::Create(*args_)); | |
| 44 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 45 MediaGalleries::GetMediaFileSystemsInteractivity interactivity = "silent"; | |
| 46 if (params->details.get() && params->details->interactivity.get()) | |
| 47 interactivity = *params->details->interactivity; | |
|
Evan Stade
2012/07/19 00:10:55
don't know why git failed to notice the move. The
| |
| 48 | |
| 49 if (interactivity == "silent") { | |
| 50 const content::RenderProcessHost* rph = render_view_host()->GetProcess(); | |
| 51 chrome::MediaFileSystemRegistry* media_fs_registry = | |
| 52 MediaFileSystemRegistry::GetInstance(); | |
| 53 const std::vector<MediaFileSystemRegistry::MediaFSIDAndPath> filesystems = | |
| 54 media_fs_registry->GetMediaFileSystems(rph); | |
| 55 | |
| 56 const int child_id = rph->GetID(); | |
| 57 base::ListValue* list = new base::ListValue(); | |
| 58 for (size_t i = 0; i < filesystems.size(); i++) { | |
| 59 // TODO(thestig) Check permissions to file systems when that capability | |
| 60 // exists. | |
| 61 const MediaFileSystemRegistry::MediaFSIDAndPath& fsid_and_path = | |
| 62 filesystems[i]; | |
| 63 const std::string& fsid = fsid_and_path.first; | |
| 64 const FilePath& path = fsid_and_path.second; | |
| 65 | |
| 66 base::DictionaryValue* dict_value = new base::DictionaryValue(); | |
| 67 dict_value->SetWithoutPathExpansion( | |
| 68 "fsid", Value::CreateStringValue(fsid)); | |
| 69 // The directory name is not exposed to the js layer. | |
| 70 dict_value->SetWithoutPathExpansion( | |
| 71 "dirname", Value::CreateStringValue("_")); | |
| 72 list->Append(dict_value); | |
| 73 | |
| 74 content::ChildProcessSecurityPolicy* policy = | |
| 75 ChildProcessSecurityPolicy::GetInstance(); | |
| 76 if (!policy->CanReadFile(child_id, path)) | |
| 77 policy->GrantReadFile(child_id, path); | |
| 78 policy->GrantReadFileSystem(child_id, fsid); | |
| 79 } | |
| 80 | |
| 81 SetResult(list); | |
| 82 return true; | |
| 83 } else if (interactivity == "prompt") { | |
| 84 // TODO(estade): implement. | |
| 85 } else if (interactivity == "prompt_if_needed") { | |
| 86 // TODO(estade): implement. | |
| 87 } else { | |
| 88 error_ = kInvalidInteractivity; | |
| 89 } | |
| 90 | |
| 91 return false; | |
| 92 } | |
| 93 | |
| 94 MediaGalleriesAssembleMediaFileFunction:: | |
| 95 ~MediaGalleriesAssembleMediaFileFunction() {} | |
| 96 | |
| 97 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { | |
| 98 // TODO(vandebo) Update the metadata and return the new file. | |
| 99 SetResult(Value::CreateNullValue()); | |
| 100 return true; | |
| 101 } | |
| 102 | |
| 103 } // namespace extensions | |
| OLD | NEW |