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

Side by Side Diff: content/ppapi_plugin/broker_process_dispatcher.cc

Issue 10479015: Pepper Flash settings integration - camera and microphone. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 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
« no previous file with comments | « content/ppapi_plugin/broker_process_dispatcher.h ('k') | ppapi/ppapi_shared.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "content/ppapi_plugin/broker_process_dispatcher.h" 5 #include "content/ppapi_plugin/broker_process_dispatcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_ptr.h"
9 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
10 #include "content/common/child_process.h" 11 #include "content/common/child_process.h"
11 #include "ppapi/c/pp_bool.h" 12 #include "ppapi/c/pp_bool.h"
12 #include "ppapi/c/private/ppp_flash_browser_operations.h" 13 #include "ppapi/c/private/ppp_flash_browser_operations.h"
13 #include "ppapi/proxy/ppapi_messages.h" 14 #include "ppapi/proxy/ppapi_messages.h"
15 #include "ppapi/shared_impl/ppapi_globals.h"
16 #include "ppapi/shared_impl/var.h"
17 #include "ppapi/shared_impl/var_tracker.h"
14 18
15 namespace { 19 namespace {
16 20
17 // How long we wait before releasing the broker process. 21 // How long we wait before releasing the broker process.
18 const int kBrokerReleaseTimeSeconds = 30; 22 const int kBrokerReleaseTimeSeconds = 30;
19 23
20 std::string ConvertPluginDataPath(const FilePath& plugin_data_path) { 24 std::string ConvertPluginDataPath(const FilePath& plugin_data_path) {
21 // The string is always 8-bit, convert on Windows. 25 // The string is always 8-bit, convert on Windows.
22 #if defined(OS_WIN) 26 #if defined(OS_WIN)
23 return WideToUTF8(plugin_data_path.value()); 27 return WideToUTF8(plugin_data_path.value());
24 #else 28 #else
25 return plugin_data_path.value(); 29 return plugin_data_path.value();
26 #endif 30 #endif
27 } 31 }
28 32
33 struct GetPermissionSettingsContext {
34 GetPermissionSettingsContext(
35 const base::WeakPtr<BrokerProcessDispatcher> in_dispatcher,
36 uint32 in_request_id)
37 : dispatcher(in_dispatcher),
38 request_id(in_request_id) {
39 }
40
41 base::WeakPtr<BrokerProcessDispatcher> dispatcher;
42 uint32 request_id;
43 };
44
45 void GetPermissionSettingsCallback(
46 void* user_data,
47 PP_Bool success,
48 PP_Flash_BrowserOperations_Permission default_permission,
49 uint32_t site_count,
50 const PP_Flash_BrowserOperations_SiteSetting sites[]) {
51 scoped_ptr<GetPermissionSettingsContext> context(
52 reinterpret_cast<GetPermissionSettingsContext*>(user_data));
53
54 if (!context->dispatcher)
55 return;
56
57 ppapi::FlashSiteSettings site_vector;
58 if (success) {
59 site_vector.reserve(site_count);
60 for (uint32_t i = 0; i < site_count; ++i) {
61 ppapi::StringVar* string_var = ppapi::StringVar::FromPPVar(sites[i].site);
62 if (!string_var) {
63 success = PP_FALSE;
64 break;
65 }
66 site_vector.push_back(
67 ppapi::FlashSiteSetting(string_var->value(), sites[i].permission));
68 }
69
70 if (!success)
71 site_vector.clear();
72 }
73 context->dispatcher->OnGetPermissionSettingsCompleted(
74 context->request_id, PP_ToBool(success), default_permission, site_vector);
75 }
76
29 } // namespace 77 } // namespace
30 78
31 BrokerProcessDispatcher::BrokerProcessDispatcher( 79 BrokerProcessDispatcher::BrokerProcessDispatcher(
32 PP_GetInterface_Func get_plugin_interface, 80 PP_GetInterface_Func get_plugin_interface,
33 PP_ConnectInstance_Func connect_instance) 81 PP_ConnectInstance_Func connect_instance)
34 : ppapi::proxy::BrokerSideDispatcher(connect_instance), 82 : ppapi::proxy::BrokerSideDispatcher(connect_instance),
35 get_plugin_interface_(get_plugin_interface) { 83 get_plugin_interface_(get_plugin_interface),
84 flash_browser_operations_1_1_(NULL),
85 flash_browser_operations_1_0_(NULL) {
36 ChildProcess::current()->AddRefProcess(); 86 ChildProcess::current()->AddRefProcess();
87
88 if (get_plugin_interface) {
89 flash_browser_operations_1_0_ =
90 static_cast<const PPP_Flash_BrowserOperations_1_0*>(
91 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_0));
92
93 flash_browser_operations_1_1_ =
94 static_cast<const PPP_Flash_BrowserOperations_1_1*>(
95 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_1));
96 }
37 } 97 }
38 98
39 BrokerProcessDispatcher::~BrokerProcessDispatcher() { 99 BrokerProcessDispatcher::~BrokerProcessDispatcher() {
40 DVLOG(1) << "BrokerProcessDispatcher::~BrokerProcessDispatcher()"; 100 DVLOG(1) << "BrokerProcessDispatcher::~BrokerProcessDispatcher()";
41 // Don't free the process right away. This timer allows the child process 101 // Don't free the process right away. This timer allows the child process
42 // to be re-used if the user rapidly goes to a new page that requires this 102 // to be re-used if the user rapidly goes to a new page that requires this
43 // plugin. This is the case for common plugins where they may be used on a 103 // plugin. This is the case for common plugins where they may be used on a
44 // source and destination page of a navigation. We don't want to tear down 104 // source and destination page of a navigation. We don't want to tear down
45 // and re-start processes each time in these cases. 105 // and re-start processes each time in these cases.
46 MessageLoop::current()->PostDelayedTask( 106 MessageLoop::current()->PostDelayedTask(
47 FROM_HERE, 107 FROM_HERE,
48 base::Bind(&ChildProcess::ReleaseProcess, 108 base::Bind(&ChildProcess::ReleaseProcess,
49 base::Unretained(ChildProcess::current())), 109 base::Unretained(ChildProcess::current())),
50 base::TimeDelta::FromSeconds(kBrokerReleaseTimeSeconds)); 110 base::TimeDelta::FromSeconds(kBrokerReleaseTimeSeconds));
51 } 111 }
52 112
53 bool BrokerProcessDispatcher::OnMessageReceived(const IPC::Message& msg) { 113 bool BrokerProcessDispatcher::OnMessageReceived(const IPC::Message& msg) {
54 IPC_BEGIN_MESSAGE_MAP(BrokerProcessDispatcher, msg) 114 IPC_BEGIN_MESSAGE_MAP(BrokerProcessDispatcher, msg)
55 IPC_MESSAGE_HANDLER(PpapiMsg_ClearSiteData, OnMsgClearSiteData) 115 IPC_MESSAGE_HANDLER(PpapiMsg_ClearSiteData, OnMsgClearSiteData)
56 IPC_MESSAGE_HANDLER(PpapiMsg_DeauthorizeContentLicenses, 116 IPC_MESSAGE_HANDLER(PpapiMsg_DeauthorizeContentLicenses,
57 OnMsgDeauthorizeContentLicenses) 117 OnMsgDeauthorizeContentLicenses)
118 IPC_MESSAGE_HANDLER(PpapiMsg_GetPermissionSettings,
119 OnMsgGetPermissionSettings)
120 IPC_MESSAGE_HANDLER(PpapiMsg_SetDefaultPermission,
121 OnMsgSetDefaultPermission)
122 IPC_MESSAGE_HANDLER(PpapiMsg_SetSitePermission, OnMsgSetSitePermission)
58 IPC_MESSAGE_UNHANDLED(return BrokerSideDispatcher::OnMessageReceived(msg)) 123 IPC_MESSAGE_UNHANDLED(return BrokerSideDispatcher::OnMessageReceived(msg))
59 IPC_END_MESSAGE_MAP() 124 IPC_END_MESSAGE_MAP()
60 return true; 125 return true;
61 } 126 }
62 127
128 void BrokerProcessDispatcher::OnGetPermissionSettingsCompleted(
129 uint32 request_id,
130 bool success,
131 PP_Flash_BrowserOperations_Permission default_permission,
132 const ppapi::FlashSiteSettings& sites) {
133 Send(new PpapiHostMsg_GetPermissionSettingsResult(
134 request_id, success, default_permission, sites));
135 }
136
63 void BrokerProcessDispatcher::OnMsgClearSiteData( 137 void BrokerProcessDispatcher::OnMsgClearSiteData(
64 const FilePath& plugin_data_path, 138 const FilePath& plugin_data_path,
65 const std::string& site, 139 const std::string& site,
66 uint64 flags, 140 uint64 flags,
67 uint64 max_age) { 141 uint64 max_age) {
68 Send(new PpapiHostMsg_ClearSiteDataResult( 142 Send(new PpapiHostMsg_ClearSiteDataResult(
69 ClearSiteData(plugin_data_path, site, flags, max_age))); 143 ClearSiteData(plugin_data_path, site, flags, max_age)));
70 } 144 }
71 145
72 void BrokerProcessDispatcher::OnMsgDeauthorizeContentLicenses( 146 void BrokerProcessDispatcher::OnMsgDeauthorizeContentLicenses(
73 uint32 request_id, 147 uint32 request_id,
74 const FilePath& plugin_data_path) { 148 const FilePath& plugin_data_path) {
75 Send(new PpapiHostMsg_DeauthorizeContentLicensesResult( 149 Send(new PpapiHostMsg_DeauthorizeContentLicensesResult(
76 request_id, DeauthorizeContentLicenses(plugin_data_path))); 150 request_id, DeauthorizeContentLicenses(plugin_data_path)));
77 } 151 }
78 152
153 void BrokerProcessDispatcher::OnMsgGetPermissionSettings(
154 uint32 request_id,
155 const FilePath& plugin_data_path,
156 PP_Flash_BrowserOperations_SettingType setting_type) {
157 if (!flash_browser_operations_1_1_) {
158 OnGetPermissionSettingsCompleted(
159 request_id, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT,
160 ppapi::FlashSiteSettings());
161 return;
162 }
163
164 std::string data_str = ConvertPluginDataPath(plugin_data_path);
165 // The GetPermissionSettingsContext object will be deleted in
166 // GetPermissionSettingsCallback().
167 flash_browser_operations_1_1_->GetPermissionSettings(
168 data_str.c_str(), setting_type, &GetPermissionSettingsCallback,
169 new GetPermissionSettingsContext(AsWeakPtr(), request_id));
170 }
171
172 void BrokerProcessDispatcher::OnMsgSetDefaultPermission(
173 uint32 request_id,
174 const FilePath& plugin_data_path,
175 PP_Flash_BrowserOperations_SettingType setting_type,
176 PP_Flash_BrowserOperations_Permission permission,
177 bool clear_site_specific) {
178 Send(new PpapiHostMsg_SetDefaultPermissionResult(
179 request_id,
180 SetDefaultPermission(plugin_data_path, setting_type, permission,
181 clear_site_specific)));
182 }
183
184 void BrokerProcessDispatcher::OnMsgSetSitePermission(
185 uint32 request_id,
186 const FilePath& plugin_data_path,
187 PP_Flash_BrowserOperations_SettingType setting_type,
188 const ppapi::FlashSiteSettings& sites) {
189 Send(new PpapiHostMsg_SetSitePermissionResult(
190 request_id, SetSitePermission(plugin_data_path, setting_type, sites)));
191 }
192
79 bool BrokerProcessDispatcher::ClearSiteData(const FilePath& plugin_data_path, 193 bool BrokerProcessDispatcher::ClearSiteData(const FilePath& plugin_data_path,
80 const std::string& site, 194 const std::string& site,
81 uint64 flags, 195 uint64 flags,
82 uint64 max_age) { 196 uint64 max_age) {
83 if (!get_plugin_interface_) 197 std::string data_str = ConvertPluginDataPath(plugin_data_path);
84 return false; 198 if (flash_browser_operations_1_1_) {
85 199 flash_browser_operations_1_1_->ClearSiteData(
86 const PPP_Flash_BrowserOperations_1_1* browser_interface = 200 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age);
87 static_cast<const PPP_Flash_BrowserOperations_1_1*>(
88 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_1));
89 if (browser_interface) {
90 std::string data_str = ConvertPluginDataPath(plugin_data_path);
91 browser_interface->ClearSiteData(data_str.c_str(),
92 site.empty() ? NULL : site.c_str(),
93 flags, max_age);
94 return true; 201 return true;
95 } 202 }
96 203
97 // TODO(viettrungluu): Remove this (and the 1.0 interface) sometime after M21 204 // TODO(viettrungluu): Remove this (and the 1.0 interface) sometime after M21
98 // goes to Stable. 205 // goes to Stable.
99 const PPP_Flash_BrowserOperations_1_0* browser_interface_1_0 = 206 if (flash_browser_operations_1_0_) {
100 static_cast<const PPP_Flash_BrowserOperations_1_0*>( 207 flash_browser_operations_1_0_->ClearSiteData(
101 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_0)); 208 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age);
102 if (browser_interface_1_0) {
103 std::string data_str = ConvertPluginDataPath(plugin_data_path);
104 browser_interface_1_0->ClearSiteData(data_str.c_str(),
105 site.empty() ? NULL : site.c_str(),
106 flags, max_age);
107 return true; 209 return true;
108 } 210 }
109 211
110 return false; 212 return false;
111 } 213 }
112 214
113 bool BrokerProcessDispatcher::DeauthorizeContentLicenses( 215 bool BrokerProcessDispatcher::DeauthorizeContentLicenses(
114 const FilePath& plugin_data_path) { 216 const FilePath& plugin_data_path) {
115 if (!get_plugin_interface_) 217 if (!flash_browser_operations_1_1_)
116 return false;
117 const PPP_Flash_BrowserOperations_1_1* browser_interface =
118 static_cast<const PPP_Flash_BrowserOperations_1_1*>(
119 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_1));
120 if (!browser_interface)
121 return false; 218 return false;
122 219
123 std::string data_str = ConvertPluginDataPath(plugin_data_path); 220 std::string data_str = ConvertPluginDataPath(plugin_data_path);
124 return PP_ToBool(browser_interface->DeauthorizeContentLicenses( 221 return PP_ToBool(flash_browser_operations_1_1_->DeauthorizeContentLicenses(
125 data_str.c_str())); 222 data_str.c_str()));
126 } 223 }
127 224
225 bool BrokerProcessDispatcher::SetDefaultPermission(
226 const FilePath& plugin_data_path,
227 PP_Flash_BrowserOperations_SettingType setting_type,
228 PP_Flash_BrowserOperations_Permission permission,
229 bool clear_site_specific) {
230 if (!flash_browser_operations_1_1_)
231 return false;
232
233 std::string data_str = ConvertPluginDataPath(plugin_data_path);
234 return PP_ToBool(flash_browser_operations_1_1_->SetDefaultPermission(
235 data_str.c_str(), setting_type, permission,
236 PP_FromBool(clear_site_specific)));
237 }
238
239 bool BrokerProcessDispatcher::SetSitePermission(
240 const FilePath& plugin_data_path,
241 PP_Flash_BrowserOperations_SettingType setting_type,
242 const ppapi::FlashSiteSettings& sites) {
243 if (!flash_browser_operations_1_1_)
244 return false;
245
246 if (sites.empty())
247 return true;
248
249 std::string data_str = ConvertPluginDataPath(plugin_data_path);
250 scoped_array<PP_Flash_BrowserOperations_SiteSetting> site_array(
251 new PP_Flash_BrowserOperations_SiteSetting[sites.size()]);
252
253 for (size_t i = 0; i < sites.size(); ++i) {
254 site_array[i].site = ppapi::StringVar::StringToPPVar(sites[i].site);
255 site_array[i].permission = sites[i].permission;
256 }
257
258 PP_Bool result = flash_browser_operations_1_1_->SetSitePermission(
259 data_str.c_str(), setting_type, sites.size(), site_array.get());
260
261 for (size_t i = 0; i < sites.size(); ++i)
262 ppapi::PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(site_array[i].site);
263
264 return PP_ToBool(result);
265 }
OLDNEW
« no previous file with comments | « content/ppapi_plugin/broker_process_dispatcher.h ('k') | ppapi/ppapi_shared.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698