Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc

Issue 10826129: Media galleries: configuration dialog controller and GTK impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/common/extensions/api/media_galleries.h" 17 #include "chrome/common/extensions/api/media_galleries.h"
17 #include "content/public/browser/child_process_security_policy.h" 18 #include "content/public/browser/child_process_security_policy.h"
18 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/render_view_host.h" 20 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/web_contents.h"
20 22
21 #if defined(OS_WIN) 23 #if defined(OS_WIN)
22 #include "base/sys_string_conversions.h" 24 #include "base/sys_string_conversions.h"
23 #endif 25 #endif
24 26
27 using content::WebContents;
28
25 namespace extensions { 29 namespace extensions {
26 30
27 namespace { 31 namespace {
28 32
29 const char kInvalidInteractive[] = "Unknown value for interactive."; 33 const char kInvalidInteractive[] = "Unknown value for interactive.";
30 34
31 } // namespace 35 } // namespace
32 36
33 using chrome::MediaFileSystemRegistry; 37 using chrome::MediaFileSystemRegistry;
34 using content::ChildProcessSecurityPolicy; 38 using content::ChildProcessSecurityPolicy;
35 39
36 namespace MediaGalleries = extensions::api::media_galleries; 40 namespace MediaGalleries = extensions::api::media_galleries;
37 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; 41 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems;
38 42
39 MediaGalleriesGetMediaFileSystemsFunction:: 43 MediaGalleriesGetMediaFileSystemsFunction::
40 ~MediaGalleriesGetMediaFileSystemsFunction() {} 44 ~MediaGalleriesGetMediaFileSystemsFunction() {}
41 45
42 bool MediaGalleriesGetMediaFileSystemsFunction::RunImpl() { 46 bool MediaGalleriesGetMediaFileSystemsFunction::RunImpl() {
43 scoped_ptr<GetMediaFileSystems::Params> params( 47 scoped_ptr<GetMediaFileSystems::Params> params(
44 GetMediaFileSystems::Params::Create(*args_)); 48 GetMediaFileSystems::Params::Create(*args_));
45 EXTENSION_FUNCTION_VALIDATE(params.get()); 49 EXTENSION_FUNCTION_VALIDATE(params.get());
46 MediaGalleries::GetMediaFileSystemsInteractivity interactive = "no"; 50 MediaGalleries::GetMediaFileSystemsInteractivity interactive = "no";
47 if (params->details.get() && params->details->interactive.get()) 51 if (params->details.get() && params->details->interactive.get())
48 interactive = *params->details->interactive; 52 interactive = *params->details->interactive;
49 53
50 if (interactive == "yes") { 54 if (interactive == "yes") {
51 // TODO(estade): implement. 55 ShowDialog();
56 return true;
52 } else if (interactive == "if_needed") { 57 } else if (interactive == "if_needed") {
53 // TODO(estade): implement. 58 // TODO(estade): implement.
54 } else if (interactive != "no") { 59 } else if (interactive == "no") {
55 error_ = kInvalidInteractive; 60 ReturnGalleries();
56 return false; 61 return true;
57 } 62 }
58 63
64 error_ = kInvalidInteractive;
65 return false;
66 }
67
68 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries() {
59 const content::RenderProcessHost* rph = render_view_host()->GetProcess(); 69 const content::RenderProcessHost* rph = render_view_host()->GetProcess();
60 chrome::MediaFileSystemRegistry* media_fs_registry = 70 chrome::MediaFileSystemRegistry* media_fs_registry =
61 MediaFileSystemRegistry::GetInstance(); 71 MediaFileSystemRegistry::GetInstance();
62 const std::vector<MediaFileSystemRegistry::MediaFSInfo> filesystems = 72 const std::vector<MediaFileSystemRegistry::MediaFSInfo> filesystems =
63 media_fs_registry->GetMediaFileSystemsForExtension(rph, *GetExtension()); 73 media_fs_registry->GetMediaFileSystemsForExtension(rph, *GetExtension());
64 74
65 const int child_id = rph->GetID(); 75 const int child_id = rph->GetID();
66 base::ListValue* list = new base::ListValue(); 76 base::ListValue* list = new base::ListValue();
67 for (size_t i = 0; i < filesystems.size(); i++) { 77 for (size_t i = 0; i < filesystems.size(); i++) {
68 base::DictionaryValue* dict_value = new base::DictionaryValue(); 78 base::DictionaryValue* dict_value = new base::DictionaryValue();
69 dict_value->SetWithoutPathExpansion( 79 dict_value->SetWithoutPathExpansion(
70 "fsid", Value::CreateStringValue(filesystems[i].fsid)); 80 "fsid", Value::CreateStringValue(filesystems[i].fsid));
71 // The directory name is not exposed to the js layer. 81 // The directory name is not exposed to the js layer.
72 dict_value->SetWithoutPathExpansion( 82 dict_value->SetWithoutPathExpansion(
73 "name", Value::CreateStringValue(filesystems[i].name)); 83 "name", Value::CreateStringValue(filesystems[i].name));
74 list->Append(dict_value); 84 list->Append(dict_value);
75 85
76 if (GetExtension()->HasAPIPermission( 86 if (GetExtension()->HasAPIPermission(
77 extensions::APIPermission::kMediaGalleriesRead)) { 87 extensions::APIPermission::kMediaGalleriesRead)) {
78 content::ChildProcessSecurityPolicy* policy = 88 content::ChildProcessSecurityPolicy* policy =
79 ChildProcessSecurityPolicy::GetInstance(); 89 ChildProcessSecurityPolicy::GetInstance();
80 if (!policy->CanReadFile(child_id, filesystems[i].path)) 90 if (!policy->CanReadFile(child_id, filesystems[i].path))
81 policy->GrantReadFile(child_id, filesystems[i].path); 91 policy->GrantReadFile(child_id, filesystems[i].path);
82 policy->GrantReadFileSystem(child_id, filesystems[i].fsid); 92 policy->GrantReadFileSystem(child_id, filesystems[i].fsid);
83 } 93 }
84 // TODO(vandebo) Handle write permission. 94 // TODO(vandebo) Handle write permission.
85 } 95 }
86 96
87 SetResult(list); 97 SendResponse(list);
88 return true;
89 } 98 }
90 99
100 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialog() {
101 AddRef(); // Balanced in MediaGalleriesDialogFinished.
102
103 WebContents* contents = WebContents::FromRenderViewHost(render_view_host());
104 TabContents* tab_contents =
105 contents ? TabContents::FromWebContents(contents) : NULL;
106 if (!tab_contents) {
107 // TODO(estade): for now it just gives up, but it might be nice to first
108 // attempt to find the active window for this extension.
109 MediaGalleriesDialogFinished();
110 return;
111 }
112
113 // Controller will delete itself.
114 new chrome::MediaGalleriesDialogController(
115 tab_contents, GetExtension(), this);
116 }
117
118 void MediaGalleriesGetMediaFileSystemsFunction::MediaGalleriesDialogFinished() {
119 ReturnGalleries();
120 Release();
121 }
122
123 // MediaGalleriesAssembleMediaFileFunction -------------------------------------
124
91 MediaGalleriesAssembleMediaFileFunction:: 125 MediaGalleriesAssembleMediaFileFunction::
92 ~MediaGalleriesAssembleMediaFileFunction() {} 126 ~MediaGalleriesAssembleMediaFileFunction() {}
93 127
94 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { 128 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() {
95 // TODO(vandebo) Update the metadata and return the new file. 129 // TODO(vandebo) Update the metadata and return the new file.
96 SetResult(Value::CreateNullValue()); 130 SetResult(Value::CreateNullValue());
97 return true; 131 return true;
98 } 132 }
99 133
100 } // namespace extensions 134 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698