| 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/memory/scoped_ptr.h" |
| 14 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/extensions/shell_window_registry.h" | 19 #include "chrome/browser/extensions/shell_window_registry.h" |
| 20 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 20 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 21 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" | 21 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" |
| 22 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 22 #include "chrome/browser/ui/chrome_select_file_policy.h" | 23 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 23 #include "chrome/browser/ui/extensions/shell_window.h" | 24 #include "chrome/browser/ui/extensions/shell_window.h" |
| 24 #include "chrome/common/extensions/api/experimental_media_galleries.h" | 25 #include "chrome/common/extensions/api/experimental_media_galleries.h" |
| 25 #include "chrome/common/extensions/api/media_galleries.h" | 26 #include "chrome/common/extensions/api/media_galleries.h" |
| 26 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
| 27 #include "chrome/common/extensions/permissions/api_permission.h" | 28 #include "chrome/common/extensions/permissions/api_permission.h" |
| 28 #include "chrome/common/extensions/permissions/media_galleries_permission.h" | 29 #include "chrome/common/extensions/permissions/media_galleries_permission.h" |
| 29 #include "chrome/common/extensions/permissions/permissions_data.h" | 30 #include "chrome/common/extensions/permissions/permissions_data.h" |
| 30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 31 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 32 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 scoped_ptr<GetMediaFileSystems::Params> params( | 86 scoped_ptr<GetMediaFileSystems::Params> params( |
| 86 GetMediaFileSystems::Params::Create(*args_)); | 87 GetMediaFileSystems::Params::Create(*args_)); |
| 87 EXTENSION_FUNCTION_VALIDATE(params.get()); | 88 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 88 MediaGalleries::GetMediaFileSystemsInteractivity interactive = | 89 MediaGalleries::GetMediaFileSystemsInteractivity interactive = |
| 89 MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO; | 90 MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO; |
| 90 if (params->details.get() && params->details->interactive != MediaGalleries:: | 91 if (params->details.get() && params->details->interactive != MediaGalleries:: |
| 91 GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE) { | 92 GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE) { |
| 92 interactive = params->details->interactive; | 93 interactive = params->details->interactive; |
| 93 } | 94 } |
| 94 | 95 |
| 96 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind( |
| 97 &MediaGalleriesGetMediaFileSystemsFunction::OnStorageMonitorInit, |
| 98 this, |
| 99 interactive)); |
| 100 return true; |
| 101 } |
| 102 |
| 103 void MediaGalleriesGetMediaFileSystemsFunction::OnStorageMonitorInit( |
| 104 MediaGalleries::GetMediaFileSystemsInteractivity interactive) { |
| 95 switch (interactive) { | 105 switch (interactive) { |
| 96 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_YES: { | 106 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_YES: { |
| 97 // The MediaFileSystemRegistry only updates preferences for extensions | 107 // The MediaFileSystemRegistry only updates preferences for extensions |
| 98 // that it knows are in use. Since this may be the first call to | 108 // that it knows are in use. Since this may be the first call to |
| 99 // chrome.getMediaFileSystems for this extension, call | 109 // chrome.getMediaFileSystems for this extension, call |
| 100 // GetMediaFileSystemsForExtension() here solely so that | 110 // GetMediaFileSystemsForExtension() here solely so that |
| 101 // MediaFileSystemRegistry will send preference changes. | 111 // MediaFileSystemRegistry will send preference changes. |
| 102 GetMediaFileSystemsForExtension(base::Bind( | 112 GetMediaFileSystemsForExtension(base::Bind( |
| 103 &MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog, this)); | 113 &MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog, this)); |
| 104 return true; | 114 return; |
| 105 } | 115 } |
| 106 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_IF_NEEDED: { | 116 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_IF_NEEDED: { |
| 107 GetMediaFileSystemsForExtension(base::Bind( | 117 GetMediaFileSystemsForExtension(base::Bind( |
| 108 &MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries, | 118 &MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries, |
| 109 this)); | 119 this)); |
| 110 return true; | 120 return; |
| 111 } | 121 } |
| 112 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO: | 122 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO: |
| 113 GetAndReturnGalleries(); | 123 GetAndReturnGalleries(); |
| 114 return true; | 124 return; |
| 115 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE: | 125 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE: |
| 116 NOTREACHED(); | 126 NOTREACHED(); |
| 117 } | 127 } |
| 118 NOTREACHED(); | 128 SendResponse(false); |
| 119 return false; | |
| 120 } | 129 } |
| 121 | 130 |
| 122 void MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog( | 131 void MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog( |
| 123 const std::vector<MediaFileSystemInfo>& /*filesystems*/) { | 132 const std::vector<MediaFileSystemInfo>& /*filesystems*/) { |
| 124 ShowDialog(); | 133 ShowDialog(); |
| 125 } | 134 } |
| 126 | 135 |
| 127 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries( | 136 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries( |
| 128 const std::vector<MediaFileSystemInfo>& filesystems) { | 137 const std::vector<MediaFileSystemInfo>& filesystems) { |
| 129 if (filesystems.empty()) | 138 if (filesystems.empty()) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 new chrome::MediaGalleriesDialogController(contents, *GetExtension(), cb); | 226 new chrome::MediaGalleriesDialogController(contents, *GetExtension(), cb); |
| 218 } | 227 } |
| 219 | 228 |
| 220 void MediaGalleriesGetMediaFileSystemsFunction::GetMediaFileSystemsForExtension( | 229 void MediaGalleriesGetMediaFileSystemsFunction::GetMediaFileSystemsForExtension( |
| 221 const chrome::MediaFileSystemsCallback& cb) { | 230 const chrome::MediaFileSystemsCallback& cb) { |
| 222 if (!render_view_host()) { | 231 if (!render_view_host()) { |
| 223 cb.Run(std::vector<MediaFileSystemInfo>()); | 232 cb.Run(std::vector<MediaFileSystemInfo>()); |
| 224 return; | 233 return; |
| 225 } | 234 } |
| 226 | 235 |
| 236 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); |
| 227 MediaFileSystemRegistry* registry = | 237 MediaFileSystemRegistry* registry = |
| 228 g_browser_process->media_file_system_registry(); | 238 g_browser_process->media_file_system_registry(); |
| 229 registry->GetMediaFileSystemsForExtension( | 239 registry->GetMediaFileSystemsForExtension( |
| 230 render_view_host(), GetExtension(), cb); | 240 render_view_host(), GetExtension(), cb); |
| 231 } | 241 } |
| 232 | 242 |
| 233 // MediaGalleriesAssembleMediaFileFunction ------------------------------------- | 243 // MediaGalleriesAssembleMediaFileFunction ------------------------------------- |
| 234 | 244 |
| 235 MediaGalleriesAssembleMediaFileFunction:: | 245 MediaGalleriesAssembleMediaFileFunction:: |
| 236 ~MediaGalleriesAssembleMediaFileFunction() {} | 246 ~MediaGalleriesAssembleMediaFileFunction() {} |
| 237 | 247 |
| 238 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { | 248 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { |
| 239 if (!ApiIsAccessible(&error_)) | 249 if (!ApiIsAccessible(&error_)) |
| 240 return false; | 250 return false; |
| 241 | 251 |
| 242 // TODO(vandebo) Update the metadata and return the new file. | 252 // TODO(vandebo) Update the metadata and return the new file. |
| 243 SetResult(base::Value::CreateNullValue()); | 253 SetResult(base::Value::CreateNullValue()); |
| 244 return true; | 254 return true; |
| 245 } | 255 } |
| 246 | 256 |
| 247 } // namespace extensions | 257 } // namespace extensions |
| OLD | NEW |