| 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/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/extensions/shell_window_registry.h" | 17 #include "chrome/browser/extensions/shell_window_registry.h" |
| 18 #include "chrome/browser/media_gallery/media_file_system_registry.h" | 18 #include "chrome/browser/media_gallery/media_file_system_registry.h" |
| 19 #include "chrome/browser/media_gallery/media_galleries_dialog_controller.h" | 19 #include "chrome/browser/media_gallery/media_galleries_dialog_controller.h" |
| 20 #include "chrome/browser/ui/chrome_select_file_policy.h" | 20 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 21 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 21 #include "chrome/browser/ui/extensions/shell_window.h" | 22 #include "chrome/browser/ui/extensions/shell_window.h" |
| 22 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 23 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
| 24 #include "chrome/common/extensions/api/experimental_media_galleries.h" | 24 #include "chrome/common/extensions/api/experimental_media_galleries.h" |
| 25 #include "chrome/common/extensions/api/media_galleries.h" | 25 #include "chrome/common/extensions/api/media_galleries.h" |
| 26 #include "chrome/common/extensions/permissions/api_permission.h" | 26 #include "chrome/common/extensions/permissions/api_permission.h" |
| 27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 28 #include "content/public/browser/child_process_security_policy.h" | 28 #include "content/public/browser/child_process_security_policy.h" |
| 29 #include "content/public/browser/render_process_host.h" | 29 #include "content/public/browser/render_process_host.h" |
| 30 #include "content/public/browser/render_view_host.h" | 30 #include "content/public/browser/render_view_host.h" |
| 31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 32 | 32 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 160 } |
| 161 // TODO(vandebo) Handle write permission. | 161 // TODO(vandebo) Handle write permission. |
| 162 } | 162 } |
| 163 | 163 |
| 164 SetResult(list); | 164 SetResult(list); |
| 165 SendResponse(true); | 165 SendResponse(true); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialog() { | 168 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialog() { |
| 169 WebContents* contents = WebContents::FromRenderViewHost(render_view_host()); | 169 WebContents* contents = WebContents::FromRenderViewHost(render_view_host()); |
| 170 TabContents* tab_contents = | 170 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
| 171 contents ? TabContents::FromWebContents(contents) : NULL; | 171 ConstrainedWindowTabHelper::FromWebContents(contents); |
| 172 if (!tab_contents) { | 172 if (!constrained_window_tab_helper) { |
| 173 // If there is no ConstrainedWindowTabHelper, then this contents is probably |
| 174 // the background page for an app. Try to find a shell window to host the |
| 175 // dialog. |
| 173 ShellWindow* window = ShellWindowRegistry::Get(profile())-> | 176 ShellWindow* window = ShellWindowRegistry::Get(profile())-> |
| 174 GetCurrentShellWindowForApp(GetExtension()->id()); | 177 GetCurrentShellWindowForApp(GetExtension()->id()); |
| 175 if (window) { | 178 if (window) { |
| 176 tab_contents = window->tab_contents(); | 179 contents = window->web_contents(); |
| 177 } else { | 180 } else { |
| 178 // Abort showing the dialog. TODO(estade) Perhaps return an error instead. | 181 // Abort showing the dialog. TODO(estade) Perhaps return an error instead. |
| 179 GetAndReturnGalleries(); | 182 GetAndReturnGalleries(); |
| 180 return; | 183 return; |
| 181 } | 184 } |
| 182 } | 185 } |
| 183 | 186 |
| 184 // Controller will delete itself. | 187 // Controller will delete itself. |
| 185 base::Closure cb = base::Bind( | 188 base::Closure cb = base::Bind( |
| 186 &MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries, this); | 189 &MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries, this); |
| 187 new chrome::MediaGalleriesDialogController(tab_contents, *GetExtension(), cb); | 190 new chrome::MediaGalleriesDialogController(contents, *GetExtension(), cb); |
| 188 } | 191 } |
| 189 | 192 |
| 190 // MediaGalleriesAssembleMediaFileFunction ------------------------------------- | 193 // MediaGalleriesAssembleMediaFileFunction ------------------------------------- |
| 191 | 194 |
| 192 MediaGalleriesAssembleMediaFileFunction:: | 195 MediaGalleriesAssembleMediaFileFunction:: |
| 193 ~MediaGalleriesAssembleMediaFileFunction() {} | 196 ~MediaGalleriesAssembleMediaFileFunction() {} |
| 194 | 197 |
| 195 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { | 198 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { |
| 196 if (!ApiIsAccessible(&error_)) | 199 if (!ApiIsAccessible(&error_)) |
| 197 return false; | 200 return false; |
| 198 | 201 |
| 199 // TODO(vandebo) Update the metadata and return the new file. | 202 // TODO(vandebo) Update the metadata and return the new file. |
| 200 SetResult(Value::CreateNullValue()); | 203 SetResult(Value::CreateNullValue()); |
| 201 return true; | 204 return true; |
| 202 } | 205 } |
| 203 | 206 |
| 204 } // namespace extensions | 207 } // namespace extensions |
| OLD | NEW |