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 PP_Resource equal to 0 on |
| 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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 | 978 |
955 void PluginInstance::StopFind() { | 979 void PluginInstance::StopFind() { |
956 // Keep a reference on the stack. See NOTE above. | 980 // Keep a reference on the stack. See NOTE above. |
957 scoped_refptr<PluginInstance> ref(this); | 981 scoped_refptr<PluginInstance> ref(this); |
958 if (!LoadFindInterface()) | 982 if (!LoadFindInterface()) |
959 return; | 983 return; |
960 find_identifier_ = -1; | 984 find_identifier_ = -1; |
961 plugin_find_interface_->StopFind(pp_instance()); | 985 plugin_find_interface_->StopFind(pp_instance()); |
962 } | 986 } |
963 | 987 |
| 988 bool PluginInstance::LoadContentDecryptionModuleInterface() { |
| 989 if (!plugin_decryption_interface_) { |
| 990 plugin_decryption_interface_ = |
| 991 static_cast<const PPP_ContentDecryptor_Dev*>( |
| 992 module_->GetPluginInterface( |
| 993 PPP_CONTENTDECRYPTOR_DEV_INTERFACE)); |
| 994 } |
| 995 return !!plugin_decryption_interface_; |
| 996 } |
| 997 |
964 bool PluginInstance::LoadFindInterface() { | 998 bool PluginInstance::LoadFindInterface() { |
965 if (!plugin_find_interface_) { | 999 if (!plugin_find_interface_) { |
966 plugin_find_interface_ = | 1000 plugin_find_interface_ = |
967 static_cast<const PPP_Find_Dev*>(module_->GetPluginInterface( | 1001 static_cast<const PPP_Find_Dev*>(module_->GetPluginInterface( |
968 PPP_FIND_DEV_INTERFACE)); | 1002 PPP_FIND_DEV_INTERFACE)); |
969 } | 1003 } |
970 | 1004 |
971 return !!plugin_find_interface_; | 1005 return !!plugin_find_interface_; |
972 } | 1006 } |
973 | 1007 |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 if (!LoadPdfInterface()) | 1305 if (!LoadPdfInterface()) |
1272 return; | 1306 return; |
1273 PP_PrivatePageTransformType transform_type = | 1307 PP_PrivatePageTransformType transform_type = |
1274 type == WebPlugin::RotationType90Clockwise ? | 1308 type == WebPlugin::RotationType90Clockwise ? |
1275 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW : | 1309 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW : |
1276 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW; | 1310 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW; |
1277 plugin_pdf_interface_->Transform(pp_instance(), transform_type); | 1311 plugin_pdf_interface_->Transform(pp_instance(), transform_type); |
1278 // NOTE: plugin instance may have been deleted. | 1312 // NOTE: plugin instance may have been deleted. |
1279 } | 1313 } |
1280 | 1314 |
| 1315 bool PluginInstance::GenerateKeyRequest(const std::string& key_system, |
| 1316 const std::string& init_data) { |
| 1317 if (!LoadContentDecryptionModuleInterface()) |
| 1318 return false; |
| 1319 if (key_system.empty()) |
| 1320 return false; |
| 1321 PP_Var init_data_array = |
| 1322 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
| 1323 init_data.size(), init_data.data()); |
| 1324 return PP_ToBool(plugin_decryption_interface_->GenerateKeyRequest( |
| 1325 pp_instance(), |
| 1326 StringVar::StringToPPVar(key_system), |
| 1327 init_data_array)); |
| 1328 } |
| 1329 |
| 1330 bool PluginInstance::AddKey(const std::string& session_id, |
| 1331 const std::string& key) { |
| 1332 if (!LoadContentDecryptionModuleInterface()) |
| 1333 return false; |
| 1334 StringVar session_id_var(session_id); |
| 1335 PP_Var key_array = |
| 1336 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(key.size(), |
| 1337 key.data()); |
| 1338 return PP_ToBool(plugin_decryption_interface_->AddKey( |
| 1339 pp_instance(), |
| 1340 session_id_var.GetPPVar(), |
| 1341 key_array)); |
| 1342 } |
| 1343 |
| 1344 bool PluginInstance::CancelKeyRequest(const std::string& session_id) { |
| 1345 if (!LoadContentDecryptionModuleInterface()) |
| 1346 return false; |
| 1347 StringVar session_id_var(session_id); |
| 1348 return PP_ToBool(plugin_decryption_interface_->CancelKeyRequest( |
| 1349 pp_instance(), |
| 1350 session_id_var.GetPPVar())); |
| 1351 } |
| 1352 |
| 1353 bool PluginInstance::Decrypt(const base::StringPiece& encrypted_block, |
| 1354 const DecryptedDataCB& callback) { |
| 1355 if (!LoadContentDecryptionModuleInterface()) |
| 1356 return false; |
| 1357 ScopedPPResource encrypted_resource(MakeBufferResource(pp_instance(), |
| 1358 encrypted_block)); |
| 1359 if (!encrypted_resource.get()) |
| 1360 return false; |
| 1361 // TODO(tomfinegan): Store callback and ID in a map, and pass ID to decryptor. |
| 1362 return PP_ToBool(plugin_decryption_interface_->Decrypt(pp_instance(), |
| 1363 encrypted_resource, |
| 1364 0)); |
| 1365 } |
| 1366 |
| 1367 bool PluginInstance::DecryptAndDecode(const base::StringPiece& encrypted_block, |
| 1368 const DecryptedDataCB& callback) { |
| 1369 if (!LoadContentDecryptionModuleInterface()) |
| 1370 return false; |
| 1371 ScopedPPResource encrypted_resource(ScopedPPResource::PassRef(), |
| 1372 MakeBufferResource(pp_instance(), |
| 1373 encrypted_block)); |
| 1374 if (!encrypted_resource.get()) |
| 1375 return false; |
| 1376 // TODO(tomfinegan): Store callback and ID in a map, and pass ID to decryptor. |
| 1377 return PP_ToBool(plugin_decryption_interface_->DecryptAndDecode( |
| 1378 pp_instance(), |
| 1379 encrypted_resource, |
| 1380 0)); |
| 1381 } |
| 1382 |
1281 bool PluginInstance::FlashIsFullscreenOrPending() { | 1383 bool PluginInstance::FlashIsFullscreenOrPending() { |
1282 return fullscreen_container_ != NULL; | 1384 return fullscreen_container_ != NULL; |
1283 } | 1385 } |
1284 | 1386 |
1285 bool PluginInstance::IsFullscreenOrPending() { | 1387 bool PluginInstance::IsFullscreenOrPending() { |
1286 return desired_fullscreen_state_; | 1388 return desired_fullscreen_state_; |
1287 } | 1389 } |
1288 | 1390 |
1289 bool PluginInstance::SetFullscreen(bool fullscreen) { | 1391 bool PluginInstance::SetFullscreen(bool fullscreen) { |
1290 // Keep a reference on the stack. See NOTE above. | 1392 // Keep a reference on the stack. See NOTE above. |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1872 PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) { | 1974 PP_Var PluginInstance::GetDefaultCharSet(PP_Instance instance) { |
1873 std::string encoding = delegate()->GetDefaultEncoding(); | 1975 std::string encoding = delegate()->GetDefaultEncoding(); |
1874 return StringVar::StringToPPVar(encoding); | 1976 return StringVar::StringToPPVar(encoding); |
1875 } | 1977 } |
1876 | 1978 |
1877 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) { | 1979 PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) { |
1878 // No in-process implementation. | 1980 // No in-process implementation. |
1879 return PP_MakeUndefined(); | 1981 return PP_MakeUndefined(); |
1880 } | 1982 } |
1881 | 1983 |
| 1984 void PluginInstance::NeedKey(PP_Instance instance, |
| 1985 PP_Var key_system_var, |
| 1986 PP_Var session_id_var, |
| 1987 PP_Var init_data_var) { |
| 1988 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
| 1989 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
| 1990 StringVar* init_data_string = StringVar::FromPPVar(init_data_var); |
| 1991 |
| 1992 if (!key_system_string || !session_id_string || !init_data_string) |
| 1993 return; |
| 1994 |
| 1995 // TODO(tomfinegan): Where does the call to this method come from? Or, where |
| 1996 // does it go for handling. I need to read more of the EME proposed spec, but |
| 1997 // this is what I understand so far: |
| 1998 // - JS app sends needkey before anything else when it knows that encrypted |
| 1999 // data is going to be streamed to the user agent. |
| 2000 // - OR is the media stack going to see something in the stream that looks |
| 2001 // like init data, and then send NeedKey. If this is the case NeedKey |
| 2002 // probably needs to move to the PPP interface. |
| 2003 } |
| 2004 |
| 2005 void PluginInstance::KeyAdded(PP_Instance instance, |
| 2006 PP_Var key_system_var, |
| 2007 PP_Var session_id_var) { |
| 2008 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
| 2009 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
| 2010 |
| 2011 if (!key_system_string || !session_id_string) { |
| 2012 // TODO(tomfinegan): KeyError here? |
| 2013 return; |
| 2014 } |
| 2015 |
| 2016 // TODO(tomfinegan): send the data to media stack. |
| 2017 } |
| 2018 |
| 2019 void PluginInstance::KeyMessage(PP_Instance instance, |
| 2020 PP_Var key_system_var, |
| 2021 PP_Var session_id_var, |
| 2022 PP_Resource message_resource, |
| 2023 PP_Var default_url_var) { |
| 2024 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
| 2025 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
| 2026 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); |
| 2027 |
| 2028 if (!key_system_string || !session_id_string || !default_url_string) { |
| 2029 // TODO(tomfinegan): KeyError here? |
| 2030 return; |
| 2031 } |
| 2032 |
| 2033 EnterResourceNoLock<PPB_Buffer_API> enter(message_resource, true); |
| 2034 if (enter.failed()) { |
| 2035 // TODO(tomfinegan): KeyError here? |
| 2036 return; |
| 2037 } |
| 2038 |
| 2039 BufferAutoMapper mapper(enter.object()); |
| 2040 if (!mapper.data() || !mapper.size()) { |
| 2041 // TODO(tomfinegan): KeyError here? |
| 2042 return; |
| 2043 } |
| 2044 |
| 2045 std::string message(reinterpret_cast<char*>(mapper.data()), mapper.size()); |
| 2046 if (message.empty()) { |
| 2047 // TODO(tomfinegan): KeyError here? |
| 2048 return; |
| 2049 } |
| 2050 |
| 2051 // TODO(tomfinegan): send the data to media stack. |
| 2052 } |
| 2053 |
| 2054 void PluginInstance::KeyError(PP_Instance instance, |
| 2055 PP_Var key_system_var, |
| 2056 PP_Var session_id_var, |
| 2057 int32_t media_error, |
| 2058 int32_t system_error) { |
| 2059 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
| 2060 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
| 2061 |
| 2062 if (!key_system_string || !session_id_string) |
| 2063 return; |
| 2064 |
| 2065 // TODO(tomfinegan): send the data to media stack. |
| 2066 } |
| 2067 |
| 2068 void PluginInstance::DeliverBlock(PP_Instance instance, |
| 2069 PP_Resource decrypted_block, |
| 2070 uint64_t request_id) { |
| 2071 // TODO(tomfinegan): Determine where |decrypted_block| goes, and what |
| 2072 // callback actually is (callback will likely be the result of some |
| 2073 // base::Bind usage in the media stack. Hash this out with xhwang. |
| 2074 // |
| 2075 } |
| 2076 |
| 2077 void PluginInstance::DeliverFrame(PP_Instance instance, |
| 2078 PP_Resource decrypted_frame, |
| 2079 uint64_t request_id) { |
| 2080 // TODO(tomfinegan): To be implemented after completion of v0.1 of the |
| 2081 // EME/CDM work. |
| 2082 } |
| 2083 |
| 2084 void PluginInstance::DeliverSamples(PP_Instance instance, |
| 2085 PP_Resource decrypted_samples, |
| 2086 uint64_t request_id) { |
| 2087 // TODO(tomfinegan): To be implemented after completion of v0.1 of the |
| 2088 // EME/CDM work. |
| 2089 } |
| 2090 |
| 2091 |
1882 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, | 2092 void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, |
1883 int32_t total, | 2093 int32_t total, |
1884 PP_Bool final_result) { | 2094 PP_Bool final_result) { |
1885 DCHECK_NE(find_identifier_, -1); | 2095 DCHECK_NE(find_identifier_, -1); |
1886 delegate_->NumberOfFindResultsChanged(find_identifier_, total, | 2096 delegate_->NumberOfFindResultsChanged(find_identifier_, total, |
1887 PP_ToBool(final_result)); | 2097 PP_ToBool(final_result)); |
1888 } | 2098 } |
1889 | 2099 |
1890 void PluginInstance::SelectedFindResultChanged(PP_Instance instance, | 2100 void PluginInstance::SelectedFindResultChanged(PP_Instance instance, |
1891 int32_t index) { | 2101 int32_t index) { |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2248 screen_size_for_fullscreen_ = gfx::Size(); | 2458 screen_size_for_fullscreen_ = gfx::Size(); |
2249 WebElement element = container_->element(); | 2459 WebElement element = container_->element(); |
2250 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2460 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
2251 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2461 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
2252 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2462 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
2253 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2463 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
2254 } | 2464 } |
2255 | 2465 |
2256 } // namespace ppapi | 2466 } // namespace ppapi |
2257 } // namespace webkit | 2467 } // namespace webkit |
OLD | NEW |