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

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 10545036: Add PPAPI decryptor interfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updates resulting from David's comments Created 8 years, 5 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 | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | no next file » | 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 "webkit/plugins/ppapi/ppapi_plugin_instance.h" 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/linked_ptr.h" 10 #include "base/memory/linked_ptr.h"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // returned vector are only guaranteed valid so long as the vector of strings 287 // returned vector are only guaranteed valid so long as the vector of strings
288 // is not modified. 288 // is not modified.
289 scoped_array<const char*> StringVectorToArgArray( 289 scoped_array<const char*> StringVectorToArgArray(
290 const std::vector<std::string>& vector) { 290 const std::vector<std::string>& vector) {
291 scoped_array<const char*> array(new const char*[vector.size()]); 291 scoped_array<const char*> array(new const char*[vector.size()]);
292 for (size_t i = 0; i < vector.size(); ++i) 292 for (size_t i = 0; i < vector.size(); ++i)
293 array[i] = vector[i].c_str(); 293 array[i] = vector[i].c_str();
294 return array.Pass(); 294 return array.Pass();
295 } 295 }
296 296
297 // Creates a PP_Resource containing a PPB_Buffer_Impl, copies |data| into the
298 // buffer resource, and returns it. Returns a PP_Resource equal to 0 on
299 // failure.
300 PP_Resource MakeBufferResource(PP_Instance instance,
301 const std::string& data) {
302 if (!data.size())
303 return 0;
304
305 ScopedPPResource resource(PPB_Buffer_Impl::Create(instance, data.size()));
306 if (!resource.get())
307 return 0;
308
309 EnterResourceNoLock<PPB_Buffer_API> enter(resource, true);
310 if (enter.failed())
311 return 0;
312
313 BufferAutoMapper mapper(enter.object());
314 if (!mapper.data() || mapper.size() < data.size())
315 return 0;
316 memcpy(mapper.data(), data.data(), data.size());
317
318 // Add the resource to the tracker...
319 // TODO(tomfinegan): wild guess/no idea if this is right.
320 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource.get());
321
322 return resource.Release();
323 }
324
297 } // namespace 325 } // namespace
298 326
299 // static 327 // static
300 PluginInstance* PluginInstance::Create(PluginDelegate* delegate, 328 PluginInstance* PluginInstance::Create(PluginDelegate* delegate,
301 PluginModule* module) { 329 PluginModule* module) {
302 base::Callback<const void*(const char*)> get_plugin_interface_func = 330 base::Callback<const void*(const char*)> get_plugin_interface_func =
303 base::Bind(&PluginModule::GetPluginInterface, module); 331 base::Bind(&PluginModule::GetPluginInterface, module);
304 PPP_Instance_Combined* ppp_instance_combined = 332 PPP_Instance_Combined* ppp_instance_combined =
305 PPP_Instance_Combined::Create(get_plugin_interface_func); 333 PPP_Instance_Combined::Create(get_plugin_interface_func);
306 if (!ppp_instance_combined) 334 if (!ppp_instance_combined)
307 return NULL; 335 return NULL;
308 return new PluginInstance(delegate, module, ppp_instance_combined); 336 return new PluginInstance(delegate, module, ppp_instance_combined);
309 } 337 }
310 338
311 PluginInstance::PluginInstance( 339 PluginInstance::PluginInstance(
312 PluginDelegate* delegate, 340 PluginDelegate* delegate,
313 PluginModule* module, 341 PluginModule* module,
314 ::ppapi::PPP_Instance_Combined* instance_interface) 342 ::ppapi::PPP_Instance_Combined* instance_interface)
315 : delegate_(delegate), 343 : delegate_(delegate),
316 module_(module), 344 module_(module),
317 instance_interface_(instance_interface), 345 instance_interface_(instance_interface),
318 pp_instance_(0), 346 pp_instance_(0),
319 container_(NULL), 347 container_(NULL),
320 full_frame_(false), 348 full_frame_(false),
321 sent_initial_did_change_view_(false), 349 sent_initial_did_change_view_(false),
322 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 350 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
323 has_webkit_focus_(false), 351 has_webkit_focus_(false),
324 has_content_area_focus_(false), 352 has_content_area_focus_(false),
325 find_identifier_(-1), 353 find_identifier_(-1),
354 plugin_decryption_interface_(NULL),
326 plugin_find_interface_(NULL), 355 plugin_find_interface_(NULL),
327 plugin_input_event_interface_(NULL), 356 plugin_input_event_interface_(NULL),
328 plugin_messaging_interface_(NULL), 357 plugin_messaging_interface_(NULL),
329 plugin_mouse_lock_interface_(NULL), 358 plugin_mouse_lock_interface_(NULL),
330 plugin_pdf_interface_(NULL), 359 plugin_pdf_interface_(NULL),
331 plugin_private_interface_(NULL), 360 plugin_private_interface_(NULL),
332 plugin_selection_interface_(NULL), 361 plugin_selection_interface_(NULL),
333 plugin_textinput_interface_(NULL), 362 plugin_textinput_interface_(NULL),
334 plugin_zoom_interface_(NULL), 363 plugin_zoom_interface_(NULL),
335 checked_for_plugin_input_event_interface_(false), 364 checked_for_plugin_input_event_interface_(false),
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 981
953 void PluginInstance::StopFind() { 982 void PluginInstance::StopFind() {
954 // Keep a reference on the stack. See NOTE above. 983 // Keep a reference on the stack. See NOTE above.
955 scoped_refptr<PluginInstance> ref(this); 984 scoped_refptr<PluginInstance> ref(this);
956 if (!LoadFindInterface()) 985 if (!LoadFindInterface())
957 return; 986 return;
958 find_identifier_ = -1; 987 find_identifier_ = -1;
959 plugin_find_interface_->StopFind(pp_instance()); 988 plugin_find_interface_->StopFind(pp_instance());
960 } 989 }
961 990
991 bool PluginInstance::LoadContentDecryptionModuleInterface() {
992 if (!plugin_decryption_interface_) {
993 plugin_decryption_interface_ =
994 static_cast<const PPP_ContentDecryptor_Dev*>(
995 module_->GetPluginInterface(
996 PPP_CONTENTDECRYPTOR_DEV_INTERFACE));
997 }
998 return !!plugin_decryption_interface_;
999 }
1000
962 bool PluginInstance::LoadFindInterface() { 1001 bool PluginInstance::LoadFindInterface() {
963 if (!plugin_find_interface_) { 1002 if (!plugin_find_interface_) {
964 plugin_find_interface_ = 1003 plugin_find_interface_ =
965 static_cast<const PPP_Find_Dev*>(module_->GetPluginInterface( 1004 static_cast<const PPP_Find_Dev*>(module_->GetPluginInterface(
966 PPP_FIND_DEV_INTERFACE)); 1005 PPP_FIND_DEV_INTERFACE));
967 } 1006 }
968 1007
969 return !!plugin_find_interface_; 1008 return !!plugin_find_interface_;
970 } 1009 }
971 1010
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 if (!LoadPdfInterface()) 1302 if (!LoadPdfInterface())
1264 return; 1303 return;
1265 PP_PrivatePageTransformType transform_type = 1304 PP_PrivatePageTransformType transform_type =
1266 type == WebPlugin::RotationType90Clockwise ? 1305 type == WebPlugin::RotationType90Clockwise ?
1267 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW : 1306 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW :
1268 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW; 1307 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW;
1269 plugin_pdf_interface_->Transform(pp_instance(), transform_type); 1308 plugin_pdf_interface_->Transform(pp_instance(), transform_type);
1270 // NOTE: plugin instance may have been deleted. 1309 // NOTE: plugin instance may have been deleted.
1271 } 1310 }
1272 1311
1312 bool PluginInstance::GenerateKeyRequest(const std::string& key_system,
1313 const std::string& init_data) {
1314 if (!LoadContentDecryptionModuleInterface())
1315 return false;
1316
1317 if (key_system.empty())
1318 return false;
1319
1320 PP_Resource init_data_resource = 0;
1321 if (init_data.size()) {
1322 ScopedPPResource local_init_data(ScopedPPResource::PassRef(),
1323 MakeBufferResource(pp_instance(),
1324 init_data));
1325
1326 if (!local_init_data.get())
1327 return false;
1328 init_data_resource = local_init_data.Release();
1329 }
1330
1331 return PP_ToBool(plugin_decryption_interface_->GenerateKeyRequest(
1332 pp_instance(),
1333 StringVar::StringToPPVar(key_system),
1334 init_data_resource));
1335 }
1336
1337 bool PluginInstance::AddKey(const std::string& session_id,
1338 const std::string& key) {
1339 if (!LoadContentDecryptionModuleInterface())
1340 return false;
1341
1342 StringVar session_id_var(session_id);
1343 if (session_id_var.value().size() < session_id.size())
1344 return false;
1345
1346 ScopedPPResource key_resource(ScopedPPResource::PassRef(),
1347 MakeBufferResource(pp_instance(), key));
1348 if (!key_resource.get())
1349 return false;
1350
1351 return PP_ToBool(plugin_decryption_interface_->AddKey(
1352 pp_instance(),
1353 session_id_var.GetPPVar(),
1354 key_resource));
1355 }
1356
1357 bool PluginInstance::CancelKeyRequest(const std::string& session_id) {
1358 if (!LoadContentDecryptionModuleInterface())
1359 return false;
1360 StringVar session_id_var(session_id);
1361 if (session_id_var.value().size() < session_id.size())
1362 return false;
1363 return PP_ToBool(plugin_decryption_interface_->CancelKeyRequest(
1364 pp_instance(),
1365 session_id_var.GetPPVar()));
1366 }
1367
1368 bool PluginInstance::Decrypt(const std::string& encrypted_block,
1369 const CDMStatusCB& callback) {
1370 if (!LoadContentDecryptionModuleInterface())
1371 return false;
1372 ScopedPPResource encrypted_resource(ScopedPPResource::PassRef(),
1373 MakeBufferResource(pp_instance(),
1374 encrypted_block));
1375 if (!encrypted_resource.get())
1376 return false;
1377 // TODO(tomfinegan): wrap callback in PP_CompletionCallback and pass it to
1378 // the plugin.
1379 PP_CompletionCallback pp_callback = {NULL, NULL, 0};
1380 return PP_ToBool(plugin_decryption_interface_->Decrypt(pp_instance(),
1381 encrypted_resource,
1382 pp_callback));
1383 }
1384
1385 bool PluginInstance::DecryptAndDecode(const std::string& encrypted_block,
1386 const CDMStatusCB& callback) {
1387 if (!LoadContentDecryptionModuleInterface())
1388 return false;
1389 ScopedPPResource encrypted_resource(ScopedPPResource::PassRef(),
1390 MakeBufferResource(pp_instance(),
1391 encrypted_block));
1392 if (!encrypted_resource.get())
1393 return false;
1394 // TODO(tomfinegan): wrap callback in PP_CompletionCallback and pass it to
1395 // the plugin.
1396 PP_CompletionCallback pp_callback = {NULL, NULL, 0};
1397 return PP_ToBool(plugin_decryption_interface_->DecryptAndDecode(
1398 pp_instance(),
1399 encrypted_resource,
1400 pp_callback));
1401 }
1402
1273 bool PluginInstance::FlashIsFullscreenOrPending() { 1403 bool PluginInstance::FlashIsFullscreenOrPending() {
1274 return fullscreen_container_ != NULL; 1404 return fullscreen_container_ != NULL;
1275 } 1405 }
1276 1406
1277 bool PluginInstance::IsFullscreenOrPending() { 1407 bool PluginInstance::IsFullscreenOrPending() {
1278 return desired_fullscreen_state_; 1408 return desired_fullscreen_state_;
1279 } 1409 }
1280 1410
1281 bool PluginInstance::SetFullscreen(bool fullscreen) { 1411 bool PluginInstance::SetFullscreen(bool fullscreen) {
1282 // Keep a reference on the stack. See NOTE above. 1412 // Keep a reference on the stack. See NOTE above.
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) { 1977 PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) {
1848 std::string encoding = delegate()->GetDefaultEncoding(); 1978 std::string encoding = delegate()->GetDefaultEncoding();
1849 return StringVar::StringToPPVar(encoding); 1979 return StringVar::StringToPPVar(encoding);
1850 } 1980 }
1851 1981
1852 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) { 1982 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) {
1853 // No in-process implementation. 1983 // No in-process implementation.
1854 return PP_MakeUndefined(); 1984 return PP_MakeUndefined();
1855 } 1985 }
1856 1986
1987 void PluginInstance::NeedKey(PP_Instance instance,
1988 PP_Var key_system,
1989 PP_Var session_id,
1990 PP_Resource init_data) {
1991 }
1992
1993 void PluginInstance::KeyAdded(PP_Instance instance,
1994 PP_Var key_system,
1995 PP_Var session_id) {
1996 }
1997
1998 void PluginInstance::KeyMessage(PP_Instance instance,
1999 PP_Var key_system_var,
2000 PP_Var session_id_var,
2001 PP_Resource message_resource,
2002 PP_Var default_url_var) {
2003 // Extract the std::strings from the PP_Vars.
2004 StringVar* key_system_string = StringVar::FromPPVar(key_system_var);
ddorwin 2012/07/17 21:47:56 Just checking, are these non-owning pointers?
Tom Finegan 2012/07/17 22:15:34 Correct-- this just gives access to the data. It d
2005 StringVar* session_id_string = StringVar::FromPPVar(session_id_var);
2006 StringVar* default_url_string = StringVar::FromPPVar(default_url_var);
2007
2008 if (!key_system_string || !session_id_string || !default_url_string) {
ddorwin 2012/07/17 21:47:56 Does this mean they are NULL or what? Maybe DCHECK
Tom Finegan 2012/07/17 22:15:34 It means they're NULL. I'll DCHECK The first two a
2009 // TODO(tomfinegan): KeyError here?
2010 return;
2011 }
2012
2013 EnterResourceNoLock<PPB_Buffer_API> enter(message_resource, true);
2014 if (enter.failed()) {
2015 // TODO(tomfinegan): KeyError here?
2016 NOTREACHED();
2017 return;
2018 }
2019
2020 BufferAutoMapper mapper(enter.object());
2021 if (!mapper.data() || !mapper.size()) {
2022 // TODO(tomfinegan): KeyError here?
2023 NOTREACHED();
2024 return;
2025 }
2026
2027 std::string message(reinterpret_cast<char*>(mapper.data()), mapper.size());
2028 if (message.empty()) {
2029 // TODO(tomfinegan): KeyError here?
2030 NOTREACHED();
2031 return;
2032 }
2033
ddorwin 2012/07/17 21:47:56 What about the other values? And where would we ac
Tom Finegan 2012/07/17 22:15:34 The callback would happen right about where this c
2034 // Relase the PP_Vars.
ddorwin 2012/07/17 21:47:56 Release
Tom Finegan 2012/07/17 22:15:34 Done.
2035 HostGlobals::Get()->GetVarTracker()->ReleaseVar(key_system_var);
2036 HostGlobals::Get()->GetVarTracker()->ReleaseVar(session_id_var);
2037 HostGlobals::Get()->GetVarTracker()->ReleaseVar(default_url_var);
2038
2039 // Release the PP_Resource.
2040 // TODO(tomfinegan): Confirm that the buffer is freed.
2041 HostGlobals::Get()->GetResourceTracker()->ReleaseResource(message_resource);
2042 }
2043
2044 void PluginInstance::KeyError(PP_Instance instance,
2045 PP_Var key_system,
2046 PP_Var session_id,
2047 uint16_t media_error,
2048 uint16_t system_error) {
2049 }
2050
2051 void PluginInstance::DeliverBlock(PP_Instance instance,
2052 PP_Resource decrypted_block,
2053 PP_CompletionCallback callback) {
2054 }
2055
2056 void PluginInstance::DeliverFrame(PP_Instance instance,
2057 PP_Resource decrypted_frame,
2058 PP_CompletionCallback callback) {
2059 }
2060
2061 void PluginInstance::DeliverSamples(PP_Instance instance,
2062 PP_Resource decrypted_samples,
2063 PP_CompletionCallback callback) {
2064 }
2065
2066
1857 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, 2067 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance,
1858 int32_t total, 2068 int32_t total,
1859 PP_Bool final_result) { 2069 PP_Bool final_result) {
1860 DCHECK_NE(find_identifier_, -1); 2070 DCHECK_NE(find_identifier_, -1);
1861 delegate_->NumberOfFindResultsChanged(find_identifier_, total, 2071 delegate_->NumberOfFindResultsChanged(find_identifier_, total,
1862 PP_ToBool(final_result)); 2072 PP_ToBool(final_result));
1863 } 2073 }
1864 2074
1865 void PluginInstance::SelectedFindResultChanged(PP_Instance instance, 2075 void PluginInstance::SelectedFindResultChanged(PP_Instance instance,
1866 int32_t index) { 2076 int32_t index) {
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
2214 screen_size_for_fullscreen_ = gfx::Size(); 2424 screen_size_for_fullscreen_ = gfx::Size();
2215 WebElement element = container_->element(); 2425 WebElement element = container_->element();
2216 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2426 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2217 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2427 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2218 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2428 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2219 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2429 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2220 } 2430 }
2221 2431
2222 } // namespace ppapi 2432 } // namespace ppapi
2223 } // namespace webkit 2433 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698