Chromium Code Reviews| 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 <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/media_gallery/media_file_system_registry.h" | 14 #include "chrome/browser/media_gallery/media_file_system_registry.h" |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 15 #include "chrome/common/extensions/api/experimental_media_galleries.h" | 16 #include "chrome/common/extensions/api/experimental_media_galleries.h" |
| 16 #include "content/public/browser/child_process_security_policy.h" | 17 #include "content/public/browser/child_process_security_policy.h" |
| 17 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
| 18 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/web_contents.h" | |
| 19 | 21 |
| 20 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 21 #include "base/sys_string_conversions.h" | 23 #include "base/sys_string_conversions.h" |
| 22 #endif | 24 #endif |
| 23 | 25 |
| 26 using content::WebContents; | |
| 27 | |
| 24 namespace extensions { | 28 namespace extensions { |
| 25 | 29 |
| 26 namespace { | 30 namespace { |
| 27 | 31 |
| 28 const char kInvalidInteractive[] = "Unknown value for interactive."; | 32 const char kInvalidInteractive[] = "Unknown value for interactive."; |
| 29 | 33 |
| 30 } // namespace | 34 } // namespace |
| 31 | 35 |
| 32 using chrome::MediaFileSystemRegistry; | 36 using chrome::MediaFileSystemRegistry; |
| 33 using content::ChildProcessSecurityPolicy; | 37 using content::ChildProcessSecurityPolicy; |
| 34 | 38 |
| 35 namespace MediaGalleries = extensions::api::experimental_media_galleries; | 39 namespace MediaGalleries = extensions::api::experimental_media_galleries; |
| 36 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; | 40 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; |
| 37 | 41 |
| 38 MediaGalleriesGetMediaFileSystemsFunction:: | 42 MediaGalleriesGetMediaFileSystemsFunction:: |
| 39 ~MediaGalleriesGetMediaFileSystemsFunction() {} | 43 ~MediaGalleriesGetMediaFileSystemsFunction() {} |
| 40 | 44 |
| 41 bool MediaGalleriesGetMediaFileSystemsFunction::RunImpl() { | 45 bool MediaGalleriesGetMediaFileSystemsFunction::RunImpl() { |
| 42 scoped_ptr<GetMediaFileSystems::Params> params( | 46 scoped_ptr<GetMediaFileSystems::Params> params( |
| 43 GetMediaFileSystems::Params::Create(*args_)); | 47 GetMediaFileSystems::Params::Create(*args_)); |
| 44 EXTENSION_FUNCTION_VALIDATE(params.get()); | 48 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 45 MediaGalleries::GetMediaFileSystemsInteractivity interactive = "no"; | 49 MediaGalleries::GetMediaFileSystemsInteractivity interactive = "no"; |
| 46 if (params->details.get() && params->details->interactive.get()) | 50 if (params->details.get() && params->details->interactive.get()) |
| 47 interactive = *params->details->interactive; | 51 interactive = *params->details->interactive; |
| 48 | 52 |
| 49 if (interactive == "yes") { | 53 if (interactive == "yes") { |
| 50 // TODO(estade): implement. | 54 ShowDialog(); |
| 55 return true; | |
| 51 } else if (interactive == "if_needed") { | 56 } else if (interactive == "if_needed") { |
|
vandebo (ex-Chrome)
2012/08/08 19:24:21
nit: fall through to no for now.
| |
| 52 // TODO(estade): implement. | 57 // TODO(estade): implement. |
| 53 } else if (interactive != "no") { | 58 } else if (interactive == "no") { |
| 54 error_ = kInvalidInteractive; | 59 ReturnGalleries(); |
| 55 return false; | 60 return true; |
| 56 } | 61 } |
| 57 | 62 |
| 63 error_ = kInvalidInteractive; | |
| 64 return false; | |
| 65 } | |
| 66 | |
| 67 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries() { | |
| 58 const content::RenderProcessHost* rph = render_view_host()->GetProcess(); | 68 const content::RenderProcessHost* rph = render_view_host()->GetProcess(); |
| 59 chrome::MediaFileSystemRegistry* media_fs_registry = | 69 chrome::MediaFileSystemRegistry* media_fs_registry = |
| 60 MediaFileSystemRegistry::GetInstance(); | 70 MediaFileSystemRegistry::GetInstance(); |
| 61 const std::vector<MediaFileSystemRegistry::MediaFSInfo> filesystems = | 71 const std::vector<MediaFileSystemRegistry::MediaFSInfo> filesystems = |
| 62 media_fs_registry->GetMediaFileSystemsForExtension(rph, *GetExtension()); | 72 media_fs_registry->GetMediaFileSystemsForExtension(rph, *GetExtension()); |
| 63 | 73 |
| 64 const int child_id = rph->GetID(); | 74 const int child_id = rph->GetID(); |
| 65 base::ListValue* list = new base::ListValue(); | 75 base::ListValue* list = new base::ListValue(); |
| 66 for (size_t i = 0; i < filesystems.size(); i++) { | 76 for (size_t i = 0; i < filesystems.size(); i++) { |
| 67 base::DictionaryValue* dict_value = new base::DictionaryValue(); | 77 base::DictionaryValue* dict_value = new base::DictionaryValue(); |
| 68 dict_value->SetWithoutPathExpansion( | 78 dict_value->SetWithoutPathExpansion( |
| 69 "fsid", Value::CreateStringValue(filesystems[i].fsid)); | 79 "fsid", Value::CreateStringValue(filesystems[i].fsid)); |
| 70 // The directory name is not exposed to the js layer. | 80 // The directory name is not exposed to the js layer. |
| 71 dict_value->SetWithoutPathExpansion( | 81 dict_value->SetWithoutPathExpansion( |
| 72 "name", Value::CreateStringValue(filesystems[i].name)); | 82 "name", Value::CreateStringValue(filesystems[i].name)); |
| 73 list->Append(dict_value); | 83 list->Append(dict_value); |
| 74 | 84 |
| 75 if (GetExtension()->HasAPIPermission( | 85 if (GetExtension()->HasAPIPermission( |
| 76 extensions::APIPermission::kMediaGalleriesRead)) { | 86 extensions::APIPermission::kMediaGalleriesRead)) { |
| 77 content::ChildProcessSecurityPolicy* policy = | 87 content::ChildProcessSecurityPolicy* policy = |
| 78 ChildProcessSecurityPolicy::GetInstance(); | 88 ChildProcessSecurityPolicy::GetInstance(); |
| 79 if (!policy->CanReadFile(child_id, filesystems[i].path)) | 89 if (!policy->CanReadFile(child_id, filesystems[i].path)) |
| 80 policy->GrantReadFile(child_id, filesystems[i].path); | 90 policy->GrantReadFile(child_id, filesystems[i].path); |
| 81 policy->GrantReadFileSystem(child_id, filesystems[i].fsid); | 91 policy->GrantReadFileSystem(child_id, filesystems[i].fsid); |
| 82 } | 92 } |
| 83 // TODO(vandebo) Handle write permission. | 93 // TODO(vandebo) Handle write permission. |
| 84 } | 94 } |
| 85 | 95 |
| 86 SetResult(list); | 96 SendResponse(list); |
| 87 return true; | |
| 88 } | 97 } |
| 89 | 98 |
| 99 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialog() { | |
| 100 AddRef(); // Balanced in MediaGalleriesDialogFinished. | |
| 101 | |
| 102 WebContents* contents = WebContents::FromRenderViewHost(render_view_host()); | |
| 103 TabContents* tab_contents = | |
| 104 contents ? TabContents::FromWebContents(contents) : NULL; | |
| 105 if (!tab_contents) { | |
| 106 // TODO(estade): for now it just gives up, but it might be nice to first | |
| 107 // attempt to find the active window for this extension. | |
| 108 MediaGalleriesDialogFinished(); | |
| 109 return; | |
| 110 } | |
| 111 | |
| 112 #if defined(TOOLKIT_GTK) | |
| 113 // Controller will delete itself. | |
| 114 new chrome::MediaGalleriesDialogController( | |
| 115 tab_contents, *GetExtension(), this); | |
| 116 #else | |
| 117 // TODO(estade): implement dialog on Views and Cocoa. | |
| 118 MediaGalleriesDialogFinished(); | |
| 119 #endif | |
| 120 } | |
| 121 | |
| 122 void MediaGalleriesGetMediaFileSystemsFunction::MediaGalleriesDialogFinished() { | |
| 123 ReturnGalleries(); | |
| 124 Release(); | |
| 125 } | |
| 126 | |
| 127 // MediaGalleriesAssembleMediaFileFunction ------------------------------------- | |
| 128 | |
| 90 MediaGalleriesAssembleMediaFileFunction:: | 129 MediaGalleriesAssembleMediaFileFunction:: |
| 91 ~MediaGalleriesAssembleMediaFileFunction() {} | 130 ~MediaGalleriesAssembleMediaFileFunction() {} |
| 92 | 131 |
| 93 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { | 132 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { |
| 94 // TODO(vandebo) Update the metadata and return the new file. | 133 // TODO(vandebo) Update the metadata and return the new file. |
| 95 SetResult(Value::CreateNullValue()); | 134 SetResult(Value::CreateNullValue()); |
| 96 return true; | 135 return true; |
| 97 } | 136 } |
| 98 | 137 |
| 99 } // namespace extensions | 138 } // namespace extensions |
| OLD | NEW |