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 | |
dmichael (off chromium)
2012/08/15 19:01:00
note that the reterned reference count is 1?
dmichael (off chromium)
2012/08/16 17:02:28
Maybe note that the returned Buffer resource has a
Tom Finegan
2012/08/16 18:10:58
Done; sorry, missed this one too.
| |
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 Loading... | |
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 Loading... | |
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 LOG(ERROR) << "PluginInstance::CancelKeyRequest sending...\n"; | |
1352 | |
1353 return PP_ToBool(plugin_decryption_interface_->CancelKeyRequest( | |
1354 pp_instance(), | |
1355 StringVar::StringToPPVar(session_id))); | |
1356 } | |
1357 | |
1358 bool PluginInstance::Decrypt(const base::StringPiece& encrypted_block, | |
1359 const DecryptedDataCB& callback) { | |
1360 if (!LoadContentDecryptorInterface()) | |
1361 return false; | |
1362 ScopedPPResource encrypted_resource(MakeBufferResource(pp_instance(), | |
1363 encrypted_block)); | |
1364 if (!encrypted_resource.get()) | |
1365 return false; | |
1366 // TODO(tomfinegan): Store callback and ID in a map, and pass ID to decryptor. | |
1367 return PP_ToBool(plugin_decryption_interface_->Decrypt(pp_instance(), | |
1368 encrypted_resource, | |
1369 0)); | |
1370 } | |
1371 | |
1372 bool PluginInstance::DecryptAndDecode(const base::StringPiece& encrypted_block, | |
1373 const DecryptedDataCB& callback) { | |
1374 if (!LoadContentDecryptorInterface()) | |
1375 return false; | |
1376 ScopedPPResource encrypted_resource(ScopedPPResource::PassRef(), | |
dmichael (off chromium)
2012/08/15 19:01:00
I don't think you want the PassRef version here, d
Tom Finegan
2012/08/16 18:10:58
Done.
| |
1377 MakeBufferResource(pp_instance(), | |
1378 encrypted_block)); | |
1379 if (!encrypted_resource.get()) | |
1380 return false; | |
1381 // TODO(tomfinegan): Store callback and ID in a map, and pass ID to decryptor. | |
1382 return PP_ToBool(plugin_decryption_interface_->DecryptAndDecode( | |
1383 pp_instance(), | |
1384 encrypted_resource, | |
1385 0)); | |
1386 } | |
1387 | |
1285 bool PluginInstance::FlashIsFullscreenOrPending() { | 1388 bool PluginInstance::FlashIsFullscreenOrPending() { |
1286 return fullscreen_container_ != NULL; | 1389 return fullscreen_container_ != NULL; |
1287 } | 1390 } |
1288 | 1391 |
1289 bool PluginInstance::IsFullscreenOrPending() { | 1392 bool PluginInstance::IsFullscreenOrPending() { |
1290 return desired_fullscreen_state_; | 1393 return desired_fullscreen_state_; |
1291 } | 1394 } |
1292 | 1395 |
1293 bool PluginInstance::SetFullscreen(bool fullscreen) { | 1396 bool PluginInstance::SetFullscreen(bool fullscreen) { |
1294 // Keep a reference on the stack. See NOTE above. | 1397 // 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) { | 1986 PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) { |
1884 std::string encoding = delegate()->GetDefaultEncoding(); | 1987 std::string encoding = delegate()->GetDefaultEncoding(); |
1885 return StringVar::StringToPPVar(encoding); | 1988 return StringVar::StringToPPVar(encoding); |
1886 } | 1989 } |
1887 | 1990 |
1888 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) { | 1991 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) { |
1889 // No in-process implementation. | 1992 // No in-process implementation. |
1890 return PP_MakeUndefined(); | 1993 return PP_MakeUndefined(); |
1891 } | 1994 } |
1892 | 1995 |
1996 void PluginInstance::NeedKey(PP_Instance instance, | |
1997 PP_Var key_system_var, | |
1998 PP_Var session_id_var, | |
1999 PP_Var init_data_var) { | |
2000 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | |
2001 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | |
2002 StringVar* init_data_string = StringVar::FromPPVar(init_data_var); | |
2003 | |
2004 if (!key_system_string || !session_id_string || !init_data_string) | |
2005 return; | |
2006 } | |
2007 | |
2008 void PluginInstance::KeyAdded(PP_Instance instance, | |
2009 PP_Var key_system_var, | |
2010 PP_Var session_id_var) { | |
2011 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | |
2012 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | |
2013 | |
2014 if (!key_system_string || !session_id_string) { | |
2015 // TODO(tomfinegan): KeyError here? | |
2016 return; | |
2017 } | |
2018 | |
2019 // TODO(tomfinegan): send the data to media stack. | |
2020 } | |
2021 | |
2022 void PluginInstance::KeyMessage(PP_Instance instance, | |
2023 PP_Var key_system_var, | |
2024 PP_Var session_id_var, | |
2025 PP_Resource message_resource, | |
2026 PP_Var default_url_var) { | |
2027 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | |
2028 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | |
2029 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); | |
2030 | |
2031 if (!key_system_string || !session_id_string || !default_url_string) { | |
2032 // TODO(tomfinegan): KeyError here? | |
2033 return; | |
2034 } | |
2035 | |
2036 EnterResourceNoLock<PPB_Buffer_API> enter(message_resource, true); | |
2037 if (enter.failed()) { | |
2038 // TODO(tomfinegan): KeyError here? | |
2039 return; | |
2040 } | |
2041 | |
2042 BufferAutoMapper mapper(enter.object()); | |
2043 if (!mapper.data() || !mapper.size()) { | |
2044 // TODO(tomfinegan): KeyError here? | |
2045 return; | |
2046 } | |
2047 | |
2048 std::string message(reinterpret_cast<char*>(mapper.data()), mapper.size()); | |
2049 if (message.empty()) { | |
2050 // TODO(tomfinegan): KeyError here? | |
2051 return; | |
2052 } | |
2053 | |
2054 // TODO(tomfinegan): send the data to media stack. | |
2055 } | |
2056 | |
2057 void PluginInstance::KeyError(PP_Instance instance, | |
2058 PP_Var key_system_var, | |
2059 PP_Var session_id_var, | |
2060 int32_t media_error, | |
2061 int32_t system_code) { | |
2062 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | |
2063 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | |
2064 | |
2065 if (!key_system_string || !session_id_string) | |
2066 return; | |
2067 | |
2068 // TODO(tomfinegan): send the data to media stack. | |
2069 } | |
2070 | |
2071 void PluginInstance::DeliverBlock(PP_Instance instance, | |
2072 PP_Resource decrypted_block, | |
2073 int32_t request_id) { | |
2074 // TODO(tomfinegan): Determine where |decrypted_block| goes, and what | |
2075 // callback actually is (callback will likely be the result of some | |
2076 // base::Bind usage in the media stack. Hash this out with xhwang. | |
2077 // | |
2078 | |
2079 EnterResourceNoLock<PPB_Buffer_API> enter(decrypted_block, true); | |
2080 if (enter.failed()) { | |
2081 // TODO(tomfinegan): KeyError here? | |
2082 return; | |
2083 } | |
2084 | |
2085 BufferAutoMapper mapper(enter.object()); | |
2086 if (!mapper.data() || !mapper.size()) { | |
2087 // TODO(tomfinegan): KeyError here? | |
2088 return; | |
2089 } | |
2090 | |
2091 } | |
2092 | |
2093 void PluginInstance::DeliverFrame(PP_Instance instance, | |
2094 PP_Resource decrypted_frame, | |
2095 int32_t request_id) { | |
2096 // TODO(tomfinegan): To be implemented after completion of v0.1 of the | |
2097 // EME/CDM work. | |
2098 } | |
2099 | |
2100 void PluginInstance::DeliverSamples(PP_Instance instance, | |
2101 PP_Resource decrypted_samples, | |
2102 int32_t request_id) { | |
2103 // TODO(tomfinegan): To be implemented after completion of v0.1 of the | |
2104 // EME/CDM work. | |
2105 } | |
2106 | |
2107 | |
1893 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, | 2108 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, |
1894 int32_t total, | 2109 int32_t total, |
1895 PP_Bool final_result) { | 2110 PP_Bool final_result) { |
1896 DCHECK_NE(find_identifier_, -1); | 2111 DCHECK_NE(find_identifier_, -1); |
1897 delegate_->NumberOfFindResultsChanged(find_identifier_, total, | 2112 delegate_->NumberOfFindResultsChanged(find_identifier_, total, |
1898 PP_ToBool(final_result)); | 2113 PP_ToBool(final_result)); |
1899 } | 2114 } |
1900 | 2115 |
1901 void PluginInstance::SelectedFindResultChanged(PP_Instance instance, | 2116 void PluginInstance::SelectedFindResultChanged(PP_Instance instance, |
1902 int32_t index) { | 2117 int32_t index) { |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2258 screen_size_for_fullscreen_ = gfx::Size(); | 2473 screen_size_for_fullscreen_ = gfx::Size(); |
2259 WebElement element = container_->element(); | 2474 WebElement element = container_->element(); |
2260 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2475 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
2261 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2476 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
2262 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2477 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
2263 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2478 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
2264 } | 2479 } |
2265 | 2480 |
2266 } // namespace ppapi | 2481 } // namespace ppapi |
2267 } // namespace webkit | 2482 } // namespace webkit |
OLD | NEW |