Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6918)

Unified Diff: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc

Issue 10806023: switch mediaGalleries to .idl api definition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile and test fixes Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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.
vandebo (ex-Chrome) 2012/07/19 19:58:31 This file didn't get detected as a move.
Evan Stade 2012/07/19 20:55:28 yes, I know. What would you like me to do about it
+// 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;
+
+ 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") {
vandebo (ex-Chrome) 2012/07/19 19:58:31 For prompt and prompt_if_needed, we should still r
Evan Stade 2012/07/19 20:55:28 not exactly, showing the prompt is asynchronous. W
vandebo (ex-Chrome) 2012/07/19 22:45:22 Sure... but this structure will break expectations
Evan Stade 2012/07/19 23:06:33 ok
+ // 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

Powered by Google App Engine
This is Rietveld 408576698