diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-11 19:13:03 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-11 19:13:03 +0000 |
commit | 01cb1991150f05ffb77a43e98005661671a0aff0 (patch) | |
tree | c61b5e8446110c284eed4812ce511d5117853a9e /content/renderer/npapi | |
parent | 35179be6fcd7cf9cb4db346e266621aab6941c14 (diff) | |
download | chromium_src-01cb1991150f05ffb77a43e98005661671a0aff0.zip chromium_src-01cb1991150f05ffb77a43e98005661671a0aff0.tar.gz chromium_src-01cb1991150f05ffb77a43e98005661671a0aff0.tar.bz2 |
Load NPAPI plugin resources through the browser process directly instead of going through the renderer. This is needed because when we have site isolation enabled we won't trust the renderer to fetch urls from arbitrary origins, which is something that NPAPI plugins can do.
In a followup I'll implement range requests.
For now this is behind the --direct-npapi-requests flag.
BUG=286074
R=ananta@chromium.org, jschuh@chromium.org
Review URL: https://codereview.chromium.org/23503043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222602 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/npapi')
-rw-r--r-- | content/renderer/npapi/webplugin_delegate_proxy.cc | 53 | ||||
-rw-r--r-- | content/renderer/npapi/webplugin_delegate_proxy.h | 34 | ||||
-rw-r--r-- | content/renderer/npapi/webplugin_impl.cc | 67 | ||||
-rw-r--r-- | content/renderer/npapi/webplugin_impl.h | 54 |
4 files changed, 138 insertions, 70 deletions
diff --git a/content/renderer/npapi/webplugin_delegate_proxy.cc b/content/renderer/npapi/webplugin_delegate_proxy.cc index de133d5..cf34bee 100644 --- a/content/renderer/npapi/webplugin_delegate_proxy.cc +++ b/content/renderer/npapi/webplugin_delegate_proxy.cc @@ -28,13 +28,13 @@ #include "content/child/npapi/npobject_proxy.h" #include "content/child/npapi/npobject_stub.h" #include "content/child/npapi/npobject_util.h" -#include "content/child/npapi/webplugin.h" #include "content/child/npapi/webplugin_resource_client.h" #include "content/child/plugin_messages.h" #include "content/common/content_constants_internal.h" #include "content/common/view_messages.h" #include "content/public/renderer/content_renderer_client.h" #include "content/renderer/npapi/plugin_channel_host.h" +#include "content/renderer/npapi/webplugin_impl.h" #include "content/renderer/render_thread_impl.h" #include "content/renderer/render_view_impl.h" #include "content/renderer/sad_plugin.h" @@ -201,10 +201,11 @@ class ResourceClientProxy : public WebPluginResourceClient { } // namespace WebPluginDelegateProxy::WebPluginDelegateProxy( + WebPluginImpl* plugin, const std::string& mime_type, const base::WeakPtr<RenderViewImpl>& render_view) : render_view_(render_view), - plugin_(NULL), + plugin_(plugin), uses_shared_bitmaps_(false), #if defined(OS_MACOSX) uses_compositor_(false), @@ -284,7 +285,6 @@ bool WebPluginDelegateProxy::Initialize( const GURL& url, const std::vector<std::string>& arg_names, const std::vector<std::string>& arg_values, - WebPlugin* plugin, bool load_manually) { // TODO(shess): Attempt to work around http://crbug.com/97285 and // http://crbug.com/141055 by retrying the connection. Reports seem @@ -373,8 +373,6 @@ bool WebPluginDelegateProxy::Initialize( params.host_render_view_routing_id = render_view_->routing_id(); params.load_manually = load_manually; - plugin_ = plugin; - result = false; Send(new PluginMsg_Init(instance_id_, params, &transparent_, &result)); @@ -440,10 +438,6 @@ bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow) -#if defined(OS_WIN) - IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindowlessData, OnSetWindowlessData) - IPC_MESSAGE_HANDLER(PluginHostMsg_NotifyIMEStatus, OnNotifyIMEStatus) -#endif IPC_MESSAGE_HANDLER(PluginHostMsg_CancelResource, OnCancelResource) IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) IPC_MESSAGE_HANDLER(PluginHostMsg_GetWindowScriptNPObject, @@ -458,7 +452,14 @@ bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { OnInitiateHTTPRangeRequest) IPC_MESSAGE_HANDLER(PluginHostMsg_DeferResourceLoading, OnDeferResourceLoading) - + IPC_MESSAGE_HANDLER(PluginHostMsg_URLRedirectResponse, + OnURLRedirectResponse) + IPC_MESSAGE_HANDLER(PluginHostMsg_CheckIfRunInsecureContent, + OnCheckIfRunInsecureContent) +#if defined(OS_WIN) + IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindowlessData, OnSetWindowlessData) + IPC_MESSAGE_HANDLER(PluginHostMsg_NotifyIMEStatus, OnNotifyIMEStatus) +#endif #if defined(OS_MACOSX) IPC_MESSAGE_HANDLER(PluginHostMsg_FocusChanged, OnFocusChanged); @@ -471,8 +472,6 @@ bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(PluginHostMsg_AcceleratedPluginSwappedIOSurface, OnAcceleratedPluginSwappedIOSurface) #endif - IPC_MESSAGE_HANDLER(PluginHostMsg_URLRedirectResponse, - OnURLRedirectResponse) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() DCHECK(handled); @@ -1119,6 +1118,31 @@ WebPluginResourceClient* WebPluginDelegateProxy::CreateSeekableResourceClient( return proxy; } +void WebPluginDelegateProxy::FetchURL(unsigned long resource_id, + int notify_id, + const GURL& url, + const GURL& first_party_for_cookies, + const std::string& method, + const std::string& post_data, + const GURL& referrer, + bool notify_redirects, + bool is_plugin_src_load, + int origin_pid, + int render_view_id) { + PluginMsg_FetchURL_Params params; + params.resource_id = resource_id; + params.notify_id = notify_id; + params.url = url; + params.first_party_for_cookies = first_party_for_cookies; + params.method = method; + params.post_data = post_data; + params.referrer = referrer; + params.notify_redirect = notify_redirects; + params.is_plugin_src_load = is_plugin_src_load; + params.render_view_id = render_view_id; + Send(new PluginMsg_FetchURL(instance_id_, params)); +} + #if defined(OS_MACOSX) void WebPluginDelegateProxy::OnFocusChanged(bool focused) { if (render_view_) @@ -1204,4 +1228,9 @@ void WebPluginDelegateProxy::OnURLRedirectResponse(bool allow, plugin_->URLRedirectResponse(allow, resource_id); } +void WebPluginDelegateProxy::OnCheckIfRunInsecureContent(const GURL& url, + bool* result) { + *result = plugin_->CheckIfRunInsecureContent(url); +} + } // namespace content diff --git a/content/renderer/npapi/webplugin_delegate_proxy.h b/content/renderer/npapi/webplugin_delegate_proxy.h index 3c5e5a2..168f890 100644 --- a/content/renderer/npapi/webplugin_delegate_proxy.h +++ b/content/renderer/npapi/webplugin_delegate_proxy.h @@ -39,6 +39,7 @@ namespace content { class NPObjectStub; class PluginChannelHost; class RenderViewImpl; +class WebPluginImpl; // An implementation of WebPluginDelegate that proxies all calls to // the plugin process. @@ -48,7 +49,8 @@ class WebPluginDelegateProxy public IPC::Sender, public base::SupportsWeakPtr<WebPluginDelegateProxy> { public: - WebPluginDelegateProxy(const std::string& mime_type, + WebPluginDelegateProxy(WebPluginImpl* plugin, + const std::string& mime_type, const base::WeakPtr<RenderViewImpl>& render_view); // WebPluginDelegate implementation: @@ -56,7 +58,6 @@ class WebPluginDelegateProxy virtual bool Initialize(const GURL& url, const std::vector<std::string>& arg_names, const std::vector<std::string>& arg_values, - WebPlugin* plugin, bool load_manually) OVERRIDE; virtual void UpdateGeometry(const gfx::Rect& window_rect, const gfx::Rect& clip_rect) OVERRIDE; @@ -122,6 +123,17 @@ class WebPluginDelegateProxy unsigned long resource_id, const GURL& url, int notify_id) OVERRIDE; virtual WebPluginResourceClient* CreateSeekableResourceClient( unsigned long resource_id, int range_request_id) OVERRIDE; + virtual void FetchURL(unsigned long resource_id, + int notify_id, + const GURL& url, + const GURL& first_party_for_cookies, + const std::string& method, + const std::string& post_data, + const GURL& referrer, + bool notify_redirects, + bool is_plugin_src_load, + int origin_pid, + int render_view_id) OVERRIDE; gfx::PluginWindowHandle GetPluginWindowHandle(); @@ -141,11 +153,6 @@ class WebPluginDelegateProxy // Message handlers for messages that proxy WebPlugin methods, which // we translate into calls to the real WebPlugin. void OnSetWindow(gfx::PluginWindowHandle window); -#if defined(OS_WIN) - void OnSetWindowlessData(HANDLE modal_loop_pump_messages_event, - gfx::NativeViewId dummy_activation_window); - void OnNotifyIMEStatus(const int input_mode, const gfx::Rect& caret_rect); -#endif void OnCompleteURL(const std::string& url_in, std::string* url_out, bool* result); void OnHandleURLRequest(const PluginHostMsg_URLRequest_Params& params); @@ -164,7 +171,8 @@ class WebPluginDelegateProxy const std::string& range_info, int range_request_id); void OnDeferResourceLoading(unsigned long resource_id, bool defer); - + void OnURLRedirectResponse(bool allow, int resource_id); + void OnCheckIfRunInsecureContent(const GURL& url, bool* result); #if defined(OS_MACOSX) void OnFocusChanged(bool focused); void OnStartIme(); @@ -175,9 +183,11 @@ class WebPluginDelegateProxy uint32 surface_id); void OnAcceleratedPluginSwappedIOSurface(); #endif - - void OnURLRedirectResponse(bool allow, int resource_id); - +#if defined(OS_WIN) + void OnSetWindowlessData(HANDLE modal_loop_pump_messages_event, + gfx::NativeViewId dummy_activation_window); + void OnNotifyIMEStatus(const int input_mode, const gfx::Rect& caret_rect); +#endif // Helper function that sends the UpdateGeometry message. void SendUpdateGeometry(bool bitmaps_changed); @@ -238,7 +248,7 @@ class WebPluginDelegateProxy #endif base::WeakPtr<RenderViewImpl> render_view_; - WebPlugin* plugin_; + WebPluginImpl* plugin_; bool uses_shared_bitmaps_; #if defined(OS_MACOSX) bool uses_compositor_; diff --git a/content/renderer/npapi/webplugin_impl.cc b/content/renderer/npapi/webplugin_impl.cc index 4de0631..a80f745 100644 --- a/content/renderer/npapi/webplugin_impl.cc +++ b/content/renderer/npapi/webplugin_impl.cc @@ -5,6 +5,7 @@ #include "content/renderer/npapi/webplugin_impl.h" #include "base/bind.h" +#include "base/command_line.h" #include "base/debug/crash_logging.h" #include "base/logging.h" #include "base/memory/linked_ptr.h" @@ -20,6 +21,7 @@ #include "content/child/npapi/webplugin_resource_client.h" #include "content/common/view_messages.h" #include "content/public/common/content_constants.h" +#include "content/public/common/content_switches.h" #include "content/public/renderer/content_renderer_client.h" #include "content/renderer/npapi/webplugin_delegate_proxy.h" #include "content/renderer/render_process.h" @@ -256,7 +258,7 @@ bool WebPluginImpl::initialize(WebPluginContainer* container) { SetContainer(container); bool ok = plugin_delegate->Initialize( - plugin_url_, arg_names_, arg_values_, this, load_manually_); + plugin_url_, arg_names_, arg_values_, load_manually_); if (!ok) { plugin_delegate->PluginDestroyed(); @@ -624,10 +626,6 @@ bool WebPluginImpl::SetPostData(WebURLRequest* request, return rv; } -WebPluginDelegate* WebPluginImpl::delegate() { - return delegate_; -} - bool WebPluginImpl::IsValidUrl(const GURL& url, Referrer referrer_flag) { if (referrer_flag == PLUGIN_SRC && mime_type_ == kFlashPluginSwfMimeType && @@ -655,7 +653,7 @@ WebPluginDelegate* WebPluginImpl::CreatePluginDelegate() { bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); if (in_process_plugin) { #if defined(OS_WIN) && !defined(USE_AURA) - return WebPluginDelegateImpl::Create(file_path_, mime_type_); + return WebPluginDelegateImpl::Create(this, file_path_, mime_type_); #else // In-proc plugins aren't supported on non-Windows. NOTIMPLEMENTED(); @@ -663,7 +661,7 @@ WebPluginDelegate* WebPluginImpl::CreatePluginDelegate() { #endif } - return new WebPluginDelegateProxy(mime_type_, render_view_); + return new WebPluginDelegateProxy(this, mime_type_, render_view_); } WebPluginImpl::RoutingStatus WebPluginImpl::RouteToFrame( @@ -805,6 +803,13 @@ void WebPluginImpl::URLRedirectResponse(bool allow, int resource_id) { } } +bool WebPluginImpl::CheckIfRunInsecureContent(const GURL& url) { + if (!webframe_) + return true; + + return webframe_->checkIfRunInsecureContent(url); +} + #if defined(OS_MACOSX) WebPluginAcceleratedSurface* WebPluginImpl::GetAcceleratedSurface( gfx::GpuPreference gpu_preference) { @@ -894,6 +899,8 @@ WebPluginImpl::ClientInfo* WebPluginImpl::GetClientInfoFromLoader( void WebPluginImpl::willSendRequest(WebURLLoader* loader, WebURLRequest& request, const WebURLResponse& response) { + // TODO(jam): THIS LOGIC IS COPIED IN PluginURLFetcher::OnReceivedRedirect + // until kDirectNPAPIRequests is the default and we can remove this old path. WebPluginImpl::ClientInfo* client_info = GetClientInfoFromLoader(loader); if (client_info) { // Currently this check is just to catch an https -> http redirect when @@ -1183,16 +1190,14 @@ void WebPluginImpl::HandleURLRequestInternal(const char* url, if (!WebPluginImpl::IsValidUrl(complete_url, referrer_flag)) return; - WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( - resource_id, complete_url, notify_id); - if (!resource_client) - 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(resource_id); + WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( + resource_id, complete_url, notify_id); + if (resource_client) + resource_client->DidFail(resource_id); return; } @@ -1202,9 +1207,37 @@ void WebPluginImpl::HandleURLRequestInternal(const char* url, if (!delegate_) return; - InitiateHTTPRequest(resource_id, resource_client, complete_url, method, buf, - len, NULL, referrer_flag, notify_redirects, - is_plugin_src_load); + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDirectNPAPIRequests)) { + // We got here either because the plugin called GetURL/PostURL, or because + // we're fetching the data for an embed tag. If we're in multi-process mode, + // we want to fetch the data in the plugin process as the renderer won't be + // able to request any origin when site isolation is in place. So bounce + // this request back to the plugin process which will use ResourceDispatcher + // to fetch the url. + + // TODO(jam): any better way of getting this? Can't find a way to get + // frame()->loader()->outgoingReferrer() which + // WebFrameImpl::setReferrerForRequest does. + WebURLRequest request(complete_url); + SetReferrer(&request, referrer_flag); + GURL referrer( + request.httpHeaderField(WebString::fromUTF8("Referer")).utf8()); + + GURL first_party_for_cookies = webframe_->document().firstPartyForCookies(); + delegate_->FetchURL(resource_id, notify_id, complete_url, + first_party_for_cookies, method, std::string(buf, len), + referrer, notify_redirects, is_plugin_src_load, 0, + render_view_->routing_id()); + } else { + WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( + resource_id, complete_url, notify_id); + if (!resource_client) + return; + InitiateHTTPRequest(resource_id, resource_client, complete_url, method, buf, + len, NULL, referrer_flag, notify_redirects, + is_plugin_src_load); + } } unsigned long WebPluginImpl::GetNextResourceId() { @@ -1381,7 +1414,7 @@ bool WebPluginImpl::ReinitializePluginForResponse( container_->allowScriptObjects(); bool ok = plugin_delegate && plugin_delegate->Initialize( - plugin_url_, arg_names_, arg_values_, this, load_manually_); + plugin_url_, arg_names_, arg_values_, load_manually_); if (!ok) { container_->clearScriptObjects(); diff --git a/content/renderer/npapi/webplugin_impl.h b/content/renderer/npapi/webplugin_impl.h index 63f85fb..264a5fc 100644 --- a/content/renderer/npapi/webplugin_impl.h +++ b/content/renderer/npapi/webplugin_impl.h @@ -66,9 +66,9 @@ class WebPluginImpl : public WebPlugin, const char* buf, uint32 length); - virtual WebPluginDelegate* delegate(); + WebKit::WebFrame* webframe() { return webframe_; } + WebPluginDelegate* delegate() { return delegate_; } - private: // WebKit::WebPlugin methods: virtual bool initialize( WebKit::WebPluginContainer* container); @@ -101,12 +101,6 @@ class WebPluginImpl : public WebPlugin, virtual void SetWindow(gfx::PluginWindowHandle window) OVERRIDE; virtual void SetAcceptsInputEvents(bool accepts) OVERRIDE; virtual void WillDestroyWindow(gfx::PluginWindowHandle window) OVERRIDE; -#if defined(OS_WIN) - void SetWindowlessData(HANDLE pump_messages_event, - gfx::NativeViewId dummy_activation_window) { } - void ReparentPluginWindow(HWND window, HWND parent) { } - void ReportExecutableMemory(size_t size) { } -#endif virtual void CancelResource(unsigned long id) OVERRIDE; virtual void Invalidate() OVERRIDE; virtual void InvalidateRect(const gfx::Rect& rect) OVERRIDE; @@ -119,7 +113,29 @@ class WebPluginImpl : public WebPlugin, const std::string& cookie) OVERRIDE; virtual std::string GetCookies(const GURL& url, const GURL& first_party_for_cookies) OVERRIDE; + virtual void HandleURLRequest(const char* url, + const char *method, + const char* target, + const char* buf, + unsigned int len, + int notify_id, + bool popups_allowed, + bool notify_redirects) OVERRIDE; + virtual void CancelDocumentLoad() OVERRIDE; + virtual void InitiateHTTPRangeRequest(const char* url, + const char* range_info, + int pending_request_id) OVERRIDE; + virtual bool IsOffTheRecord() OVERRIDE; + virtual void SetDeferResourceLoading(unsigned long resource_id, + bool defer) OVERRIDE; virtual void URLRedirectResponse(bool allow, int resource_id) OVERRIDE; + virtual bool CheckIfRunInsecureContent(const GURL& url) OVERRIDE; +#if defined(OS_WIN) + void SetWindowlessData(HANDLE pump_messages_event, + gfx::NativeViewId dummy_activation_window) { } + void ReparentPluginWindow(HWND window, HWND parent) { } + void ReportExecutableMemory(size_t size) { } +#endif #if defined(OS_MACOSX) virtual WebPluginAcceleratedSurface* GetAcceleratedSurface( gfx::GpuPreference gpu_preference) OVERRIDE; @@ -130,6 +146,7 @@ class WebPluginImpl : public WebPlugin, virtual void AcceleratedPluginSwappedIOSurface() OVERRIDE; #endif + private: // Given a (maybe partial) url, completes using the base url. GURL CompleteURL(const char* url); @@ -215,27 +232,6 @@ class WebPluginImpl : public WebPlugin, // request given a handle. void RemoveClient(WebKit::WebURLLoader* loader); - virtual void HandleURLRequest(const char* url, - const char *method, - const char* target, - const char* buf, - unsigned int len, - int notify_id, - bool popups_allowed, - bool notify_redirects) OVERRIDE; - - virtual void CancelDocumentLoad() OVERRIDE; - - virtual void InitiateHTTPRangeRequest(const char* url, - const char* range_info, - int pending_request_id) OVERRIDE; - - virtual void SetDeferResourceLoading(unsigned long resource_id, - bool defer) OVERRIDE; - - // Ignore in-process plugins mode for this flag. - virtual bool IsOffTheRecord() OVERRIDE; - // Handles HTTP multipart responses, i.e. responses received with a HTTP // status code of 206. // Returns false if response is not multipart (may be if we requested |