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

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

Issue 10825018: Add GetSitesWithData and FreeSiteList methods to PPP_Flash_BrowserOperations interface and hook the… (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 #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/memory/scoped_ptr.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 context->request_id, PP_ToBool(success), default_permission, site_vector); 70 context->request_id, PP_ToBool(success), default_permission, site_vector);
71 } 71 }
72 72
73 } // namespace 73 } // namespace
74 74
75 BrokerProcessDispatcher::BrokerProcessDispatcher( 75 BrokerProcessDispatcher::BrokerProcessDispatcher(
76 PP_GetInterface_Func get_plugin_interface, 76 PP_GetInterface_Func get_plugin_interface,
77 PP_ConnectInstance_Func connect_instance) 77 PP_ConnectInstance_Func connect_instance)
78 : ppapi::proxy::BrokerSideDispatcher(connect_instance), 78 : ppapi::proxy::BrokerSideDispatcher(connect_instance),
79 get_plugin_interface_(get_plugin_interface), 79 get_plugin_interface_(get_plugin_interface),
80 flash_browser_operations_1_3_(NULL),
80 flash_browser_operations_1_2_(NULL), 81 flash_browser_operations_1_2_(NULL),
81 flash_browser_operations_1_0_(NULL) { 82 flash_browser_operations_1_0_(NULL) {
82 ChildProcess::current()->AddRefProcess(); 83 ChildProcess::current()->AddRefProcess();
83 84
84 if (get_plugin_interface) { 85 if (get_plugin_interface) {
85 flash_browser_operations_1_0_ = 86 flash_browser_operations_1_0_ =
86 static_cast<const PPP_Flash_BrowserOperations_1_0*>( 87 static_cast<const PPP_Flash_BrowserOperations_1_0*>(
87 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_0)); 88 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_0));
88 89
89 flash_browser_operations_1_2_ = 90 flash_browser_operations_1_2_ =
90 static_cast<const PPP_Flash_BrowserOperations_1_2*>( 91 static_cast<const PPP_Flash_BrowserOperations_1_2*>(
91 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_2)); 92 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_2));
93
94 flash_browser_operations_1_3_ =
95 static_cast<const PPP_Flash_BrowserOperations_1_3*>(
96 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_3));
92 } 97 }
93 } 98 }
94 99
95 BrokerProcessDispatcher::~BrokerProcessDispatcher() { 100 BrokerProcessDispatcher::~BrokerProcessDispatcher() {
96 DVLOG(1) << "BrokerProcessDispatcher::~BrokerProcessDispatcher()"; 101 DVLOG(1) << "BrokerProcessDispatcher::~BrokerProcessDispatcher()";
97 // Don't free the process right away. This timer allows the child process 102 // Don't free the process right away. This timer allows the child process
98 // to be re-used if the user rapidly goes to a new page that requires this 103 // to be re-used if the user rapidly goes to a new page that requires this
99 // plugin. This is the case for common plugins where they may be used on a 104 // plugin. This is the case for common plugins where they may be used on a
100 // source and destination page of a navigation. We don't want to tear down 105 // source and destination page of a navigation. We don't want to tear down
101 // and re-start processes each time in these cases. 106 // and re-start processes each time in these cases.
102 MessageLoop::current()->PostDelayedTask( 107 MessageLoop::current()->PostDelayedTask(
103 FROM_HERE, 108 FROM_HERE,
104 base::Bind(&ChildProcess::ReleaseProcess, 109 base::Bind(&ChildProcess::ReleaseProcess,
105 base::Unretained(ChildProcess::current())), 110 base::Unretained(ChildProcess::current())),
106 base::TimeDelta::FromSeconds(kBrokerReleaseTimeSeconds)); 111 base::TimeDelta::FromSeconds(kBrokerReleaseTimeSeconds));
107 } 112 }
108 113
109 bool BrokerProcessDispatcher::OnMessageReceived(const IPC::Message& msg) { 114 bool BrokerProcessDispatcher::OnMessageReceived(const IPC::Message& msg) {
110 IPC_BEGIN_MESSAGE_MAP(BrokerProcessDispatcher, msg) 115 IPC_BEGIN_MESSAGE_MAP(BrokerProcessDispatcher, msg)
116 IPC_MESSAGE_HANDLER(PpapiMsg_GetSitesWithData, OnMsgGetSitesWithData)
111 IPC_MESSAGE_HANDLER(PpapiMsg_ClearSiteData, OnMsgClearSiteData) 117 IPC_MESSAGE_HANDLER(PpapiMsg_ClearSiteData, OnMsgClearSiteData)
112 IPC_MESSAGE_HANDLER(PpapiMsg_DeauthorizeContentLicenses, 118 IPC_MESSAGE_HANDLER(PpapiMsg_DeauthorizeContentLicenses,
113 OnMsgDeauthorizeContentLicenses) 119 OnMsgDeauthorizeContentLicenses)
114 IPC_MESSAGE_HANDLER(PpapiMsg_GetPermissionSettings, 120 IPC_MESSAGE_HANDLER(PpapiMsg_GetPermissionSettings,
115 OnMsgGetPermissionSettings) 121 OnMsgGetPermissionSettings)
116 IPC_MESSAGE_HANDLER(PpapiMsg_SetDefaultPermission, 122 IPC_MESSAGE_HANDLER(PpapiMsg_SetDefaultPermission,
117 OnMsgSetDefaultPermission) 123 OnMsgSetDefaultPermission)
118 IPC_MESSAGE_HANDLER(PpapiMsg_SetSitePermission, OnMsgSetSitePermission) 124 IPC_MESSAGE_HANDLER(PpapiMsg_SetSitePermission, OnMsgSetSitePermission)
119 IPC_MESSAGE_UNHANDLED(return BrokerSideDispatcher::OnMessageReceived(msg)) 125 IPC_MESSAGE_UNHANDLED(return BrokerSideDispatcher::OnMessageReceived(msg))
120 IPC_END_MESSAGE_MAP() 126 IPC_END_MESSAGE_MAP()
121 return true; 127 return true;
122 } 128 }
123 129
124 void BrokerProcessDispatcher::OnGetPermissionSettingsCompleted( 130 void BrokerProcessDispatcher::OnGetPermissionSettingsCompleted(
125 uint32 request_id, 131 uint32 request_id,
126 bool success, 132 bool success,
127 PP_Flash_BrowserOperations_Permission default_permission, 133 PP_Flash_BrowserOperations_Permission default_permission,
128 const ppapi::FlashSiteSettings& sites) { 134 const ppapi::FlashSiteSettings& sites) {
129 Send(new PpapiHostMsg_GetPermissionSettingsResult( 135 Send(new PpapiHostMsg_GetPermissionSettingsResult(
130 request_id, success, default_permission, sites)); 136 request_id, success, default_permission, sites));
131 } 137 }
132 138
139 void BrokerProcessDispatcher::OnMsgGetSitesWithData(
140 uint32 request_id,
141 const FilePath& plugin_data_path) {
142 std::vector<std::string> sites;
143 GetSitesWithData(plugin_data_path, &sites);
144 Send(new PpapiHostMsg_GetSitesWithDataResult(request_id, sites));
145 }
146
133 void BrokerProcessDispatcher::OnMsgClearSiteData( 147 void BrokerProcessDispatcher::OnMsgClearSiteData(
148 uint32 request_id,
134 const FilePath& plugin_data_path, 149 const FilePath& plugin_data_path,
135 const std::string& site, 150 const std::string& site,
136 uint64 flags, 151 uint64 flags,
137 uint64 max_age) { 152 uint64 max_age) {
138 Send(new PpapiHostMsg_ClearSiteDataResult( 153 Send(new PpapiHostMsg_ClearSiteDataResult(
139 ClearSiteData(plugin_data_path, site, flags, max_age))); 154 request_id, ClearSiteData(plugin_data_path, site, flags, max_age)));
140 } 155 }
141 156
142 void BrokerProcessDispatcher::OnMsgDeauthorizeContentLicenses( 157 void BrokerProcessDispatcher::OnMsgDeauthorizeContentLicenses(
143 uint32 request_id, 158 uint32 request_id,
144 const FilePath& plugin_data_path) { 159 const FilePath& plugin_data_path) {
145 Send(new PpapiHostMsg_DeauthorizeContentLicensesResult( 160 Send(new PpapiHostMsg_DeauthorizeContentLicensesResult(
146 request_id, DeauthorizeContentLicenses(plugin_data_path))); 161 request_id, DeauthorizeContentLicenses(plugin_data_path)));
147 } 162 }
148 163
149 void BrokerProcessDispatcher::OnMsgGetPermissionSettings( 164 void BrokerProcessDispatcher::OnMsgGetPermissionSettings(
150 uint32 request_id, 165 uint32 request_id,
151 const FilePath& plugin_data_path, 166 const FilePath& plugin_data_path,
152 PP_Flash_BrowserOperations_SettingType setting_type) { 167 PP_Flash_BrowserOperations_SettingType setting_type) {
153 if (!flash_browser_operations_1_2_) { 168 if (flash_browser_operations_1_3_) {
154 OnGetPermissionSettingsCompleted( 169 std::string data_str = ConvertPluginDataPath(plugin_data_path);
155 request_id, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT, 170 // The GetPermissionSettingsContext object will be deleted in
156 ppapi::FlashSiteSettings()); 171 // GetPermissionSettingsCallback().
172 flash_browser_operations_1_3_->GetPermissionSettings(
173 data_str.c_str(), setting_type, &GetPermissionSettingsCallback,
174 new GetPermissionSettingsContext(AsWeakPtr(), request_id));
157 return; 175 return;
158 } 176 }
159 177
160 std::string data_str = ConvertPluginDataPath(plugin_data_path); 178 if (flash_browser_operations_1_2_) {
161 // The GetPermissionSettingsContext object will be deleted in 179 std::string data_str = ConvertPluginDataPath(plugin_data_path);
162 // GetPermissionSettingsCallback(). 180 // The GetPermissionSettingsContext object will be deleted in
163 flash_browser_operations_1_2_->GetPermissionSettings( 181 // GetPermissionSettingsCallback().
164 data_str.c_str(), setting_type, &GetPermissionSettingsCallback, 182 flash_browser_operations_1_2_->GetPermissionSettings(
165 new GetPermissionSettingsContext(AsWeakPtr(), request_id)); 183 data_str.c_str(), setting_type, &GetPermissionSettingsCallback,
184 new GetPermissionSettingsContext(AsWeakPtr(), request_id));
185 return;
186 }
187
188 OnGetPermissionSettingsCompleted(
189 request_id, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT,
190 ppapi::FlashSiteSettings());
191 return;
166 } 192 }
167 193
168 void BrokerProcessDispatcher::OnMsgSetDefaultPermission( 194 void BrokerProcessDispatcher::OnMsgSetDefaultPermission(
169 uint32 request_id, 195 uint32 request_id,
170 const FilePath& plugin_data_path, 196 const FilePath& plugin_data_path,
171 PP_Flash_BrowserOperations_SettingType setting_type, 197 PP_Flash_BrowserOperations_SettingType setting_type,
172 PP_Flash_BrowserOperations_Permission permission, 198 PP_Flash_BrowserOperations_Permission permission,
173 bool clear_site_specific) { 199 bool clear_site_specific) {
174 Send(new PpapiHostMsg_SetDefaultPermissionResult( 200 Send(new PpapiHostMsg_SetDefaultPermissionResult(
175 request_id, 201 request_id,
176 SetDefaultPermission(plugin_data_path, setting_type, permission, 202 SetDefaultPermission(plugin_data_path, setting_type, permission,
177 clear_site_specific))); 203 clear_site_specific)));
178 } 204 }
179 205
180 void BrokerProcessDispatcher::OnMsgSetSitePermission( 206 void BrokerProcessDispatcher::OnMsgSetSitePermission(
181 uint32 request_id, 207 uint32 request_id,
182 const FilePath& plugin_data_path, 208 const FilePath& plugin_data_path,
183 PP_Flash_BrowserOperations_SettingType setting_type, 209 PP_Flash_BrowserOperations_SettingType setting_type,
184 const ppapi::FlashSiteSettings& sites) { 210 const ppapi::FlashSiteSettings& sites) {
185 Send(new PpapiHostMsg_SetSitePermissionResult( 211 Send(new PpapiHostMsg_SetSitePermissionResult(
186 request_id, SetSitePermission(plugin_data_path, setting_type, sites))); 212 request_id, SetSitePermission(plugin_data_path, setting_type, sites)));
187 } 213 }
188 214
215 void BrokerProcessDispatcher::GetSitesWithData(
216 const FilePath& plugin_data_path,
217 std::vector<std::string>* site_vector) {
218 std::string data_str = ConvertPluginDataPath(plugin_data_path);
219 if (flash_browser_operations_1_3_) {
220 char** sites = NULL;
221 flash_browser_operations_1_3_->GetSitesWithData(data_str.c_str(), &sites);
222 if (!sites)
223 return;
224
225 for (size_t i = 0; sites[i]; ++i)
226 site_vector->push_back(sites[i]);
227
228 flash_browser_operations_1_3_->FreeSiteList(sites);
229 }
230 }
231
189 bool BrokerProcessDispatcher::ClearSiteData(const FilePath& plugin_data_path, 232 bool BrokerProcessDispatcher::ClearSiteData(const FilePath& plugin_data_path,
190 const std::string& site, 233 const std::string& site,
191 uint64 flags, 234 uint64 flags,
192 uint64 max_age) { 235 uint64 max_age) {
193 std::string data_str = ConvertPluginDataPath(plugin_data_path); 236 std::string data_str = ConvertPluginDataPath(plugin_data_path);
237 if (flash_browser_operations_1_3_) {
238 flash_browser_operations_1_3_->ClearSiteData(
239 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age);
240 return true;
241 }
242
243 // TODO(viettrungluu): Remove this (and the 1.0 interface) sometime after M21
244 // goes to Stable.
194 if (flash_browser_operations_1_2_) { 245 if (flash_browser_operations_1_2_) {
195 flash_browser_operations_1_2_->ClearSiteData( 246 flash_browser_operations_1_2_->ClearSiteData(
196 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); 247 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age);
197 return true; 248 return true;
198 } 249 }
199 250
200 // TODO(viettrungluu): Remove this (and the 1.0 interface) sometime after M21
201 // goes to Stable.
202 if (flash_browser_operations_1_0_) { 251 if (flash_browser_operations_1_0_) {
203 flash_browser_operations_1_0_->ClearSiteData( 252 flash_browser_operations_1_0_->ClearSiteData(
204 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); 253 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age);
205 return true; 254 return true;
206 } 255 }
207 256
208 return false; 257 return false;
209 } 258 }
210 259
211 bool BrokerProcessDispatcher::DeauthorizeContentLicenses( 260 bool BrokerProcessDispatcher::DeauthorizeContentLicenses(
212 const FilePath& plugin_data_path) { 261 const FilePath& plugin_data_path) {
213 if (!flash_browser_operations_1_2_) 262 if (flash_browser_operations_1_3_) {
214 return false; 263 std::string data_str = ConvertPluginDataPath(plugin_data_path);
264 return PP_ToBool(flash_browser_operations_1_3_->DeauthorizeContentLicenses(
265 data_str.c_str()));
266 }
215 267
216 std::string data_str = ConvertPluginDataPath(plugin_data_path); 268 if (flash_browser_operations_1_2_) {
217 return PP_ToBool(flash_browser_operations_1_2_->DeauthorizeContentLicenses( 269 std::string data_str = ConvertPluginDataPath(plugin_data_path);
218 data_str.c_str())); 270 return PP_ToBool(flash_browser_operations_1_2_->DeauthorizeContentLicenses(
271 data_str.c_str()));
272 }
273
274 return false;
219 } 275 }
220 276
221 bool BrokerProcessDispatcher::SetDefaultPermission( 277 bool BrokerProcessDispatcher::SetDefaultPermission(
222 const FilePath& plugin_data_path, 278 const FilePath& plugin_data_path,
223 PP_Flash_BrowserOperations_SettingType setting_type, 279 PP_Flash_BrowserOperations_SettingType setting_type,
224 PP_Flash_BrowserOperations_Permission permission, 280 PP_Flash_BrowserOperations_Permission permission,
225 bool clear_site_specific) { 281 bool clear_site_specific) {
226 if (!flash_browser_operations_1_2_) 282 if (flash_browser_operations_1_3_) {
227 return false; 283 std::string data_str = ConvertPluginDataPath(plugin_data_path);
284 return PP_ToBool(flash_browser_operations_1_3_->SetDefaultPermission(
285 data_str.c_str(), setting_type, permission,
286 PP_FromBool(clear_site_specific)));
287 }
228 288
229 std::string data_str = ConvertPluginDataPath(plugin_data_path); 289 if (flash_browser_operations_1_2_) {
230 return PP_ToBool(flash_browser_operations_1_2_->SetDefaultPermission( 290 std::string data_str = ConvertPluginDataPath(plugin_data_path);
231 data_str.c_str(), setting_type, permission, 291 return PP_ToBool(flash_browser_operations_1_2_->SetDefaultPermission(
232 PP_FromBool(clear_site_specific))); 292 data_str.c_str(), setting_type, permission,
293 PP_FromBool(clear_site_specific)));
294 }
295
296 return false;
233 } 297 }
234 298
235 bool BrokerProcessDispatcher::SetSitePermission( 299 bool BrokerProcessDispatcher::SetSitePermission(
236 const FilePath& plugin_data_path, 300 const FilePath& plugin_data_path,
237 PP_Flash_BrowserOperations_SettingType setting_type, 301 PP_Flash_BrowserOperations_SettingType setting_type,
238 const ppapi::FlashSiteSettings& sites) { 302 const ppapi::FlashSiteSettings& sites) {
239 if (!flash_browser_operations_1_2_)
240 return false;
241
242 if (sites.empty()) 303 if (sites.empty())
243 return true; 304 return true;
244 305
245 std::string data_str = ConvertPluginDataPath(plugin_data_path); 306 std::string data_str = ConvertPluginDataPath(plugin_data_path);
246 scoped_array<PP_Flash_BrowserOperations_SiteSetting> site_array( 307 scoped_array<PP_Flash_BrowserOperations_SiteSetting> site_array(
247 new PP_Flash_BrowserOperations_SiteSetting[sites.size()]); 308 new PP_Flash_BrowserOperations_SiteSetting[sites.size()]);
248 309
249 for (size_t i = 0; i < sites.size(); ++i) { 310 for (size_t i = 0; i < sites.size(); ++i) {
250 site_array[i].site = sites[i].site.c_str(); 311 site_array[i].site = sites[i].site.c_str();
251 site_array[i].permission = sites[i].permission; 312 site_array[i].permission = sites[i].permission;
252 } 313 }
253 314
254 PP_Bool result = flash_browser_operations_1_2_->SetSitePermission( 315 if (flash_browser_operations_1_3_) {
255 data_str.c_str(), setting_type, sites.size(), site_array.get()); 316 PP_Bool result = flash_browser_operations_1_3_->SetSitePermission(
317 data_str.c_str(), setting_type, sites.size(), site_array.get());
256 318
257 return PP_ToBool(result); 319 return PP_ToBool(result);
320 }
321
322 if (flash_browser_operations_1_2_) {
323 PP_Bool result = flash_browser_operations_1_2_->SetSitePermission(
324 data_str.c_str(), setting_type, sites.size(), site_array.get());
325
326 return PP_ToBool(result);
327 }
328
329 return false;
258 } 330 }
OLDNEW
« no previous file with comments | « content/ppapi_plugin/broker_process_dispatcher.h ('k') | ppapi/api/private/ppp_flash_browser_operations.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698