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

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

Issue 10543029: PPAPI/NaCl: Reinitialize some stuff when the ipc proxy starts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: enforce ordering of events, make previous view emptyenforce ordering of events, make previous view … Created 8 years, 6 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 #if defined(OS_WIN) 95 #if defined(OS_WIN)
96 #include "base/metrics/histogram.h" 96 #include "base/metrics/histogram.h"
97 #include "skia/ext/platform_canvas.h" 97 #include "skia/ext/platform_canvas.h"
98 #include "ui/gfx/codec/jpeg_codec.h" 98 #include "ui/gfx/codec/jpeg_codec.h"
99 #include "ui/gfx/gdi_util.h" 99 #include "ui/gfx/gdi_util.h"
100 #endif 100 #endif
101 101
102 using base::StringPrintf; 102 using base::StringPrintf;
103 using ppapi::InputEventData; 103 using ppapi::InputEventData;
104 using ppapi::PpapiGlobals;
104 using ppapi::PPB_InputEvent_Shared; 105 using ppapi::PPB_InputEvent_Shared;
105 using ppapi::PpapiGlobals;
106 using ppapi::PPB_View_Shared; 106 using ppapi::PPB_View_Shared;
107 using ppapi::PPP_Instance_Combined;
107 using ppapi::ScopedPPResource; 108 using ppapi::ScopedPPResource;
108 using ppapi::StringVar; 109 using ppapi::StringVar;
109 using ppapi::thunk::EnterResourceNoLock; 110 using ppapi::thunk::EnterResourceNoLock;
110 using ppapi::thunk::PPB_Buffer_API; 111 using ppapi::thunk::PPB_Buffer_API;
111 using ppapi::thunk::PPB_Graphics2D_API; 112 using ppapi::thunk::PPB_Graphics2D_API;
112 using ppapi::thunk::PPB_Graphics3D_API; 113 using ppapi::thunk::PPB_Graphics3D_API;
113 using ppapi::thunk::PPB_ImageData_API; 114 using ppapi::thunk::PPB_ImageData_API;
114 using ppapi::Var; 115 using ppapi::Var;
115 using ppapi::ViewData; 116 using ppapi::ViewData;
116 using WebKit::WebBindings; 117 using WebKit::WebBindings;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 WebKit::WebSecurityOrigin* security_origin) { 275 WebKit::WebSecurityOrigin* security_origin) {
275 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); 276 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id);
276 if (!instance) 277 if (!instance)
277 return false; 278 return false;
278 279
279 WebElement plugin_element = instance->container()->element(); 280 WebElement plugin_element = instance->container()->element();
280 *security_origin = plugin_element.document().securityOrigin(); 281 *security_origin = plugin_element.document().securityOrigin();
281 return true; 282 return true;
282 } 283 }
283 284
285 // Probe the given module's GetPluginInterface function to return a
286 // PPP_InstanceCombined the most recent
287
288 // Convert the given vector to an array of C-strings. The strings in the
289 // returned vector are only guaranteed valid so long as the vector of strings
290 // is not modified.
291 scoped_array<const char*> StringVectorToArgArray(
292 const std::vector<std::string>& vector) {
293 scoped_array<const char*> array(new const char*[vector.size()]);
294 for (size_t i = 0; i < vector.size(); ++i)
295 array[i] = vector[i].c_str();
296 return array.Pass();
297 }
298
284 } // namespace 299 } // namespace
285 300
286 // static 301 // static
287 PluginInstance* PluginInstance::Create1_0(PluginDelegate* delegate, 302 PluginInstance* PluginInstance::Create(PluginDelegate* delegate,
288 PluginModule* module, 303 PluginModule* module) {
289 const void* ppp_instance_if_1_0) { 304 base::Callback<const void*(const char*)> get_plugin_interface_func =
290 const PPP_Instance_1_0* instance = 305 base::Bind(&PluginModule::GetPluginInterface, module);
291 static_cast<const PPP_Instance_1_0*>(ppp_instance_if_1_0); 306 PPP_Instance_Combined* ppp_instance_combined =
292 return new PluginInstance( 307 PPP_Instance_Combined::Create(get_plugin_interface_func);
293 delegate, 308 if (!ppp_instance_combined)
294 module, 309 return NULL;
295 new ::ppapi::PPP_Instance_Combined(*instance)); 310 return new PluginInstance(delegate, module, ppp_instance_combined);
296 }
297
298 // static
299 PluginInstance* PluginInstance::Create1_1(PluginDelegate* delegate,
300 PluginModule* module,
301 const void* ppp_instance_if_1_1) {
302 const PPP_Instance_1_1* instance =
303 static_cast<const PPP_Instance_1_1*>(ppp_instance_if_1_1);
304 return new PluginInstance(
305 delegate,
306 module,
307 new ::ppapi::PPP_Instance_Combined(*instance));
308 } 311 }
309 312
310 PluginInstance::PluginInstance( 313 PluginInstance::PluginInstance(
311 PluginDelegate* delegate, 314 PluginDelegate* delegate,
312 PluginModule* module, 315 PluginModule* module,
313 ::ppapi::PPP_Instance_Combined* instance_interface) 316 ::ppapi::PPP_Instance_Combined* instance_interface)
314 : delegate_(delegate), 317 : delegate_(delegate),
315 module_(module), 318 module_(module),
316 instance_interface_(instance_interface), 319 instance_interface_(instance_interface),
317 pp_instance_(0), 320 pp_instance_(0),
318 container_(NULL), 321 container_(NULL),
319 full_frame_(false), 322 full_frame_(false),
320 sent_initial_did_change_view_(false), 323 sent_initial_did_change_view_(false),
321 suppress_did_change_view_(false), 324 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
322 has_webkit_focus_(false), 325 has_webkit_focus_(false),
323 has_content_area_focus_(false), 326 has_content_area_focus_(false),
324 find_identifier_(-1), 327 find_identifier_(-1),
325 resource_creation_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 328 resource_creation_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
326 plugin_find_interface_(NULL), 329 plugin_find_interface_(NULL),
330 plugin_input_event_interface_(NULL),
327 plugin_messaging_interface_(NULL), 331 plugin_messaging_interface_(NULL),
328 plugin_mouse_lock_interface_(NULL), 332 plugin_mouse_lock_interface_(NULL),
329 plugin_input_event_interface_(NULL), 333 plugin_pdf_interface_(NULL),
330 plugin_private_interface_(NULL), 334 plugin_private_interface_(NULL),
331 plugin_pdf_interface_(NULL),
332 plugin_selection_interface_(NULL), 335 plugin_selection_interface_(NULL),
333 plugin_textinput_interface_(NULL), 336 plugin_textinput_interface_(NULL),
334 plugin_zoom_interface_(NULL), 337 plugin_zoom_interface_(NULL),
335 checked_for_plugin_input_event_interface_(false), 338 checked_for_plugin_input_event_interface_(false),
336 checked_for_plugin_messaging_interface_(false), 339 checked_for_plugin_messaging_interface_(false),
337 plugin_print_interface_(NULL), 340 plugin_print_interface_(NULL),
338 plugin_graphics_3d_interface_(NULL), 341 plugin_graphics_3d_interface_(NULL),
339 always_on_top_(false), 342 always_on_top_(false),
340 fullscreen_container_(NULL), 343 fullscreen_container_(NULL),
341 flash_fullscreen_(false), 344 flash_fullscreen_(false),
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 493
491 bool PluginInstance::Initialize(WebPluginContainer* container, 494 bool PluginInstance::Initialize(WebPluginContainer* container,
492 const std::vector<std::string>& arg_names, 495 const std::vector<std::string>& arg_names,
493 const std::vector<std::string>& arg_values, 496 const std::vector<std::string>& arg_values,
494 const GURL& plugin_url, 497 const GURL& plugin_url,
495 bool full_frame) { 498 bool full_frame) {
496 container_ = container; 499 container_ = container;
497 plugin_url_ = plugin_url; 500 plugin_url_ = plugin_url;
498 full_frame_ = full_frame; 501 full_frame_ = full_frame;
499 502
500 size_t argc = 0; 503 argn_ = arg_names;
501 scoped_array<const char*> argn(new const char*[arg_names.size()]); 504 argv_ = arg_values;
502 scoped_array<const char*> argv(new const char*[arg_names.size()]); 505 scoped_array<const char*> argn_array(StringVectorToArgArray(argn_));
503 for (size_t i = 0; i < arg_names.size(); ++i) { 506 scoped_array<const char*> argv_array(StringVectorToArgArray(argv_));
504 argn[argc] = arg_names[i].c_str();
505 argv[argc] = arg_values[i].c_str();
506 argc++;
507 }
508
509 return PP_ToBool(instance_interface_->DidCreate(pp_instance(), 507 return PP_ToBool(instance_interface_->DidCreate(pp_instance(),
510 argc, 508 argn_.size(),
511 argn.get(), 509 argn_array.get(),
512 argv.get())); 510 argv_array.get()));
513 } 511 }
514 512
515 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { 513 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) {
514 if (!document_loader_)
515 document_loader_ = loader;
516 DCHECK(loader == document_loader_.get());
517
516 return PP_ToBool(instance_interface_->HandleDocumentLoad( 518 return PP_ToBool(instance_interface_->HandleDocumentLoad(
517 pp_instance(), loader->pp_resource())); 519 pp_instance(), loader->pp_resource()));
518 } 520 }
519 521
520 bool PluginInstance::SendCompositionEventToPlugin(PP_InputEvent_Type type, 522 bool PluginInstance::SendCompositionEventToPlugin(PP_InputEvent_Type type,
521 const string16& text) { 523 const string16& text) {
522 std::vector<WebKit::WebCompositionUnderline> empty; 524 std::vector<WebKit::WebCompositionUnderline> empty;
523 return SendCompositionEventWithUnderlineInformationToPlugin( 525 return SendCompositionEventWithUnderlineInformationToPlugin(
524 type, text, empty, static_cast<int>(text.size()), 526 type, text, empty, static_cast<int>(text.size()),
525 static_cast<int>(text.size())); 527 static_cast<int>(text.size()));
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 1051
1050 return !!plugin_zoom_interface_; 1052 return !!plugin_zoom_interface_;
1051 } 1053 }
1052 1054
1053 bool PluginInstance::PluginHasFocus() const { 1055 bool PluginInstance::PluginHasFocus() const {
1054 return has_webkit_focus_ && has_content_area_focus_; 1056 return has_webkit_focus_ && has_content_area_focus_;
1055 } 1057 }
1056 1058
1057 void PluginInstance::ScheduleAsyncDidChangeView( 1059 void PluginInstance::ScheduleAsyncDidChangeView(
1058 const ::ppapi::ViewData& previous_view) { 1060 const ::ppapi::ViewData& previous_view) {
1059 if (suppress_did_change_view_) 1061 if (view_change_weak_ptr_factory_.HasWeakPtrs())
1060 return; // Already scheduled. 1062 return; // Already scheduled.
1061 suppress_did_change_view_ = true;
1062 MessageLoop::current()->PostTask( 1063 MessageLoop::current()->PostTask(
1063 FROM_HERE, base::Bind(&PluginInstance::SendAsyncDidChangeView, 1064 FROM_HERE, base::Bind(&PluginInstance::SendAsyncDidChangeView,
1064 this, previous_view)); 1065 view_change_weak_ptr_factory_.GetWeakPtr(),
1066 previous_view));
1065 } 1067 }
1066 1068
1067 void PluginInstance::SendAsyncDidChangeView(const ViewData& previous_view) { 1069 void PluginInstance::SendAsyncDidChangeView(const ViewData& previous_view) {
1068 DCHECK(suppress_did_change_view_);
1069 suppress_did_change_view_ = false;
1070 SendDidChangeView(previous_view); 1070 SendDidChangeView(previous_view);
1071 } 1071 }
1072 1072
1073 void PluginInstance::SendDidChangeView(const ViewData& previous_view) { 1073 void PluginInstance::SendDidChangeView(const ViewData& previous_view) {
1074 // Don't send DidChangeView to crashed plugins. 1074 // Don't send DidChangeView to crashed plugins.
1075 if (module()->is_crashed()) 1075 if (module()->is_crashed())
1076 return; 1076 return;
1077 1077
1078 if (suppress_did_change_view_ || 1078 if (view_change_weak_ptr_factory_.HasWeakPtrs() ||
1079 (sent_initial_did_change_view_ && previous_view.Equals(view_data_))) 1079 (sent_initial_did_change_view_ && previous_view.Equals(view_data_)))
1080 return; // Nothing to update. 1080 return; // Nothing to update.
1081 1081
1082 const PP_Size& size = view_data_.rect.size; 1082 const PP_Size& size = view_data_.rect.size;
1083 // Avoid sending a notification with a huge rectangle. 1083 // Avoid sending a notification with a huge rectangle.
1084 if (size.width < 0 || size.width > kMaxPluginSideLength || 1084 if (size.width < 0 || size.width > kMaxPluginSideLength ||
1085 size.height < 0 || size.height > kMaxPluginSideLength || 1085 size.height < 0 || size.height > kMaxPluginSideLength ||
1086 // We know this won't overflow due to above checks. 1086 // We know this won't overflow due to above checks.
1087 static_cast<uint32>(size.width) * static_cast<uint32>(size.height) > 1087 static_cast<uint32>(size.width) * static_cast<uint32>(size.height) >
1088 kMaxPluginSize) { 1088 kMaxPluginSize) {
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 components); 2075 components);
2076 } 2076 }
2077 2077
2078 PP_Var PluginInstance::GetPluginInstanceURL( 2078 PP_Var PluginInstance::GetPluginInstanceURL(
2079 PP_Instance instance, 2079 PP_Instance instance,
2080 PP_URLComponents_Dev* components) { 2080 PP_URLComponents_Dev* components) {
2081 return ::ppapi::PPB_URLUtil_Shared::GenerateURLReturn(plugin_url_, 2081 return ::ppapi::PPB_URLUtil_Shared::GenerateURLReturn(plugin_url_,
2082 components); 2082 components);
2083 } 2083 }
2084 2084
2085 bool PluginInstance::ResetAsProxied() {
2086 base::Callback<const void*(const char*)> get_plugin_interface_func =
2087 base::Bind(&PluginModule::GetPluginInterface, module_.get());
2088 PPP_Instance_Combined* ppp_instance_combined =
2089 PPP_Instance_Combined::Create(get_plugin_interface_func);
2090 if (!ppp_instance_combined) {
2091 // The proxy must support at least one usable PPP_Instance interface.
2092 NOTREACHED();
2093 return false;
2094 }
2095 instance_interface_.reset(ppp_instance_combined);
2096 // Clear all PPP interfaces we may have cached.
2097 plugin_find_interface_ = NULL;
2098 plugin_input_event_interface_ = NULL;
2099 plugin_messaging_interface_ = NULL;
2100 plugin_mouse_lock_interface_ = NULL;
2101 plugin_pdf_interface_ = NULL;
2102 plugin_private_interface_ = NULL;
2103 plugin_selection_interface_ = NULL;
2104 plugin_textinput_interface_ = NULL;
2105 plugin_zoom_interface_ = NULL;
2106
2107 // Re-send the DidCreate event via the proxy.
2108 scoped_array<const char*> argn_array(StringVectorToArgArray(argn_));
2109 scoped_array<const char*> argv_array(StringVectorToArgArray(argv_));
2110 if (!instance_interface_->DidCreate(pp_instance(), argn_.size(),
2111 argn_array.get(), argv_array.get()))
2112 return false;
2113
2114 // Use a ViewData that looks like the initial DidChangeView event for the
2115 // "previous" view, and make sure it is sent immediately (before other events
2116 // like HandleDocumentLoad).
2117 ::ppapi::ViewData empty_view;
2118 empty_view.is_page_visible = delegate_->IsPageVisible();
2119 sent_initial_did_change_view_ = false;
2120 // Cancel any pending DidChangeView event.
2121 view_change_weak_ptr_factory_.InvalidateWeakPtrs();
2122 SendDidChangeView(empty_view);
2123
2124 // If we received HandleDocumentLoad, re-send it now via the proxy.
2125 if (document_loader_)
2126 HandleDocumentLoad(document_loader_.get());
2127 return true;
2128 }
2129
2085 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) { 2130 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) {
2086 cursor_.reset(cursor); 2131 cursor_.reset(cursor);
2087 if (fullscreen_container_) { 2132 if (fullscreen_container_) {
2088 fullscreen_container_->DidChangeCursor(*cursor); 2133 fullscreen_container_->DidChangeCursor(*cursor);
2089 } else { 2134 } else {
2090 delegate()->DidChangeCursor(this, *cursor); 2135 delegate()->DidChangeCursor(this, *cursor);
2091 } 2136 }
2092 } 2137 }
2093 2138
2094 bool PluginInstance::CanAccessMainFrame() const { 2139 bool PluginInstance::CanAccessMainFrame() const {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2145 screen_size_for_fullscreen_ = gfx::Size(); 2190 screen_size_for_fullscreen_ = gfx::Size();
2146 WebElement element = container_->element(); 2191 WebElement element = container_->element();
2147 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2192 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2148 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2193 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2149 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2194 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2150 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2195 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2151 } 2196 }
2152 2197
2153 } // namespace ppapi 2198 } // namespace ppapi
2154 } // namespace webkit 2199 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698