| OLD | NEW |
| 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 <set> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
| 14 #include "base/stl_util.h" |
| 13 #include "base/values.h" | 15 #include "base/values.h" |
| 14 #include "chrome/browser/extensions/shell_window_registry.h" | 16 #include "chrome/browser/extensions/shell_window_registry.h" |
| 15 #include "chrome/browser/media_gallery/media_file_system_registry.h" | 17 #include "chrome/browser/media_gallery/media_file_system_registry.h" |
| 16 #include "chrome/browser/media_gallery/media_galleries_dialog_controller.h" | 18 #include "chrome/browser/media_gallery/media_galleries_dialog_controller.h" |
| 17 #include "chrome/browser/ui/chrome_select_file_policy.h" | 19 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 18 #include "chrome/browser/ui/extensions/shell_window.h" | 20 #include "chrome/browser/ui/extensions/shell_window.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 20 #include "chrome/common/extensions/api/experimental_media_galleries.h" | 22 #include "chrome/common/extensions/api/experimental_media_galleries.h" |
| 21 #include "chrome/common/extensions/api/media_galleries.h" | 23 #include "chrome/common/extensions/api/media_galleries.h" |
| 22 #include "chrome/common/extensions/permissions/media_galleries_permission.h" | 24 #include "chrome/common/extensions/permissions/media_galleries_permission.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 104 |
| 103 void MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries() { | 105 void MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries() { |
| 104 MediaFileSystemRegistry::GetInstance()->GetMediaFileSystemsForExtension( | 106 MediaFileSystemRegistry::GetInstance()->GetMediaFileSystemsForExtension( |
| 105 render_view_host(), GetExtension(), base::Bind( | 107 render_view_host(), GetExtension(), base::Bind( |
| 106 &MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries, this)); | 108 &MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries, this)); |
| 107 } | 109 } |
| 108 | 110 |
| 109 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries( | 111 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries( |
| 110 const std::vector<MediaFileSystemInfo>& filesystems) { | 112 const std::vector<MediaFileSystemInfo>& filesystems) { |
| 111 const int child_id = render_view_host()->GetProcess()->GetID(); | 113 const int child_id = render_view_host()->GetProcess()->GetID(); |
| 114 std::set<std::string> file_system_names; |
| 112 base::ListValue* list = new base::ListValue(); | 115 base::ListValue* list = new base::ListValue(); |
| 113 for (size_t i = 0; i < filesystems.size(); i++) { | 116 for (size_t i = 0; i < filesystems.size(); i++) { |
| 114 base::DictionaryValue* dict_value = new base::DictionaryValue(); | 117 base::DictionaryValue* file_system_dict_value = new base::DictionaryValue(); |
| 115 dict_value->SetWithoutPathExpansion( | 118 |
| 119 // Send the file system id so the renderer can create a valid FileSystem |
| 120 // object. |
| 121 file_system_dict_value->SetWithoutPathExpansion( |
| 116 "fsid", Value::CreateStringValue(filesystems[i].fsid)); | 122 "fsid", Value::CreateStringValue(filesystems[i].fsid)); |
| 117 // The directory name is not exposed to the js layer. | 123 |
| 118 dict_value->SetWithoutPathExpansion( | 124 // The name must be unique according to the HTML5 File System API spec. |
| 125 if (ContainsKey(file_system_names, filesystems[i].name)) { |
| 126 NOTREACHED() << "Duplicate file system name: " << filesystems[i].name; |
| 127 continue; |
| 128 } |
| 129 file_system_names.insert(filesystems[i].name); |
| 130 file_system_dict_value->SetWithoutPathExpansion( |
| 119 "name", Value::CreateStringValue(filesystems[i].name)); | 131 "name", Value::CreateStringValue(filesystems[i].name)); |
| 120 list->Append(dict_value); | 132 |
| 133 list->Append(file_system_dict_value); |
| 121 | 134 |
| 122 if (!filesystems[i].path.empty() && | 135 if (!filesystems[i].path.empty() && |
| 123 MediaGalleriesPermission::HasReadAccess(*GetExtension())) { | 136 MediaGalleriesPermission::HasReadAccess(*GetExtension())) { |
| 124 content::ChildProcessSecurityPolicy* policy = | 137 content::ChildProcessSecurityPolicy* policy = |
| 125 ChildProcessSecurityPolicy::GetInstance(); | 138 ChildProcessSecurityPolicy::GetInstance(); |
| 126 if (!policy->CanReadFile(child_id, filesystems[i].path)) | 139 if (!policy->CanReadFile(child_id, filesystems[i].path)) |
| 127 policy->GrantReadFile(child_id, filesystems[i].path); | 140 policy->GrantReadFile(child_id, filesystems[i].path); |
| 128 policy->GrantReadFileSystem(child_id, filesystems[i].fsid); | 141 policy->GrantReadFileSystem(child_id, filesystems[i].fsid); |
| 129 } | 142 } |
| 130 // TODO(vandebo) Handle write permission. | 143 // TODO(vandebo) Handle write permission. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { | 177 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { |
| 165 if (!ApiIsAccessible(&error_)) | 178 if (!ApiIsAccessible(&error_)) |
| 166 return false; | 179 return false; |
| 167 | 180 |
| 168 // TODO(vandebo) Update the metadata and return the new file. | 181 // TODO(vandebo) Update the metadata and return the new file. |
| 169 SetResult(Value::CreateNullValue()); | 182 SetResult(Value::CreateNullValue()); |
| 170 return true; | 183 return true; |
| 171 } | 184 } |
| 172 | 185 |
| 173 } // namespace extensions | 186 } // namespace extensions |
| OLD | NEW |