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

Side by Side Diff: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc

Issue 10805064: Revert 147895 - switch mediaGalleries to .idl api definition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 kInvalidInteractive[] = "Unknown value for interactive.";
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 interactive = "no";
46 if (params->details.get() && params->details->interactive.get())
47 interactive = *params->details->interactive;
48
49 if (interactive == "yes") {
50 // TODO(estade): implement.
51 } else if (interactive == "if_needed") {
52 // TODO(estade): implement.
53 } else if (interactive != "no") {
54 error_ = kInvalidInteractive;
55 SetResult(false);
56 return true;
57 }
58
59 const content::RenderProcessHost* rph = render_view_host()->GetProcess();
60 chrome::MediaFileSystemRegistry* media_fs_registry =
61 MediaFileSystemRegistry::GetInstance();
62 const std::vector<MediaFileSystemRegistry::MediaFSIDAndPath> filesystems =
63 media_fs_registry->GetMediaFileSystems(rph);
64
65 const int child_id = rph->GetID();
66 base::ListValue* list = new base::ListValue();
67 for (size_t i = 0; i < filesystems.size(); i++) {
68 // TODO(thestig) Check permissions to file systems when that capability
69 // exists.
70 const MediaFileSystemRegistry::MediaFSIDAndPath& fsid_and_path =
71 filesystems[i];
72 const std::string& fsid = fsid_and_path.first;
73 const FilePath& path = fsid_and_path.second;
74
75 base::DictionaryValue* dict_value = new base::DictionaryValue();
76 dict_value->SetWithoutPathExpansion(
77 "fsid", Value::CreateStringValue(fsid));
78 // The directory name is not exposed to the js layer.
79 dict_value->SetWithoutPathExpansion(
80 "dirname", Value::CreateStringValue("_"));
81 list->Append(dict_value);
82
83 content::ChildProcessSecurityPolicy* policy =
84 ChildProcessSecurityPolicy::GetInstance();
85 if (!policy->CanReadFile(child_id, path))
86 policy->GrantReadFile(child_id, path);
87 policy->GrantReadFileSystem(child_id, fsid);
88 }
89
90 SetResult(list);
91 return true;
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698