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

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

Issue 10827280: Add PPAPI decryptor implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed NeedKey, addressed all comments (excluding one of dmichael's). 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 an invalid PP_Resource with an ID
300 // of 0 on failure.
301 PP_Resource MakeBufferResource(PP_Instance instance,
302 const base::StringPiece& 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 memcpy(mapper.data(), data.data(), data.size());
316
317 return resource.get();
318 }
319
297 } // namespace 320 } // namespace
298 321
299 // static 322 // static
300 PluginInstance* PluginInstance::Create(PluginDelegate* delegate, 323 PluginInstance* PluginInstance::Create(PluginDelegate* delegate,
301 PluginModule* module) { 324 PluginModule* module) {
302 base::Callback<const void*(const char*)> get_plugin_interface_func = 325 base::Callback<const void*(const char*)> get_plugin_interface_func =
303 base::Bind(&PluginModule::GetPluginInterface, module); 326 base::Bind(&PluginModule::GetPluginInterface, module);
304 PPP_Instance_Combined* ppp_instance_combined = 327 PPP_Instance_Combined* ppp_instance_combined =
305 PPP_Instance_Combined::Create(get_plugin_interface_func); 328 PPP_Instance_Combined::Create(get_plugin_interface_func);
306 if (!ppp_instance_combined) 329 if (!ppp_instance_combined)
307 return NULL; 330 return NULL;
308 return new PluginInstance(delegate, module, ppp_instance_combined); 331 return new PluginInstance(delegate, module, ppp_instance_combined);
309 } 332 }
310 333
311 PluginInstance::PluginInstance( 334 PluginInstance::PluginInstance(
312 PluginDelegate* delegate, 335 PluginDelegate* delegate,
313 PluginModule* module, 336 PluginModule* module,
314 ::ppapi::PPP_Instance_Combined* instance_interface) 337 ::ppapi::PPP_Instance_Combined* instance_interface)
315 : delegate_(delegate), 338 : delegate_(delegate),
316 module_(module), 339 module_(module),
317 instance_interface_(instance_interface), 340 instance_interface_(instance_interface),
318 pp_instance_(0), 341 pp_instance_(0),
319 container_(NULL), 342 container_(NULL),
320 full_frame_(false), 343 full_frame_(false),
321 sent_initial_did_change_view_(false), 344 sent_initial_did_change_view_(false),
322 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 345 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
323 has_webkit_focus_(false), 346 has_webkit_focus_(false),
324 has_content_area_focus_(false), 347 has_content_area_focus_(false),
325 find_identifier_(-1), 348 find_identifier_(-1),
349 plugin_decryption_interface_(NULL),
326 plugin_find_interface_(NULL), 350 plugin_find_interface_(NULL),
327 plugin_input_event_interface_(NULL), 351 plugin_input_event_interface_(NULL),
328 plugin_messaging_interface_(NULL), 352 plugin_messaging_interface_(NULL),
329 plugin_mouse_lock_interface_(NULL), 353 plugin_mouse_lock_interface_(NULL),
330 plugin_pdf_interface_(NULL), 354 plugin_pdf_interface_(NULL),
331 plugin_private_interface_(NULL), 355 plugin_private_interface_(NULL),
332 plugin_selection_interface_(NULL), 356 plugin_selection_interface_(NULL),
333 plugin_textinput_interface_(NULL), 357 plugin_textinput_interface_(NULL),
334 plugin_zoom_interface_(NULL), 358 plugin_zoom_interface_(NULL),
335 checked_for_plugin_input_event_interface_(false), 359 checked_for_plugin_input_event_interface_(false),
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 982
959 void PluginInstance::StopFind() { 983 void PluginInstance::StopFind() {
960 // Keep a reference on the stack. See NOTE above. 984 // Keep a reference on the stack. See NOTE above.
961 scoped_refptr<PluginInstance> ref(this); 985 scoped_refptr<PluginInstance> ref(this);
962 if (!LoadFindInterface()) 986 if (!LoadFindInterface())
963 return; 987 return;
964 find_identifier_ = -1; 988 find_identifier_ = -1;
965 plugin_find_interface_->StopFind(pp_instance()); 989 plugin_find_interface_->StopFind(pp_instance());
966 } 990 }
967 991
992 bool PluginInstance::LoadContentDecryptorInterface() {
993 if (!plugin_decryption_interface_) {
994 plugin_decryption_interface_ =
995 static_cast<const PPP_ContentDecryptor_Private*>(
996 module_->GetPluginInterface(
997 PPP_CONTENTDECRYPTOR_PRIVATE_INTERFACE));
998 }
999 return !!plugin_decryption_interface_;
1000 }
1001
968 bool PluginInstance::LoadFindInterface() { 1002 bool PluginInstance::LoadFindInterface() {
969 if (!plugin_find_interface_) { 1003 if (!plugin_find_interface_) {
970 plugin_find_interface_ = 1004 plugin_find_interface_ =
971 static_cast<const PPP_Find_Dev*>(module_->GetPluginInterface( 1005 static_cast<const PPP_Find_Dev*>(module_->GetPluginInterface(
972 PPP_FIND_DEV_INTERFACE)); 1006 PPP_FIND_DEV_INTERFACE));
973 } 1007 }
974 1008
975 return !!plugin_find_interface_; 1009 return !!plugin_find_interface_;
976 } 1010 }
977 1011
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 if (!LoadPdfInterface()) 1309 if (!LoadPdfInterface())
1276 return; 1310 return;
1277 PP_PrivatePageTransformType transform_type = 1311 PP_PrivatePageTransformType transform_type =
1278 type == WebPlugin::RotationType90Clockwise ? 1312 type == WebPlugin::RotationType90Clockwise ?
1279 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW : 1313 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW :
1280 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW; 1314 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW;
1281 plugin_pdf_interface_->Transform(pp_instance(), transform_type); 1315 plugin_pdf_interface_->Transform(pp_instance(), transform_type);
1282 // NOTE: plugin instance may have been deleted. 1316 // NOTE: plugin instance may have been deleted.
1283 } 1317 }
1284 1318
1319 bool PluginInstance::GenerateKeyRequest(const std::string& key_system,
1320 const std::string& init_data) {
1321 if (!LoadContentDecryptorInterface())
1322 return false;
1323 if (key_system.empty())
1324 return false;
1325 PP_Var init_data_array =
1326 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
1327 init_data.size(), init_data.data());
1328 return PP_ToBool(plugin_decryption_interface_->GenerateKeyRequest(
1329 pp_instance(),
1330 StringVar::StringToPPVar(key_system),
1331 init_data_array));
1332 }
1333
1334 bool PluginInstance::AddKey(const std::string& session_id,
1335 const std::string& key) {
1336 if (!LoadContentDecryptorInterface())
1337 return false;
1338 PP_Var key_array =
1339 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(key.size(),
1340 key.data());
1341 return PP_ToBool(plugin_decryption_interface_->AddKey(
1342 pp_instance(),
1343 StringVar::StringToPPVar(session_id),
1344 key_array));
1345 }
1346
1347 bool PluginInstance::CancelKeyRequest(const std::string& session_id) {
1348 if (!LoadContentDecryptorInterface())
1349 return false;
1350
1351
1352 return PP_ToBool(plugin_decryption_interface_->CancelKeyRequest(
1353 pp_instance(),
1354 StringVar::StringToPPVar(session_id)));
1355 }
1356
1357 bool PluginInstance::Decrypt(const base::StringPiece& encrypted_block,
1358 const DecryptedDataCB& callback) {
1359 if (!LoadContentDecryptorInterface())
1360 return false;
1361 ScopedPPResource encrypted_resource(MakeBufferResource(pp_instance(),
1362 encrypted_block));
1363 if (!encrypted_resource.get())
1364 return false;
1365 // TODO(tomfinegan): Store callback and ID in a map, and pass ID to decryptor.
1366 return PP_ToBool(plugin_decryption_interface_->Decrypt(pp_instance(),
1367 encrypted_resource,
1368 0));
1369 }
1370
1371 bool PluginInstance::DecryptAndDecode(const base::StringPiece& encrypted_block,
1372 const DecryptedDataCB& callback) {
1373 if (!LoadContentDecryptorInterface())
1374 return false;
1375 ScopedPPResource encrypted_resource(MakeBufferResource(pp_instance(),
1376 encrypted_block));
1377 if (!encrypted_resource.get())
1378 return false;
1379 // TODO(tomfinegan): Store callback and ID in a map, and pass ID to decryptor.
1380 return PP_ToBool(plugin_decryption_interface_->DecryptAndDecode(
1381 pp_instance(),
1382 encrypted_resource,
1383 0));
1384 }
1385
1285 bool PluginInstance::FlashIsFullscreenOrPending() { 1386 bool PluginInstance::FlashIsFullscreenOrPending() {
1286 return fullscreen_container_ != NULL; 1387 return fullscreen_container_ != NULL;
1287 } 1388 }
1288 1389
1289 bool PluginInstance::IsFullscreenOrPending() { 1390 bool PluginInstance::IsFullscreenOrPending() {
1290 return desired_fullscreen_state_; 1391 return desired_fullscreen_state_;
1291 } 1392 }
1292 1393
1293 bool PluginInstance::SetFullscreen(bool fullscreen) { 1394 bool PluginInstance::SetFullscreen(bool fullscreen) {
1294 // Keep a reference on the stack. See NOTE above. 1395 // Keep a reference on the stack. See NOTE above.
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) { 1984 PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) {
1884 std::string encoding = delegate()->GetDefaultEncoding(); 1985 std::string encoding = delegate()->GetDefaultEncoding();
1885 return StringVar::StringToPPVar(encoding); 1986 return StringVar::StringToPPVar(encoding);
1886 } 1987 }
1887 1988
1888 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) { 1989 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) {
1889 // No in-process implementation. 1990 // No in-process implementation.
1890 return PP_MakeUndefined(); 1991 return PP_MakeUndefined();
1891 } 1992 }
1892 1993
1994 void PluginInstance::NeedKey(PP_Instance instance,
1995 PP_Var key_system_var,
1996 PP_Var session_id_var,
1997 PP_Var init_data_var) {
1998 StringVar* key_system_string = StringVar::FromPPVar(key_system_var);
1999 StringVar* session_id_string = StringVar::FromPPVar(session_id_var);
2000 ArrayBufferVar* init_data_array = ArrayBufferVar::FromPPVar(init_data_var);
2001
2002 if (!key_system_string || !session_id_string || !init_data_array)
2003 return;
2004 }
2005
2006 void PluginInstance::KeyAdded(PP_Instance instance,
2007 PP_Var key_system_var,
2008 PP_Var session_id_var) {
2009 StringVar* key_system_string = StringVar::FromPPVar(key_system_var);
2010 StringVar* session_id_string = StringVar::FromPPVar(session_id_var);
2011
2012
2013 // TODO(tomfinegan): send the data to media stack.
2014 }
2015
2016 void PluginInstance::KeyMessage(PP_Instance instance,
2017 PP_Var key_system_var,
2018 PP_Var session_id_var,
2019 PP_Resource message_resource,
2020 PP_Var default_url_var) {
2021 StringVar* key_system_string = StringVar::FromPPVar(key_system_var);
2022 StringVar* session_id_string = StringVar::FromPPVar(session_id_var);
2023 StringVar* default_url_string = StringVar::FromPPVar(default_url_var);
2024
2025 std::string message;
2026 EnterResourceNoLock<PPB_Buffer_API> enter(message_resource, true);
2027 if (enter.succeeded()) {
2028 BufferAutoMapper mapper(enter.object());
2029 if (mapper.data() || mapper.size())
2030 message.assign(reinterpret_cast<char*>(mapper.data()), mapper.size());
2031 }
2032
2033
2034 // TODO(tomfinegan): send the data to media stack.
2035 }
2036
2037 void PluginInstance::KeyError(PP_Instance instance,
2038 PP_Var key_system_var,
2039 PP_Var session_id_var,
2040 int32_t media_error,
2041 int32_t system_code) {
2042 StringVar* key_system_string = StringVar::FromPPVar(key_system_var);
2043 StringVar* session_id_string = StringVar::FromPPVar(session_id_var);
2044
2045
2046 // TODO(tomfinegan): send the data to media stack.
2047 }
2048
2049 void PluginInstance::DeliverBlock(PP_Instance instance,
2050 PP_Resource decrypted_block,
2051 int32_t request_id) {
2052 // TODO(xhwang): Pass the decrypted block back to media stack.
2053 std::string decrypted_string;
2054 EnterResourceNoLock<PPB_Buffer_API> enter(decrypted_block, true);
2055 if (enter.succeeded()) {
2056 BufferAutoMapper mapper(enter.object());
2057 if (mapper.data() && mapper.size()) {
2058 decrypted_string.assign(reinterpret_cast<char*>(mapper.data()),
2059 mapper.size());
2060 }
2061 }
2062
2063 }
2064
2065 void PluginInstance::DeliverFrame(PP_Instance instance,
2066 PP_Resource decrypted_frame,
2067 int32_t request_id) {
2068 // TODO(tomfinegan): To be implemented after completion of v0.1 of the
2069 // EME/CDM work.
2070 }
2071
2072 void PluginInstance::DeliverSamples(PP_Instance instance,
2073 PP_Resource decrypted_samples,
2074 int32_t request_id) {
2075 // TODO(tomfinegan): To be implemented after completion of v0.1 of the
2076 // EME/CDM work.
2077 }
2078
2079
1893 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, 2080 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance,
1894 int32_t total, 2081 int32_t total,
1895 PP_Bool final_result) { 2082 PP_Bool final_result) {
1896 DCHECK_NE(find_identifier_, -1); 2083 DCHECK_NE(find_identifier_, -1);
1897 delegate_->NumberOfFindResultsChanged(find_identifier_, total, 2084 delegate_->NumberOfFindResultsChanged(find_identifier_, total,
1898 PP_ToBool(final_result)); 2085 PP_ToBool(final_result));
1899 } 2086 }
1900 2087
1901 void PluginInstance::SelectedFindResultChanged(PP_Instance instance, 2088 void PluginInstance::SelectedFindResultChanged(PP_Instance instance,
1902 int32_t index) { 2089 int32_t index) {
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
2258 screen_size_for_fullscreen_ = gfx::Size(); 2445 screen_size_for_fullscreen_ = gfx::Size();
2259 WebElement element = container_->element(); 2446 WebElement element = container_->element();
2260 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2447 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2261 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2448 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2262 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2449 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2263 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2450 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2264 } 2451 }
2265 2452
2266 } // namespace ppapi 2453 } // namespace ppapi
2267 } // namespace webkit 2454 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698