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