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

Side by Side Diff: chrome/browser/extensions/api/media_gallery/media_gallery_api.cc

Issue 10704258: Add extension permissions for Media Gallery API. (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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Implements the Chrome Extensions Media Galleries API. 5 // Implements the Chrome Extensions Media Galleries API.
6 6
7 #include "chrome/browser/extensions/api/media_gallery/media_gallery_api.h" 7 #include "chrome/browser/extensions/api/media_gallery/media_gallery_api.h"
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 10 matching lines...) Expand all
21 #endif 21 #endif
22 22
23 namespace extensions { 23 namespace extensions {
24 24
25 using chrome::MediaFileSystemRegistry; 25 using chrome::MediaFileSystemRegistry;
26 using content::ChildProcessSecurityPolicy; 26 using content::ChildProcessSecurityPolicy;
27 27
28 GetMediaFileSystemsFunction::~GetMediaFileSystemsFunction() {} 28 GetMediaFileSystemsFunction::~GetMediaFileSystemsFunction() {}
29 29
30 bool GetMediaFileSystemsFunction::RunImpl() { 30 bool GetMediaFileSystemsFunction::RunImpl() {
31 bool read_permission = GetExtension()->HasAPIPermission(
32 extensions::APIPermission::kMediaGalleriesRead);
33 bool write_permission = GetExtension()->HasAPIPermission(
34 extensions::APIPermission::kMediaGalleriesWrite);
35 if (!read_permission && !write_permission) {
36 base::ListValue* list = new base::ListValue();
37 SetResult(list);
Evan Stade 2012/07/18 05:11:00 I think the typical thing is SetResult(false). Als
vandebo (ex-Chrome) 2012/07/18 22:43:32 Done.
38 return true;
39 }
40
31 const content::RenderProcessHost* rph = render_view_host()->GetProcess(); 41 const content::RenderProcessHost* rph = render_view_host()->GetProcess();
32 chrome::MediaFileSystemRegistry* media_fs_registry = 42 chrome::MediaFileSystemRegistry* media_fs_registry =
33 MediaFileSystemRegistry::GetInstance(); 43 MediaFileSystemRegistry::GetInstance();
34 const std::vector<MediaFileSystemRegistry::MediaFSIDAndPath> filesystems = 44 const std::vector<MediaFileSystemRegistry::MediaFSIDAndPath> filesystems =
35 media_fs_registry->GetMediaFileSystems(rph); 45 media_fs_registry->GetMediaFileSystems(rph);
36 46
37 const int child_id = rph->GetID(); 47 const int child_id = rph->GetID();
38 base::ListValue* list = new base::ListValue(); 48 base::ListValue* list = new base::ListValue();
39 for (size_t i = 0; i < filesystems.size(); i++) { 49 for (size_t i = 0; i < filesystems.size(); i++) {
40 // TODO(thestig) Check permissions to file systems when that capability 50 // TODO(thestig) Check permissions to file systems when that capability
41 // exists. 51 // exists.
42 const MediaFileSystemRegistry::MediaFSIDAndPath& fsid_and_path = 52 const MediaFileSystemRegistry::MediaFSIDAndPath& fsid_and_path =
43 filesystems[i]; 53 filesystems[i];
44 const std::string& fsid = fsid_and_path.first; 54 const std::string& fsid = fsid_and_path.first;
45 const FilePath& path = fsid_and_path.second; 55 const FilePath& path = fsid_and_path.second;
46 56
47 base::DictionaryValue* dict_value = new base::DictionaryValue(); 57 base::DictionaryValue* dict_value = new base::DictionaryValue();
48 dict_value->SetWithoutPathExpansion( 58 dict_value->SetWithoutPathExpansion(
49 "fsid", Value::CreateStringValue(fsid)); 59 "fsid", Value::CreateStringValue(fsid));
50 // The directory name is not exposed to the js layer. 60 // The directory name is not exposed to the js layer.
51 dict_value->SetWithoutPathExpansion( 61 dict_value->SetWithoutPathExpansion(
52 "dirname", Value::CreateStringValue("_")); 62 "dirname", Value::CreateStringValue("_"));
53 list->Append(dict_value); 63 list->Append(dict_value);
54 64
55 content::ChildProcessSecurityPolicy* policy = 65 if (read_permission) {
56 ChildProcessSecurityPolicy::GetInstance(); 66 content::ChildProcessSecurityPolicy* policy =
57 if (!policy->CanReadFile(child_id, path)) 67 ChildProcessSecurityPolicy::GetInstance();
58 policy->GrantReadFile(child_id, path); 68 if (!policy->CanReadFile(child_id, path))
59 policy->GrantReadFileSystem(child_id, fsid); 69 policy->GrantReadFile(child_id, path);
70 policy->GrantReadFileSystem(child_id, fsid);
71 }
72 // TODO(vandebo) Handle write permission.
60 } 73 }
61 74
62 SetResult(list); 75 SetResult(list);
63 return true; 76 return true;
64 } 77 }
65 78
66 OpenMediaGalleryManagerFunction::~OpenMediaGalleryManagerFunction() {} 79 OpenMediaGalleryManagerFunction::~OpenMediaGalleryManagerFunction() {}
67 80
68 bool OpenMediaGalleryManagerFunction::RunImpl() { 81 bool OpenMediaGalleryManagerFunction::RunImpl() {
69 // TODO(vandebo) Open the Media Gallery Manager UI. 82 // TODO(vandebo) Open the Media Gallery Manager UI.
70 SetResult(Value::CreateNullValue()); 83 SetResult(Value::CreateNullValue());
71 return true; 84 return true;
72 } 85 }
73 86
74 AssembleMediaFileFunction::~AssembleMediaFileFunction() {} 87 AssembleMediaFileFunction::~AssembleMediaFileFunction() {}
75 88
76 bool AssembleMediaFileFunction::RunImpl() { 89 bool AssembleMediaFileFunction::RunImpl() {
77 // TODO(vandebo) Update the metadata and return the new file. 90 // TODO(vandebo) Update the metadata and return the new file.
78 SetResult(Value::CreateNullValue()); 91 SetResult(Value::CreateNullValue());
79 return true; 92 return true;
80 } 93 }
81 94
82 } // namespace extensions 95 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698