Chromium Code Reviews| Index: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc |
| diff --git a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7298bb45e77e571f06eaeb0a6b541f22b48e6e5e |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc |
| @@ -0,0 +1,103 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Implements the Chrome Extensions Media Galleries API. |
| + |
| +#include "chrome/browser/extensions/api/media_galleries/media_galleries_api.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 "chrome/common/extensions/api/experimental_media_galleries.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" |
| + |
| +#if defined(OS_WIN) |
| +#include "base/sys_string_conversions.h" |
| +#endif |
| + |
| +namespace extensions { |
| + |
| +namespace { |
| + |
| +const char kInvalidInteractivity[] = "Unknown value for interactivity."; |
| + |
| +} // namespace |
| + |
| +using chrome::MediaFileSystemRegistry; |
| +using content::ChildProcessSecurityPolicy; |
| + |
| +namespace MediaGalleries = extensions::api::experimental_media_galleries; |
| +namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; |
| + |
| +MediaGalleriesGetMediaFileSystemsFunction:: |
| + ~MediaGalleriesGetMediaFileSystemsFunction() {} |
| + |
| +bool MediaGalleriesGetMediaFileSystemsFunction::RunImpl() { |
| + scoped_ptr<GetMediaFileSystems::Params> params( |
| + GetMediaFileSystems::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params.get()); |
| + MediaGalleries::GetMediaFileSystemsInteractivity interactivity = "silent"; |
| + if (params->details.get() && params->details->interactivity.get()) |
| + interactivity = *params->details->interactivity; |
|
Evan Stade
2012/07/19 00:10:55
don't know why git failed to notice the move. The
|
| + |
| + if (interactivity == "silent") { |
| + const content::RenderProcessHost* rph = render_view_host()->GetProcess(); |
| + chrome::MediaFileSystemRegistry* media_fs_registry = |
| + MediaFileSystemRegistry::GetInstance(); |
| + const std::vector<MediaFileSystemRegistry::MediaFSIDAndPath> filesystems = |
| + media_fs_registry->GetMediaFileSystems(rph); |
| + |
| + const int child_id = rph->GetID(); |
| + 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; |
| + |
| + base::DictionaryValue* dict_value = new base::DictionaryValue(); |
| + dict_value->SetWithoutPathExpansion( |
| + "fsid", Value::CreateStringValue(fsid)); |
| + // The directory name is not exposed to the js layer. |
| + dict_value->SetWithoutPathExpansion( |
| + "dirname", Value::CreateStringValue("_")); |
| + list->Append(dict_value); |
| + |
| + content::ChildProcessSecurityPolicy* policy = |
| + ChildProcessSecurityPolicy::GetInstance(); |
| + if (!policy->CanReadFile(child_id, path)) |
| + policy->GrantReadFile(child_id, path); |
| + policy->GrantReadFileSystem(child_id, fsid); |
| + } |
| + |
| + SetResult(list); |
| + return true; |
| + } else if (interactivity == "prompt") { |
| + // TODO(estade): implement. |
| + } else if (interactivity == "prompt_if_needed") { |
| + // TODO(estade): implement. |
| + } else { |
| + error_ = kInvalidInteractivity; |
| + } |
| + |
| + return false; |
| +} |
| + |
| +MediaGalleriesAssembleMediaFileFunction:: |
| + ~MediaGalleriesAssembleMediaFileFunction() {} |
| + |
| +bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { |
| + // TODO(vandebo) Update the metadata and return the new file. |
| + SetResult(Value::CreateNullValue()); |
| + return true; |
| +} |
| + |
| +} // namespace extensions |