diff options
author | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-23 19:48:58 +0000 |
---|---|---|
committer | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-23 19:48:58 +0000 |
commit | 71221af8e1864119137c8c90f713d5a639478f06 (patch) | |
tree | 901c015382002a07a9fc80cf7830e4682b193274 /chrome/browser/extensions | |
parent | 36d0efe6c97a516427a2d4f1ae3fff2b1b453238 (diff) | |
download | chromium_src-71221af8e1864119137c8c90f713d5a639478f06.zip chromium_src-71221af8e1864119137c8c90f713d5a639478f06.tar.gz chromium_src-71221af8e1864119137c8c90f713d5a639478f06.tar.bz2 |
Revert 147895 - switch mediaGalleries to .idl api definition
This is part 2 of the revert. First part in 147897.
Does not compile.
BUG=none
TEST=manual
Review URL: https://chromiumcodereview.appspot.com/10806023
TBR=estade@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10816024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147902 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
3 files changed, 152 insertions, 0 deletions
diff --git a/chrome/browser/extensions/api/media_gallery/media_gallery_api.cc b/chrome/browser/extensions/api/media_gallery/media_gallery_api.cc new file mode 100644 index 0000000..15698f6 --- /dev/null +++ b/chrome/browser/extensions/api/media_gallery/media_gallery_api.cc @@ -0,0 +1,82 @@ +// 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_gallery/media_gallery_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 "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 { + +using chrome::MediaFileSystemRegistry; +using content::ChildProcessSecurityPolicy; + +GetMediaFileSystemsFunction::~GetMediaFileSystemsFunction() {} + +bool GetMediaFileSystemsFunction::RunImpl() { + 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; +} + +OpenMediaGalleryManagerFunction::~OpenMediaGalleryManagerFunction() {} + +bool OpenMediaGalleryManagerFunction::RunImpl() { + // TODO(vandebo) Open the Media Gallery Manager UI. + SetResult(Value::CreateNullValue()); + return true; +} + +AssembleMediaFileFunction::~AssembleMediaFileFunction() {} + +bool AssembleMediaFileFunction::RunImpl() { + // TODO(vandebo) Update the metadata and return the new file. + SetResult(Value::CreateNullValue()); + return true; +} + +} // namespace extensions diff --git a/chrome/browser/extensions/api/media_gallery/media_gallery_api.h b/chrome/browser/extensions/api/media_gallery/media_gallery_api.h new file mode 100644 index 0000000..4774407 --- /dev/null +++ b/chrome/browser/extensions/api/media_gallery/media_gallery_api.h @@ -0,0 +1,47 @@ +// 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. + +// Defines the Chrome Extensions Media Galleries API functions for accessing +// user's media files, as specified in the extension API JSON. + +#ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERY_MEDIA_GALLERY_API_H_ +#define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERY_MEDIA_GALLERY_API_H_ + +#include "chrome/browser/extensions/extension_function.h" + +namespace extensions { + +class GetMediaFileSystemsFunction : public SyncExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION_NAME( + "experimental.mediaGalleries.getMediaFileSystems") + + protected: + virtual ~GetMediaFileSystemsFunction(); + virtual bool RunImpl() OVERRIDE; +}; + +class OpenMediaGalleryManagerFunction : public SyncExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION_NAME( + "experimental.mediaGalleries.openMediaGalleryManager") + + protected: + virtual ~OpenMediaGalleryManagerFunction(); + virtual bool RunImpl() OVERRIDE; +}; + +class AssembleMediaFileFunction : public SyncExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION_NAME( + "experimental.mediaGalleries.assembleMediaFile") + + protected: + virtual ~AssembleMediaFileFunction(); + virtual bool RunImpl() OVERRIDE; +}; + +} // namespace extensions + +#endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERY_MEDIA_GALLERY_API_H_ diff --git a/chrome/browser/extensions/api/media_gallery/media_gallery_apitest.cc b/chrome/browser/extensions/api/media_gallery/media_gallery_apitest.cc new file mode 100644 index 0000000..31ba636 --- /dev/null +++ b/chrome/browser/extensions/api/media_gallery/media_gallery_apitest.cc @@ -0,0 +1,23 @@ +// 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. + +#include "base/command_line.h" +#include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/common/chrome_switches.h" + +namespace { + +class ExperimentalExtensionApiTest : public ExtensionApiTest { + public: + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + ExtensionApiTest::SetUpCommandLine(command_line); + command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); + } +}; + +} // namespace + +IN_PROC_BROWSER_TEST_F(ExperimentalExtensionApiTest, MediaGallery) { + ASSERT_TRUE(RunExtensionTest("media_gallery")) << message_; +} |