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