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

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: Changes in response to dmichael's comments/xhwang's testing. 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 "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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 using ppapi::PPP_Instance_Combined; 107 using ppapi::PPP_Instance_Combined;
108 using ppapi::ScopedPPResource; 108 using ppapi::ScopedPPResource;
109 using ppapi::StringVar; 109 using ppapi::StringVar;
110 using ppapi::TrackedCallback; 110 using ppapi::TrackedCallback;
111 using ppapi::thunk::EnterResourceNoLock; 111 using ppapi::thunk::EnterResourceNoLock;
112 using ppapi::thunk::PPB_Buffer_API; 112 using ppapi::thunk::PPB_Buffer_API;
113 using ppapi::thunk::PPB_Graphics2D_API; 113 using ppapi::thunk::PPB_Graphics2D_API;
114 using ppapi::thunk::PPB_Graphics3D_API; 114 using ppapi::thunk::PPB_Graphics3D_API;
115 using ppapi::thunk::PPB_ImageData_API; 115 using ppapi::thunk::PPB_ImageData_API;
116 using ppapi::Var; 116 using ppapi::Var;
117 using ppapi::ArrayBufferVar;
117 using ppapi::ViewData; 118 using ppapi::ViewData;
118 using WebKit::WebBindings; 119 using WebKit::WebBindings;
119 using WebKit::WebCanvas; 120 using WebKit::WebCanvas;
120 using WebKit::WebCursorInfo; 121 using WebKit::WebCursorInfo;
121 using WebKit::WebDocument; 122 using WebKit::WebDocument;
122 using WebKit::WebElement; 123 using WebKit::WebElement;
123 using WebKit::WebFrame; 124 using WebKit::WebFrame;
124 using WebKit::WebInputEvent; 125 using WebKit::WebInputEvent;
125 using WebKit::WebPlugin; 126 using WebKit::WebPlugin;
126 using WebKit::WebPluginContainer; 127 using WebKit::WebPluginContainer;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // returned vector are only guaranteed valid so long as the vector of strings 288 // returned vector are only guaranteed valid so long as the vector of strings
288 // is not modified. 289 // is not modified.
289 scoped_array<const char*> StringVectorToArgArray( 290 scoped_array<const char*> StringVectorToArgArray(
290 const std::vector<std::string>& vector) { 291 const std::vector<std::string>& vector) {
291 scoped_array<const char*> array(new const char*[vector.size()]); 292 scoped_array<const char*> array(new const char*[vector.size()]);
292 for (size_t i = 0; i < vector.size(); ++i) 293 for (size_t i = 0; i < vector.size(); ++i)
293 array[i] = vector[i].c_str(); 294 array[i] = vector[i].c_str();
294 return array.Pass(); 295 return array.Pass();
295 } 296 }
296 297
298 // Creates a PP_Resource containing a PPB_Buffer_Impl, copies |data| into the
299 // buffer resource, and returns it. Returns a PP_Resource equal to 0 on
300 // failure.
301 PP_Resource MakeBufferResource(PP_Instance instance,
302 const std::string& data) {
303 if (data.empty())
304 return 0;
305
306 ScopedPPResource resource(PPB_Buffer_Impl::Create(instance, data.size()));
307 if (!resource.get())
308 return 0;
309
310 EnterResourceNoLock<PPB_Buffer_API> enter(resource, true);
311 if (enter.failed())
312 return 0;
313
314 BufferAutoMapper mapper(enter.object());
315 if (!mapper.data() || mapper.size() < data.size())
316 return 0;
317 memcpy(mapper.data(), data.data(), data.size());
318
319 // Add the resource to the tracker...
320 // TODO(tomfinegan): wild guess/no idea if this is right.
321 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource.get());
322
323 return resource.Release();
324 }
325
297 } // namespace 326 } // namespace
298 327
299 // static 328 // static
300 PluginInstance* PluginInstance::Create(PluginDelegate* delegate, 329 PluginInstance* PluginInstance::Create(PluginDelegate* delegate,
301 PluginModule* module) { 330 PluginModule* module) {
302 base::Callback<const void*(const char*)> get_plugin_interface_func = 331 base::Callback<const void*(const char*)> get_plugin_interface_func =
303 base::Bind(&PluginModule::GetPluginInterface, module); 332 base::Bind(&PluginModule::GetPluginInterface, module);
304 PPP_Instance_Combined* ppp_instance_combined = 333 PPP_Instance_Combined* ppp_instance_combined =
305 PPP_Instance_Combined::Create(get_plugin_interface_func); 334 PPP_Instance_Combined::Create(get_plugin_interface_func);
306 if (!ppp_instance_combined) 335 if (!ppp_instance_combined)
307 return NULL; 336 return NULL;
308 return new PluginInstance(delegate, module, ppp_instance_combined); 337 return new PluginInstance(delegate, module, ppp_instance_combined);
309 } 338 }
310 339
311 PluginInstance::PluginInstance( 340 PluginInstance::PluginInstance(
312 PluginDelegate* delegate, 341 PluginDelegate* delegate,
313 PluginModule* module, 342 PluginModule* module,
314 ::ppapi::PPP_Instance_Combined* instance_interface) 343 ::ppapi::PPP_Instance_Combined* instance_interface)
315 : delegate_(delegate), 344 : delegate_(delegate),
316 module_(module), 345 module_(module),
317 instance_interface_(instance_interface), 346 instance_interface_(instance_interface),
318 pp_instance_(0), 347 pp_instance_(0),
319 container_(NULL), 348 container_(NULL),
320 full_frame_(false), 349 full_frame_(false),
321 sent_initial_did_change_view_(false), 350 sent_initial_did_change_view_(false),
322 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 351 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
323 has_webkit_focus_(false), 352 has_webkit_focus_(false),
324 has_content_area_focus_(false), 353 has_content_area_focus_(false),
325 find_identifier_(-1), 354 find_identifier_(-1),
355 plugin_decryption_interface_(NULL),
326 plugin_find_interface_(NULL), 356 plugin_find_interface_(NULL),
327 plugin_input_event_interface_(NULL), 357 plugin_input_event_interface_(NULL),
328 plugin_messaging_interface_(NULL), 358 plugin_messaging_interface_(NULL),
329 plugin_mouse_lock_interface_(NULL), 359 plugin_mouse_lock_interface_(NULL),
330 plugin_pdf_interface_(NULL), 360 plugin_pdf_interface_(NULL),
331 plugin_private_interface_(NULL), 361 plugin_private_interface_(NULL),
332 plugin_selection_interface_(NULL), 362 plugin_selection_interface_(NULL),
333 plugin_textinput_interface_(NULL), 363 plugin_textinput_interface_(NULL),
334 plugin_zoom_interface_(NULL), 364 plugin_zoom_interface_(NULL),
335 checked_for_plugin_input_event_interface_(false), 365 checked_for_plugin_input_event_interface_(false),
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 982
953 void PluginInstance::StopFind() { 983 void PluginInstance::StopFind() {
954 // Keep a reference on the stack. See NOTE above. 984 // Keep a reference on the stack. See NOTE above.
955 scoped_refptr<PluginInstance> ref(this); 985 scoped_refptr<PluginInstance> ref(this);
956 if (!LoadFindInterface()) 986 if (!LoadFindInterface())
957 return; 987 return;
958 find_identifier_ = -1; 988 find_identifier_ = -1;
959 plugin_find_interface_->StopFind(pp_instance()); 989 plugin_find_interface_->StopFind(pp_instance());
960 } 990 }
961 991
992 bool PluginInstance::LoadContentDecryptionModuleInterface() {
993 if (!plugin_decryption_interface_) {
994 plugin_decryption_interface_ =
995 static_cast<const PPP_ContentDecryptor_Dev*>(
996 module_->GetPluginInterface(
997 PPP_CONTENTDECRYPTOR_DEV_INTERFACE));
998 }
999 return !!plugin_decryption_interface_;
1000 }
1001
962 bool PluginInstance::LoadFindInterface() { 1002 bool PluginInstance::LoadFindInterface() {
963 if (!plugin_find_interface_) { 1003 if (!plugin_find_interface_) {
964 plugin_find_interface_ = 1004 plugin_find_interface_ =
965 static_cast<const PPP_Find_Dev*>(module_->GetPluginInterface( 1005 static_cast<const PPP_Find_Dev*>(module_->GetPluginInterface(
966 PPP_FIND_DEV_INTERFACE)); 1006 PPP_FIND_DEV_INTERFACE));
967 } 1007 }
968 1008
969 return !!plugin_find_interface_; 1009 return !!plugin_find_interface_;
970 } 1010 }
971 1011
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 if (!LoadPdfInterface()) 1309 if (!LoadPdfInterface())
1270 return; 1310 return;
1271 PP_PrivatePageTransformType transform_type = 1311 PP_PrivatePageTransformType transform_type =
1272 type == WebPlugin::RotationType90Clockwise ? 1312 type == WebPlugin::RotationType90Clockwise ?
1273 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW : 1313 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW :
1274 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW; 1314 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW;
1275 plugin_pdf_interface_->Transform(pp_instance(), transform_type); 1315 plugin_pdf_interface_->Transform(pp_instance(), transform_type);
1276 // NOTE: plugin instance may have been deleted. 1316 // NOTE: plugin instance may have been deleted.
1277 } 1317 }
1278 1318
1319 bool PluginInstance::GenerateKeyRequest(const std::string& key_system,
1320 const std::string& init_data) {
1321 if (!LoadContentDecryptionModuleInterface())
1322 return false;
1323
1324 if (key_system.empty())
1325 return false;
1326
1327 PP_Resource init_data_resource = 0;
1328 if (init_data.size()) {
1329 ScopedPPResource local_init_data(ScopedPPResource::PassRef(),
1330 MakeBufferResource(pp_instance(),
1331 init_data));
1332
1333 if (!local_init_data.get())
1334 return false;
1335 init_data_resource = local_init_data.Release();
1336 }
1337
1338 PP_Var init_data_array =
1339 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
1340 init_data.size(), init_data.data());
1341
1342 return PP_ToBool(plugin_decryption_interface_->GenerateKeyRequest(
1343 pp_instance(),
1344 StringVar::StringToPPVar(key_system),
1345 init_data_array));
1346 }
1347
1348 bool PluginInstance::AddKey(const std::string& session_id,
1349 const std::string& key) {
1350 if (!LoadContentDecryptionModuleInterface())
1351 return false;
1352
1353 StringVar session_id_var(session_id);
1354 if (session_id_var.value().size() < session_id.size())
1355 return false;
1356
1357 PP_Var key_array =
1358 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(key.size(),
1359 key.data());
1360 return PP_ToBool(plugin_decryption_interface_->AddKey(
1361 pp_instance(),
1362 session_id_var.GetPPVar(),
1363 key_array));
1364 }
1365
1366 bool PluginInstance::CancelKeyRequest(const std::string& session_id) {
1367 if (!LoadContentDecryptionModuleInterface())
1368 return false;
1369 StringVar session_id_var(session_id);
1370 if (session_id_var.value().size() < session_id.size())
1371 return false;
1372 return PP_ToBool(plugin_decryption_interface_->CancelKeyRequest(
1373 pp_instance(),
1374 session_id_var.GetPPVar()));
1375 }
1376
1377 bool PluginInstance::Decrypt(const std::string& encrypted_block,
xhwang 2012/08/01 18:55:38 Can we use base::StringPiece here and below, just
Tom Finegan 2012/08/02 01:12:04 Done.
1378 const CDMStatusCB& callback) {
1379 if (!LoadContentDecryptionModuleInterface())
1380 return false;
1381 ScopedPPResource encrypted_resource(ScopedPPResource::PassRef(),
1382 MakeBufferResource(pp_instance(),
1383 encrypted_block));
1384 if (!encrypted_resource.get())
1385 return false;
1386 // TODO(tomfinegan): wrap callback in PP_CompletionCallback and pass it to
1387 // the plugin.
1388 PP_CompletionCallback pp_callback = {NULL, NULL, 0};
1389 return PP_ToBool(plugin_decryption_interface_->Decrypt(pp_instance(),
1390 encrypted_resource,
1391 pp_callback));
1392 }
1393
1394 bool PluginInstance::DecryptAndDecode(const std::string& encrypted_block,
1395 const CDMStatusCB& callback) {
1396 if (!LoadContentDecryptionModuleInterface())
1397 return false;
1398 ScopedPPResource encrypted_resource(ScopedPPResource::PassRef(),
1399 MakeBufferResource(pp_instance(),
1400 encrypted_block));
1401 if (!encrypted_resource.get())
1402 return false;
1403 // TODO(tomfinegan): wrap callback in PP_CompletionCallback and pass it to
1404 // the plugin.
1405 PP_CompletionCallback pp_callback = {NULL, NULL, 0};
1406 return PP_ToBool(plugin_decryption_interface_->DecryptAndDecode(
1407 pp_instance(),
1408 encrypted_resource,
1409 pp_callback));
1410 }
1411
1279 bool PluginInstance::FlashIsFullscreenOrPending() { 1412 bool PluginInstance::FlashIsFullscreenOrPending() {
1280 return fullscreen_container_ != NULL; 1413 return fullscreen_container_ != NULL;
1281 } 1414 }
1282 1415
1283 bool PluginInstance::IsFullscreenOrPending() { 1416 bool PluginInstance::IsFullscreenOrPending() {
1284 return desired_fullscreen_state_; 1417 return desired_fullscreen_state_;
1285 } 1418 }
1286 1419
1287 bool PluginInstance::SetFullscreen(bool fullscreen) { 1420 bool PluginInstance::SetFullscreen(bool fullscreen) {
1288 // Keep a reference on the stack. See NOTE above. 1421 // Keep a reference on the stack. See NOTE above.
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
1872 PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) { 2005 PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) {
1873 std::string encoding = delegate()->GetDefaultEncoding(); 2006 std::string encoding = delegate()->GetDefaultEncoding();
1874 return StringVar::StringToPPVar(encoding); 2007 return StringVar::StringToPPVar(encoding);
1875 } 2008 }
1876 2009
1877 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) { 2010 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) {
1878 // No in-process implementation. 2011 // No in-process implementation.
1879 return PP_MakeUndefined(); 2012 return PP_MakeUndefined();
1880 } 2013 }
1881 2014
2015 void PluginInstance::NeedKey(PP_Instance instance,
2016 PP_Var key_system_var,
2017 PP_Var session_id_var,
2018 PP_Var init_data_var) {
2019 StringVar* key_system_string = StringVar::FromPPVar(key_system_var);
2020 StringVar* session_id_string = StringVar::FromPPVar(session_id_var);
2021 StringVar* init_data_string = StringVar::FromPPVar(init_data_var);
2022
2023 // TODO(tomfinegan): Where does the call to this method come from? Or, where
2024 // does it go for handling. I need to read more of the EME proposed spec, but
2025 // this is what I understand so far:
2026 // - JS app sends needkey before anything else when it knows that encrypted
2027 // data is going to be streamed to the user agent.
2028 // - OR is the media stack going to see something in the stream that looks
2029 // like init data, and then send NeedKey. If this is the case NeedKey
2030 // probably needs to move to the PPP interface.
2031
2032 HostGlobals::Get()->GetVarTracker()->ReleaseVar(key_system_var);
2033 HostGlobals::Get()->GetVarTracker()->ReleaseVar(session_id_var);
2034 HostGlobals::Get()->GetVarTracker()->ReleaseVar(init_data_var);
2035 }
2036
2037 void PluginInstance::KeyAdded(PP_Instance instance,
2038 PP_Var key_system,
2039 PP_Var session_id) {
2040 }
2041
2042 void PluginInstance::KeyMessage(PP_Instance instance,
2043 PP_Var key_system_var,
2044 PP_Var session_id_var,
2045 PP_Resource message_resource,
2046 PP_Var default_url_var) {
2047 StringVar* key_system_string = StringVar::FromPPVar(key_system_var);
2048 StringVar* session_id_string = StringVar::FromPPVar(session_id_var);
2049 StringVar* default_url_string = StringVar::FromPPVar(default_url_var);
2050
2051 if (!key_system_string || !session_id_string || !default_url_string) {
2052 // TODO(tomfinegan): KeyError here?
2053 return;
2054 }
2055
2056 EnterResourceNoLock<PPB_Buffer_API> enter(message_resource, true);
2057 if (enter.failed()) {
2058 // TODO(tomfinegan): KeyError here?
2059 NOTREACHED();
2060 return;
2061 }
2062
2063 BufferAutoMapper mapper(enter.object());
2064 if (!mapper.data() || !mapper.size()) {
2065 // TODO(tomfinegan): KeyError here?
2066 NOTREACHED();
2067 return;
2068 }
2069
2070 std::string message(reinterpret_cast<char*>(mapper.data()), mapper.size());
2071 if (message.empty()) {
2072 // TODO(tomfinegan): KeyError here?
2073 NOTREACHED();
2074 return;
2075 }
2076
2077 // Release the PP_Vars.
2078 HostGlobals::Get()->GetVarTracker()->ReleaseVar(key_system_var);
2079 HostGlobals::Get()->GetVarTracker()->ReleaseVar(session_id_var);
2080 HostGlobals::Get()->GetVarTracker()->ReleaseVar(default_url_var);
2081
2082 // Release the PP_Resource.
2083 // TODO(tomfinegan): Confirm that the buffer is freed.
2084 HostGlobals::Get()->GetResourceTracker()->ReleaseResource(message_resource);
2085 }
2086
2087 void PluginInstance::KeyError(PP_Instance instance,
2088 PP_Var key_system_var,
2089 PP_Var session_id_var,
2090 int32_t media_error,
2091 int32_t system_error) {
2092 StringVar* key_system_string = StringVar::FromPPVar(key_system_var);
2093 StringVar* session_id_string = StringVar::FromPPVar(session_id_var);
2094
2095 HostGlobals::Get()->GetVarTracker()->ReleaseVar(key_system_var);
2096 HostGlobals::Get()->GetVarTracker()->ReleaseVar(session_id_var);
2097 }
2098
2099 void PluginInstance::DeliverBlock(PP_Instance instance,
2100 PP_Resource decrypted_block,
2101 PP_CompletionCallback callback) {
2102 // TODO(tomfinegan): Determine where |decrypted_block| goes, and what
2103 // callback actually is (callback will likely be the result of some
2104 // base::Bind usage in the media stack. Hash this out with xhwang.
2105 //
2106 HostGlobals::Get()->GetResourceTracker()->ReleaseResource(decrypted_block);
2107 }
2108
2109 void PluginInstance::DeliverFrame(PP_Instance instance,
2110 PP_Resource decrypted_frame,
2111 PP_CompletionCallback callback) {
2112 // Not implemented in v0.1 of the EME/CDM work.
2113 }
2114
2115 void PluginInstance::DeliverSamples(PP_Instance instance,
2116 PP_Resource decrypted_samples,
2117 PP_CompletionCallback callback) {
2118 // Not implemented in v0.1 of the EME/CDM work.
2119 }
2120
2121
1882 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, 2122 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance,
1883 int32_t total, 2123 int32_t total,
1884 PP_Bool final_result) { 2124 PP_Bool final_result) {
1885 DCHECK_NE(find_identifier_, -1); 2125 DCHECK_NE(find_identifier_, -1);
1886 delegate_->NumberOfFindResultsChanged(find_identifier_, total, 2126 delegate_->NumberOfFindResultsChanged(find_identifier_, total,
1887 PP_ToBool(final_result)); 2127 PP_ToBool(final_result));
1888 } 2128 }
1889 2129
1890 void PluginInstance::SelectedFindResultChanged(PP_Instance instance, 2130 void PluginInstance::SelectedFindResultChanged(PP_Instance instance,
1891 int32_t index) { 2131 int32_t index) {
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 screen_size_for_fullscreen_ = gfx::Size(); 2483 screen_size_for_fullscreen_ = gfx::Size();
2244 WebElement element = container_->element(); 2484 WebElement element = container_->element();
2245 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2485 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2246 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2486 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2247 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2487 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2248 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2488 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2249 } 2489 }
2250 2490
2251 } // namespace ppapi 2491 } // namespace ppapi
2252 } // namespace webkit 2492 } // namespace webkit
OLDNEW
« webkit/plugins/ppapi/ppapi_plugin_instance.h ('K') | « 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