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; | |
xhwang
2012/08/15 00:27:57
It looks like these are alphabetically ordered, w/
Tom Finegan
2012/08/16 03:10:48
Yeah, wasn't sure what to do-- ArrayBufferVar next
| |
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 PP_Resource equal to 0 on | |
xhwang
2012/08/15 00:27:57
Returns an invalid PP_Resource (with a 0 ID) on fa
Tom Finegan
2012/08/16 03:10:48
Done.
| |
300 // 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 StringVar session_id_var(session_id); | |
1339 PP_Var key_array = | |
1340 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(key.size(), | |
1341 key.data()); | |
1342 return PP_ToBool(plugin_decryption_interface_->AddKey( | |
1343 pp_instance(), | |
1344 session_id_var.GetPPVar(), | |
1345 key_array)); | |
1346 } | |
1347 | |
1348 bool PluginInstance::CancelKeyRequest(const std::string& session_id) { | |
1349 if (!LoadContentDecryptorInterface()) | |
1350 return false; | |
1351 StringVar session_id_var(session_id); | |
1352 return PP_ToBool(plugin_decryption_interface_->CancelKeyRequest( | |
1353 pp_instance(), | |
1354 session_id_var.GetPPVar())); | |
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(ScopedPPResource::PassRef(), | |
1376 MakeBufferResource(pp_instance(), | |
1377 encrypted_block)); | |
1378 if (!encrypted_resource.get()) | |
1379 return false; | |
1380 // TODO(tomfinegan): Store callback and ID in a map, and pass ID to decryptor. | |
1381 return PP_ToBool(plugin_decryption_interface_->DecryptAndDecode( | |
1382 pp_instance(), | |
1383 encrypted_resource, | |
1384 0)); | |
1385 } | |
1386 | |
1285 bool PluginInstance::FlashIsFullscreenOrPending() { | 1387 bool PluginInstance::FlashIsFullscreenOrPending() { |
1286 return fullscreen_container_ != NULL; | 1388 return fullscreen_container_ != NULL; |
1287 } | 1389 } |
1288 | 1390 |
1289 bool PluginInstance::IsFullscreenOrPending() { | 1391 bool PluginInstance::IsFullscreenOrPending() { |
1290 return desired_fullscreen_state_; | 1392 return desired_fullscreen_state_; |
1291 } | 1393 } |
1292 | 1394 |
1293 bool PluginInstance::SetFullscreen(bool fullscreen) { | 1395 bool PluginInstance::SetFullscreen(bool fullscreen) { |
1294 // Keep a reference on the stack. See NOTE above. | 1396 // 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) { | 1985 PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) { |
1884 std::string encoding = delegate()->GetDefaultEncoding(); | 1986 std::string encoding = delegate()->GetDefaultEncoding(); |
1885 return StringVar::StringToPPVar(encoding); | 1987 return StringVar::StringToPPVar(encoding); |
1886 } | 1988 } |
1887 | 1989 |
1888 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) { | 1990 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) { |
1889 // No in-process implementation. | 1991 // No in-process implementation. |
1890 return PP_MakeUndefined(); | 1992 return PP_MakeUndefined(); |
1891 } | 1993 } |
1892 | 1994 |
1995 void PluginInstance::NeedKey(PP_Instance instance, | |
1996 PP_Var key_system_var, | |
1997 PP_Var session_id_var, | |
1998 PP_Var init_data_var) { | |
1999 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | |
2000 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | |
2001 StringVar* init_data_string = StringVar::FromPPVar(init_data_var); | |
2002 | |
2003 if (!key_system_string || !session_id_string || !init_data_string) | |
2004 return; | |
2005 } | |
2006 | |
2007 void PluginInstance::KeyAdded(PP_Instance instance, | |
2008 PP_Var key_system_var, | |
2009 PP_Var session_id_var) { | |
2010 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | |
2011 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | |
2012 | |
2013 if (!key_system_string || !session_id_string) { | |
2014 // TODO(tomfinegan): KeyError here? | |
xhwang
2012/08/15 00:27:57
The CDMWrapper should check this. Here we probably
Tom Finegan
2012/08/16 03:10:48
No DCHECKs-- per dmichael we're supposed to treat
| |
2015 return; | |
2016 } | |
2017 | |
2018 // TODO(tomfinegan): send the data to media stack. | |
2019 } | |
2020 | |
2021 void PluginInstance::KeyMessage(PP_Instance instance, | |
2022 PP_Var key_system_var, | |
2023 PP_Var session_id_var, | |
2024 PP_Resource message_resource, | |
2025 PP_Var default_url_var) { | |
2026 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | |
2027 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | |
2028 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); | |
2029 | |
2030 if (!key_system_string || !session_id_string || !default_url_string) { | |
2031 // TODO(tomfinegan): KeyError here? | |
xhwang
2012/08/15 00:27:57
ditto.
Tom Finegan
2012/08/16 03:10:48
Done/removed checks.
| |
2032 return; | |
2033 } | |
2034 | |
2035 EnterResourceNoLock<PPB_Buffer_API> enter(message_resource, true); | |
2036 if (enter.failed()) { | |
2037 // TODO(tomfinegan): KeyError here? | |
xhwang
2012/08/15 00:27:57
Can this happen if we implemented everything corre
Tom Finegan
2012/08/16 03:10:48
Initial question: presumably yes, at the very leas
| |
2038 return; | |
2039 } | |
2040 | |
2041 BufferAutoMapper mapper(enter.object()); | |
2042 if (!mapper.data() || !mapper.size()) { | |
2043 // TODO(tomfinegan): KeyError here? | |
xhwang
2012/08/15 00:27:57
ditto here and below.
Tom Finegan
2012/08/16 03:10:48
Done/removed checks.
| |
2044 return; | |
2045 } | |
2046 | |
2047 std::string message(reinterpret_cast<char*>(mapper.data()), mapper.size()); | |
2048 if (message.empty()) { | |
2049 // TODO(tomfinegan): KeyError here? | |
2050 return; | |
2051 } | |
2052 | |
2053 // TODO(tomfinegan): send the data to media stack. | |
2054 } | |
2055 | |
2056 void PluginInstance::KeyError(PP_Instance instance, | |
2057 PP_Var key_system_var, | |
2058 PP_Var session_id_var, | |
2059 int32_t media_error, | |
2060 int32_t system_code) { | |
2061 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | |
2062 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | |
2063 | |
2064 if (!key_system_string || !session_id_string) | |
2065 return; | |
2066 | |
2067 // TODO(tomfinegan): send the data to media stack. | |
2068 } | |
2069 | |
2070 void PluginInstance::DeliverBlock(PP_Instance instance, | |
2071 PP_Resource decrypted_block, | |
2072 int32_t request_id) { | |
2073 // TODO(tomfinegan): Determine where |decrypted_block| goes, and what | |
2074 // callback actually is (callback will likely be the result of some | |
2075 // base::Bind usage in the media stack. Hash this out with xhwang. | |
xhwang
2012/08/15 00:27:57
You can simplify this to:
TODO(xhwang): Pass the d
Tom Finegan
2012/08/16 03:10:48
Done.
| |
2076 // | |
2077 } | |
2078 | |
2079 void PluginInstance::DeliverFrame(PP_Instance instance, | |
2080 PP_Resource decrypted_frame, | |
2081 int32_t request_id) { | |
2082 // TODO(tomfinegan): To be implemented after completion of v0.1 of the | |
2083 // EME/CDM work. | |
xhwang
2012/08/15 00:27:57
Add NOTREACHED();
Tom Finegan
2012/08/16 03:10:48
dmichael said not to use things that can bring dow
| |
2084 } | |
2085 | |
2086 void PluginInstance::DeliverSamples(PP_Instance instance, | |
2087 PP_Resource decrypted_samples, | |
2088 int32_t request_id) { | |
2089 // TODO(tomfinegan): To be implemented after completion of v0.1 of the | |
2090 // EME/CDM work. | |
xhwang
2012/08/15 00:27:57
Add NOTREACHED();
Tom Finegan
2012/08/16 03:10:48
Ditto.
| |
2091 } | |
2092 | |
2093 | |
1893 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, | 2094 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, |
1894 int32_t total, | 2095 int32_t total, |
1895 PP_Bool final_result) { | 2096 PP_Bool final_result) { |
1896 DCHECK_NE(find_identifier_, -1); | 2097 DCHECK_NE(find_identifier_, -1); |
1897 delegate_->NumberOfFindResultsChanged(find_identifier_, total, | 2098 delegate_->NumberOfFindResultsChanged(find_identifier_, total, |
1898 PP_ToBool(final_result)); | 2099 PP_ToBool(final_result)); |
1899 } | 2100 } |
1900 | 2101 |
1901 void PluginInstance::SelectedFindResultChanged(PP_Instance instance, | 2102 void PluginInstance::SelectedFindResultChanged(PP_Instance instance, |
1902 int32_t index) { | 2103 int32_t index) { |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2258 screen_size_for_fullscreen_ = gfx::Size(); | 2459 screen_size_for_fullscreen_ = gfx::Size(); |
2259 WebElement element = container_->element(); | 2460 WebElement element = container_->element(); |
2260 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2461 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
2261 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2462 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
2262 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2463 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
2263 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2464 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
2264 } | 2465 } |
2265 | 2466 |
2266 } // namespace ppapi | 2467 } // namespace ppapi |
2267 } // namespace webkit | 2468 } // namespace webkit |
OLD | NEW |