| 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> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
| 32 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
| 33 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 34 | 34 |
| 35 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
| 36 #include "base/sys_string_conversions.h" | 36 #include "base/sys_string_conversions.h" |
| 37 #endif | 37 #endif |
| 38 | 38 |
| 39 using chrome::MediaFileSystemInfo; | 39 using chrome::MediaFileSystemInfo; |
| 40 using chrome::MediaFileSystemRegistry; | 40 using chrome::MediaFileSystemRegistry; |
| 41 using chrome::MediaFileSystemsCallback; |
| 41 using content::ChildProcessSecurityPolicy; | 42 using content::ChildProcessSecurityPolicy; |
| 42 using content::WebContents; | 43 using content::WebContents; |
| 43 | 44 |
| 44 namespace MediaGalleries = extensions::api::media_galleries; | 45 namespace MediaGalleries = extensions::api::media_galleries; |
| 45 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; | 46 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; |
| 46 | 47 |
| 47 namespace extensions { | 48 namespace extensions { |
| 48 | 49 |
| 49 namespace { | 50 namespace { |
| 50 | 51 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 80 GetMediaFileSystems::Params::Create(*args_)); | 81 GetMediaFileSystems::Params::Create(*args_)); |
| 81 EXTENSION_FUNCTION_VALIDATE(params.get()); | 82 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 82 MediaGalleries::GetMediaFileSystemsInteractivity interactive = | 83 MediaGalleries::GetMediaFileSystemsInteractivity interactive = |
| 83 MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO; | 84 MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO; |
| 84 if (params->details.get() && params->details->interactive != MediaGalleries:: | 85 if (params->details.get() && params->details->interactive != MediaGalleries:: |
| 85 GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE) { | 86 GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE) { |
| 86 interactive = params->details->interactive; | 87 interactive = params->details->interactive; |
| 87 } | 88 } |
| 88 | 89 |
| 89 switch (interactive) { | 90 switch (interactive) { |
| 90 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_YES: | 91 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_YES: { |
| 91 ShowDialog(); | 92 // The MediaFileSystemRegistry only updates preferences for extensions |
| 93 // that it knows are in use. Since this may be the first call to |
| 94 // chrome.getMediaFileSystems for this extension, call |
| 95 // GetMediaFileSystemsForExtension() here solely so that |
| 96 // MediaFileSystemRegistry will send preference changes. |
| 97 GetMediaFileSystemsForExtension(base::Bind( |
| 98 &MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog, this)); |
| 92 return true; | 99 return true; |
| 100 } |
| 93 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_IF_NEEDED: { | 101 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_IF_NEEDED: { |
| 94 MediaFileSystemRegistry* registry = | 102 GetMediaFileSystemsForExtension(base::Bind( |
| 95 g_browser_process->media_file_system_registry(); | 103 &MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries, |
| 96 registry->GetMediaFileSystemsForExtension( | 104 this)); |
| 97 render_view_host(), GetExtension(), base::Bind( | |
| 98 &MediaGalleriesGetMediaFileSystemsFunction:: | |
| 99 ShowDialogIfNoGalleries, | |
| 100 this)); | |
| 101 return true; | 105 return true; |
| 102 } | 106 } |
| 103 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO: | 107 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO: |
| 104 GetAndReturnGalleries(); | 108 GetAndReturnGalleries(); |
| 105 return true; | 109 return true; |
| 106 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE: | 110 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE: |
| 107 NOTREACHED(); | 111 NOTREACHED(); |
| 108 } | 112 } |
| 109 error_ = kInvalidInteractive; | 113 error_ = kInvalidInteractive; |
| 110 return false; | 114 return false; |
| 111 } | 115 } |
| 112 | 116 |
| 117 void MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog( |
| 118 const std::vector<MediaFileSystemInfo>& /*filesystems*/) { |
| 119 ShowDialog(); |
| 120 } |
| 121 |
| 113 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries( | 122 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries( |
| 114 const std::vector<MediaFileSystemInfo>& filesystems) { | 123 const std::vector<MediaFileSystemInfo>& filesystems) { |
| 115 if (filesystems.empty()) | 124 if (filesystems.empty()) |
| 116 ShowDialog(); | 125 ShowDialog(); |
| 117 else | 126 else |
| 118 ReturnGalleries(filesystems); | 127 ReturnGalleries(filesystems); |
| 119 } | 128 } |
| 120 | 129 |
| 121 void MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries() { | 130 void MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries() { |
| 122 MediaFileSystemRegistry* registry = | 131 GetMediaFileSystemsForExtension(base::Bind( |
| 123 g_browser_process->media_file_system_registry(); | 132 &MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries, this)); |
| 124 registry->GetMediaFileSystemsForExtension( | |
| 125 render_view_host(), GetExtension(), base::Bind( | |
| 126 &MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries, this)); | |
| 127 } | 133 } |
| 128 | 134 |
| 129 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries( | 135 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries( |
| 130 const std::vector<MediaFileSystemInfo>& filesystems) { | 136 const std::vector<MediaFileSystemInfo>& filesystems) { |
| 131 content::RenderViewHost* rvh = render_view_host(); | 137 content::RenderViewHost* rvh = render_view_host(); |
| 132 if (!rvh) { | 138 if (!rvh) { |
| 133 SendResponse(false); | 139 SendResponse(false); |
| 134 return; | 140 return; |
| 135 } | 141 } |
| 136 MediaGalleriesPermission::CheckParam read_param( | 142 MediaGalleriesPermission::CheckParam read_param( |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 return; | 220 return; |
| 215 } | 221 } |
| 216 } | 222 } |
| 217 | 223 |
| 218 // Controller will delete itself. | 224 // Controller will delete itself. |
| 219 base::Closure cb = base::Bind( | 225 base::Closure cb = base::Bind( |
| 220 &MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries, this); | 226 &MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries, this); |
| 221 new chrome::MediaGalleriesDialogController(contents, *GetExtension(), cb); | 227 new chrome::MediaGalleriesDialogController(contents, *GetExtension(), cb); |
| 222 } | 228 } |
| 223 | 229 |
| 230 void MediaGalleriesGetMediaFileSystemsFunction::GetMediaFileSystemsForExtension( |
| 231 const chrome::MediaFileSystemsCallback& cb) { |
| 232 MediaFileSystemRegistry* registry = |
| 233 g_browser_process->media_file_system_registry(); |
| 234 registry->GetMediaFileSystemsForExtension( |
| 235 render_view_host(), GetExtension(), cb); |
| 236 } |
| 237 |
| 224 // MediaGalleriesAssembleMediaFileFunction ------------------------------------- | 238 // MediaGalleriesAssembleMediaFileFunction ------------------------------------- |
| 225 | 239 |
| 226 MediaGalleriesAssembleMediaFileFunction:: | 240 MediaGalleriesAssembleMediaFileFunction:: |
| 227 ~MediaGalleriesAssembleMediaFileFunction() {} | 241 ~MediaGalleriesAssembleMediaFileFunction() {} |
| 228 | 242 |
| 229 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { | 243 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { |
| 230 if (!ApiIsAccessible(&error_)) | 244 if (!ApiIsAccessible(&error_)) |
| 231 return false; | 245 return false; |
| 232 | 246 |
| 233 // TODO(vandebo) Update the metadata and return the new file. | 247 // TODO(vandebo) Update the metadata and return the new file. |
| 234 SetResult(base::Value::CreateNullValue()); | 248 SetResult(base::Value::CreateNullValue()); |
| 235 return true; | 249 return true; |
| 236 } | 250 } |
| 237 | 251 |
| 238 } // namespace extensions | 252 } // namespace extensions |
| OLD | NEW |