diff options
author | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-05 18:27:10 +0000 |
---|---|---|
committer | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-05 18:27:10 +0000 |
commit | fb3ac0dc2399fe55c40cfc6b6a1d68669176531f (patch) | |
tree | f608080916e0099b1f37158c79d5badd9c8dbdcc | |
parent | d0fef94d21559d72a47dc44a23d2adf147e79264 (diff) | |
download | chromium_src-fb3ac0dc2399fe55c40cfc6b6a1d68669176531f.zip chromium_src-fb3ac0dc2399fe55c40cfc6b6a1d68669176531f.tar.gz chromium_src-fb3ac0dc2399fe55c40cfc6b6a1d68669176531f.tar.bz2 |
Revert 214920 "Pepper: Make PepperPluginInstance::Navigate async."
> Pepper: Make PepperPluginInstance::Navigate async.
>
> The primary motivation for this change is to enable the FileRef refactor; an
> operation that Navigate depends on must be made asychronous. However, this
> change cleans up some weirdness in PepperFlashRendererHost anyway, so I think
> it's worth submitting as is so far. Plus, it makes sure this change is viable
> before I go through modifying the whole call chain.
>
> TBR=joi
> BUG=225441
>
> Review URL: https://chromiumcodereview.appspot.com/21340006
TBR=teravest@chromium.org
Review URL: https://codereview.chromium.org/21794004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215647 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 41 insertions, 62 deletions
diff --git a/chrome/renderer/pepper/pepper_flash_renderer_host.cc b/chrome/renderer/pepper/pepper_flash_renderer_host.cc index 7e8b421..e305946 100644 --- a/chrome/renderer/pepper/pepper_flash_renderer_host.cc +++ b/chrome/renderer/pepper/pepper_flash_renderer_host.cc @@ -220,16 +220,20 @@ int32_t PepperFlashRendererHost::OnNavigate( ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); host_dispatcher->set_allow_plugin_reentrancy(); + // Grab a weak pointer to ourselves on the stack so we can check if we are + // still alive. + base::WeakPtr<PepperFlashRendererHost> weak_ptr = weak_factory_.GetWeakPtr(); // Keep track of reply contexts in case we are destroyed during a Navigate // call. Even if we are destroyed, we still need to send these replies to // unblock the plugin process. navigate_replies_.push_back(host_context->MakeReplyMessageContext()); - - // If the object is destroyed before the callback is invoked, the reply will - // be sent by the destructor. - plugin_instance->Navigate(data, target.c_str(), from_user_action, - base::Bind(&PepperFlashRendererHost::DidNavigate, - weak_factory_.GetWeakPtr())); + plugin_instance->Navigate(data, target.c_str(), from_user_action); + // This object might have been destroyed by this point. If it is destroyed + // the reply will be sent in the destructor. Otherwise send the reply here. + if (weak_ptr.get()) { + SendReply(navigate_replies_.back(), IPC::Message()); + navigate_replies_.pop_back(); + } // Return PP_OK_COMPLETIONPENDING so that no reply is automatically sent. return PP_OK_COMPLETIONPENDING; @@ -252,9 +256,4 @@ int32_t PepperFlashRendererHost::OnInvokePrinting( return PP_OK; } -void PepperFlashRendererHost::DidNavigate(int32_t unused) { - SendReply(navigate_replies_.back(), IPC::Message()); - navigate_replies_.pop_back(); -} - } // namespace chrome diff --git a/chrome/renderer/pepper/pepper_flash_renderer_host.h b/chrome/renderer/pepper/pepper_flash_renderer_host.h index ede076b..299b109 100644 --- a/chrome/renderer/pepper/pepper_flash_renderer_host.h +++ b/chrome/renderer/pepper/pepper_flash_renderer_host.h @@ -59,8 +59,6 @@ class PepperFlashRendererHost : public ppapi::host::ResourceHost { const PP_Rect& rect); int32_t OnInvokePrinting(ppapi::host::HostMessageContext* host_context); - void DidNavigate(int32_t unused); - base::WeakPtrFactory<PepperFlashRendererHost> weak_factory_; // A stack of ReplyMessageContexts to track Navigate() calls which have not // yet been replied to. diff --git a/content/public/renderer/pepper_plugin_instance.h b/content/public/renderer/pepper_plugin_instance.h index 8b48bfa..211752d 100644 --- a/content/public/renderer/pepper_plugin_instance.h +++ b/content/public/renderer/pepper_plugin_instance.h @@ -6,7 +6,6 @@ #define CONTENT_PUBLIC_RENDERER_PEPPER_PLUGIN_INSTANCE_H_ #include "base/basictypes.h" -#include "base/callback_forward.h" #include "base/process/process_handle.h" #include "content/common/content_export.h" #include "ppapi/c/pp_resource.h" @@ -90,10 +89,10 @@ class PepperPluginInstance { virtual bool IsRectTopmost(const gfx::Rect& rect) = 0; - virtual void Navigate(const ppapi::URLRequestInfoData& request, - const char* target, - bool from_user_action, - const base::Callback<void(int32_t)>& callback) = 0; + virtual int32_t Navigate(const ppapi::URLRequestInfoData& request, + const char* target, + bool from_user_action) = 0; + }; } // namespace content diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.cc b/content/renderer/pepper/pepper_plugin_instance_impl.cc index 869850a..7cd0e0ba 100644 --- a/content/renderer/pepper/pepper_plugin_instance_impl.cc +++ b/content/renderer/pepper/pepper_plugin_instance_impl.cc @@ -2685,65 +2685,49 @@ bool PepperPluginInstanceImpl::IsRectTopmost(const gfx::Rect& rect) { return container_->isRectTopmost(rect); } -void PepperPluginInstanceImpl::Navigate( +int32_t PepperPluginInstanceImpl::Navigate( const ::ppapi::URLRequestInfoData& request, const char* target, - bool from_user_action, - const base::Callback<void(int32_t)>& callback) { - if (!container_) { - base::MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(callback, static_cast<int32_t>(PP_ERROR_FAILED))); - return; - } + bool from_user_action) { + if (!container_) + return PP_ERROR_FAILED; WebDocument document = container_->element().document(); WebFrame* frame = document.frame(); - if (!frame) { - base::MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(callback, static_cast<int32_t>(PP_ERROR_FAILED))); - return; - } + if (!frame) + return PP_ERROR_FAILED; ::ppapi::URLRequestInfoData completed_request = request; WebURLRequest web_request; - if (!CreateWebURLRequest(&completed_request, frame, &web_request)) { - base::MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(callback, static_cast<int32_t>(PP_ERROR_FAILED))); - return; - } + if (!CreateWebURLRequest(&completed_request, frame, &web_request)) + return PP_ERROR_FAILED; web_request.setFirstPartyForCookies(document.firstPartyForCookies()); web_request.setHasUserGesture(from_user_action); GURL gurl(web_request.url()); - - int32_t rc = PP_ERROR_FAILED; if (gurl.SchemeIs("javascript")) { // In imitation of the NPAPI implementation, only |target_frame == frame| is // allowed for security reasons. WebFrame* target_frame = frame->view()->findFrameByName(WebString::fromUTF8(target), frame); - if (target_frame != frame) { - rc = PP_ERROR_NOACCESS; - } else { - // TODO(viettrungluu): NPAPI sends the result back to the plugin -- do we - // need that? - WebString result = container_->executeScriptURL(gurl, from_user_action); - rc = result.isNull() ? PP_ERROR_FAILED : PP_OK; - } - } else { - // Only GETs and POSTs are supported. - if (web_request.httpMethod() != "GET" && - web_request.httpMethod() != "POST") { - rc = PP_ERROR_BADARGUMENT; - } else { - WebString target_str = WebString::fromUTF8(target); - container_->loadFrameRequest(web_request, target_str, false, NULL); - rc = PP_OK; - } + if (target_frame != frame) + return PP_ERROR_NOACCESS; + + // TODO(viettrungluu): NPAPI sends the result back to the plugin -- do we + // need that? + WebString result = container_->executeScriptURL(gurl, from_user_action); + return result.isNull() ? PP_ERROR_FAILED : PP_OK; } - base::MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(callback, static_cast<int32_t>(rc))); + + // Only GETs and POSTs are supported. + if (web_request.httpMethod() != "GET" && + web_request.httpMethod() != "POST") + return PP_ERROR_BADARGUMENT; + + WebString target_str = WebString::fromUTF8(target); + container_->loadFrameRequest(web_request, target_str, false, NULL); + return PP_OK; } bool PepperPluginInstanceImpl::CanAccessMainFrame() const { diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.h b/content/renderer/pepper/pepper_plugin_instance_impl.h index 3f5b886..c1eac40 100644 --- a/content/renderer/pepper/pepper_plugin_instance_impl.h +++ b/content/renderer/pepper/pepper_plugin_instance_impl.h @@ -368,10 +368,9 @@ class CONTENT_EXPORT PepperPluginInstanceImpl virtual bool IsFullPagePlugin() OVERRIDE; virtual void FlashSetFullscreen(bool fullscreen, bool delay_report) OVERRIDE; virtual bool IsRectTopmost(const gfx::Rect& rect) OVERRIDE; - virtual void Navigate(const ::ppapi::URLRequestInfoData& request, - const char* target, - bool from_user_action, - const base::Callback<void(int32_t)>& callback) OVERRIDE; + virtual int32_t Navigate(const ::ppapi::URLRequestInfoData& request, + const char* target, + bool from_user_action) OVERRIDE; // PPB_Instance_API implementation. virtual PP_Bool BindGraphics(PP_Instance instance, |