diff options
-rw-r--r-- | chrome/common/plugin_messages.h | 74 | ||||
-rw-r--r-- | chrome/common/plugin_messages_internal.h | 44 | ||||
-rw-r--r-- | chrome/plugin/webplugin_delegate_stub.cc | 33 | ||||
-rw-r--r-- | chrome/plugin/webplugin_delegate_stub.h | 25 | ||||
-rw-r--r-- | chrome/plugin/webplugin_proxy.cc | 59 | ||||
-rw-r--r-- | chrome/plugin/webplugin_proxy.h | 35 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.cc | 34 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.h | 14 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_proxy.cc | 92 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_proxy.h | 23 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_host.cc | 27 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_instance.cc | 128 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_instance.h | 64 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_impl.cc | 33 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_impl.h | 16 | ||||
-rw-r--r-- | webkit/glue/webplugin.h | 22 | ||||
-rw-r--r-- | webkit/glue/webplugin_delegate.h | 15 | ||||
-rw-r--r-- | webkit/glue/webplugin_impl.cc | 146 | ||||
-rw-r--r-- | webkit/glue/webplugin_impl.h | 50 |
19 files changed, 425 insertions, 509 deletions
diff --git a/chrome/common/plugin_messages.h b/chrome/common/plugin_messages.h index 736e55e..74de33f 100644 --- a/chrome/common/plugin_messages.h +++ b/chrome/common/plugin_messages.h @@ -42,25 +42,14 @@ struct PluginMsg_Init_Params { }; struct PluginHostMsg_URLRequest_Params { + std::string url; std::string method; - bool is_javascript_url; std::string target; std::vector<char> buffer; - bool is_file_data; - bool notify; - std::string url; - intptr_t notify_data; + int notify_id; bool popups_allowed; }; -struct PluginMsg_URLRequestReply_Params { - unsigned long resource_id; - GURL url; - bool notify_needed; - intptr_t notify_data; - intptr_t stream; -}; - struct PluginMsg_DidReceiveResponseParams { unsigned long id; std::string mime_type; @@ -163,45 +152,33 @@ template <> struct ParamTraits<PluginHostMsg_URLRequest_Params> { typedef PluginHostMsg_URLRequest_Params param_type; static void Write(Message* m, const param_type& p) { + WriteParam(m, p.url); WriteParam(m, p.method); - WriteParam(m, p.is_javascript_url); WriteParam(m, p.target); WriteParam(m, p.buffer); - WriteParam(m, p.is_file_data); - WriteParam(m, p.notify); - WriteParam(m, p.url); - WriteParam(m, p.notify_data); + WriteParam(m, p.notify_id); WriteParam(m, p.popups_allowed); } static bool Read(const Message* m, void** iter, param_type* p) { return + ReadParam(m, iter, &p->url) && ReadParam(m, iter, &p->method) && - ReadParam(m, iter, &p->is_javascript_url) && ReadParam(m, iter, &p->target) && ReadParam(m, iter, &p->buffer) && - ReadParam(m, iter, &p->is_file_data) && - ReadParam(m, iter, &p->notify) && - ReadParam(m, iter, &p->url) && - ReadParam(m, iter, &p->notify_data) && + ReadParam(m, iter, &p->notify_id) && ReadParam(m, iter, &p->popups_allowed); } static void Log(const param_type& p, std::wstring* l) { l->append(L"("); - LogParam(p.method, l); + LogParam(p.url, l); l->append(L", "); - LogParam(p.is_javascript_url, l); + LogParam(p.method, l); l->append(L", "); LogParam(p.target, l); l->append(L", "); LogParam(p.buffer, l); l->append(L", "); - LogParam(p.is_file_data, l); - l->append(L", "); - LogParam(p.notify, l); - l->append(L", "); - LogParam(p.url, l); - l->append(L", "); - LogParam(p.notify_data, l); + LogParam(p.notify_id, l); l->append(L", "); LogParam(p.popups_allowed, l); l->append(L")"); @@ -209,39 +186,6 @@ struct ParamTraits<PluginHostMsg_URLRequest_Params> { }; template <> -struct ParamTraits<PluginMsg_URLRequestReply_Params> { - typedef PluginMsg_URLRequestReply_Params param_type; - static void Write(Message* m, const param_type& p) { - WriteParam(m, p.resource_id); - WriteParam(m, p.url); - WriteParam(m, p.notify_needed); - WriteParam(m, p.notify_data); - WriteParam(m, p.stream); - } - static bool Read(const Message* m, void** iter, param_type* p) { - return - ReadParam(m, iter, &p->resource_id) && - ReadParam(m, iter, &p->url) && - ReadParam(m, iter, &p->notify_needed) && - ReadParam(m, iter, &p->notify_data) && - ReadParam(m, iter, &p->stream); - } - static void Log(const param_type& p, std::wstring* l) { - l->append(L"("); - LogParam(p.resource_id, l); - l->append(L", "); - LogParam(p.url, l); - l->append(L", "); - LogParam(p.notify_needed, l); - l->append(L", "); - LogParam(p.notify_data, l); - l->append(L", "); - LogParam(p.stream, l); - l->append(L")"); - } -}; - -template <> struct ParamTraits<PluginMsg_DidReceiveResponseParams> { typedef PluginMsg_DidReceiveResponseParams param_type; static void Write(Message* m, const param_type& p) { diff --git a/chrome/common/plugin_messages_internal.h b/chrome/common/plugin_messages_internal.h index c220b8b..f65816c 100644 --- a/chrome/common/plugin_messages_internal.h +++ b/chrome/common/plugin_messages_internal.h @@ -202,14 +202,13 @@ IPC_BEGIN_MESSAGES(Plugin) base::SharedMemoryHandle /* shared_memory*/, size_t /* size */) - IPC_SYNC_MESSAGE_ROUTED0_2(PluginMsg_GetPluginScriptableObject, - int /* route_id */, - intptr_t /* npobject_ptr */) + IPC_SYNC_MESSAGE_ROUTED0_1(PluginMsg_GetPluginScriptableObject, + int /* route_id */) - IPC_SYNC_MESSAGE_ROUTED3_0(PluginMsg_DidFinishLoadWithReason, - GURL /* url */, - int /* reason */, - intptr_t /* notify_data */) + IPC_MESSAGE_ROUTED3(PluginMsg_DidFinishLoadWithReason, + GURL /* url */, + int /* reason */, + int /* notify_id */) // Updates the plugin location. IPC_MESSAGE_ROUTED1(PluginMsg_UpdateGeometry, @@ -244,12 +243,11 @@ IPC_BEGIN_MESSAGES(Plugin) IPC_MESSAGE_ROUTED1(PluginMsg_DidFail, unsigned long /* id */) - IPC_MESSAGE_ROUTED5(PluginMsg_SendJavaScriptStream, + IPC_MESSAGE_ROUTED4(PluginMsg_SendJavaScriptStream, GURL /* url */, std::string /* result */, bool /* success */, - bool /* notify required */, - intptr_t /* notify data */) + int /* notify_id */) IPC_MESSAGE_ROUTED2(PluginMsg_DidReceiveManualResponse, GURL /* url */, @@ -264,8 +262,14 @@ IPC_BEGIN_MESSAGES(Plugin) IPC_MESSAGE_ROUTED0(PluginMsg_InstallMissingPlugin) - IPC_SYNC_MESSAGE_ROUTED1_0(PluginMsg_HandleURLRequestReply, - PluginMsg_URLRequestReply_Params) + IPC_MESSAGE_ROUTED3(PluginMsg_HandleURLRequestReply, + unsigned long /* resource_id */, + GURL /* url */, + int /* notify_id */) + + IPC_MESSAGE_ROUTED2(PluginMsg_HTTPRangeRequestReply, + unsigned long /* resource_id */, + int /* range_request_id */) IPC_SYNC_MESSAGE_ROUTED0_1(PluginMsg_CreateCommandBuffer, int /* route_id */) @@ -307,15 +311,13 @@ IPC_BEGIN_MESSAGES(PluginHost) IPC_MESSAGE_ROUTED1(PluginHostMsg_InvalidateRect, gfx::Rect /* rect */) - IPC_SYNC_MESSAGE_ROUTED1_2(PluginHostMsg_GetWindowScriptNPObject, + IPC_SYNC_MESSAGE_ROUTED1_1(PluginHostMsg_GetWindowScriptNPObject, int /* route id */, - bool /* success */, - intptr_t /* npobject_ptr */) + bool /* success */) - IPC_SYNC_MESSAGE_ROUTED1_2(PluginHostMsg_GetPluginElement, + IPC_SYNC_MESSAGE_ROUTED1_1(PluginHostMsg_GetPluginElement, int /* route id */, - bool /* success */, - intptr_t /* npobject_ptr */) + bool /* success */) IPC_MESSAGE_ROUTED3(PluginHostMsg_SetCookie, GURL /* url */, @@ -356,12 +358,10 @@ IPC_BEGIN_MESSAGES(PluginHost) IPC_MESSAGE_ROUTED0(PluginHostMsg_CancelDocumentLoad) - IPC_MESSAGE_ROUTED5(PluginHostMsg_InitiateHTTPRangeRequest, + IPC_MESSAGE_ROUTED3(PluginHostMsg_InitiateHTTPRangeRequest, std::string /* url */, std::string /* range_info */, - intptr_t /* existing_stream */, - bool /* notify_needed */, - intptr_t /* notify_data */) + int /* range_request_id */) IPC_MESSAGE_ROUTED2(PluginHostMsg_DeferResourceLoading, unsigned long /* resource_id */, diff --git a/chrome/plugin/webplugin_delegate_stub.cc b/chrome/plugin/webplugin_delegate_stub.cc index 49c535c..1764366 100644 --- a/chrome/plugin/webplugin_delegate_stub.cc +++ b/chrome/plugin/webplugin_delegate_stub.cc @@ -130,6 +130,8 @@ void WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(PluginMsg_InstallMissingPlugin, OnInstallMissingPlugin) IPC_MESSAGE_HANDLER(PluginMsg_HandleURLRequestReply, OnHandleURLRequestReply) + IPC_MESSAGE_HANDLER(PluginMsg_HTTPRangeRequestReply, + OnHTTPRangeRequestReply) IPC_MESSAGE_HANDLER(PluginMsg_CreateCommandBuffer, OnCreateCommandBuffer) IPC_MESSAGE_UNHANDLED_ERROR() @@ -237,8 +239,8 @@ void WebPluginDelegateStub::OnDidFail(int id) { } void WebPluginDelegateStub::OnDidFinishLoadWithReason( - const GURL& url, int reason, intptr_t notify_data) { - delegate_->DidFinishLoadWithReason(url, reason, notify_data); + const GURL& url, int reason, int notify_id) { + delegate_->DidFinishLoadWithReason(url, reason, notify_id); } void WebPluginDelegateStub::OnSetFocus() { @@ -304,9 +306,7 @@ void WebPluginDelegateStub::OnUpdateGeometry( ); } -void WebPluginDelegateStub::OnGetPluginScriptableObject( - int* route_id, - intptr_t* npobject_ptr) { +void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id) { NPObject* object = delegate_->GetPluginScriptableObject(); if (!object) { *route_id = MSG_ROUTING_NONE; @@ -314,7 +314,6 @@ void WebPluginDelegateStub::OnGetPluginScriptableObject( } *route_id = channel_->GenerateRouteID(); - *npobject_ptr = reinterpret_cast<intptr_t>(object); // The stub will delete itself when the proxy tells it that it's released, or // otherwise when the channel is closed. new NPObjectStub( @@ -328,10 +327,8 @@ void WebPluginDelegateStub::OnGetPluginScriptableObject( void WebPluginDelegateStub::OnSendJavaScriptStream(const GURL& url, const std::string& result, bool success, - bool notify_needed, - intptr_t notify_data) { - delegate_->SendJavaScriptStream(url, result, success, notify_needed, - notify_data); + int notify_id) { + delegate_->SendJavaScriptStream(url, result, success, notify_id); } void WebPluginDelegateStub::OnDidReceiveManualResponse( @@ -404,11 +401,15 @@ void WebPluginDelegateStub::CreateSharedBuffer( } void WebPluginDelegateStub::OnHandleURLRequestReply( - const PluginMsg_URLRequestReply_Params& params) { + unsigned long resource_id, const GURL& url, int notify_id) { WebPluginResourceClient* resource_client = - delegate_->CreateResourceClient(params.resource_id, params.url, - params.notify_needed, - params.notify_data, - params.stream); - webplugin_->OnResourceCreated(params.resource_id, resource_client); + delegate_->CreateResourceClient(resource_id, url, notify_id); + webplugin_->OnResourceCreated(resource_id, resource_client); +} + +void WebPluginDelegateStub::OnHTTPRangeRequestReply( + unsigned long resource_id, int range_request_id) { + WebPluginResourceClient* resource_client = + delegate_->CreateSeekableResourceClient(resource_id, range_request_id); + webplugin_->OnResourceCreated(resource_id, resource_client); } diff --git a/chrome/plugin/webplugin_delegate_stub.h b/chrome/plugin/webplugin_delegate_stub.h index 34358fa..ddc8632 100644 --- a/chrome/plugin/webplugin_delegate_stub.h +++ b/chrome/plugin/webplugin_delegate_stub.h @@ -24,7 +24,6 @@ class WebPluginProxy; struct PluginMsg_Init_Params; struct PluginMsg_DidReceiveResponseParams; struct PluginMsg_UpdateGeometry_Param; -struct PluginMsg_URLRequestReply_Params; class WebCursor; namespace WebKit { @@ -59,32 +58,25 @@ class WebPluginDelegateStub : public IPC::Channel::Listener, // Message handlers for the WebPluginDelegate calls that are proxied from the // renderer over the IPC channel. void OnInit(const PluginMsg_Init_Params& params, bool* result); - void OnWillSendRequest(int id, const GURL& url); void OnDidReceiveResponse(const PluginMsg_DidReceiveResponseParams& params); void OnDidReceiveData(int id, const std::vector<char>& buffer, int data_offset); void OnDidFinishLoading(int id); void OnDidFail(int id); - - void OnDidFinishLoadWithReason(const GURL& url, int reason, - intptr_t notify_data); + void OnDidFinishLoadWithReason(const GURL& url, int reason, int notify_id); void OnSetFocus(); void OnHandleInputEvent(const WebKit::WebInputEvent* event, bool* handled, WebCursor* cursor); - void OnPaint(const gfx::Rect& damaged_rect); void OnDidPaint(); - void OnPrint(base::SharedMemoryHandle* shared_memory, size_t* size); - void OnUpdateGeometry(const PluginMsg_UpdateGeometry_Param& param); - void OnGetPluginScriptableObject(int* route_id, intptr_t* npobject_ptr); + void OnGetPluginScriptableObject(int* route_id); void OnSendJavaScriptStream(const GURL& url, const std::string& result, - bool success, bool notify_needed, - intptr_t notify_data); - + bool success, + int notify_id); void OnDidReceiveManualResponse( const GURL& url, const PluginMsg_DidReceiveResponseParams& params); @@ -92,12 +84,11 @@ class WebPluginDelegateStub : public IPC::Channel::Listener, void OnDidFinishManualLoading(); void OnDidManualLoadFail(); void OnInstallMissingPlugin(); - - void OnHandleURLRequestReply( - const PluginMsg_URLRequestReply_Params& params); - + void OnHandleURLRequestReply(unsigned long resource_id, + const GURL& url, + int notify_id); + void OnHTTPRangeRequestReply(unsigned long resource_id, int range_request_id); void OnCreateCommandBuffer(int* route_id); - void CreateSharedBuffer(size_t size, base::SharedMemory* shared_buf, base::SharedMemoryHandle* remote_handle); diff --git a/chrome/plugin/webplugin_proxy.cc b/chrome/plugin/webplugin_proxy.cc index 34091e9..a05113b 100644 --- a/chrome/plugin/webplugin_proxy.cc +++ b/chrome/plugin/webplugin_proxy.cc @@ -26,7 +26,6 @@ #include "chrome/plugin/npobject_util.h" #include "chrome/plugin/plugin_channel.h" #include "chrome/plugin/plugin_thread.h" -#include "chrome/plugin/webplugin_delegate_stub.h" #include "skia/ext/platform_device.h" #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h" #include "webkit/glue/plugins/webplugin_delegate_impl.h" @@ -151,9 +150,8 @@ NPObject* WebPluginProxy::GetWindowScriptNPObject() { int npobject_route_id = channel_->GenerateRouteID(); bool success = false; - intptr_t npobject_ptr = NULL; Send(new PluginHostMsg_GetWindowScriptNPObject( - route_id_, npobject_route_id, &success, &npobject_ptr)); + route_id_, npobject_route_id, &success)); if (!success) return NULL; @@ -169,9 +167,7 @@ NPObject* WebPluginProxy::GetPluginElement() { int npobject_route_id = channel_->GenerateRouteID(); bool success = false; - intptr_t npobject_ptr = NULL; - Send(new PluginHostMsg_GetPluginElement( - route_id_, npobject_route_id, &success, &npobject_ptr)); + Send(new PluginHostMsg_GetPluginElement(route_id_, npobject_route_id, &success)); if (!success) return NULL; @@ -254,31 +250,20 @@ void WebPluginProxy::DidPaint() { InvalidateRect(damaged_rect_); } -void WebPluginProxy::OnResourceCreated(int resource_id, HANDLE cookie) { - WebPluginResourceClient* resource_client = - reinterpret_cast<WebPluginResourceClient*>(cookie); - if (!resource_client) { - NOTREACHED(); - return; - } - +void WebPluginProxy::OnResourceCreated(int resource_id, + WebPluginResourceClient* client) { DCHECK(resource_clients_.find(resource_id) == resource_clients_.end()); - resource_clients_[resource_id] = resource_client; + resource_clients_[resource_id] = client; } -void WebPluginProxy::HandleURLRequest(const char *method, - bool is_javascript_url, - const char* target, unsigned int len, - const char* buf, bool is_file_data, - bool notify, const char* url, - intptr_t notify_data, +void WebPluginProxy::HandleURLRequest(const char* url, + const char *method, + const char* target, + const char* buf, + unsigned int len, + int notify_id, bool popups_allowed) { - if (!url) { - NOTREACHED(); - return; - } - - if (!target && (0 == base::strcasecmp(method, "GET"))) { + if (!target && (0 == base::strcasecmp(method, "GET"))) { // Please refer to https://bugzilla.mozilla.org/show_bug.cgi?id=366082 // for more details on this. if (delegate_->GetQuirks() & @@ -293,8 +278,8 @@ void WebPluginProxy::HandleURLRequest(const char *method, } PluginHostMsg_URLRequest_Params params; + params.url = url; params.method = method; - params.is_javascript_url = is_javascript_url; if (target) params.target = std::string(target); @@ -303,10 +288,7 @@ void WebPluginProxy::HandleURLRequest(const char *method, memcpy(¶ms.buffer.front(), buf, len); } - params.is_file_data = is_file_data; - params.notify = notify; - params.url = url; - params.notify_data = notify_data; + params.notify_id = notify_id; params.popups_allowed = popups_allowed; Send(new PluginHostMsg_URLRequest(route_id_, params)); @@ -567,15 +549,10 @@ void WebPluginProxy::CancelDocumentLoad() { Send(new PluginHostMsg_CancelDocumentLoad(route_id_)); } -void WebPluginProxy::InitiateHTTPRangeRequest(const char* url, - const char* range_info, - intptr_t existing_stream, - bool notify_needed, - intptr_t notify_data) { - - Send(new PluginHostMsg_InitiateHTTPRangeRequest(route_id_, url, - range_info, existing_stream, - notify_needed, notify_data)); +void WebPluginProxy::InitiateHTTPRangeRequest( + const char* url, const char* range_info, int range_request_id) { + Send(new PluginHostMsg_InitiateHTTPRangeRequest( + route_id_, url, range_info, range_request_id)); } void WebPluginProxy::SetDeferResourceLoading(unsigned long resource_id, diff --git a/chrome/plugin/webplugin_proxy.h b/chrome/plugin/webplugin_proxy.h index 4a91685..5fc699c 100644 --- a/chrome/plugin/webplugin_proxy.h +++ b/chrome/plugin/webplugin_proxy.h @@ -103,17 +103,17 @@ class WebPluginProxy : public webkit_glue::WebPlugin { // Callback from the renderer to let us know that a paint occurred. void DidPaint(); - // Notification received on a plugin issued resource request - // creation. - void OnResourceCreated(int resource_id, HANDLE cookie); - - void HandleURLRequest(const char *method, - bool is_javascript_url, - const char* target, unsigned int len, - const char* buf, bool is_file_data, - bool notify, const char* url, - intptr_t notify_data, bool popups_allowed); - + // Notification received on a plugin issued resource request creation. + void OnResourceCreated(int resource_id, + webkit_glue::WebPluginResourceClient* client); + + void HandleURLRequest(const char* url, + const char *method, + const char* target, + const char* buf, + unsigned int len, + int notify_id, + bool popups_allowed); void UpdateGeometry(const gfx::Rect& window_rect, const gfx::Rect& clip_rect, const TransportDIB::Handle& windowless_buffer, @@ -123,22 +123,13 @@ class WebPluginProxy : public webkit_glue::WebPlugin { int ack_key #endif ); - void CancelDocumentLoad(); - - void InitiateHTTPRangeRequest(const char* url, - const char* range_info, - intptr_t existing_stream, - bool notify_needed, - intptr_t notify_data); - + void InitiateHTTPRangeRequest( + const char* url, const char* range_info, int range_request_id); void SetDeferResourceLoading(unsigned long resource_id, bool defer); - bool IsOffTheRecord(); - void ResourceClientDeleted( webkit_glue::WebPluginResourceClient* resource_client); - gfx::NativeViewId containing_window() { return containing_window_; } private: diff --git a/chrome/renderer/webplugin_delegate_pepper.cc b/chrome/renderer/webplugin_delegate_pepper.cc index d25364f..b9b61fe 100644 --- a/chrome/renderer/webplugin_delegate_pepper.cc +++ b/chrome/renderer/webplugin_delegate_pepper.cc @@ -173,11 +173,8 @@ NPObject* WebPluginDelegatePepper::GetPluginScriptableObject() { } void WebPluginDelegatePepper::DidFinishLoadWithReason( - const GURL& url, - NPReason reason, - intptr_t notify_data) { - instance()->DidFinishLoadWithReason( - url, reason, reinterpret_cast<void*>(notify_data)); + const GURL& url, NPReason reason, int notify_id) { + instance()->DidFinishLoadWithReason(url, reason, notify_id); } int WebPluginDelegatePepper::GetProcessId() { @@ -189,10 +186,8 @@ void WebPluginDelegatePepper::SendJavaScriptStream( const GURL& url, const std::string& result, bool success, - bool notify_needed, - intptr_t notify_data) { - instance()->SendJavaScriptStream(url, result, success, notify_needed, - notify_data); + int notify_id) { + instance()->SendJavaScriptStream(url, result, success, notify_id); } void WebPluginDelegatePepper::DidReceiveManualResponse( @@ -220,22 +215,13 @@ FilePath WebPluginDelegatePepper::GetPluginPath() { } WebPluginResourceClient* WebPluginDelegatePepper::CreateResourceClient( - unsigned long resource_id, const GURL& url, bool notify_needed, - intptr_t notify_data, intptr_t existing_stream) { - // Stream already exists. This typically happens for range requests - // initiated via NPN_RequestRead. - if (existing_stream) { - NPAPI::PluginStream* plugin_stream = - reinterpret_cast<NPAPI::PluginStream*>(existing_stream); - - return plugin_stream->AsResourceClient(); - } + unsigned long resource_id, const GURL& url, int notify_id) { + return instance()->CreateStream(resource_id, url, std::string(), notify_id); +} - std::string mime_type; - NPAPI::PluginStreamUrl *stream = instance()->CreateStream( - resource_id, url, mime_type, notify_needed, - reinterpret_cast<void*>(notify_data)); - return stream; +WebPluginResourceClient* WebPluginDelegatePepper::CreateSeekableResourceClient( + unsigned long resource_id, int range_request_id) { + return instance()->GetRangeRequest(range_request_id); } NPError WebPluginDelegatePepper::Device2DQueryCapability(int32 capability, diff --git a/chrome/renderer/webplugin_delegate_pepper.h b/chrome/renderer/webplugin_delegate_pepper.h index b2ac3c6..b316789 100644 --- a/chrome/renderer/webplugin_delegate_pepper.h +++ b/chrome/renderer/webplugin_delegate_pepper.h @@ -53,12 +53,12 @@ class WebPluginDelegatePepper : public webkit_glue::WebPluginDelegate { WebKit::WebCursorInfo* cursor); virtual NPObject* GetPluginScriptableObject(); virtual void DidFinishLoadWithReason(const GURL& url, NPReason reason, - intptr_t notify_data); + int notify_id); virtual int GetProcessId(); virtual void SendJavaScriptStream(const GURL& url, const std::string& result, - bool success, bool notify_needed, - intptr_t notify_data); + bool success, + int notify_id); virtual void DidReceiveManualResponse(const GURL& url, const std::string& mime_type, const std::string& headers, @@ -69,11 +69,9 @@ class WebPluginDelegatePepper : public webkit_glue::WebPluginDelegate { virtual void DidManualLoadFail(); virtual void InstallMissingPlugin(); virtual webkit_glue::WebPluginResourceClient* CreateResourceClient( - unsigned long resource_id, - const GURL& url, - bool notify_needed, - intptr_t notify_data, - intptr_t stream); + unsigned long resource_id, const GURL& url, int notify_id); + virtual webkit_glue::WebPluginResourceClient* CreateSeekableResourceClient( + unsigned long resource_id, int range_request_id); // WebPlugin2DDeviceDelegate implementation. virtual NPError Device2DQueryCapability(int32 capability, int32* value); diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc index 5cfe049..83666d5 100644 --- a/chrome/renderer/webplugin_delegate_proxy.cc +++ b/chrome/renderer/webplugin_delegate_proxy.cc @@ -66,31 +66,24 @@ class ResourceClientProxy : public webkit_glue::WebPluginResourceClient { public: ResourceClientProxy(PluginChannelHost* channel, int instance_id) : channel_(channel), instance_id_(instance_id), resource_id_(0), - notify_needed_(false), notify_data_(0), multibyte_response_expected_(false) { } ~ResourceClientProxy() { } - void Initialize(unsigned long resource_id, const GURL& url, - bool notify_needed, intptr_t notify_data, - intptr_t existing_stream) { + void Initialize(unsigned long resource_id, const GURL& url, int notify_id) { resource_id_ = resource_id; - url_ = url; - notify_needed_ = notify_needed; - notify_data_ = notify_data; - - PluginMsg_URLRequestReply_Params params; - params.resource_id = resource_id; - params.url = url_; - params.notify_needed = notify_needed_; - params.notify_data = notify_data_; - params.stream = existing_stream; - - multibyte_response_expected_ = (existing_stream != 0); + channel_->Send(new PluginMsg_HandleURLRequestReply( + instance_id_, resource_id, url, notify_id)); + } - channel_->Send(new PluginMsg_HandleURLRequestReply(instance_id_, params)); + void InitializeForSeekableStream(unsigned long resource_id, + int range_request_id) { + resource_id_ = resource_id; + multibyte_response_expected_ = true; + channel_->Send(new PluginMsg_HTTPRangeRequestReply( + instance_id_, resource_id, range_request_id)); } // PluginResourceClient implementation: @@ -154,9 +147,6 @@ class ResourceClientProxy : public webkit_glue::WebPluginResourceClient { scoped_refptr<PluginChannelHost> channel_; int instance_id_; unsigned long resource_id_; - GURL url_; - bool notify_needed_; - intptr_t notify_data_; // Set to true if the response expected is a multibyte response. // For e.g. response for a HTTP byte range request. bool multibyte_response_expected_; @@ -314,13 +304,9 @@ bool WebPluginDelegateProxy::Send(IPC::Message* msg) { void WebPluginDelegateProxy::SendJavaScriptStream(const GURL& url, const std::string& result, bool success, - bool notify_needed, - intptr_t notify_data) { - PluginMsg_SendJavaScriptStream* msg = - new PluginMsg_SendJavaScriptStream(instance_id_, url, result, - success, notify_needed, - notify_data); - Send(msg); + int notify_id) { + Send(new PluginMsg_SendJavaScriptStream( + instance_id_, url, result, success, notify_id)); } void WebPluginDelegateProxy::DidReceiveManualResponse( @@ -823,9 +809,7 @@ NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() { return WebBindings::retainObject(npobject_); int route_id = MSG_ROUTING_NONE; - intptr_t npobject_ptr; - Send(new PluginMsg_GetPluginScriptableObject( - instance_id_, &route_id, &npobject_ptr)); + Send(new PluginMsg_GetPluginScriptableObject(instance_id_, &route_id)); if (route_id == MSG_ROUTING_NONE) return NULL; @@ -836,9 +820,9 @@ NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() { } void WebPluginDelegateProxy::DidFinishLoadWithReason( - const GURL& url, NPReason reason, intptr_t notify_data) { + const GURL& url, NPReason reason, int notify_id) { Send(new PluginMsg_DidFinishLoadWithReason( - instance_id_, url, reason, notify_data)); + instance_id_, url, reason, notify_id)); } void WebPluginDelegateProxy::SetFocus() { @@ -909,7 +893,7 @@ void WebPluginDelegateProxy::OnInvalidateRect(const gfx::Rect& rect) { } void WebPluginDelegateProxy::OnGetWindowScriptNPObject( - int route_id, bool* success, intptr_t* npobject_ptr) { + int route_id, bool* success) { *success = false; NPObject* npobject = NULL; if (plugin_) @@ -923,11 +907,9 @@ void WebPluginDelegateProxy::OnGetWindowScriptNPObject( window_script_object_ = (new NPObjectStub( npobject, channel_host_.get(), route_id, 0, page_url_))->AsWeakPtr(); *success = true; - *npobject_ptr = reinterpret_cast<intptr_t>(npobject); } -void WebPluginDelegateProxy::OnGetPluginElement( - int route_id, bool* success, intptr_t* npobject_ptr) { +void WebPluginDelegateProxy::OnGetPluginElement(int route_id, bool* success) { *success = false; NPObject* npobject = NULL; if (plugin_) @@ -940,7 +922,6 @@ void WebPluginDelegateProxy::OnGetPluginElement( new NPObjectStub( npobject, channel_host_.get(), route_id, 0, page_url_); *success = true; - *npobject_ptr = reinterpret_cast<intptr_t>(npobject); } void WebPluginDelegateProxy::OnSetCookie(const GURL& url, @@ -1155,24 +1136,33 @@ void WebPluginDelegateProxy::OnHandleURLRequest( if (params.target.length()) target = params.target.c_str(); - plugin_->HandleURLRequest(params.method.c_str(), - params.is_javascript_url, target, - static_cast<unsigned int>(params.buffer.size()), - data, params.is_file_data, params.notify, - params.url.c_str(), params.notify_data, - params.popups_allowed); + plugin_->HandleURLRequest( + params.url.c_str(), params.method.c_str(), target, data, + static_cast<unsigned int>(params.buffer.size()), params.notify_id, + params.popups_allowed); } webkit_glue::WebPluginResourceClient* WebPluginDelegateProxy::CreateResourceClient( - unsigned long resource_id, const GURL& url, bool notify_needed, - intptr_t notify_data, intptr_t npstream) { + unsigned long resource_id, const GURL& url, int notify_id) { + if (!channel_host_) + return NULL; + + ResourceClientProxy* proxy = new ResourceClientProxy(channel_host_, + instance_id_); + proxy->Initialize(resource_id, url, notify_id); + return proxy; +} + +webkit_glue::WebPluginResourceClient* +WebPluginDelegateProxy::CreateSeekableResourceClient( + unsigned long resource_id, int range_request_id) { if (!channel_host_) return NULL; ResourceClientProxy* proxy = new ResourceClientProxy(channel_host_, instance_id_); - proxy->Initialize(resource_id, url, notify_needed, notify_data, npstream); + proxy->InitializeForSeekableStream(resource_id, range_request_id); return proxy; } @@ -1195,11 +1185,11 @@ void WebPluginDelegateProxy::OnCancelDocumentLoad() { } void WebPluginDelegateProxy::OnInitiateHTTPRangeRequest( - const std::string& url, const std::string& range_info, - intptr_t existing_stream, bool notify_needed, intptr_t notify_data) { - plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(), - existing_stream, notify_needed, - notify_data); + const std::string& url, + const std::string& range_info, + int range_request_id) { + plugin_->InitiateHTTPRangeRequest( + url.c_str(), range_info.c_str(), range_request_id); } void WebPluginDelegateProxy::OnDeferResourceLoading(unsigned long resource_id, diff --git a/chrome/renderer/webplugin_delegate_proxy.h b/chrome/renderer/webplugin_delegate_proxy.h index c884c9f..510f977 100644 --- a/chrome/renderer/webplugin_delegate_proxy.h +++ b/chrome/renderer/webplugin_delegate_proxy.h @@ -65,7 +65,7 @@ class WebPluginDelegateProxy virtual void Print(gfx::NativeDrawingContext context); virtual NPObject* GetPluginScriptableObject(); virtual void DidFinishLoadWithReason(const GURL& url, NPReason reason, - intptr_t notify_data); + int notify_id); virtual void SetFocus(); virtual bool HandleInputEvent(const WebKit::WebInputEvent& event, WebKit::WebCursorInfo* cursor); @@ -80,8 +80,8 @@ class WebPluginDelegateProxy virtual void SendJavaScriptStream(const GURL& url, const std::string& result, - bool success, bool notify_needed, - intptr_t notify_data); + bool success, + int notify_id); virtual void DidReceiveManualResponse(const GURL& url, const std::string& mime_type, @@ -93,11 +93,9 @@ class WebPluginDelegateProxy virtual void DidManualLoadFail(); virtual void InstallMissingPlugin(); virtual webkit_glue::WebPluginResourceClient* CreateResourceClient( - unsigned long resource_id, - const GURL& url, - bool notify_needed, - intptr_t notify_data, - intptr_t existing_stream); + unsigned long resource_id, const GURL& url, int notify_id); + virtual webkit_glue::WebPluginResourceClient* CreateSeekableResourceClient( + unsigned long resource_id, int range_request_id); CommandBufferProxy* CreateCommandBuffer(); @@ -117,9 +115,8 @@ class WebPluginDelegateProxy void OnHandleURLRequest(const PluginHostMsg_URLRequest_Params& params); void OnCancelResource(int id); void OnInvalidateRect(const gfx::Rect& rect); - void OnGetWindowScriptNPObject(int route_id, bool* success, - intptr_t* npobject_ptr); - void OnGetPluginElement(int route_id, bool* success, intptr_t* npobject_ptr); + void OnGetWindowScriptNPObject(int route_id, bool* success); + void OnGetPluginElement(int route_id, bool* success); void OnSetCookie(const GURL& url, const GURL& first_party_for_cookies, const std::string& cookie); @@ -137,9 +134,7 @@ class WebPluginDelegateProxy void OnCancelDocumentLoad(); void OnInitiateHTTPRangeRequest(const std::string& url, const std::string& range_info, - intptr_t existing_stream, - bool notify_needed, - intptr_t notify_data); + int range_request_id); void OnDeferResourceLoading(unsigned long resource_id, bool defer); #if defined(OS_MACOSX) diff --git a/webkit/glue/plugins/plugin_host.cc b/webkit/glue/plugins/plugin_host.cc index 544597b..c8c652d 100644 --- a/webkit/glue/plugins/plugin_host.cc +++ b/webkit/glue/plugins/plugin_host.cc @@ -313,12 +313,7 @@ NPError NPN_RequestRead(NPStream* stream, NPByteRange* range_list) { return NPERR_NO_ERROR; } -static bool IsJavaScriptUrl(const std::string& url) { - return StartsWithASCII(url, "javascript:", false); -} - -// Generic form of GetURL for common code between -// GetURL() and GetURLNotify(). +// Generic form of GetURL for common code between GetURL and GetURLNotify. static NPError GetURLNotify(NPP id, const char* url, const char* target, @@ -327,18 +322,13 @@ static NPError GetURLNotify(NPP id, if (!url) return NPERR_INVALID_URL; - bool is_javascript_url = IsJavaScriptUrl(url); - scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); - if (plugin.get()) { - plugin->webplugin()->HandleURLRequest( - "GET", is_javascript_url, target, 0, 0, false, - notify, url, reinterpret_cast<intptr_t>(notify_data), - plugin->popups_allowed()); - } else { + if (!plugin.get()) { NOTREACHED(); return NPERR_GENERIC_ERROR; } + + plugin->RequestURL(url, "GET", target, NULL, 0, notify, notify_data); return NPERR_NO_ERROR; } @@ -385,8 +375,7 @@ NPError NPN_GetURL(NPP id, const char* url, const char* target) { return GetURLNotify(id, url, target, false, 0); } -// Generic form of PostURL for common code between -// PostURL() and PostURLNotify(). +// Generic form of PostURL for common code between PostURL and PostURLNotify. static NPError PostURLNotify(NPP id, const char* url, const char* target, @@ -460,8 +449,6 @@ static NPError PostURLNotify(NPP id, len = post_file_contents.size(); } - bool is_javascript_url = IsJavaScriptUrl(url); - // The post data sent by a plugin contains both headers // and post data. Example: // Content-type: text/html @@ -472,9 +459,7 @@ static NPError PostURLNotify(NPP id, // Unfortunately, our stream needs these broken apart, // so we need to parse the data and set headers and data // separately. - plugin->webplugin()->HandleURLRequest( - "POST", is_javascript_url, target, len, buf, false, notify, url, - reinterpret_cast<intptr_t>(notify_data), plugin->popups_allowed()); + plugin->RequestURL(url, "POST", target, buf, len, notify, notify_data); return NPERR_NO_ERROR; } diff --git a/webkit/glue/plugins/plugin_instance.cc b/webkit/glue/plugins/plugin_instance.cc index d560d42..1d01f8e 100644 --- a/webkit/glue/plugins/plugin_instance.cc +++ b/webkit/glue/plugins/plugin_instance.cc @@ -40,16 +40,16 @@ PluginInstance::PluginInstance(PluginLib *plugin, const std::string &mime_type) event_model_(0), currently_handled_event_(NULL), #endif - message_loop_(MessageLoop::current()), load_manually_(false), in_close_streams_(false), - next_timer_id_(1) { + next_timer_id_(1), + next_notify_id_(0), + next_range_request_id_(0) { npp_ = new NPP_t(); npp_->ndata = 0; npp_->pdata = 0; memset(&zero_padding_, 0, sizeof(zero_padding_)); - DCHECK(message_loop_); } PluginInstance::~PluginInstance() { @@ -67,10 +67,13 @@ PluginInstance::~PluginInstance() { PluginStreamUrl* PluginInstance::CreateStream(unsigned long resource_id, const GURL& url, const std::string& mime_type, - bool notify_needed, - void* notify_data) { + int notify_id) { + + bool notify; + void* notify_data; + GetNotifyData(notify_id, ¬ify, ¬ify_data); PluginStreamUrl* stream = new PluginStreamUrl( - resource_id, url, this, notify_needed, notify_data); + resource_id, url, this, notify, notify_data); AddStream(stream); return stream; @@ -115,6 +118,19 @@ void PluginInstance::CloseStreams() { in_close_streams_ = false; } +webkit_glue::WebPluginResourceClient* PluginInstance::GetRangeRequest( + int id) { + PendingRangeRequestMap::iterator iter = pending_range_requests_.find(id); + if (iter == pending_range_requests_.end()) { + NOTREACHED(); + return NULL; + } + + webkit_glue::WebPluginResourceClient* rv = iter->second->AsResourceClient(); + pending_range_requests_.erase(iter); + return rv; +} + bool PluginInstance::Start(const GURL& url, char** const param_names, char** const param_values, @@ -138,8 +154,16 @@ NPObject *PluginInstance::GetPluginScriptableObject() { } // WebPluginLoadDelegate methods -void PluginInstance::DidFinishLoadWithReason(const GURL& url, NPReason reason, - void* notify_data) { +void PluginInstance::DidFinishLoadWithReason( + const GURL& url, NPReason reason, int notify_id) { + bool notify; + void* notify_data; + GetNotifyData(notify_id, ¬ify, ¬ify_data); + if (!notify) { + NOTREACHED(); + return; + } + NPP_URLNotify(url.spec().c_str(), reason, notify_data); } @@ -305,21 +329,21 @@ bool PluginInstance::NPP_Print(NPPrint* platform_print) { void PluginInstance::SendJavaScriptStream(const GURL& url, const std::string& result, bool success, - bool notify_needed, - intptr_t notify_data) { + int notify_id) { + bool notify; + void* notify_data; + GetNotifyData(notify_id, ¬ify, ¬ify_data); + if (success) { PluginStringStream *stream = - new PluginStringStream(this, url, notify_needed, - reinterpret_cast<void*>(notify_data)); + new PluginStringStream(this, url, notify, notify_data); AddStream(stream); stream->SendToPlugin(result, "text/html"); } else { // NOTE: Sending an empty stream here will crash MacroMedia // Flash 9. Just send the URL Notify. - if (notify_needed) { - this->NPP_URLNotify(url.spec().c_str(), NPRES_DONE, - reinterpret_cast<void*>(notify_data)); - } + if (notify) + NPP_URLNotify(url.spec().c_str(), NPRES_DONE, notify_data); } } @@ -330,8 +354,7 @@ void PluginInstance::DidReceiveManualResponse(const GURL& url, uint32 last_modified) { DCHECK(load_manually_); - plugin_data_stream_ = CreateStream(-1, url, mime_type, false, NULL); - + plugin_data_stream_ = CreateStream(-1, url, mime_type, 0); plugin_data_stream_->DidReceiveResponse(mime_type, headers, expected_length, last_modified, true); } @@ -362,8 +385,9 @@ void PluginInstance::DidManualLoadFail() { void PluginInstance::PluginThreadAsyncCall(void (*func)(void *), void *user_data) { - message_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &PluginInstance::OnPluginThreadAsyncCall, func, user_data)); + MessageLoop::current()->PostTask( + FROM_HERE, NewRunnableMethod( + this, &PluginInstance::OnPluginThreadAsyncCall, func, user_data)); } void PluginInstance::OnPluginThreadAsyncCall(void (*func)(void *), @@ -389,13 +413,11 @@ uint32 PluginInstance::ScheduleTimer(uint32 interval, timers_[timer_id] = info; // Schedule the callback. - message_loop_->PostDelayedTask(FROM_HERE, - NewRunnableMethod(this, - &PluginInstance::OnTimerCall, - func, - npp_, - timer_id), - interval); + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + NewRunnableMethod( + this, &PluginInstance::OnTimerCall, func, npp_, timer_id), + interval); return timer_id; } @@ -434,14 +456,11 @@ void PluginInstance::OnTimerCall(void (*func)(NPP id, uint32 timer_id), // Reschedule repeating timers after invoking the callback so callback is not // re-entered if it pumps the messager loop. if (info.repeat) { - message_loop_->PostDelayedTask(FROM_HERE, - NewRunnableMethod( - this, - &PluginInstance::OnTimerCall, - func, - npp_, - timer_id), - info.interval); + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + NewRunnableMethod( + this, &PluginInstance::OnTimerCall, func, npp_, timer_id), + info.interval); } else { timers_.erase(it); } @@ -490,14 +509,30 @@ void PluginInstance::RequestRead(NPStream* stream, NPByteRange* range_list) { // is called on it. plugin_stream->set_seekable(true); + pending_range_requests_[++next_range_request_id_] = plugin_stream; webplugin_->InitiateHTTPRangeRequest( - stream->url, range_info.c_str(), - reinterpret_cast<intptr_t>(plugin_stream), - plugin_stream->notify_needed(), - reinterpret_cast<intptr_t>(plugin_stream->notify_data())); - break; + stream->url, range_info.c_str(), next_range_request_id_); + return; } } + NOTREACHED(); +} + +void PluginInstance::RequestURL(const char* url, + const char* method, + const char* target, + const char* buf, + unsigned int len, + bool notify, + void* notify_data) { + int notify_id = 0; + if (notify) { + notify_id = ++next_notify_id_; + pending_requests_[notify_id] = notify_data; + } + + webplugin_->HandleURLRequest( + url, method, target, buf, len, notify_id, popups_allowed()); } bool PluginInstance::ConvertPoint(double source_x, double source_y, @@ -566,4 +601,17 @@ bool PluginInstance::ConvertPoint(double source_x, double source_y, #endif } +void PluginInstance::GetNotifyData( + int notify_id, bool* notify, void** notify_data) { + PendingRequestMap::iterator iter = pending_requests_.find(notify_id); + if (iter != pending_requests_.end()) { + *notify = true; + *notify_data = iter->second; + pending_requests_.erase(iter); + } else { + *notify = false; + *notify_data = NULL; + } +} + } // namespace NPAPI diff --git a/webkit/glue/plugins/plugin_instance.h b/webkit/glue/plugins/plugin_instance.h index 4043ed4..7cb72aa 100644 --- a/webkit/glue/plugins/plugin_instance.h +++ b/webkit/glue/plugins/plugin_instance.h @@ -24,10 +24,10 @@ #include "googleurl/src/gurl.h" #include "third_party/npapi/bindings/npapi.h" -class MessageLoop; namespace webkit_glue { class WebPlugin; +class WebPluginResourceClient; } namespace NPAPI @@ -116,17 +116,15 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { void set_plugin_origin(gfx::Point origin) { plugin_origin_ = origin; } #endif - // Creates a stream for sending an URL. If notify_needed - // is true, it will send a notification to the plugin - // when the stream is complete; otherwise it will not. - // Set object_url to true if the load is for the object tag's - // url, or false if it's for a url that the plugin - // fetched through NPN_GetUrl[Notify]. + // Creates a stream for sending an URL. If notify_id is non-zero, it will + // send a notification to the plugin when the stream is complete; otherwise it + // will not. Set object_url to true if the load is for the object tag's url, + // or false if it's for a url that the plugin fetched through + // NPN_GetUrl[Notify]. PluginStreamUrl* CreateStream(unsigned long resource_id, const GURL& url, const std::string& mime_type, - bool notify_needed, - void* notify_data); + int notify_id); // For each instance, we track all streams. When the // instance closes, all remaining streams are also @@ -142,13 +140,16 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { // Closes all open streams on this instance. void CloseStreams(); + // Returns the WebPluginResourceClient object for a stream that has become + // seekable. + webkit_glue::WebPluginResourceClient* GetRangeRequest(int id); + // Have the plugin create it's script object. NPObject *GetPluginScriptableObject(); // WebViewDelegate methods that we implement. This is for handling // callbacks during getURLNotify. - virtual void DidFinishLoadWithReason(const GURL& url, NPReason reason, - void* notify_data); + void DidFinishLoadWithReason(const GURL& url, NPReason reason, int notify_id); // If true, send the Mozilla user agent instead of Chrome's to the plugin. bool use_mozilla_user_agent() { return use_mozilla_user_agent_; } @@ -188,9 +189,10 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { void NPP_Destroy(); bool NPP_Print(NPPrint* platform_print); - void SendJavaScriptStream(const GURL& url, const std::string& result, - bool success, bool notify_needed, - intptr_t notify_data); + void SendJavaScriptStream(const GURL& url, + const std::string& result, + bool success, + int notify_id); void DidReceiveManualResponse(const GURL& url, const std::string& mime_type, @@ -211,6 +213,16 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { // Initiates byte range reads for plugins. void RequestRead(NPStream* stream, NPByteRange* range_list); + // Handles GetURL/GetURLNotify/PostURL/PostURLNotify requests initiated + // by plugins. + void RequestURL(const char* url, + const char* method, + const char* target, + const char* buf, + unsigned int len, + bool notify, + void* notify_data); + private: friend class base::RefCountedThreadSafe<PluginInstance>; @@ -225,15 +237,12 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { } #endif - virtual ~PluginInstance(); - - void OnPluginThreadAsyncCall(void (*func)(void *), - void *userData); + ~PluginInstance(); + void OnPluginThreadAsyncCall(void (*func)(void *), void *userData); void OnTimerCall(void (*func)(NPP id, uint32 timer_id), - NPP id, - uint32 timer_id); - + NPP id, uint32 timer_id); bool IsValidStream(const NPStream* stream); + void GetNotifyData(int notify_id, bool* notify, void** notify_data); // This is a hack to get the real player plugin to work with chrome // The real player plugin dll(nppl3260) when loaded by firefox is loaded via @@ -275,7 +284,6 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { gfx::Point plugin_origin_; NPCocoaEvent* currently_handled_event_; // weak #endif - MessageLoop* message_loop_; scoped_refptr<PluginStreamUrl> plugin_data_stream_; // This flag if true indicates that the plugin data would be passed from @@ -304,6 +312,18 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { typedef std::map<uint32, TimerInfo> TimerMap; TimerMap timers_; + // Tracks pending GET/POST requests so that the plugin-given data doesn't + // cross process boundaries to an untrusted process. + typedef std::map<int, void*> PendingRequestMap; + PendingRequestMap pending_requests_; + int next_notify_id_; + + // Used to track pending range requests so that when WebPlugin replies to us + // we can match the reply to the stream. + typedef std::map<int, scoped_refptr<PluginStream> > PendingRangeRequestMap; + PendingRangeRequestMap pending_range_requests_; + int next_range_request_id_; + DISALLOW_EVIL_CONSTRUCTORS(PluginInstance); }; diff --git a/webkit/glue/plugins/webplugin_delegate_impl.cc b/webkit/glue/plugins/webplugin_delegate_impl.cc index 4d3b43c..d2ecbc7 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl.cc @@ -143,15 +143,14 @@ NPObject* WebPluginDelegateImpl::GetPluginScriptableObject() { void WebPluginDelegateImpl::DidFinishLoadWithReason(const GURL& url, NPReason reason, - intptr_t notify_data) { + int notify_id) { if (quirks_ & PLUGIN_QUIRK_ALWAYS_NOTIFY_SUCCESS && reason == NPRES_NETWORK_ERR) { // Flash needs this or otherwise it unloads the launching swf object. reason = NPRES_DONE; } - instance()->DidFinishLoadWithReason( - url, reason, reinterpret_cast<void*>(notify_data)); + instance()->DidFinishLoadWithReason(url, reason, notify_id); } int WebPluginDelegateImpl::GetProcessId() { @@ -162,10 +161,8 @@ int WebPluginDelegateImpl::GetProcessId() { void WebPluginDelegateImpl::SendJavaScriptStream(const GURL& url, const std::string& result, bool success, - bool notify_needed, - intptr_t notify_data) { - instance()->SendJavaScriptStream(url, result, success, notify_needed, - notify_data); + int notify_id) { + instance()->SendJavaScriptStream(url, result, success, notify_id); } void WebPluginDelegateImpl::DidReceiveManualResponse( @@ -209,20 +206,12 @@ void WebPluginDelegateImpl::WindowedUpdateGeometry( } WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( - unsigned long resource_id, const GURL& url, bool notify_needed, - intptr_t notify_data, intptr_t existing_stream) { - // Stream already exists. This typically happens for range requests - // initiated via NPN_RequestRead. - if (existing_stream) { - NPAPI::PluginStream* plugin_stream = - reinterpret_cast<NPAPI::PluginStream*>(existing_stream); - - return plugin_stream->AsResourceClient(); - } + unsigned long resource_id, const GURL& url, int notify_id) { + return instance()->CreateStream( + resource_id, url, std::string(), notify_id); +} - std::string mime_type; - NPAPI::PluginStreamUrl *stream = instance()->CreateStream( - resource_id, url, mime_type, notify_needed, - reinterpret_cast<void*>(notify_data)); - return stream; +WebPluginResourceClient* WebPluginDelegateImpl::CreateSeekableResourceClient( + unsigned long resource_id, int range_request_id) { + return instance()->GetRangeRequest(range_request_id); } diff --git a/webkit/glue/plugins/webplugin_delegate_impl.h b/webkit/glue/plugins/webplugin_delegate_impl.h index 6864e31..ce19bb5 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.h +++ b/webkit/glue/plugins/webplugin_delegate_impl.h @@ -79,13 +79,13 @@ class WebPluginDelegateImpl : public webkit_glue::WebPluginDelegate { virtual bool HandleInputEvent(const WebKit::WebInputEvent& event, WebKit::WebCursorInfo* cursor); virtual NPObject* GetPluginScriptableObject(); - virtual void DidFinishLoadWithReason(const GURL& url, NPReason reason, - intptr_t notify_data); + virtual void DidFinishLoadWithReason( + const GURL& url, NPReason reason, int notify_id); virtual int GetProcessId(); virtual void SendJavaScriptStream(const GURL& url, const std::string& result, - bool success, bool notify_needed, - intptr_t notify_data); + bool success, + int notify_id); virtual void DidReceiveManualResponse(const GURL& url, const std::string& mime_type, const std::string& headers, @@ -96,11 +96,9 @@ class WebPluginDelegateImpl : public webkit_glue::WebPluginDelegate { virtual void DidManualLoadFail(); virtual void InstallMissingPlugin(); virtual webkit_glue::WebPluginResourceClient* CreateResourceClient( - unsigned long resource_id, - const GURL& url, - bool notify_needed, - intptr_t notify_data, - intptr_t stream); + unsigned long resource_id, const GURL& url, int notify_id); + virtual webkit_glue::WebPluginResourceClient* CreateSeekableResourceClient( + unsigned long resource_id, int range_request_id); // End of WebPluginDelegate implementation. bool IsWindowless() const { return windowless_ ; } diff --git a/webkit/glue/webplugin.h b/webkit/glue/webplugin.h index c4e2272..051eb2c 100644 --- a/webkit/glue/webplugin.h +++ b/webkit/glue/webplugin.h @@ -105,23 +105,23 @@ class WebPlugin { virtual void OnMissingPluginStatus(int status) = 0; // Handles GetURL/GetURLNotify/PostURL/PostURLNotify requests initiated - // by plugins. - virtual void HandleURLRequest(const char *method, - bool is_javascript_url, - const char* target, unsigned int len, - const char* buf, bool is_file_data, - bool notify, const char* url, - intptr_t notify_data, bool popups_allowed) = 0; + // by plugins. If the plugin wants notification of the result, notify_id will + // be non-zero. + virtual void HandleURLRequest(const char* url, + const char *method, + const char* target, + const char* buf, + unsigned int len, + int notify_id, + bool popups_allowed) = 0; // Cancels document load. virtual void CancelDocumentLoad() = 0; - // Initiates a HTTP range request. + // Initiates a HTTP range request for an existing stream. virtual void InitiateHTTPRangeRequest(const char* url, const char* range_info, - intptr_t existing_stream, - bool notify_needed, - intptr_t notify_data) = 0; + int range_request_id) = 0; // Returns true iff in off the record (Incognito) mode. virtual bool IsOffTheRecord() = 0; diff --git a/webkit/glue/webplugin_delegate.h b/webkit/glue/webplugin_delegate.h index e88a706..52c7186 100644 --- a/webkit/glue/webplugin_delegate.h +++ b/webkit/glue/webplugin_delegate.h @@ -94,7 +94,7 @@ class WebPluginDelegate : public WebPlugin2DDeviceDelegate, // Receives notification about a resource load that the plugin initiated // for a frame. virtual void DidFinishLoadWithReason(const GURL& url, NPReason reason, - intptr_t notify_data) = 0; + int notify_id) = 0; // Returns the process id of the process that is running the plugin. virtual int GetProcessId() = 0; @@ -103,8 +103,8 @@ class WebPluginDelegate : public WebPlugin2DDeviceDelegate, // function. virtual void SendJavaScriptStream(const GURL& url, const std::string& result, - bool success, bool notify_needed, - intptr_t notify_data) = 0; + bool success, + int notify_id) = 0; // Receives notification about data being available. virtual void DidReceiveManualResponse(const GURL& url, @@ -129,9 +129,12 @@ class WebPluginDelegate : public WebPlugin2DDeviceDelegate, virtual WebPluginResourceClient* CreateResourceClient( unsigned long resource_id, const GURL& url, - bool notify_needed, - intptr_t notify_data, - intptr_t stream) = 0; + int notify_id) = 0; + + // Creates a WebPluginResourceClient instance for an existing stream that is + // has become seekable. + virtual WebPluginResourceClient* CreateSeekableResourceClient( + unsigned long resource_id, int range_request_id) = 0; }; } // namespace webkit_glue diff --git a/webkit/glue/webplugin_impl.cc b/webkit/glue/webplugin_impl.cc index 20e9a76..f032340 100644 --- a/webkit/glue/webplugin_impl.cc +++ b/webkit/glue/webplugin_impl.cc @@ -354,7 +354,7 @@ void WebPluginImpl::didFinishLoadingFrameRequest( const WebURL& url, void* notify_data) { if (delegate_) { delegate_->DidFinishLoadWithReason( - url, NPRES_DONE, reinterpret_cast<intptr_t>(notify_data)); + url, NPRES_DONE, reinterpret_cast<int>(notify_data)); } } @@ -366,7 +366,7 @@ void WebPluginImpl::didFailLoadingFrameRequest( NPReason reason = error.reason == net::ERR_ABORTED ? NPRES_USER_BREAK : NPRES_NETWORK_ERR; delegate_->DidFinishLoadWithReason( - url, reason, reinterpret_cast<intptr_t>(notify_data)); + url, reason, reinterpret_cast<int>(notify_data)); } // ----------------------------------------------------------------------------- @@ -478,15 +478,13 @@ bool WebPluginImpl::SetPostData(WebURLRequest* request, } WebPluginImpl::RoutingStatus WebPluginImpl::RouteToFrame( - const char *method, + const char* url, bool is_javascript_url, + const char* method, const char* target, - unsigned int len, const char* buf, - bool is_file_data, - bool notify_needed, - intptr_t notify_data, - const char* url, + unsigned int len, + int notify_id, Referrer referrer_flag) { // If there is no target, there is nothing to do if (!target) @@ -534,23 +532,16 @@ WebPluginImpl::RoutingStatus WebPluginImpl::RouteToFrame( request.setHTTPMethod(WebString::fromUTF8(method)); if (len > 0) { - if (!is_file_data) { - if (!SetPostData(&request, buf, len)) { - // Uhoh - we're in trouble. There isn't a good way - // to recover at this point. Break out. - NOTREACHED(); - return ROUTED; - } - } else { - // TODO: Support "file" mode. For now, just break out - // since proceeding may do something unintentional. + if (!SetPostData(&request, buf, len)) { + // Uhoh - we're in trouble. There isn't a good way + // to recover at this point. Break out. NOTREACHED(); return ROUTED; } } - container_->loadFrameRequest(request, target_str, notify_needed, - reinterpret_cast<void*>(notify_data)); + container_->loadFrameRequest( + request, target_str, notify_id != 0, reinterpret_cast<void*>(notify_id)); return ROUTED; } @@ -603,9 +594,8 @@ void WebPluginImpl::InvalidateRect(const gfx::Rect& rect) { } void WebPluginImpl::OnDownloadPluginSrcUrl() { - HandleURLRequestInternal("GET", false, NULL, 0, NULL, false, false, - plugin_url_.spec().c_str(), NULL, false, - DOCUMENT_URL); + HandleURLRequestInternal( + plugin_url_.spec().c_str(), "GET", NULL, NULL, 0, 0, false, DOCUMENT_URL); } WebPluginResourceClient* WebPluginImpl::GetClientFromLoader( @@ -683,8 +673,7 @@ void WebPluginImpl::didReceiveResponse(WebURLLoader* loader, for (size_t i = 0; i < clients_.size(); ++i) { if (clients_[i].loader.get() == loader) { WebPluginResourceClient* resource_client = - delegate_->CreateResourceClient(clients_[i].id, plugin_url_, - false, 0, NULL); + delegate_->CreateResourceClient(clients_[i].id, plugin_url_, 0); clients_[i].client = resource_client; client = resource_client; break; @@ -816,24 +805,27 @@ void WebPluginImpl::SetContainer(WebPluginContainer* container) { container_ = container; } -void WebPluginImpl::HandleURLRequest(const char *method, - bool is_javascript_url, - const char* target, unsigned int len, - const char* buf, bool is_file_data, - bool notify, const char* url, - intptr_t notify_data, bool popups_allowed) { +void WebPluginImpl::HandleURLRequest(const char* url, + const char *method, + const char* target, + const char* buf, + unsigned int len, + int notify_id, + bool popups_allowed) { // GetURL/PostURL requests initiated explicitly by plugins should specify the // plugin SRC url as the referrer if it is available. - HandleURLRequestInternal(method, is_javascript_url, target, len, buf, - is_file_data, notify, url, notify_data, - popups_allowed, PLUGIN_SRC); + HandleURLRequestInternal( + url, method, target, buf, len, notify_id, popups_allowed, PLUGIN_SRC); } -void WebPluginImpl::HandleURLRequestInternal( - const char *method, bool is_javascript_url, const char* target, - unsigned int len, const char* buf, bool is_file_data, bool notify, - const char* url, intptr_t notify_data, bool popups_allowed, - Referrer referrer_flag) { +void WebPluginImpl::HandleURLRequestInternal(const char* url, + const char *method, + const char* target, + const char* buf, + unsigned int len, + int notify_id, + bool popups_allowed, + Referrer referrer_flag) { // For this request, we either route the output to a frame // because a target has been specified, or we handle the request // here, i.e. by executing the script if it is a javascript url @@ -841,9 +833,10 @@ void WebPluginImpl::HandleURLRequestInternal( // case in that the request is a javascript url and the target is "_self", // in which case we route the output to the plugin rather than routing it // to the plugin's frame. - RoutingStatus routing_status = - RouteToFrame(method, is_javascript_url, target, len, buf, is_file_data, - notify, notify_data, url, referrer_flag); + bool is_javascript_url = StartsWithASCII(url, "javascript:", false); + RoutingStatus routing_status = RouteToFrame( + url, is_javascript_url, method, target, buf, len, notify_id, + referrer_flag); if (routing_status == ROUTED) return; @@ -855,37 +848,38 @@ void WebPluginImpl::HandleURLRequestInternal( // be deleted. if (delegate_) { delegate_->SendJavaScriptStream( - gurl, result.utf8(), !result.isNull(), notify, notify_data); + gurl, result.utf8(), !result.isNull(), notify_id); } - } else { - GURL complete_url = CompleteURL(url); - unsigned long resource_id = GetNextResourceId(); - if (!resource_id) - return; - - WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( - resource_id, complete_url, notify, notify_data, NULL); - if (!resource_client) - return; + return; + } - // If the RouteToFrame call returned a failure then inform the result - // back to the plugin asynchronously. - if ((routing_status == INVALID_URL) || - (routing_status == GENERAL_FAILURE)) { - resource_client->DidFail(); - return; - } + unsigned long resource_id = GetNextResourceId(); + if (!resource_id) + return; - // CreateResourceClient() sends a synchronous IPC message so it's possible - // that TearDownPluginInstance() may have been called in the nested - // message loop. If so, don't start the request. - if (!delegate_) - return; + GURL complete_url = CompleteURL(url); + WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( + resource_id, complete_url, notify_id); + if (!resource_client) + return; - InitiateHTTPRequest(resource_id, resource_client, method, buf, len, - complete_url, NULL, referrer_flag); + // If the RouteToFrame call returned a failure then inform the result + // back to the plugin asynchronously. + if ((routing_status == INVALID_URL) || + (routing_status == GENERAL_FAILURE)) { + resource_client->DidFail(); + return; } + + // CreateResourceClient() sends a synchronous IPC message so it's possible + // that TearDownPluginInstance() may have been called in the nested + // message loop. If so, don't start the request. + if (!delegate_) + return; + + InitiateHTTPRequest(resource_id, resource_client, complete_url, method, buf, + len, NULL, referrer_flag); } unsigned long WebPluginImpl::GetNextResourceId() { @@ -899,9 +893,10 @@ unsigned long WebPluginImpl::GetNextResourceId() { bool WebPluginImpl::InitiateHTTPRequest(unsigned long resource_id, WebPluginResourceClient* client, - const char* method, const char* buf, - int buf_len, const GURL& url, + const char* method, + const char* buf, + int buf_len, const char* range_info, Referrer referrer_flag) { if (!client) { @@ -956,21 +951,18 @@ void WebPluginImpl::CancelDocumentLoad() { } } -void WebPluginImpl::InitiateHTTPRangeRequest(const char* url, - const char* range_info, - intptr_t existing_stream, - bool notify_needed, - intptr_t notify_data) { +void WebPluginImpl::InitiateHTTPRangeRequest( + const char* url, const char* range_info, int range_request_id) { unsigned long resource_id = GetNextResourceId(); if (!resource_id) return; GURL complete_url = CompleteURL(url); - WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( - resource_id, complete_url, notify_needed, notify_data, existing_stream); + WebPluginResourceClient* resource_client = + delegate_->CreateSeekableResourceClient(resource_id, range_request_id); InitiateHTTPRequest( - resource_id, resource_client, "GET", NULL, 0, complete_url, range_info, + resource_id, resource_client, complete_url, "GET", NULL, 0, range_info, load_manually_ ? NO_REFERRER : PLUGIN_SRC); } diff --git a/webkit/glue/webplugin_impl.h b/webkit/glue/webplugin_impl.h index 21a6cee..fbe9ff6 100644 --- a/webkit/glue/webplugin_impl.h +++ b/webkit/glue/webplugin_impl.h @@ -128,11 +128,14 @@ class WebPluginImpl : public WebPlugin, // Given a download request, check if we need to route the output to a frame. // Returns ROUTED if the load is done and routed to a frame, NOT_ROUTED or // corresponding error codes otherwise. - RoutingStatus RouteToFrame(const char* method, bool is_javascript_url, - const char* target, unsigned int len, - const char* buf, bool is_file_data, - bool notify_needed, intptr_t notify_data, - const char* url, Referrer referrer_flag); + RoutingStatus RouteToFrame(const char* url, + bool is_javascript_url, + const char* method, + const char* target, + const char* buf, + unsigned int len, + int notify_id, + Referrer referrer_flag); // Cancels a pending request. void CancelResource(unsigned long id); @@ -145,8 +148,11 @@ class WebPluginImpl : public WebPlugin, // Returns true on success. bool InitiateHTTPRequest(unsigned long resource_id, WebPluginResourceClient* client, - const char* method, const char* buf, int buf_len, - const GURL& url, const char* range_info, + const GURL& url, + const char* method, + const char* buf, + int len, + const char* range_info, Referrer referrer_flag); gfx::Rect GetWindowClipRect(const gfx::Rect& rect); @@ -199,18 +205,18 @@ class WebPluginImpl : public WebPlugin, // request given a handle. void RemoveClient(WebKit::WebURLLoader* loader); - void HandleURLRequest(const char *method, - bool is_javascript_url, - const char* target, unsigned int len, - const char* buf, bool is_file_data, - bool notify, const char* url, - intptr_t notify_data, bool popups_allowed); + void HandleURLRequest(const char* url, + const char *method, + const char* target, + const char* buf, + unsigned int len, + int notify_id, + bool popups_allowed); void CancelDocumentLoad(); - void InitiateHTTPRangeRequest(const char* url, const char* range_info, - intptr_t existing_stream, bool notify_needed, - intptr_t notify_data); + void InitiateHTTPRangeRequest( + const char* url, const char* range_info, int pending_request_id); void SetDeferResourceLoading(unsigned long resource_id, bool defer); @@ -222,11 +228,13 @@ class WebPluginImpl : public WebPlugin, void HandleHttpMultipartResponse(const WebKit::WebURLResponse& response, WebPluginResourceClient* client); - void HandleURLRequestInternal(const char *method, bool is_javascript_url, - const char* target, unsigned int len, - const char* buf, bool is_file_data, - bool notify, const char* url, - intptr_t notify_data, bool popups_allowed, + void HandleURLRequestInternal(const char* url, + const char *method, + const char* target, + const char* buf, + unsigned int len, + int notify_id, + bool popups_allowed, Referrer referrer_flag); // Tears down the existing plugin instance and creates a new plugin instance |