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

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: Perhaps I've gone too far :) 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
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())
fgalligan1 2012/07/24 04:33:41 nit: data.empty()
Tom Finegan 2012/07/25 02:00:07 Done.
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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) { 1975 PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) {
1846 std::string encoding = delegate()->GetDefaultEncoding(); 1976 std::string encoding = delegate()->GetDefaultEncoding();
1847 return StringVar::StringToPPVar(encoding); 1977 return StringVar::StringToPPVar(encoding);
1848 } 1978 }
1849 1979
1850 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) { 1980 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) {
1851 // No in-process implementation. 1981 // No in-process implementation.
1852 return PP_MakeUndefined(); 1982 return PP_MakeUndefined();
1853 } 1983 }
1854 1984
1985 void PluginInstance::NeedKey(PP_Instance instance,
1986 PP_Var key_system,
1987 PP_Var session_id,
1988 PP_Resource init_data) {
1989 }
1990
1991 void PluginInstance::KeyAdded(PP_Instance instance,
1992 PP_Var key_system,
1993 PP_Var session_id) {
1994 }
1995
1996 void PluginInstance::KeyMessage(PP_Instance instance,
1997 PP_Var key_system_var,
1998 PP_Var session_id_var,
1999 PP_Resource message_resource,
2000 PP_Var default_url_var) {
2001 // Extract the std::strings from the PP_Vars.
2002 StringVar* key_system_string = StringVar::FromPPVar(key_system_var);
2003 StringVar* session_id_string = StringVar::FromPPVar(session_id_var);
2004 StringVar* default_url_string = StringVar::FromPPVar(default_url_var);
2005
2006 if (!key_system_string || !session_id_string || !default_url_string) {
2007 // TODO(tomfinegan): KeyError here?
2008 return;
2009 }
2010
2011 EnterResourceNoLock<PPB_Buffer_API> enter(message_resource, true);
2012 if (enter.failed()) {
2013 // TODO(tomfinegan): KeyError here?
2014 NOTREACHED();
2015 return;
2016 }
2017
2018 BufferAutoMapper mapper(enter.object());
2019 if (!mapper.data() || !mapper.size()) {
2020 // TODO(tomfinegan): KeyError here?
2021 NOTREACHED();
2022 return;
2023 }
2024
2025 std::string message(reinterpret_cast<char*>(mapper.data()), mapper.size());
2026 if (message.empty()) {
2027 // TODO(tomfinegan): KeyError here?
2028 NOTREACHED();
2029 return;
2030 }
2031
2032 // Release the PP_Vars.
2033 HostGlobals::Get()->GetVarTracker()->ReleaseVar(key_system_var);
2034 HostGlobals::Get()->GetVarTracker()->ReleaseVar(session_id_var);
2035 HostGlobals::Get()->GetVarTracker()->ReleaseVar(default_url_var);
2036
2037 // Release the PP_Resource.
2038 // TODO(tomfinegan): Confirm that the buffer is freed.
2039 HostGlobals::Get()->GetResourceTracker()->ReleaseResource(message_resource);
2040 }
2041
2042 void PluginInstance::KeyError(PP_Instance instance,
2043 PP_Var key_system,
2044 PP_Var session_id,
2045 uint16_t media_error,
2046 uint16_t system_error) {
2047 }
2048
2049 void PluginInstance::DeliverBlock(PP_Instance instance,
2050 PP_Resource decrypted_block,
2051 PP_CompletionCallback callback) {
2052 }
2053
2054 void PluginInstance::DeliverFrame(PP_Instance instance,
2055 PP_Resource decrypted_frame,
2056 PP_CompletionCallback callback) {
2057 }
2058
2059 void PluginInstance::DeliverSamples(PP_Instance instance,
2060 PP_Resource decrypted_samples,
2061 PP_CompletionCallback callback) {
2062 }
2063
2064
1855 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, 2065 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance,
1856 int32_t total, 2066 int32_t total,
1857 PP_Bool final_result) { 2067 PP_Bool final_result) {
1858 DCHECK_NE(find_identifier_, -1); 2068 DCHECK_NE(find_identifier_, -1);
1859 delegate_->NumberOfFindResultsChanged(find_identifier_, total, 2069 delegate_->NumberOfFindResultsChanged(find_identifier_, total,
1860 PP_ToBool(final_result)); 2070 PP_ToBool(final_result));
1861 } 2071 }
1862 2072
1863 void PluginInstance::SelectedFindResultChanged(PP_Instance instance, 2073 void PluginInstance::SelectedFindResultChanged(PP_Instance instance,
1864 int32_t index) { 2074 int32_t index) {
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
2212 screen_size_for_fullscreen_ = gfx::Size(); 2422 screen_size_for_fullscreen_ = gfx::Size();
2213 WebElement element = container_->element(); 2423 WebElement element = container_->element();
2214 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2424 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2215 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2425 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2216 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2426 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2217 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2427 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2218 } 2428 }
2219 2429
2220 } // namespace ppapi 2430 } // namespace ppapi
2221 } // namespace webkit 2431 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698