| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 scoped_ptr<GetMediaFileSystems::Params> params( | 87 scoped_ptr<GetMediaFileSystems::Params> params( |
| 87 GetMediaFileSystems::Params::Create(*args_)); | 88 GetMediaFileSystems::Params::Create(*args_)); |
| 88 EXTENSION_FUNCTION_VALIDATE(params.get()); | 89 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 89 MediaGalleries::GetMediaFileSystemsInteractivity interactive = | 90 MediaGalleries::GetMediaFileSystemsInteractivity interactive = |
| 90 MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO; | 91 MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO; |
| 91 if (params->details.get() && params->details->interactive != MediaGalleries:: | 92 if (params->details.get() && params->details->interactive != MediaGalleries:: |
| 92 GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE) { | 93 GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE) { |
| 93 interactive = params->details->interactive; | 94 interactive = params->details->interactive; |
| 94 } | 95 } |
| 95 | 96 |
| 97 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind( |
| 98 &MediaGalleriesGetMediaFileSystemsFunction::OnStorageMonitorInit, |
| 99 this, |
| 100 interactive)); |
| 101 return true; |
| 102 } |
| 103 |
| 104 void MediaGalleriesGetMediaFileSystemsFunction::OnStorageMonitorInit( |
| 105 MediaGalleries::GetMediaFileSystemsInteractivity interactive) { |
| 96 switch (interactive) { | 106 switch (interactive) { |
| 97 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_YES: { | 107 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_YES: { |
| 98 // The MediaFileSystemRegistry only updates preferences for extensions | 108 // The MediaFileSystemRegistry only updates preferences for extensions |
| 99 // that it knows are in use. Since this may be the first call to | 109 // that it knows are in use. Since this may be the first call to |
| 100 // chrome.getMediaFileSystems for this extension, call | 110 // chrome.getMediaFileSystems for this extension, call |
| 101 // GetMediaFileSystemsForExtension() here solely so that | 111 // GetMediaFileSystemsForExtension() here solely so that |
| 102 // MediaFileSystemRegistry will send preference changes. | 112 // MediaFileSystemRegistry will send preference changes. |
| 103 GetMediaFileSystemsForExtension(base::Bind( | 113 GetMediaFileSystemsForExtension(base::Bind( |
| 104 &MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog, this)); | 114 &MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog, this)); |
| 105 return true; | 115 return; |
| 106 } | 116 } |
| 107 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_IF_NEEDED: { | 117 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_IF_NEEDED: { |
| 108 GetMediaFileSystemsForExtension(base::Bind( | 118 GetMediaFileSystemsForExtension(base::Bind( |
| 109 &MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries, | 119 &MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries, |
| 110 this)); | 120 this)); |
| 111 return true; | 121 return; |
| 112 } | 122 } |
| 113 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO: | 123 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO: |
| 114 GetAndReturnGalleries(); | 124 GetAndReturnGalleries(); |
| 115 return true; | 125 return; |
| 116 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE: | 126 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE: |
| 117 NOTREACHED(); | 127 NOTREACHED(); |
| 118 } | 128 } |
| 119 error_ = kInvalidInteractive; | 129 error_ = kInvalidInteractive; |
| 120 return false; | 130 SendResponse(false); |
| 121 } | 131 } |
| 122 | 132 |
| 123 void MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog( | 133 void MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog( |
| 124 const std::vector<MediaFileSystemInfo>& /*filesystems*/) { | 134 const std::vector<MediaFileSystemInfo>& /*filesystems*/) { |
| 125 ShowDialog(); | 135 ShowDialog(); |
| 126 } | 136 } |
| 127 | 137 |
| 128 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries( | 138 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries( |
| 129 const std::vector<MediaFileSystemInfo>& filesystems) { | 139 const std::vector<MediaFileSystemInfo>& filesystems) { |
| 130 if (filesystems.empty()) | 140 if (filesystems.empty()) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 new chrome::MediaGalleriesDialogController(contents, *GetExtension(), cb); | 228 new chrome::MediaGalleriesDialogController(contents, *GetExtension(), cb); |
| 219 } | 229 } |
| 220 | 230 |
| 221 void MediaGalleriesGetMediaFileSystemsFunction::GetMediaFileSystemsForExtension( | 231 void MediaGalleriesGetMediaFileSystemsFunction::GetMediaFileSystemsForExtension( |
| 222 const chrome::MediaFileSystemsCallback& cb) { | 232 const chrome::MediaFileSystemsCallback& cb) { |
| 223 if (!render_view_host()) { | 233 if (!render_view_host()) { |
| 224 cb.Run(std::vector<MediaFileSystemInfo>()); | 234 cb.Run(std::vector<MediaFileSystemInfo>()); |
| 225 return; | 235 return; |
| 226 } | 236 } |
| 227 | 237 |
| 238 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); |
| 228 MediaFileSystemRegistry* registry = | 239 MediaFileSystemRegistry* registry = |
| 229 g_browser_process->media_file_system_registry(); | 240 g_browser_process->media_file_system_registry(); |
| 230 registry->GetMediaFileSystemsForExtension( | 241 registry->GetMediaFileSystemsForExtension( |
| 231 render_view_host(), GetExtension(), cb); | 242 render_view_host(), GetExtension(), cb); |
| 232 } | 243 } |
| 233 | 244 |
| 234 // MediaGalleriesAssembleMediaFileFunction ------------------------------------- | 245 // MediaGalleriesAssembleMediaFileFunction ------------------------------------- |
| 235 | 246 |
| 236 MediaGalleriesAssembleMediaFileFunction:: | 247 MediaGalleriesAssembleMediaFileFunction:: |
| 237 ~MediaGalleriesAssembleMediaFileFunction() {} | 248 ~MediaGalleriesAssembleMediaFileFunction() {} |
| 238 | 249 |
| 239 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { | 250 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { |
| 240 if (!ApiIsAccessible(&error_)) | 251 if (!ApiIsAccessible(&error_)) |
| 241 return false; | 252 return false; |
| 242 | 253 |
| 243 // TODO(vandebo) Update the metadata and return the new file. | 254 // TODO(vandebo) Update the metadata and return the new file. |
| 244 SetResult(base::Value::CreateNullValue()); | 255 SetResult(base::Value::CreateNullValue()); |
| 245 return true; | 256 return true; |
| 246 } | 257 } |
| 247 | 258 |
| 248 } // namespace extensions | 259 } // namespace extensions |
| OLD | NEW |