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

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

Issue 10871049: Connect MediaFileSystemRegistry with MediaGalleriesPreferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 3 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_galleries/media_galleries_api.h" 7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h"
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 MediaGalleries::GetMediaFileSystemsInteractivity interactive = "no"; 72 MediaGalleries::GetMediaFileSystemsInteractivity interactive = "no";
73 if (params->details.get() && params->details->interactive.get()) 73 if (params->details.get() && params->details->interactive.get())
74 interactive = *params->details->interactive; 74 interactive = *params->details->interactive;
75 75
76 if (interactive == "yes") { 76 if (interactive == "yes") {
77 ShowDialog(); 77 ShowDialog();
78 return true; 78 return true;
79 } else if (interactive == "if_needed") { 79 } else if (interactive == "if_needed") {
80 std::vector<MediaFileSystemRegistry::MediaFSInfo> filesystems = 80 std::vector<MediaFileSystemRegistry::MediaFSInfo> filesystems =
81 MediaFileSystemRegistry::GetInstance()->GetMediaFileSystemsForExtension( 81 MediaFileSystemRegistry::GetInstance()->GetMediaFileSystemsForExtension(
82 render_view_host()->GetProcess(), *GetExtension()); 82 render_view_host(), GetExtension());
83 if (filesystems.empty()) 83 if (filesystems.empty())
84 ShowDialog(); 84 ShowDialog();
85 else 85 else
86 ReturnGalleries(filesystems); 86 ReturnGalleries(filesystems);
87 87
88 return true; 88 return true;
89 } else if (interactive == "no") { 89 } else if (interactive == "no") {
90 GetAndReturnGalleries(); 90 GetAndReturnGalleries();
91 return true; 91 return true;
92 } 92 }
93 93
94 error_ = kInvalidInteractive; 94 error_ = kInvalidInteractive;
95 return false; 95 return false;
96 } 96 }
97 97
98 void MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries() { 98 void MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries() {
99 std::vector<MediaFileSystemRegistry::MediaFSInfo> filesystems = 99 std::vector<MediaFileSystemRegistry::MediaFSInfo> filesystems =
100 MediaFileSystemRegistry::GetInstance()->GetMediaFileSystemsForExtension( 100 MediaFileSystemRegistry::GetInstance()->GetMediaFileSystemsForExtension(
101 render_view_host()->GetProcess(), *GetExtension()); 101 render_view_host(), GetExtension());
102 ReturnGalleries(filesystems); 102 ReturnGalleries(filesystems);
103 } 103 }
104 104
105 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries( 105 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries(
106 const std::vector<MediaFileSystemRegistry::MediaFSInfo>& filesystems) { 106 const std::vector<MediaFileSystemRegistry::MediaFSInfo>& filesystems) {
107 const int child_id = render_view_host()->GetProcess()->GetID(); 107 const int child_id = render_view_host()->GetProcess()->GetID();
108 base::ListValue* list = new base::ListValue(); 108 base::ListValue* list = new base::ListValue();
109 for (size_t i = 0; i < filesystems.size(); i++) { 109 for (size_t i = 0; i < filesystems.size(); i++) {
110 base::DictionaryValue* dict_value = new base::DictionaryValue(); 110 base::DictionaryValue* dict_value = new base::DictionaryValue();
111 dict_value->SetWithoutPathExpansion( 111 dict_value->SetWithoutPathExpansion(
112 "fsid", Value::CreateStringValue(filesystems[i].fsid)); 112 "fsid", Value::CreateStringValue(filesystems[i].fsid));
113 // The directory name is not exposed to the js layer. 113 // The directory name is not exposed to the js layer.
114 dict_value->SetWithoutPathExpansion( 114 dict_value->SetWithoutPathExpansion(
115 "name", Value::CreateStringValue(filesystems[i].name)); 115 "name", Value::CreateStringValue(filesystems[i].name));
116 list->Append(dict_value); 116 list->Append(dict_value);
117 117
118 if (GetExtension()->HasAPIPermission( 118 if (!filesystems[i].path.empty() && GetExtension()->HasAPIPermission(
119 extensions::APIPermission::kMediaGalleriesRead)) { 119 extensions::APIPermission::kMediaGalleriesRead)) {
120 content::ChildProcessSecurityPolicy* policy = 120 content::ChildProcessSecurityPolicy* policy =
121 ChildProcessSecurityPolicy::GetInstance(); 121 ChildProcessSecurityPolicy::GetInstance();
122 if (!policy->CanReadFile(child_id, filesystems[i].path)) 122 if (!policy->CanReadFile(child_id, filesystems[i].path))
123 policy->GrantReadFile(child_id, filesystems[i].path); 123 policy->GrantReadFile(child_id, filesystems[i].path);
124 policy->GrantReadFileSystem(child_id, filesystems[i].fsid); 124 policy->GrantReadFileSystem(child_id, filesystems[i].fsid);
125 } 125 }
126 // TODO(vandebo) Handle write permission. 126 // TODO(vandebo) Handle write permission.
127 } 127 }
128 128
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { 160 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() {
161 if (!ApiIsAccessible(&error_)) 161 if (!ApiIsAccessible(&error_))
162 return false; 162 return false;
163 163
164 // TODO(vandebo) Update the metadata and return the new file. 164 // TODO(vandebo) Update the metadata and return the new file.
165 SetResult(Value::CreateNullValue()); 165 SetResult(Value::CreateNullValue());
166 return true; 166 return true;
167 } 167 }
168 168
169 } // namespace extensions 169 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698