| 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 "content/renderer/pepper/pepper_plugin_delegate_impl.h" | 5 #include "content/renderer/pepper/pepper_helper_impl.h" | 
| 6 | 6 | 
| 7 #include <cmath> | 7 #include <cmath> | 
| 8 #include <cstddef> | 8 #include <cstddef> | 
| 9 #include <map> | 9 #include <map> | 
| 10 #include <queue> | 10 #include <queue> | 
| 11 | 11 | 
| 12 #include "base/bind.h" | 12 #include "base/bind.h" | 
| 13 #include "base/callback.h" | 13 #include "base/callback.h" | 
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" | 
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" | 
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 104       PepperPluginRegistry::GetInstance()->GetInfoForPlugin( | 104       PepperPluginRegistry::GetInstance()->GetInfoForPlugin( | 
| 105           webplugin_info)->permissions); | 105           webplugin_info)->permissions); | 
| 106   RendererPpapiHostImpl* host_impl = | 106   RendererPpapiHostImpl* host_impl = | 
| 107       RendererPpapiHostImpl::CreateOnModuleForInProcess( | 107       RendererPpapiHostImpl::CreateOnModuleForInProcess( | 
| 108           module, perms); | 108           module, perms); | 
| 109   render_view->PpapiPluginCreated(host_impl); | 109   render_view->PpapiPluginCreated(host_impl); | 
| 110 } | 110 } | 
| 111 | 111 | 
| 112 }  // namespace | 112 }  // namespace | 
| 113 | 113 | 
| 114 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view) | 114 PepperHelperImpl::PepperHelperImpl(RenderViewImpl* render_view) | 
| 115     : RenderViewObserver(render_view), | 115     : RenderViewObserver(render_view), | 
| 116       render_view_(render_view), | 116       render_view_(render_view), | 
| 117       pepper_browser_connection_(this), | 117       pepper_browser_connection_(this), | 
| 118       focused_plugin_(NULL), | 118       focused_plugin_(NULL), | 
| 119       last_mouse_event_target_(NULL) { | 119       last_mouse_event_target_(NULL) { | 
| 120 } | 120 } | 
| 121 | 121 | 
| 122 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { | 122 PepperHelperImpl::~PepperHelperImpl() { | 
| 123 } | 123 } | 
| 124 | 124 | 
| 125 WebKit::WebPlugin* PepperPluginDelegateImpl::CreatePepperWebPlugin( | 125 WebKit::WebPlugin* PepperHelperImpl::CreatePepperWebPlugin( | 
| 126     const WebPluginInfo& webplugin_info, | 126     const WebPluginInfo& webplugin_info, | 
| 127     const WebKit::WebPluginParams& params) { | 127     const WebKit::WebPluginParams& params) { | 
| 128   bool pepper_plugin_was_registered = false; | 128   bool pepper_plugin_was_registered = false; | 
| 129   scoped_refptr<PluginModule> pepper_module( | 129   scoped_refptr<PluginModule> pepper_module( | 
| 130       CreatePepperPluginModule(webplugin_info, &pepper_plugin_was_registered)); | 130       CreatePepperPluginModule(webplugin_info, &pepper_plugin_was_registered)); | 
| 131 | 131 | 
| 132   if (pepper_plugin_was_registered) { | 132   if (pepper_plugin_was_registered) { | 
| 133     if (!pepper_module.get()) | 133     if (!pepper_module.get()) | 
| 134       return NULL; | 134       return NULL; | 
| 135     return new PepperWebPluginImpl( | 135     return new PepperWebPluginImpl( | 
| 136         pepper_module.get(), params, AsWeakPtr(), render_view_->AsWeakPtr()); | 136         pepper_module.get(), params, AsWeakPtr(), render_view_->AsWeakPtr()); | 
| 137   } | 137   } | 
| 138 | 138 | 
| 139   return NULL; | 139   return NULL; | 
| 140 } | 140 } | 
| 141 | 141 | 
| 142 scoped_refptr<PluginModule> PepperPluginDelegateImpl::CreatePepperPluginModule( | 142 scoped_refptr<PluginModule> PepperHelperImpl::CreatePepperPluginModule( | 
| 143     const WebPluginInfo& webplugin_info, | 143     const WebPluginInfo& webplugin_info, | 
| 144     bool* pepper_plugin_was_registered) { | 144     bool* pepper_plugin_was_registered) { | 
| 145   *pepper_plugin_was_registered = true; | 145   *pepper_plugin_was_registered = true; | 
| 146 | 146 | 
| 147   // See if a module has already been loaded for this plugin. | 147   // See if a module has already been loaded for this plugin. | 
| 148   base::FilePath path(webplugin_info.path); | 148   base::FilePath path(webplugin_info.path); | 
| 149   scoped_refptr<PluginModule> module = | 149   scoped_refptr<PluginModule> module = | 
| 150       PepperPluginRegistry::GetInstance()->GetLiveModule(path); | 150       PepperPluginRegistry::GetInstance()->GetLiveModule(path); | 
| 151   if (module.get()) { | 151   if (module.get()) { | 
| 152     if (!module->renderer_ppapi_host()) { | 152     if (!module->renderer_ppapi_host()) { | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 195                                 permissions, | 195                                 permissions, | 
| 196                                 channel_handle, | 196                                 channel_handle, | 
| 197                                 peer_pid, | 197                                 peer_pid, | 
| 198                                 plugin_child_id, | 198                                 plugin_child_id, | 
| 199                                 false))  // is_external = false | 199                                 false))  // is_external = false | 
| 200     return scoped_refptr<PluginModule>(); | 200     return scoped_refptr<PluginModule>(); | 
| 201 | 201 | 
| 202   return module; | 202   return module; | 
| 203 } | 203 } | 
| 204 | 204 | 
| 205 scoped_refptr<PepperBroker> PepperPluginDelegateImpl::CreateBroker( | 205 scoped_refptr<PepperBroker> PepperHelperImpl::CreateBroker( | 
| 206     PluginModule* plugin_module) { | 206     PluginModule* plugin_module) { | 
| 207   DCHECK(plugin_module); | 207   DCHECK(plugin_module); | 
| 208   DCHECK(!plugin_module->GetBroker()); | 208   DCHECK(!plugin_module->GetBroker()); | 
| 209 | 209 | 
| 210   // The broker path is the same as the plugin. | 210   // The broker path is the same as the plugin. | 
| 211   const base::FilePath& broker_path = plugin_module->path(); | 211   const base::FilePath& broker_path = plugin_module->path(); | 
| 212 | 212 | 
| 213   scoped_refptr<PepperBroker> broker = new PepperBroker(plugin_module, this); | 213   scoped_refptr<PepperBroker> broker = new PepperBroker(plugin_module, this); | 
| 214 | 214 | 
| 215   int request_id = | 215   int request_id = | 
| 216       pending_connect_broker_.Add(new scoped_refptr<PepperBroker>(broker)); | 216       pending_connect_broker_.Add(new scoped_refptr<PepperBroker>(broker)); | 
| 217 | 217 | 
| 218   // Have the browser start the broker process for us. | 218   // Have the browser start the broker process for us. | 
| 219   Send(new ViewHostMsg_OpenChannelToPpapiBroker( | 219   Send(new ViewHostMsg_OpenChannelToPpapiBroker( | 
| 220       routing_id(), request_id, broker_path)); | 220       routing_id(), request_id, broker_path)); | 
| 221 | 221 | 
| 222   return broker; | 222   return broker; | 
| 223 } | 223 } | 
| 224 | 224 | 
| 225 RendererPpapiHost* PepperPluginDelegateImpl::CreateOutOfProcessModule( | 225 RendererPpapiHost* PepperHelperImpl::CreateOutOfProcessModule( | 
| 226     PluginModule* module, | 226     PluginModule* module, | 
| 227     const base::FilePath& path, | 227     const base::FilePath& path, | 
| 228     ppapi::PpapiPermissions permissions, | 228     ppapi::PpapiPermissions permissions, | 
| 229     const IPC::ChannelHandle& channel_handle, | 229     const IPC::ChannelHandle& channel_handle, | 
| 230     base::ProcessId peer_pid, | 230     base::ProcessId peer_pid, | 
| 231     int plugin_child_id, | 231     int plugin_child_id, | 
| 232     bool is_external) { | 232     bool is_external) { | 
| 233   scoped_refptr<PepperHungPluginFilter> hung_filter( | 233   scoped_refptr<PepperHungPluginFilter> hung_filter( | 
| 234       new PepperHungPluginFilter(path, routing_id(), plugin_child_id)); | 234       new PepperHungPluginFilter(path, routing_id(), plugin_child_id)); | 
| 235   scoped_ptr<HostDispatcherWrapper> dispatcher( | 235   scoped_ptr<HostDispatcherWrapper> dispatcher( | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 247 | 247 | 
| 248   RendererPpapiHostImpl* host_impl = | 248   RendererPpapiHostImpl* host_impl = | 
| 249       RendererPpapiHostImpl::CreateOnModuleForOutOfProcess( | 249       RendererPpapiHostImpl::CreateOnModuleForOutOfProcess( | 
| 250           module, dispatcher->dispatcher(), permissions); | 250           module, dispatcher->dispatcher(), permissions); | 
| 251   render_view_->PpapiPluginCreated(host_impl); | 251   render_view_->PpapiPluginCreated(host_impl); | 
| 252 | 252 | 
| 253   module->InitAsProxied(dispatcher.release()); | 253   module->InitAsProxied(dispatcher.release()); | 
| 254   return host_impl; | 254   return host_impl; | 
| 255 } | 255 } | 
| 256 | 256 | 
| 257 void PepperPluginDelegateImpl::OnPpapiBrokerChannelCreated( | 257 void PepperHelperImpl::OnPpapiBrokerChannelCreated( | 
| 258     int request_id, | 258     int request_id, | 
| 259     base::ProcessId broker_pid, | 259     base::ProcessId broker_pid, | 
| 260     const IPC::ChannelHandle& handle) { | 260     const IPC::ChannelHandle& handle) { | 
| 261   scoped_refptr<PepperBroker>* broker_ptr = | 261   scoped_refptr<PepperBroker>* broker_ptr = | 
| 262       pending_connect_broker_.Lookup(request_id); | 262       pending_connect_broker_.Lookup(request_id); | 
| 263   if (broker_ptr) { | 263   if (broker_ptr) { | 
| 264     scoped_refptr<PepperBroker> broker = *broker_ptr; | 264     scoped_refptr<PepperBroker> broker = *broker_ptr; | 
| 265     pending_connect_broker_.Remove(request_id); | 265     pending_connect_broker_.Remove(request_id); | 
| 266     broker->OnBrokerChannelConnected(broker_pid, handle); | 266     broker->OnBrokerChannelConnected(broker_pid, handle); | 
| 267   } else { | 267   } else { | 
| 268     // There is no broker waiting for this channel. Close it so the broker can | 268     // There is no broker waiting for this channel. Close it so the broker can | 
| 269     // clean up and possibly exit. | 269     // clean up and possibly exit. | 
| 270     // The easiest way to clean it up is to just put it in an object | 270     // The easiest way to clean it up is to just put it in an object | 
| 271     // and then close them. This failure case is not performance critical. | 271     // and then close them. This failure case is not performance critical. | 
| 272     PepperBrokerDispatcherWrapper temp_dispatcher; | 272     PepperBrokerDispatcherWrapper temp_dispatcher; | 
| 273     temp_dispatcher.Init(broker_pid, handle); | 273     temp_dispatcher.Init(broker_pid, handle); | 
| 274   } | 274   } | 
| 275 } | 275 } | 
| 276 | 276 | 
| 277 // Iterates through pending_connect_broker_ to find the broker. | 277 // Iterates through pending_connect_broker_ to find the broker. | 
| 278 // Cannot use Lookup() directly because pending_connect_broker_ does not store | 278 // Cannot use Lookup() directly because pending_connect_broker_ does not store | 
| 279 // the raw pointer to the broker. Assumes maximum of one copy of broker exists. | 279 // the raw pointer to the broker. Assumes maximum of one copy of broker exists. | 
| 280 bool PepperPluginDelegateImpl::StopWaitingForBrokerConnection( | 280 bool PepperHelperImpl::StopWaitingForBrokerConnection( | 
| 281     PepperBroker* broker) { | 281     PepperBroker* broker) { | 
| 282   for (BrokerMap::iterator i(&pending_connect_broker_); | 282   for (BrokerMap::iterator i(&pending_connect_broker_); | 
| 283        !i.IsAtEnd(); i.Advance()) { | 283        !i.IsAtEnd(); i.Advance()) { | 
| 284     if (i.GetCurrentValue()->get() == broker) { | 284     if (i.GetCurrentValue()->get() == broker) { | 
| 285       pending_connect_broker_.Remove(i.GetCurrentKey()); | 285       pending_connect_broker_.Remove(i.GetCurrentKey()); | 
| 286       return true; | 286       return true; | 
| 287     } | 287     } | 
| 288   } | 288   } | 
| 289 | 289 | 
| 290   return false; | 290   return false; | 
| 291 } | 291 } | 
| 292 | 292 | 
| 293 void PepperPluginDelegateImpl::ViewWillInitiatePaint() { | 293 void PepperHelperImpl::ViewWillInitiatePaint() { | 
| 294   // Notify all of our instances that we started painting. This is used for | 294   // Notify all of our instances that we started painting. This is used for | 
| 295   // internal bookkeeping only, so we know that the set can not change under | 295   // internal bookkeeping only, so we know that the set can not change under | 
| 296   // us. | 296   // us. | 
| 297   for (std::set<PepperPluginInstanceImpl*>::iterator i = | 297   for (std::set<PepperPluginInstanceImpl*>::iterator i = | 
| 298            active_instances_.begin(); | 298            active_instances_.begin(); | 
| 299        i != active_instances_.end(); ++i) | 299        i != active_instances_.end(); ++i) | 
| 300     (*i)->ViewWillInitiatePaint(); | 300     (*i)->ViewWillInitiatePaint(); | 
| 301 } | 301 } | 
| 302 | 302 | 
| 303 void PepperPluginDelegateImpl::ViewInitiatedPaint() { | 303 void PepperHelperImpl::ViewInitiatedPaint() { | 
| 304   // Notify all instances that we painted.  The same caveats apply as for | 304   // Notify all instances that we painted.  The same caveats apply as for | 
| 305   // ViewFlushedPaint regarding instances closing themselves, so we take | 305   // ViewFlushedPaint regarding instances closing themselves, so we take | 
| 306   // similar precautions. | 306   // similar precautions. | 
| 307   std::set<PepperPluginInstanceImpl*> plugins = active_instances_; | 307   std::set<PepperPluginInstanceImpl*> plugins = active_instances_; | 
| 308   for (std::set<PepperPluginInstanceImpl*>::iterator i = plugins.begin(); | 308   for (std::set<PepperPluginInstanceImpl*>::iterator i = plugins.begin(); | 
| 309        i != plugins.end(); ++i) { | 309        i != plugins.end(); ++i) { | 
| 310     if (active_instances_.find(*i) != active_instances_.end()) | 310     if (active_instances_.find(*i) != active_instances_.end()) | 
| 311       (*i)->ViewInitiatedPaint(); | 311       (*i)->ViewInitiatedPaint(); | 
| 312   } | 312   } | 
| 313 } | 313 } | 
| 314 | 314 | 
| 315 void PepperPluginDelegateImpl::ViewFlushedPaint() { | 315 void PepperHelperImpl::ViewFlushedPaint() { | 
| 316   // Notify all instances that we flushed. This will call into the plugin, and | 316   // Notify all instances that we flushed. This will call into the plugin, and | 
| 317   // we it may ask to close itself as a result. This will, in turn, modify our | 317   // we it may ask to close itself as a result. This will, in turn, modify our | 
| 318   // set, possibly invalidating the iterator. So we iterate on a copy that | 318   // set, possibly invalidating the iterator. So we iterate on a copy that | 
| 319   // won't change out from under us. | 319   // won't change out from under us. | 
| 320   std::set<PepperPluginInstanceImpl*> plugins = active_instances_; | 320   std::set<PepperPluginInstanceImpl*> plugins = active_instances_; | 
| 321   for (std::set<PepperPluginInstanceImpl*>::iterator i = plugins.begin(); | 321   for (std::set<PepperPluginInstanceImpl*>::iterator i = plugins.begin(); | 
| 322        i != plugins.end(); ++i) { | 322        i != plugins.end(); ++i) { | 
| 323     // The copy above makes sure our iterator is never invalid if some plugins | 323     // The copy above makes sure our iterator is never invalid if some plugins | 
| 324     // are destroyed. But some plugin may decide to close all of its views in | 324     // are destroyed. But some plugin may decide to close all of its views in | 
| 325     // response to a paint in one of them, so we need to make sure each one is | 325     // response to a paint in one of them, so we need to make sure each one is | 
| 326     // still "current" before using it. | 326     // still "current" before using it. | 
| 327     // | 327     // | 
| 328     // It's possible that a plugin was destroyed, but another one was created | 328     // It's possible that a plugin was destroyed, but another one was created | 
| 329     // with the same address. In this case, we'll call ViewFlushedPaint on that | 329     // with the same address. In this case, we'll call ViewFlushedPaint on that | 
| 330     // new plugin. But that's OK for this particular case since we're just | 330     // new plugin. But that's OK for this particular case since we're just | 
| 331     // notifying all of our instances that the view flushed, and the new one is | 331     // notifying all of our instances that the view flushed, and the new one is | 
| 332     // one of our instances. | 332     // one of our instances. | 
| 333     // | 333     // | 
| 334     // What about the case where a new one is created in a callback at a new | 334     // What about the case where a new one is created in a callback at a new | 
| 335     // address and we don't issue the callback? We're still OK since this | 335     // address and we don't issue the callback? We're still OK since this | 
| 336     // callback is used for flush callbacks and we could not have possibly | 336     // callback is used for flush callbacks and we could not have possibly | 
| 337     // started a new paint (ViewWillInitiatePaint) for the new plugin while | 337     // started a new paint (ViewWillInitiatePaint) for the new plugin while | 
| 338     // processing a previous paint for an existing one. | 338     // processing a previous paint for an existing one. | 
| 339     if (active_instances_.find(*i) != active_instances_.end()) | 339     if (active_instances_.find(*i) != active_instances_.end()) | 
| 340       (*i)->ViewFlushedPaint(); | 340       (*i)->ViewFlushedPaint(); | 
| 341   } | 341   } | 
| 342 } | 342 } | 
| 343 | 343 | 
| 344 PepperPluginInstanceImpl* PepperPluginDelegateImpl:: | 344 PepperPluginInstanceImpl* PepperHelperImpl::GetBitmapForOptimizedPluginPaint( | 
| 345     GetBitmapForOptimizedPluginPaint( | 345     const gfx::Rect& paint_bounds, | 
| 346         const gfx::Rect& paint_bounds, | 346     TransportDIB** dib, | 
| 347         TransportDIB** dib, | 347     gfx::Rect* location, | 
| 348         gfx::Rect* location, | 348     gfx::Rect* clip, | 
| 349         gfx::Rect* clip, | 349     float* scale_factor) { | 
| 350         float* scale_factor) { |  | 
| 351   for (std::set<PepperPluginInstanceImpl*>::iterator i = | 350   for (std::set<PepperPluginInstanceImpl*>::iterator i = | 
| 352            active_instances_.begin(); | 351            active_instances_.begin(); | 
| 353        i != active_instances_.end(); ++i) { | 352        i != active_instances_.end(); ++i) { | 
| 354     PepperPluginInstanceImpl* instance = *i; | 353     PepperPluginInstanceImpl* instance = *i; | 
| 355     // In Flash fullscreen , the plugin contents should be painted onto the | 354     // In Flash fullscreen , the plugin contents should be painted onto the | 
| 356     // fullscreen widget instead of the web page. | 355     // fullscreen widget instead of the web page. | 
| 357     if (!instance->FlashIsFullscreenOrPending() && | 356     if (!instance->FlashIsFullscreenOrPending() && | 
| 358         instance->GetBitmapForOptimizedPluginPaint(paint_bounds, dib, location, | 357         instance->GetBitmapForOptimizedPluginPaint(paint_bounds, dib, location, | 
| 359                                                    clip, scale_factor)) | 358                                                    clip, scale_factor)) | 
| 360       return *i; | 359       return *i; | 
| 361   } | 360   } | 
| 362   return NULL; | 361   return NULL; | 
| 363 } | 362 } | 
| 364 | 363 | 
| 365 void PepperPluginDelegateImpl::PluginFocusChanged( | 364 void PepperHelperImpl::PluginFocusChanged( | 
| 366     PepperPluginInstanceImpl* instance, | 365     PepperPluginInstanceImpl* instance, | 
| 367     bool focused) { | 366     bool focused) { | 
| 368   if (focused) | 367   if (focused) | 
| 369     focused_plugin_ = instance; | 368     focused_plugin_ = instance; | 
| 370   else if (focused_plugin_ == instance) | 369   else if (focused_plugin_ == instance) | 
| 371     focused_plugin_ = NULL; | 370     focused_plugin_ = NULL; | 
| 372   if (render_view_) | 371   if (render_view_) | 
| 373     render_view_->PpapiPluginFocusChanged(); | 372     render_view_->PpapiPluginFocusChanged(); | 
| 374 } | 373 } | 
| 375 | 374 | 
| 376 void PepperPluginDelegateImpl::PluginTextInputTypeChanged( | 375 void PepperHelperImpl::PluginTextInputTypeChanged( | 
| 377     PepperPluginInstanceImpl* instance) { | 376     PepperPluginInstanceImpl* instance) { | 
| 378   if (focused_plugin_ == instance && render_view_) | 377   if (focused_plugin_ == instance && render_view_) | 
| 379     render_view_->PpapiPluginTextInputTypeChanged(); | 378     render_view_->PpapiPluginTextInputTypeChanged(); | 
| 380 } | 379 } | 
| 381 | 380 | 
| 382 void PepperPluginDelegateImpl::PluginCaretPositionChanged( | 381 void PepperHelperImpl::PluginCaretPositionChanged( | 
| 383     PepperPluginInstanceImpl* instance) { | 382     PepperPluginInstanceImpl* instance) { | 
| 384   if (focused_plugin_ == instance && render_view_) | 383   if (focused_plugin_ == instance && render_view_) | 
| 385     render_view_->PpapiPluginCaretPositionChanged(); | 384     render_view_->PpapiPluginCaretPositionChanged(); | 
| 386 } | 385 } | 
| 387 | 386 | 
| 388 void PepperPluginDelegateImpl::PluginRequestedCancelComposition( | 387 void PepperHelperImpl::PluginRequestedCancelComposition( | 
| 389     PepperPluginInstanceImpl* instance) { | 388     PepperPluginInstanceImpl* instance) { | 
| 390   if (focused_plugin_ == instance && render_view_) | 389   if (focused_plugin_ == instance && render_view_) | 
| 391     render_view_->PpapiPluginCancelComposition(); | 390     render_view_->PpapiPluginCancelComposition(); | 
| 392 } | 391 } | 
| 393 | 392 | 
| 394 void PepperPluginDelegateImpl::PluginSelectionChanged( | 393 void PepperHelperImpl::PluginSelectionChanged( | 
| 395     PepperPluginInstanceImpl* instance) { | 394     PepperPluginInstanceImpl* instance) { | 
| 396   if (focused_plugin_ == instance && render_view_) | 395   if (focused_plugin_ == instance && render_view_) | 
| 397     render_view_->PpapiPluginSelectionChanged(); | 396     render_view_->PpapiPluginSelectionChanged(); | 
| 398 } | 397 } | 
| 399 | 398 | 
| 400 void PepperPluginDelegateImpl::OnImeSetComposition( | 399 void PepperHelperImpl::OnImeSetComposition( | 
| 401     const string16& text, | 400     const string16& text, | 
| 402     const std::vector<WebKit::WebCompositionUnderline>& underlines, | 401     const std::vector<WebKit::WebCompositionUnderline>& underlines, | 
| 403     int selection_start, | 402     int selection_start, | 
| 404     int selection_end) { | 403     int selection_end) { | 
| 405   if (!IsPluginAcceptingCompositionEvents()) { | 404   if (!IsPluginAcceptingCompositionEvents()) { | 
| 406     composition_text_ = text; | 405     composition_text_ = text; | 
| 407   } else { | 406   } else { | 
| 408     // TODO(kinaba) currently all composition events are sent directly to | 407     // TODO(kinaba) currently all composition events are sent directly to | 
| 409     // plugins. Use DOM event mechanism after WebKit is made aware about | 408     // plugins. Use DOM event mechanism after WebKit is made aware about | 
| 410     // plugins that support composition. | 409     // plugins that support composition. | 
| 411     // The code below mimics the behavior of WebCore::Editor::setComposition. | 410     // The code below mimics the behavior of WebCore::Editor::setComposition. | 
| 412 | 411 | 
| 413     // Empty -> nonempty: composition started. | 412     // Empty -> nonempty: composition started. | 
| 414     if (composition_text_.empty() && !text.empty()) | 413     if (composition_text_.empty() && !text.empty()) | 
| 415       focused_plugin_->HandleCompositionStart(string16()); | 414       focused_plugin_->HandleCompositionStart(string16()); | 
| 416     // Nonempty -> empty: composition canceled. | 415     // Nonempty -> empty: composition canceled. | 
| 417     if (!composition_text_.empty() && text.empty()) | 416     if (!composition_text_.empty() && text.empty()) | 
| 418        focused_plugin_->HandleCompositionEnd(string16()); | 417        focused_plugin_->HandleCompositionEnd(string16()); | 
| 419     composition_text_ = text; | 418     composition_text_ = text; | 
| 420     // Nonempty: composition is ongoing. | 419     // Nonempty: composition is ongoing. | 
| 421     if (!composition_text_.empty()) { | 420     if (!composition_text_.empty()) { | 
| 422       focused_plugin_->HandleCompositionUpdate(composition_text_, underlines, | 421       focused_plugin_->HandleCompositionUpdate(composition_text_, underlines, | 
| 423                                                selection_start, selection_end); | 422                                                selection_start, selection_end); | 
| 424     } | 423     } | 
| 425   } | 424   } | 
| 426 } | 425 } | 
| 427 | 426 | 
| 428 void PepperPluginDelegateImpl::OnImeConfirmComposition(const string16& text) { | 427 void PepperHelperImpl::OnImeConfirmComposition(const string16& text) { | 
| 429   // Here, text.empty() has a special meaning. It means to commit the last | 428   // Here, text.empty() has a special meaning. It means to commit the last | 
| 430   // update of composition text (see RenderWidgetHost::ImeConfirmComposition()). | 429   // update of composition text (see RenderWidgetHost::ImeConfirmComposition()). | 
| 431   const string16& last_text = text.empty() ? composition_text_ : text; | 430   const string16& last_text = text.empty() ? composition_text_ : text; | 
| 432 | 431 | 
| 433   // last_text is empty only when both text and composition_text_ is. Ignore it. | 432   // last_text is empty only when both text and composition_text_ is. Ignore it. | 
| 434   if (last_text.empty()) | 433   if (last_text.empty()) | 
| 435     return; | 434     return; | 
| 436 | 435 | 
| 437   if (!IsPluginAcceptingCompositionEvents()) { | 436   if (!IsPluginAcceptingCompositionEvents()) { | 
| 438     for (size_t i = 0; i < text.size(); ++i) { | 437     for (size_t i = 0; i < text.size(); ++i) { | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 449     } | 448     } | 
| 450   } else { | 449   } else { | 
| 451     // Mimics the order of events sent by WebKit. | 450     // Mimics the order of events sent by WebKit. | 
| 452     // See WebCore::Editor::setComposition() for the corresponding code. | 451     // See WebCore::Editor::setComposition() for the corresponding code. | 
| 453     focused_plugin_->HandleCompositionEnd(last_text); | 452     focused_plugin_->HandleCompositionEnd(last_text); | 
| 454     focused_plugin_->HandleTextInput(last_text); | 453     focused_plugin_->HandleTextInput(last_text); | 
| 455   } | 454   } | 
| 456   composition_text_.clear(); | 455   composition_text_.clear(); | 
| 457 } | 456 } | 
| 458 | 457 | 
| 459 gfx::Rect PepperPluginDelegateImpl::GetCaretBounds() const { | 458 gfx::Rect PepperHelperImpl::GetCaretBounds() const { | 
| 460   if (!focused_plugin_) | 459   if (!focused_plugin_) | 
| 461     return gfx::Rect(0, 0, 0, 0); | 460     return gfx::Rect(0, 0, 0, 0); | 
| 462   return focused_plugin_->GetCaretBounds(); | 461   return focused_plugin_->GetCaretBounds(); | 
| 463 } | 462 } | 
| 464 | 463 | 
| 465 ui::TextInputType PepperPluginDelegateImpl::GetTextInputType() const { | 464 ui::TextInputType PepperHelperImpl::GetTextInputType() const { | 
| 466   if (!focused_plugin_) | 465   if (!focused_plugin_) | 
| 467     return ui::TEXT_INPUT_TYPE_NONE; | 466     return ui::TEXT_INPUT_TYPE_NONE; | 
| 468   return focused_plugin_->text_input_type(); | 467   return focused_plugin_->text_input_type(); | 
| 469 } | 468 } | 
| 470 | 469 | 
| 471 void PepperPluginDelegateImpl::GetSurroundingText(string16* text, | 470 void PepperHelperImpl::GetSurroundingText(string16* text, | 
| 472                                                   ui::Range* range) const { | 471                                           ui::Range* range) const { | 
| 473   if (!focused_plugin_) | 472   if (!focused_plugin_) | 
| 474     return; | 473     return; | 
| 475   return focused_plugin_->GetSurroundingText(text, range); | 474   return focused_plugin_->GetSurroundingText(text, range); | 
| 476 } | 475 } | 
| 477 | 476 | 
| 478 bool PepperPluginDelegateImpl::IsPluginAcceptingCompositionEvents() const { | 477 bool PepperHelperImpl::IsPluginAcceptingCompositionEvents() const { | 
| 479   if (!focused_plugin_) | 478   if (!focused_plugin_) | 
| 480     return false; | 479     return false; | 
| 481   return focused_plugin_->IsPluginAcceptingCompositionEvents(); | 480   return focused_plugin_->IsPluginAcceptingCompositionEvents(); | 
| 482 } | 481 } | 
| 483 | 482 | 
| 484 bool PepperPluginDelegateImpl::CanComposeInline() const { | 483 bool PepperHelperImpl::CanComposeInline() const { | 
| 485   return IsPluginAcceptingCompositionEvents(); | 484   return IsPluginAcceptingCompositionEvents(); | 
| 486 } | 485 } | 
| 487 | 486 | 
| 488 void PepperPluginDelegateImpl::InstanceCreated( | 487 void PepperHelperImpl::InstanceCreated( | 
| 489     PepperPluginInstanceImpl* instance) { | 488     PepperPluginInstanceImpl* instance) { | 
| 490   active_instances_.insert(instance); | 489   active_instances_.insert(instance); | 
| 491 | 490 | 
| 492   // Set the initial focus. | 491   // Set the initial focus. | 
| 493   instance->SetContentAreaFocus(render_view_->has_focus()); | 492   instance->SetContentAreaFocus(render_view_->has_focus()); | 
| 494 } | 493 } | 
| 495 | 494 | 
| 496 void PepperPluginDelegateImpl::InstanceDeleted( | 495 void PepperHelperImpl::InstanceDeleted( | 
| 497     PepperPluginInstanceImpl* instance) { | 496     PepperPluginInstanceImpl* instance) { | 
| 498   active_instances_.erase(instance); | 497   active_instances_.erase(instance); | 
| 499 | 498 | 
| 500   if (last_mouse_event_target_ == instance) | 499   if (last_mouse_event_target_ == instance) | 
| 501     last_mouse_event_target_ = NULL; | 500     last_mouse_event_target_ = NULL; | 
| 502   if (focused_plugin_ == instance) | 501   if (focused_plugin_ == instance) | 
| 503     PluginFocusChanged(instance, false); | 502     PluginFocusChanged(instance, false); | 
| 504 } | 503 } | 
| 505 | 504 | 
| 506 // If a broker has not already been created for this plugin, creates one. | 505 // If a broker has not already been created for this plugin, creates one. | 
| 507 PepperBroker* PepperPluginDelegateImpl::ConnectToBroker( | 506 PepperBroker* PepperHelperImpl::ConnectToBroker( | 
| 508     PPB_Broker_Impl* client) { | 507     PPB_Broker_Impl* client) { | 
| 509   DCHECK(client); | 508   DCHECK(client); | 
| 510 | 509 | 
| 511   PluginModule* plugin_module = ResourceHelper::GetPluginModule(client); | 510   PluginModule* plugin_module = ResourceHelper::GetPluginModule(client); | 
| 512   if (!plugin_module) | 511   if (!plugin_module) | 
| 513     return NULL; | 512     return NULL; | 
| 514 | 513 | 
| 515   scoped_refptr<PepperBroker> broker = | 514   scoped_refptr<PepperBroker> broker = | 
| 516       static_cast<PepperBroker*>(plugin_module->GetBroker()); | 515       static_cast<PepperBroker*>(plugin_module->GetBroker()); | 
| 517   if (!broker.get()) | 516   if (!broker.get()) | 
| 518     broker = CreateBroker(plugin_module); | 517     broker = CreateBroker(plugin_module); | 
| 519 | 518 | 
| 520   int request_id = pending_permission_requests_.Add( | 519   int request_id = pending_permission_requests_.Add( | 
| 521       new base::WeakPtr<PPB_Broker_Impl>(client->AsWeakPtr())); | 520       new base::WeakPtr<PPB_Broker_Impl>(client->AsWeakPtr())); | 
| 522   Send(new ViewHostMsg_RequestPpapiBrokerPermission( | 521   Send(new ViewHostMsg_RequestPpapiBrokerPermission( | 
| 523       routing_id(), | 522       routing_id(), | 
| 524       request_id, | 523       request_id, | 
| 525       client->GetDocumentUrl(), | 524       client->GetDocumentUrl(), | 
| 526       plugin_module->path())); | 525       plugin_module->path())); | 
| 527 | 526 | 
| 528   // Adds a reference, ensuring that the broker is not deleted when | 527   // Adds a reference, ensuring that the broker is not deleted when | 
| 529   // |broker| goes out of scope. | 528   // |broker| goes out of scope. | 
| 530   broker->AddPendingConnect(client); | 529   broker->AddPendingConnect(client); | 
| 531 | 530 | 
| 532   return broker.get(); | 531   return broker.get(); | 
| 533 } | 532 } | 
| 534 | 533 | 
| 535 void PepperPluginDelegateImpl::OnPpapiBrokerPermissionResult( | 534 void PepperHelperImpl::OnPpapiBrokerPermissionResult(int request_id, | 
| 536     int request_id, | 535                                                      bool result) { | 
| 537     bool result) { |  | 
| 538   scoped_ptr<base::WeakPtr<PPB_Broker_Impl> > client_ptr( | 536   scoped_ptr<base::WeakPtr<PPB_Broker_Impl> > client_ptr( | 
| 539       pending_permission_requests_.Lookup(request_id)); | 537       pending_permission_requests_.Lookup(request_id)); | 
| 540   DCHECK(client_ptr.get()); | 538   DCHECK(client_ptr.get()); | 
| 541   pending_permission_requests_.Remove(request_id); | 539   pending_permission_requests_.Remove(request_id); | 
| 542   base::WeakPtr<PPB_Broker_Impl> client = *client_ptr; | 540   base::WeakPtr<PPB_Broker_Impl> client = *client_ptr; | 
| 543   if (!client.get()) | 541   if (!client.get()) | 
| 544     return; | 542     return; | 
| 545 | 543 | 
| 546   PluginModule* plugin_module = ResourceHelper::GetPluginModule(client.get()); | 544   PluginModule* plugin_module = ResourceHelper::GetPluginModule(client.get()); | 
| 547   if (!plugin_module) | 545   if (!plugin_module) | 
| 548     return; | 546     return; | 
| 549 | 547 | 
| 550   PepperBroker* broker = static_cast<PepperBroker*>(plugin_module->GetBroker()); | 548   PepperBroker* broker = static_cast<PepperBroker*>(plugin_module->GetBroker()); | 
| 551   broker->OnBrokerPermissionResult(client.get(), result); | 549   broker->OnBrokerPermissionResult(client.get(), result); | 
| 552 } | 550 } | 
| 553 | 551 | 
| 554 bool PepperPluginDelegateImpl::AsyncOpenFile( | 552 bool PepperHelperImpl::AsyncOpenFile(const base::FilePath& path, | 
| 555     const base::FilePath& path, | 553                                      int flags, | 
| 556     int flags, | 554                                      const AsyncOpenFileCallback& callback) { | 
| 557     const AsyncOpenFileCallback& callback) { |  | 
| 558   int message_id = pending_async_open_files_.Add( | 555   int message_id = pending_async_open_files_.Add( | 
| 559       new AsyncOpenFileCallback(callback)); | 556       new AsyncOpenFileCallback(callback)); | 
| 560   return Send(new ViewHostMsg_AsyncOpenFile( | 557   return Send(new ViewHostMsg_AsyncOpenFile( | 
| 561       routing_id(), path, flags, message_id)); | 558       routing_id(), path, flags, message_id)); | 
| 562 } | 559 } | 
| 563 | 560 | 
| 564 void PepperPluginDelegateImpl::OnAsyncFileOpened( | 561 void PepperHelperImpl::OnAsyncFileOpened( | 
| 565     base::PlatformFileError error_code, | 562     base::PlatformFileError error_code, | 
| 566     IPC::PlatformFileForTransit file_for_transit, | 563     IPC::PlatformFileForTransit file_for_transit, | 
| 567     int message_id) { | 564     int message_id) { | 
| 568   AsyncOpenFileCallback* callback = | 565   AsyncOpenFileCallback* callback = | 
| 569       pending_async_open_files_.Lookup(message_id); | 566       pending_async_open_files_.Lookup(message_id); | 
| 570   DCHECK(callback); | 567   DCHECK(callback); | 
| 571   pending_async_open_files_.Remove(message_id); | 568   pending_async_open_files_.Remove(message_id); | 
| 572 | 569 | 
| 573   base::PlatformFile file = | 570   base::PlatformFile file = | 
| 574       IPC::PlatformFileForTransitToPlatformFile(file_for_transit); | 571       IPC::PlatformFileForTransitToPlatformFile(file_for_transit); | 
| 575   callback->Run(error_code, base::PassPlatformFile(&file)); | 572   callback->Run(error_code, base::PassPlatformFile(&file)); | 
| 576   // Make sure we won't leak file handle if the requester has died. | 573   // Make sure we won't leak file handle if the requester has died. | 
| 577   if (file != base::kInvalidPlatformFileValue) { | 574   if (file != base::kInvalidPlatformFileValue) { | 
| 578     base::FileUtilProxy::Close( | 575     base::FileUtilProxy::Close( | 
| 579         RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(), | 576         RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(), | 
| 580         file, | 577         file, | 
| 581         base::FileUtilProxy::StatusCallback()); | 578         base::FileUtilProxy::StatusCallback()); | 
| 582   } | 579   } | 
| 583   delete callback; | 580   delete callback; | 
| 584 } | 581 } | 
| 585 | 582 | 
| 586 void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) { | 583 void PepperHelperImpl::OnSetFocus(bool has_focus) { | 
| 587   for (std::set<PepperPluginInstanceImpl*>::iterator i = | 584   for (std::set<PepperPluginInstanceImpl*>::iterator i = | 
| 588            active_instances_.begin(); | 585            active_instances_.begin(); | 
| 589        i != active_instances_.end(); ++i) | 586        i != active_instances_.end(); ++i) | 
| 590     (*i)->SetContentAreaFocus(has_focus); | 587     (*i)->SetContentAreaFocus(has_focus); | 
| 591 } | 588 } | 
| 592 | 589 | 
| 593 void PepperPluginDelegateImpl::PageVisibilityChanged(bool is_visible) { | 590 void PepperHelperImpl::PageVisibilityChanged(bool is_visible) { | 
| 594   for (std::set<PepperPluginInstanceImpl*>::iterator i = | 591   for (std::set<PepperPluginInstanceImpl*>::iterator i = | 
| 595            active_instances_.begin(); | 592            active_instances_.begin(); | 
| 596        i != active_instances_.end(); ++i) | 593        i != active_instances_.end(); ++i) | 
| 597     (*i)->PageVisibilityChanged(is_visible); | 594     (*i)->PageVisibilityChanged(is_visible); | 
| 598 } | 595 } | 
| 599 | 596 | 
| 600 bool PepperPluginDelegateImpl::IsPluginFocused() const { | 597 bool PepperHelperImpl::IsPluginFocused() const { | 
| 601   return focused_plugin_ != NULL; | 598   return focused_plugin_ != NULL; | 
| 602 } | 599 } | 
| 603 | 600 | 
| 604 void PepperPluginDelegateImpl::WillHandleMouseEvent() { | 601 void PepperHelperImpl::WillHandleMouseEvent() { | 
| 605   // This method is called for every mouse event that the render view receives. | 602   // This method is called for every mouse event that the render view receives. | 
| 606   // And then the mouse event is forwarded to WebKit, which dispatches it to the | 603   // And then the mouse event is forwarded to WebKit, which dispatches it to the | 
| 607   // event target. Potentially a Pepper plugin will receive the event. | 604   // event target. Potentially a Pepper plugin will receive the event. | 
| 608   // In order to tell whether a plugin gets the last mouse event and which it | 605   // In order to tell whether a plugin gets the last mouse event and which it | 
| 609   // is, we set |last_mouse_event_target_| to NULL here. If a plugin gets the | 606   // is, we set |last_mouse_event_target_| to NULL here. If a plugin gets the | 
| 610   // event, it will notify us via DidReceiveMouseEvent() and set itself as | 607   // event, it will notify us via DidReceiveMouseEvent() and set itself as | 
| 611   // |last_mouse_event_target_|. | 608   // |last_mouse_event_target_|. | 
| 612   last_mouse_event_target_ = NULL; | 609   last_mouse_event_target_ = NULL; | 
| 613 } | 610 } | 
| 614 | 611 | 
| 615 void PepperPluginDelegateImpl::RegisterTCPSocket( | 612 void PepperHelperImpl::RegisterTCPSocket( | 
| 616     PPB_TCPSocket_Private_Impl* socket, | 613     PPB_TCPSocket_Private_Impl* socket, | 
| 617     uint32 socket_id) { | 614     uint32 socket_id) { | 
| 618   tcp_sockets_.AddWithID(socket, socket_id); | 615   tcp_sockets_.AddWithID(socket, socket_id); | 
| 619 } | 616 } | 
| 620 | 617 | 
| 621 void PepperPluginDelegateImpl::UnregisterTCPSocket(uint32 socket_id) { | 618 void PepperHelperImpl::UnregisterTCPSocket(uint32 socket_id) { | 
| 622   // There is no DCHECK(tcp_sockets_.Lookup(socket_id)) because this method | 619   // There is no DCHECK(tcp_sockets_.Lookup(socket_id)) because this method | 
| 623   // can be called before TCPSocketConnect or TCPSocketConnectWithNetAddress. | 620   // can be called before TCPSocketConnect or TCPSocketConnectWithNetAddress. | 
| 624   if (tcp_sockets_.Lookup(socket_id)) | 621   if (tcp_sockets_.Lookup(socket_id)) | 
| 625     tcp_sockets_.Remove(socket_id); | 622     tcp_sockets_.Remove(socket_id); | 
| 626 } | 623 } | 
| 627 | 624 | 
| 628 void PepperPluginDelegateImpl::TCPServerSocketStopListening(uint32 socket_id) { | 625 void PepperHelperImpl::TCPServerSocketStopListening(uint32 socket_id) { | 
| 629   tcp_server_sockets_.Remove(socket_id); | 626   tcp_server_sockets_.Remove(socket_id); | 
| 630 } | 627 } | 
| 631 | 628 | 
| 632 void PepperPluginDelegateImpl::HandleDocumentLoad( | 629 void PepperHelperImpl::HandleDocumentLoad( | 
| 633     PepperPluginInstanceImpl* instance, | 630     PepperPluginInstanceImpl* instance, | 
| 634     const WebKit::WebURLResponse& response) { | 631     const WebKit::WebURLResponse& response) { | 
| 635   DCHECK(!instance->document_loader()); | 632   DCHECK(!instance->document_loader()); | 
| 636 | 633 | 
| 637   PP_Instance pp_instance = instance->pp_instance(); | 634   PP_Instance pp_instance = instance->pp_instance(); | 
| 638   RendererPpapiHostImpl* host_impl = instance->module()->renderer_ppapi_host(); | 635   RendererPpapiHostImpl* host_impl = instance->module()->renderer_ppapi_host(); | 
| 639 | 636 | 
| 640   // Create a loader resource host for this load. Note that we have to set | 637   // Create a loader resource host for this load. Note that we have to set | 
| 641   // the document_loader before issuing the in-process | 638   // the document_loader before issuing the in-process | 
| 642   // PPP_Instance.HandleDocumentLoad call below, since this may reentrantly | 639   // PPP_Instance.HandleDocumentLoad call below, since this may reentrantly | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 679   } else { | 676   } else { | 
| 680     // Running out-of-process. Initiate an IPC call to notify the plugin | 677     // Running out-of-process. Initiate an IPC call to notify the plugin | 
| 681     // process. | 678     // process. | 
| 682     ppapi::proxy::HostDispatcher* dispatcher = | 679     ppapi::proxy::HostDispatcher* dispatcher = | 
| 683         ppapi::proxy::HostDispatcher::GetForInstance(pp_instance); | 680         ppapi::proxy::HostDispatcher::GetForInstance(pp_instance); | 
| 684     dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 681     dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 
| 685         ppapi::API_ID_PPP_INSTANCE, pp_instance, pending_host_id, data)); | 682         ppapi::API_ID_PPP_INSTANCE, pp_instance, pending_host_id, data)); | 
| 686   } | 683   } | 
| 687 } | 684 } | 
| 688 | 685 | 
| 689 RendererPpapiHost* PepperPluginDelegateImpl::CreateExternalPluginModule( | 686 RendererPpapiHost* PepperHelperImpl::CreateExternalPluginModule( | 
| 690     scoped_refptr<PluginModule> module, | 687     scoped_refptr<PluginModule> module, | 
| 691     const base::FilePath& path, | 688     const base::FilePath& path, | 
| 692     ppapi::PpapiPermissions permissions, | 689     ppapi::PpapiPermissions permissions, | 
| 693     const IPC::ChannelHandle& channel_handle, | 690     const IPC::ChannelHandle& channel_handle, | 
| 694     base::ProcessId peer_pid, | 691     base::ProcessId peer_pid, | 
| 695     int plugin_child_id) { | 692     int plugin_child_id) { | 
| 696   // We don't call PepperPluginRegistry::AddLiveModule, as this module is | 693   // We don't call PepperPluginRegistry::AddLiveModule, as this module is | 
| 697   // managed externally. | 694   // managed externally. | 
| 698   return CreateOutOfProcessModule(module.get(), | 695   return CreateOutOfProcessModule(module.get(), | 
| 699                                   path, | 696                                   path, | 
| 700                                   permissions, | 697                                   permissions, | 
| 701                                   channel_handle, | 698                                   channel_handle, | 
| 702                                   peer_pid, | 699                                   peer_pid, | 
| 703                                   plugin_child_id, | 700                                   plugin_child_id, | 
| 704                                   true);  // is_external = true | 701                                   true);  // is_external = true | 
| 705 } | 702 } | 
| 706 | 703 | 
| 707 void PepperPluginDelegateImpl::DidChangeCursor( | 704 void PepperHelperImpl::DidChangeCursor(PepperPluginInstanceImpl* instance, | 
| 708     PepperPluginInstanceImpl* instance, | 705                                        const WebKit::WebCursorInfo& cursor) { | 
| 709     const WebKit::WebCursorInfo& cursor) { |  | 
| 710   // Update the cursor appearance immediately if the requesting plugin is the | 706   // Update the cursor appearance immediately if the requesting plugin is the | 
| 711   // one which receives the last mouse event. Otherwise, the new cursor won't be | 707   // one which receives the last mouse event. Otherwise, the new cursor won't be | 
| 712   // picked up until the plugin gets the next input event. That is bad if, e.g., | 708   // picked up until the plugin gets the next input event. That is bad if, e.g., | 
| 713   // the plugin would like to set an invisible cursor when there isn't any user | 709   // the plugin would like to set an invisible cursor when there isn't any user | 
| 714   // input for a while. | 710   // input for a while. | 
| 715   if (instance == last_mouse_event_target_) | 711   if (instance == last_mouse_event_target_) | 
| 716     render_view_->didChangeCursor(cursor); | 712     render_view_->didChangeCursor(cursor); | 
| 717 } | 713 } | 
| 718 | 714 | 
| 719 void PepperPluginDelegateImpl::DidReceiveMouseEvent( | 715 void PepperHelperImpl::DidReceiveMouseEvent( | 
| 720     PepperPluginInstanceImpl* instance) { | 716     PepperPluginInstanceImpl* instance) { | 
| 721   last_mouse_event_target_ = instance; | 717   last_mouse_event_target_ = instance; | 
| 722 } | 718 } | 
| 723 | 719 | 
| 724 void PepperPluginDelegateImpl::SampleGamepads(WebKit::WebGamepads* data) { | 720 void PepperHelperImpl::SampleGamepads(WebKit::WebGamepads* data) { | 
| 725   if (!gamepad_shared_memory_reader_) | 721   if (!gamepad_shared_memory_reader_) | 
| 726     gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader); | 722     gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader); | 
| 727   gamepad_shared_memory_reader_->SampleGamepads(*data); | 723   gamepad_shared_memory_reader_->SampleGamepads(*data); | 
| 728 } | 724 } | 
| 729 | 725 | 
| 730 bool PepperPluginDelegateImpl::OnMessageReceived(const IPC::Message& message) { | 726 bool PepperHelperImpl::OnMessageReceived(const IPC::Message& message) { | 
| 731   if (pepper_browser_connection_.OnMessageReceived(message)) | 727   if (pepper_browser_connection_.OnMessageReceived(message)) | 
| 732     return true; | 728     return true; | 
| 733 | 729 | 
| 734   bool handled = true; | 730   bool handled = true; | 
| 735   IPC_BEGIN_MESSAGE_MAP(PepperPluginDelegateImpl, message) | 731   IPC_BEGIN_MESSAGE_MAP(PepperHelperImpl, message) | 
| 736     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ConnectACK, | 732     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ConnectACK, | 
| 737                         OnTCPSocketConnectACK) | 733                         OnTCPSocketConnectACK) | 
| 738     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SSLHandshakeACK, | 734     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SSLHandshakeACK, | 
| 739                         OnTCPSocketSSLHandshakeACK) | 735                         OnTCPSocketSSLHandshakeACK) | 
| 740     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ReadACK, OnTCPSocketReadACK) | 736     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ReadACK, OnTCPSocketReadACK) | 
| 741     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_WriteACK, OnTCPSocketWriteACK) | 737     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_WriteACK, OnTCPSocketWriteACK) | 
| 742     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SetOptionACK, | 738     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SetOptionACK, | 
| 743                         OnTCPSocketSetOptionACK) | 739                         OnTCPSocketSetOptionACK) | 
| 744     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPServerSocket_ListenACK, | 740     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPServerSocket_ListenACK, | 
| 745                         OnTCPServerSocketListenACK) | 741                         OnTCPServerSocketListenACK) | 
| 746     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPServerSocket_AcceptACK, | 742     IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPServerSocket_AcceptACK, | 
| 747                         OnTCPServerSocketAcceptACK) | 743                         OnTCPServerSocketAcceptACK) | 
| 748     IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated, | 744     IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated, | 
| 749                         OnPpapiBrokerChannelCreated) | 745                         OnPpapiBrokerChannelCreated) | 
| 750     IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened) | 746     IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened) | 
| 751     IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult, | 747     IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult, | 
| 752                         OnPpapiBrokerPermissionResult) | 748                         OnPpapiBrokerPermissionResult) | 
| 753     IPC_MESSAGE_UNHANDLED(handled = false) | 749     IPC_MESSAGE_UNHANDLED(handled = false) | 
| 754   IPC_END_MESSAGE_MAP() | 750   IPC_END_MESSAGE_MAP() | 
| 755   return handled; | 751   return handled; | 
| 756 } | 752 } | 
| 757 | 753 | 
| 758 void PepperPluginDelegateImpl::OnDestruct() { | 754 void PepperHelperImpl::OnDestruct() { | 
| 759   // Nothing to do here. Default implementation in RenderViewObserver does | 755   // Nothing to do here. Default implementation in RenderViewObserver does | 
| 760   // 'delete this' but it's not suitable for PepperPluginDelegateImpl because | 756   // 'delete this' but it's not suitable for PepperHelperImpl because | 
| 761   // it's non-pointer member in RenderViewImpl. | 757   // it's non-pointer member in RenderViewImpl. | 
| 762 } | 758 } | 
| 763 | 759 | 
| 764 void PepperPluginDelegateImpl::OnTCPSocketConnectACK( | 760 void PepperHelperImpl::OnTCPSocketConnectACK( | 
| 765     uint32 plugin_dispatcher_id, | 761     uint32 plugin_dispatcher_id, | 
| 766     uint32 socket_id, | 762     uint32 socket_id, | 
| 767     int32_t result, | 763     int32_t result, | 
| 768     const PP_NetAddress_Private& local_addr, | 764     const PP_NetAddress_Private& local_addr, | 
| 769     const PP_NetAddress_Private& remote_addr) { | 765     const PP_NetAddress_Private& remote_addr) { | 
| 770   PPB_TCPSocket_Private_Impl* socket = tcp_sockets_.Lookup(socket_id); | 766   PPB_TCPSocket_Private_Impl* socket = tcp_sockets_.Lookup(socket_id); | 
| 771   if (socket) | 767   if (socket) | 
| 772     socket->OnConnectCompleted(result, local_addr, remote_addr); | 768     socket->OnConnectCompleted(result, local_addr, remote_addr); | 
| 773   if (result != PP_OK) | 769   if (result != PP_OK) | 
| 774     tcp_sockets_.Remove(socket_id); | 770     tcp_sockets_.Remove(socket_id); | 
| 775 } | 771 } | 
| 776 | 772 | 
| 777 void PepperPluginDelegateImpl::OnTCPSocketSSLHandshakeACK( | 773 void PepperHelperImpl::OnTCPSocketSSLHandshakeACK( | 
| 778     uint32 plugin_dispatcher_id, | 774     uint32 plugin_dispatcher_id, | 
| 779     uint32 socket_id, | 775     uint32 socket_id, | 
| 780     bool succeeded, | 776     bool succeeded, | 
| 781     const ppapi::PPB_X509Certificate_Fields& certificate_fields) { | 777     const ppapi::PPB_X509Certificate_Fields& certificate_fields) { | 
| 782   PPB_TCPSocket_Private_Impl* socket = tcp_sockets_.Lookup(socket_id); | 778   PPB_TCPSocket_Private_Impl* socket = tcp_sockets_.Lookup(socket_id); | 
| 783   if (socket) | 779   if (socket) | 
| 784     socket->OnSSLHandshakeCompleted(succeeded, certificate_fields); | 780     socket->OnSSLHandshakeCompleted(succeeded, certificate_fields); | 
| 785 } | 781 } | 
| 786 | 782 | 
| 787 void PepperPluginDelegateImpl::OnTCPSocketReadACK(uint32 plugin_dispatcher_id, | 783 void PepperHelperImpl::OnTCPSocketReadACK(uint32 plugin_dispatcher_id, | 
| 788                                                   uint32 socket_id, | 784                                           uint32 socket_id, | 
| 789                                                   int32_t result, | 785                                           int32_t result, | 
| 790                                                   const std::string& data) { | 786                                           const std::string& data) { | 
| 791   PPB_TCPSocket_Private_Impl* socket = tcp_sockets_.Lookup(socket_id); | 787   PPB_TCPSocket_Private_Impl* socket = tcp_sockets_.Lookup(socket_id); | 
| 792   if (socket) | 788   if (socket) | 
| 793     socket->OnReadCompleted(result, data); | 789     socket->OnReadCompleted(result, data); | 
| 794 } | 790 } | 
| 795 | 791 | 
| 796 void PepperPluginDelegateImpl::OnTCPSocketWriteACK(uint32 plugin_dispatcher_id, | 792 void PepperHelperImpl::OnTCPSocketWriteACK(uint32 plugin_dispatcher_id, | 
| 797                                                    uint32 socket_id, | 793                                            uint32 socket_id, | 
| 798                                                    int32_t result) { | 794                                            int32_t result) { | 
| 799   PPB_TCPSocket_Private_Impl* socket = tcp_sockets_.Lookup(socket_id); | 795   PPB_TCPSocket_Private_Impl* socket = tcp_sockets_.Lookup(socket_id); | 
| 800   if (socket) | 796   if (socket) | 
| 801     socket->OnWriteCompleted(result); | 797     socket->OnWriteCompleted(result); | 
| 802 } | 798 } | 
| 803 | 799 | 
| 804 void PepperPluginDelegateImpl::OnTCPSocketSetOptionACK( | 800 void PepperHelperImpl::OnTCPSocketSetOptionACK( | 
| 805     uint32 plugin_dispatcher_id, | 801     uint32 plugin_dispatcher_id, | 
| 806     uint32 socket_id, | 802     uint32 socket_id, | 
| 807     int32_t result) { | 803     int32_t result) { | 
| 808   PPB_TCPSocket_Private_Impl* socket = tcp_sockets_.Lookup(socket_id); | 804   PPB_TCPSocket_Private_Impl* socket = tcp_sockets_.Lookup(socket_id); | 
| 809   if (socket) | 805   if (socket) | 
| 810     socket->OnSetOptionCompleted(result); | 806     socket->OnSetOptionCompleted(result); | 
| 811 } | 807 } | 
| 812 | 808 | 
| 813 void PepperPluginDelegateImpl::OnTCPServerSocketListenACK( | 809 void PepperHelperImpl::OnTCPServerSocketListenACK( | 
| 814     uint32 plugin_dispatcher_id, | 810     uint32 plugin_dispatcher_id, | 
| 815     PP_Resource socket_resource, | 811     PP_Resource socket_resource, | 
| 816     uint32 socket_id, | 812     uint32 socket_id, | 
| 817     const PP_NetAddress_Private& local_addr, | 813     const PP_NetAddress_Private& local_addr, | 
| 818     int32_t status) { | 814     int32_t status) { | 
| 819   ppapi::thunk::EnterResource<ppapi::thunk::PPB_TCPServerSocket_Private_API> | 815   ppapi::thunk::EnterResource<ppapi::thunk::PPB_TCPServerSocket_Private_API> | 
| 820       enter(socket_resource, true); | 816       enter(socket_resource, true); | 
| 821   if (enter.succeeded()) { | 817   if (enter.succeeded()) { | 
| 822     ppapi::PPB_TCPServerSocket_Shared* socket = | 818     ppapi::PPB_TCPServerSocket_Shared* socket = | 
| 823         static_cast<ppapi::PPB_TCPServerSocket_Shared*>(enter.object()); | 819         static_cast<ppapi::PPB_TCPServerSocket_Shared*>(enter.object()); | 
| 824     if (status == PP_OK) | 820     if (status == PP_OK) | 
| 825       tcp_server_sockets_.AddWithID(socket, socket_id); | 821       tcp_server_sockets_.AddWithID(socket, socket_id); | 
| 826     socket->OnListenCompleted(socket_id, local_addr, status); | 822     socket->OnListenCompleted(socket_id, local_addr, status); | 
| 827   } else if (socket_id != 0 && status == PP_OK) { | 823   } else if (socket_id != 0 && status == PP_OK) { | 
| 828     // StopListening was called before completion of Listen. | 824     // StopListening was called before completion of Listen. | 
| 829     Send(new PpapiHostMsg_PPBTCPServerSocket_Destroy(socket_id)); | 825     Send(new PpapiHostMsg_PPBTCPServerSocket_Destroy(socket_id)); | 
| 830   } | 826   } | 
| 831 } | 827 } | 
| 832 | 828 | 
| 833 void PepperPluginDelegateImpl::OnTCPServerSocketAcceptACK( | 829 void PepperHelperImpl::OnTCPServerSocketAcceptACK( | 
| 834     uint32 plugin_dispatcher_id, | 830     uint32 plugin_dispatcher_id, | 
| 835     uint32 server_socket_id, | 831     uint32 server_socket_id, | 
| 836     uint32 accepted_socket_id, | 832     uint32 accepted_socket_id, | 
| 837     const PP_NetAddress_Private& local_addr, | 833     const PP_NetAddress_Private& local_addr, | 
| 838     const PP_NetAddress_Private& remote_addr) { | 834     const PP_NetAddress_Private& remote_addr) { | 
| 839   ppapi::PPB_TCPServerSocket_Shared* socket = | 835   ppapi::PPB_TCPServerSocket_Shared* socket = | 
| 840       tcp_server_sockets_.Lookup(server_socket_id); | 836       tcp_server_sockets_.Lookup(server_socket_id); | 
| 841   if (socket) { | 837   if (socket) { | 
| 842     bool succeeded = (accepted_socket_id != 0); | 838     bool succeeded = (accepted_socket_id != 0); | 
| 843     socket->OnAcceptCompleted(succeeded, | 839     socket->OnAcceptCompleted(succeeded, | 
| 844                               accepted_socket_id, | 840                               accepted_socket_id, | 
| 845                               local_addr, | 841                               local_addr, | 
| 846                               remote_addr); | 842                               remote_addr); | 
| 847   } else if (accepted_socket_id != 0) { | 843   } else if (accepted_socket_id != 0) { | 
| 848     Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(accepted_socket_id)); | 844     Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(accepted_socket_id)); | 
| 849   } | 845   } | 
| 850 } | 846 } | 
| 851 | 847 | 
| 852 }  // namespace content | 848 }  // namespace content | 
| OLD | NEW | 
|---|