| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/npapi/webplugin_delegate_proxy.h" | 5 #include "content/renderer/npapi/webplugin_delegate_proxy.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 ScopedLogLevel::ScopedLogLevel(int level) | 88 ScopedLogLevel::ScopedLogLevel(int level) |
| 89 : old_level_(logging::GetMinLogLevel()) { | 89 : old_level_(logging::GetMinLogLevel()) { |
| 90 logging::SetMinLogLevel(level); | 90 logging::SetMinLogLevel(level); |
| 91 } | 91 } |
| 92 | 92 |
| 93 ScopedLogLevel::~ScopedLogLevel() { | 93 ScopedLogLevel::~ScopedLogLevel() { |
| 94 logging::SetMinLogLevel(old_level_); | 94 logging::SetMinLogLevel(old_level_); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Proxy for WebPluginResourceClient. The object owns itself after creation, | |
| 98 // deleting itself after its callback has been called. | |
| 99 class ResourceClientProxy : public WebPluginResourceClient { | |
| 100 public: | |
| 101 ResourceClientProxy(PluginChannelHost* channel, int instance_id) | |
| 102 : channel_(channel), instance_id_(instance_id), resource_id_(0) { | |
| 103 } | |
| 104 | |
| 105 ~ResourceClientProxy() override {} | |
| 106 | |
| 107 // PluginResourceClient implementation: | |
| 108 void WillSendRequest(const GURL& url, int http_status_code) override { | |
| 109 DCHECK(channel_.get() != NULL); | |
| 110 channel_->Send(new PluginMsg_WillSendRequest( | |
| 111 instance_id_, resource_id_, url, http_status_code)); | |
| 112 } | |
| 113 | |
| 114 void DidReceiveResponse(const std::string& mime_type, | |
| 115 const std::string& headers, | |
| 116 uint32_t expected_length, | |
| 117 uint32_t last_modified, | |
| 118 bool request_is_seekable) override { | |
| 119 DCHECK(channel_.get() != NULL); | |
| 120 PluginMsg_DidReceiveResponseParams params; | |
| 121 params.id = resource_id_; | |
| 122 params.mime_type = mime_type; | |
| 123 params.headers = headers; | |
| 124 params.expected_length = expected_length; | |
| 125 params.last_modified = last_modified; | |
| 126 params.request_is_seekable = request_is_seekable; | |
| 127 // Grab a reference on the underlying channel so it does not get | |
| 128 // deleted from under us. | |
| 129 scoped_refptr<PluginChannelHost> channel_ref(channel_); | |
| 130 channel_->Send(new PluginMsg_DidReceiveResponse(instance_id_, params)); | |
| 131 } | |
| 132 | |
| 133 void DidReceiveData(const char* buffer, | |
| 134 int length, | |
| 135 int data_offset) override { | |
| 136 DCHECK(channel_.get() != NULL); | |
| 137 DCHECK_GT(length, 0); | |
| 138 std::vector<char> data; | |
| 139 data.resize(static_cast<size_t>(length)); | |
| 140 memcpy(&data.front(), buffer, length); | |
| 141 // Grab a reference on the underlying channel so it does not get | |
| 142 // deleted from under us. | |
| 143 scoped_refptr<PluginChannelHost> channel_ref(channel_); | |
| 144 channel_->Send(new PluginMsg_DidReceiveData(instance_id_, resource_id_, | |
| 145 data, data_offset)); | |
| 146 } | |
| 147 | |
| 148 void DidFinishLoading(unsigned long resource_id) override { | |
| 149 DCHECK(channel_.get() != NULL); | |
| 150 DCHECK_EQ(resource_id, resource_id_); | |
| 151 channel_->Send(new PluginMsg_DidFinishLoading(instance_id_, resource_id_)); | |
| 152 channel_ = NULL; | |
| 153 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
| 154 } | |
| 155 | |
| 156 void DidFail(unsigned long resource_id) override { | |
| 157 DCHECK(channel_.get() != NULL); | |
| 158 DCHECK_EQ(resource_id, resource_id_); | |
| 159 channel_->Send(new PluginMsg_DidFail(instance_id_, resource_id_)); | |
| 160 channel_ = NULL; | |
| 161 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
| 162 } | |
| 163 | |
| 164 int ResourceId() override { return resource_id_; } | |
| 165 | |
| 166 private: | |
| 167 scoped_refptr<PluginChannelHost> channel_; | |
| 168 int instance_id_; | |
| 169 unsigned long resource_id_; | |
| 170 }; | |
| 171 | |
| 172 } // namespace | 97 } // namespace |
| 173 | 98 |
| 174 WebPluginDelegateProxy::WebPluginDelegateProxy( | 99 WebPluginDelegateProxy::WebPluginDelegateProxy( |
| 175 WebPluginImpl* plugin, | 100 WebPluginImpl* plugin, |
| 176 const std::string& mime_type, | 101 const std::string& mime_type, |
| 177 const base::WeakPtr<RenderViewImpl>& render_view, | 102 const base::WeakPtr<RenderViewImpl>& render_view, |
| 178 RenderFrameImpl* render_frame) | 103 RenderFrameImpl* render_frame) |
| 179 : render_view_(render_view), | 104 : render_view_(render_view), |
| 180 render_frame_(render_frame), | 105 render_frame_(render_frame), |
| 181 plugin_(plugin), | 106 plugin_(plugin), |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 291 |
| 367 return channel_host_->Send(msg); | 292 return channel_host_->Send(msg); |
| 368 } | 293 } |
| 369 | 294 |
| 370 bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { | 295 bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { |
| 371 GetContentClient()->SetActiveURL(page_url_); | 296 GetContentClient()->SetActiveURL(page_url_); |
| 372 | 297 |
| 373 bool handled = true; | 298 bool handled = true; |
| 374 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) | 299 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) |
| 375 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow) | 300 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow) |
| 376 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelResource, OnCancelResource) | |
| 377 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) | 301 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) |
| 378 IPC_MESSAGE_HANDLER(PluginHostMsg_GetWindowScriptNPObject, | 302 IPC_MESSAGE_HANDLER(PluginHostMsg_GetWindowScriptNPObject, |
| 379 OnGetWindowScriptNPObject) | 303 OnGetWindowScriptNPObject) |
| 380 IPC_MESSAGE_HANDLER(PluginHostMsg_GetPluginElement, OnGetPluginElement) | 304 IPC_MESSAGE_HANDLER(PluginHostMsg_GetPluginElement, OnGetPluginElement) |
| 381 IPC_MESSAGE_HANDLER(PluginHostMsg_ResolveProxy, OnResolveProxy) | 305 IPC_MESSAGE_HANDLER(PluginHostMsg_ResolveProxy, OnResolveProxy) |
| 382 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie) | 306 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie) |
| 383 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies) | 307 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies) |
| 384 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelDocumentLoad, OnCancelDocumentLoad) | 308 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelDocumentLoad, OnCancelDocumentLoad) |
| 385 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStartLoading, OnDidStartLoading) | 309 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStartLoading, OnDidStartLoading) |
| 386 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStopLoading, OnDidStopLoading) | 310 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStopLoading, OnDidStopLoading) |
| 387 IPC_MESSAGE_HANDLER(PluginHostMsg_DeferResourceLoading, | |
| 388 OnDeferResourceLoading) | |
| 389 IPC_MESSAGE_HANDLER(PluginHostMsg_URLRedirectResponse, | |
| 390 OnURLRedirectResponse) | |
| 391 #if defined(OS_WIN) | 311 #if defined(OS_WIN) |
| 392 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindowlessData, OnSetWindowlessData) | 312 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindowlessData, OnSetWindowlessData) |
| 393 IPC_MESSAGE_HANDLER(PluginHostMsg_NotifyIMEStatus, OnNotifyIMEStatus) | 313 IPC_MESSAGE_HANDLER(PluginHostMsg_NotifyIMEStatus, OnNotifyIMEStatus) |
| 394 #endif | 314 #endif |
| 395 #if defined(OS_MACOSX) | 315 #if defined(OS_MACOSX) |
| 396 IPC_MESSAGE_HANDLER(PluginHostMsg_FocusChanged, | 316 IPC_MESSAGE_HANDLER(PluginHostMsg_FocusChanged, |
| 397 OnFocusChanged); | 317 OnFocusChanged); |
| 398 IPC_MESSAGE_HANDLER(PluginHostMsg_StartIme, | 318 IPC_MESSAGE_HANDLER(PluginHostMsg_StartIme, |
| 399 OnStartIme); | 319 OnStartIme); |
| 400 IPC_MESSAGE_HANDLER(PluginHostMsg_AcceleratedPluginEnabledRendering, | 320 IPC_MESSAGE_HANDLER(PluginHostMsg_AcceleratedPluginEnabledRendering, |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 bounds_params.anchor_rect = bounds_params.focus_rect = caret_rect; | 773 bounds_params.anchor_rect = bounds_params.focus_rect = caret_rect; |
| 854 bounds_params.anchor_dir = bounds_params.focus_dir = | 774 bounds_params.anchor_dir = bounds_params.focus_dir = |
| 855 blink::WebTextDirectionLeftToRight; | 775 blink::WebTextDirectionLeftToRight; |
| 856 bounds_params.is_anchor_first = true; | 776 bounds_params.is_anchor_first = true; |
| 857 render_view_->Send(new ViewHostMsg_SelectionBoundsChanged( | 777 render_view_->Send(new ViewHostMsg_SelectionBoundsChanged( |
| 858 render_view_->routing_id(), | 778 render_view_->routing_id(), |
| 859 bounds_params)); | 779 bounds_params)); |
| 860 } | 780 } |
| 861 #endif | 781 #endif |
| 862 | 782 |
| 863 void WebPluginDelegateProxy::OnCancelResource(int id) { | |
| 864 if (plugin_) | |
| 865 plugin_->CancelResource(id); | |
| 866 } | |
| 867 | |
| 868 void WebPluginDelegateProxy::OnInvalidateRect(const gfx::Rect& rect) { | 783 void WebPluginDelegateProxy::OnInvalidateRect(const gfx::Rect& rect) { |
| 869 if (!plugin_) | 784 if (!plugin_) |
| 870 return; | 785 return; |
| 871 | 786 |
| 872 // Clip the invalidation rect to the plugin bounds; the plugin may have been | 787 // Clip the invalidation rect to the plugin bounds; the plugin may have been |
| 873 // resized since the invalidate message was sent. | 788 // resized since the invalidate message was sent. |
| 874 gfx::Rect clipped_rect = | 789 gfx::Rect clipped_rect = |
| 875 gfx::IntersectRects(rect, gfx::Rect(plugin_rect_.size())); | 790 gfx::IntersectRects(rect, gfx::Rect(plugin_rect_.size())); |
| 876 | 791 |
| 877 invalidate_pending_ = true; | 792 invalidate_pending_ = true; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 } | 928 } |
| 1014 | 929 |
| 1015 void WebPluginDelegateProxy::OnDidStartLoading() { | 930 void WebPluginDelegateProxy::OnDidStartLoading() { |
| 1016 plugin_->DidStartLoading(); | 931 plugin_->DidStartLoading(); |
| 1017 } | 932 } |
| 1018 | 933 |
| 1019 void WebPluginDelegateProxy::OnDidStopLoading() { | 934 void WebPluginDelegateProxy::OnDidStopLoading() { |
| 1020 plugin_->DidStopLoading(); | 935 plugin_->DidStopLoading(); |
| 1021 } | 936 } |
| 1022 | 937 |
| 1023 void WebPluginDelegateProxy::OnDeferResourceLoading(unsigned long resource_id, | |
| 1024 bool defer) { | |
| 1025 plugin_->SetDeferResourceLoading(resource_id, defer); | |
| 1026 } | |
| 1027 | |
| 1028 #if defined(OS_MACOSX) | 938 #if defined(OS_MACOSX) |
| 1029 void WebPluginDelegateProxy::OnAcceleratedPluginEnabledRendering() { | 939 void WebPluginDelegateProxy::OnAcceleratedPluginEnabledRendering() { |
| 1030 uses_compositor_ = true; | 940 uses_compositor_ = true; |
| 1031 OnSetWindow(gfx::kNullPluginWindow); | 941 OnSetWindow(gfx::kNullPluginWindow); |
| 1032 } | 942 } |
| 1033 | 943 |
| 1034 void WebPluginDelegateProxy::OnAcceleratedPluginAllocatedIOSurface( | 944 void WebPluginDelegateProxy::OnAcceleratedPluginAllocatedIOSurface( |
| 1035 int32_t width, | 945 int32_t width, |
| 1036 int32_t height, | 946 int32_t height, |
| 1037 uint32_t surface_id) { | 947 uint32_t surface_id) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1063 index->mime_type == "application/x-vnd.moveplay2.qm" || | 973 index->mime_type == "application/x-vnd.moveplay2.qm" || |
| 1064 index->mime_type == "application/x-vnd.movenetworks.qm" || | 974 index->mime_type == "application/x-vnd.movenetworks.qm" || |
| 1065 index->mime_type == "application/x-vnd.mnplayer.qm") { | 975 index->mime_type == "application/x-vnd.mnplayer.qm") { |
| 1066 return true; | 976 return true; |
| 1067 } | 977 } |
| 1068 } | 978 } |
| 1069 return false; | 979 return false; |
| 1070 } | 980 } |
| 1071 #endif | 981 #endif |
| 1072 | 982 |
| 1073 void WebPluginDelegateProxy::OnURLRedirectResponse(bool allow, | |
| 1074 int resource_id) { | |
| 1075 if (!plugin_) | |
| 1076 return; | |
| 1077 | |
| 1078 plugin_->URLRedirectResponse(allow, resource_id); | |
| 1079 } | |
| 1080 | |
| 1081 } // namespace content | 983 } // namespace content |
| OLD | NEW |