| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 ScopedLogLevel::~ScopedLogLevel() { | 90 ScopedLogLevel::~ScopedLogLevel() { |
| 91 logging::SetMinLogLevel(old_level_); | 91 logging::SetMinLogLevel(old_level_); |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Proxy for WebPluginResourceClient. The object owns itself after creation, | 94 // Proxy for WebPluginResourceClient. The object owns itself after creation, |
| 95 // deleting itself after its callback has been called. | 95 // deleting itself after its callback has been called. |
| 96 class ResourceClientProxy : public WebPluginResourceClient { | 96 class ResourceClientProxy : public WebPluginResourceClient { |
| 97 public: | 97 public: |
| 98 ResourceClientProxy(PluginChannelHost* channel, int instance_id) | 98 ResourceClientProxy(PluginChannelHost* channel, int instance_id) |
| 99 : channel_(channel), instance_id_(instance_id), resource_id_(0), | 99 : channel_(channel), instance_id_(instance_id), resource_id_(0) { |
| 100 multibyte_response_expected_(false) { | |
| 101 } | 100 } |
| 102 | 101 |
| 103 ~ResourceClientProxy() override {} | 102 ~ResourceClientProxy() override {} |
| 104 | 103 |
| 105 void Initialize(unsigned long resource_id, const GURL& url, int notify_id) { | |
| 106 resource_id_ = resource_id; | |
| 107 channel_->Send(new PluginMsg_HandleURLRequestReply( | |
| 108 instance_id_, resource_id, url, notify_id)); | |
| 109 } | |
| 110 | |
| 111 void InitializeForSeekableStream(unsigned long resource_id, | |
| 112 int range_request_id) { | |
| 113 resource_id_ = resource_id; | |
| 114 multibyte_response_expected_ = true; | |
| 115 channel_->Send(new PluginMsg_HTTPRangeRequestReply( | |
| 116 instance_id_, resource_id, range_request_id)); | |
| 117 } | |
| 118 | |
| 119 // PluginResourceClient implementation: | 104 // PluginResourceClient implementation: |
| 120 void WillSendRequest(const GURL& url, int http_status_code) override { | 105 void WillSendRequest(const GURL& url, int http_status_code) override { |
| 121 DCHECK(channel_.get() != NULL); | 106 DCHECK(channel_.get() != NULL); |
| 122 channel_->Send(new PluginMsg_WillSendRequest( | 107 channel_->Send(new PluginMsg_WillSendRequest( |
| 123 instance_id_, resource_id_, url, http_status_code)); | 108 instance_id_, resource_id_, url, http_status_code)); |
| 124 } | 109 } |
| 125 | 110 |
| 126 void DidReceiveResponse(const std::string& mime_type, | 111 void DidReceiveResponse(const std::string& mime_type, |
| 127 const std::string& headers, | 112 const std::string& headers, |
| 128 uint32 expected_length, | 113 uint32 expected_length, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 151 } |
| 167 | 152 |
| 168 void DidFail(unsigned long resource_id) override { | 153 void DidFail(unsigned long resource_id) override { |
| 169 DCHECK(channel_.get() != NULL); | 154 DCHECK(channel_.get() != NULL); |
| 170 DCHECK_EQ(resource_id, resource_id_); | 155 DCHECK_EQ(resource_id, resource_id_); |
| 171 channel_->Send(new PluginMsg_DidFail(instance_id_, resource_id_)); | 156 channel_->Send(new PluginMsg_DidFail(instance_id_, resource_id_)); |
| 172 channel_ = NULL; | 157 channel_ = NULL; |
| 173 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 158 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 174 } | 159 } |
| 175 | 160 |
| 176 bool IsMultiByteResponseExpected() override { | |
| 177 return multibyte_response_expected_; | |
| 178 } | |
| 179 | |
| 180 int ResourceId() override { return resource_id_; } | 161 int ResourceId() override { return resource_id_; } |
| 181 | 162 |
| 182 private: | 163 private: |
| 183 scoped_refptr<PluginChannelHost> channel_; | 164 scoped_refptr<PluginChannelHost> channel_; |
| 184 int instance_id_; | 165 int instance_id_; |
| 185 unsigned long resource_id_; | 166 unsigned long resource_id_; |
| 186 // Set to true if the response expected is a multibyte response. | |
| 187 // For e.g. response for a HTTP byte range request. | |
| 188 bool multibyte_response_expected_; | |
| 189 }; | 167 }; |
| 190 | 168 |
| 191 } // namespace | 169 } // namespace |
| 192 | 170 |
| 193 WebPluginDelegateProxy::WebPluginDelegateProxy( | 171 WebPluginDelegateProxy::WebPluginDelegateProxy( |
| 194 WebPluginImpl* plugin, | 172 WebPluginImpl* plugin, |
| 195 const std::string& mime_type, | 173 const std::string& mime_type, |
| 196 const base::WeakPtr<RenderViewImpl>& render_view, | 174 const base::WeakPtr<RenderViewImpl>& render_view, |
| 197 RenderFrameImpl* render_frame) | 175 RenderFrameImpl* render_frame) |
| 198 : render_view_(render_view), | 176 : render_view_(render_view), |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 bool WebPluginDelegateProxy::Send(IPC::Message* msg) { | 357 bool WebPluginDelegateProxy::Send(IPC::Message* msg) { |
| 380 if (!channel_host_.get()) { | 358 if (!channel_host_.get()) { |
| 381 DLOG(WARNING) << "dropping message because channel host is null"; | 359 DLOG(WARNING) << "dropping message because channel host is null"; |
| 382 delete msg; | 360 delete msg; |
| 383 return false; | 361 return false; |
| 384 } | 362 } |
| 385 | 363 |
| 386 return channel_host_->Send(msg); | 364 return channel_host_->Send(msg); |
| 387 } | 365 } |
| 388 | 366 |
| 389 void WebPluginDelegateProxy::SendJavaScriptStream(const GURL& url, | |
| 390 const std::string& result, | |
| 391 bool success, | |
| 392 int notify_id) { | |
| 393 Send(new PluginMsg_SendJavaScriptStream( | |
| 394 instance_id_, url, result, success, notify_id)); | |
| 395 } | |
| 396 | |
| 397 void WebPluginDelegateProxy::DidReceiveManualResponse( | |
| 398 const GURL& url, const std::string& mime_type, | |
| 399 const std::string& headers, uint32 expected_length, | |
| 400 uint32 last_modified) { | |
| 401 PluginMsg_DidReceiveResponseParams params; | |
| 402 params.id = 0; | |
| 403 params.mime_type = mime_type; | |
| 404 params.headers = headers; | |
| 405 params.expected_length = expected_length; | |
| 406 params.last_modified = last_modified; | |
| 407 Send(new PluginMsg_DidReceiveManualResponse(instance_id_, url, params)); | |
| 408 } | |
| 409 | |
| 410 void WebPluginDelegateProxy::DidReceiveManualData(const char* buffer, | |
| 411 int length) { | |
| 412 DCHECK_GT(length, 0); | |
| 413 std::vector<char> data; | |
| 414 data.resize(static_cast<size_t>(length)); | |
| 415 memcpy(&data.front(), buffer, length); | |
| 416 Send(new PluginMsg_DidReceiveManualData(instance_id_, data)); | |
| 417 } | |
| 418 | |
| 419 void WebPluginDelegateProxy::DidFinishManualLoading() { | |
| 420 Send(new PluginMsg_DidFinishManualLoading(instance_id_)); | |
| 421 } | |
| 422 | |
| 423 void WebPluginDelegateProxy::DidManualLoadFail() { | |
| 424 Send(new PluginMsg_DidManualLoadFail(instance_id_)); | |
| 425 } | |
| 426 | |
| 427 bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { | 367 bool WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { |
| 428 GetContentClient()->SetActiveURL(page_url_); | 368 GetContentClient()->SetActiveURL(page_url_); |
| 429 | 369 |
| 430 bool handled = true; | 370 bool handled = true; |
| 431 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) | 371 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) |
| 432 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow) | 372 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow) |
| 433 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelResource, OnCancelResource) | 373 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelResource, OnCancelResource) |
| 434 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) | 374 IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect) |
| 435 IPC_MESSAGE_HANDLER(PluginHostMsg_GetWindowScriptNPObject, | 375 IPC_MESSAGE_HANDLER(PluginHostMsg_GetWindowScriptNPObject, |
| 436 OnGetWindowScriptNPObject) | 376 OnGetWindowScriptNPObject) |
| 437 IPC_MESSAGE_HANDLER(PluginHostMsg_GetPluginElement, OnGetPluginElement) | 377 IPC_MESSAGE_HANDLER(PluginHostMsg_GetPluginElement, OnGetPluginElement) |
| 438 IPC_MESSAGE_HANDLER(PluginHostMsg_ResolveProxy, OnResolveProxy) | 378 IPC_MESSAGE_HANDLER(PluginHostMsg_ResolveProxy, OnResolveProxy) |
| 439 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie) | 379 IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie) |
| 440 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies) | 380 IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies) |
| 441 IPC_MESSAGE_HANDLER(PluginHostMsg_URLRequest, OnHandleURLRequest) | |
| 442 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelDocumentLoad, OnCancelDocumentLoad) | 381 IPC_MESSAGE_HANDLER(PluginHostMsg_CancelDocumentLoad, OnCancelDocumentLoad) |
| 443 IPC_MESSAGE_HANDLER(PluginHostMsg_InitiateHTTPRangeRequest, | |
| 444 OnInitiateHTTPRangeRequest) | |
| 445 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStartLoading, OnDidStartLoading) | 382 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStartLoading, OnDidStartLoading) |
| 446 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStopLoading, OnDidStopLoading) | 383 IPC_MESSAGE_HANDLER(PluginHostMsg_DidStopLoading, OnDidStopLoading) |
| 447 IPC_MESSAGE_HANDLER(PluginHostMsg_DeferResourceLoading, | 384 IPC_MESSAGE_HANDLER(PluginHostMsg_DeferResourceLoading, |
| 448 OnDeferResourceLoading) | 385 OnDeferResourceLoading) |
| 449 IPC_MESSAGE_HANDLER(PluginHostMsg_URLRedirectResponse, | 386 IPC_MESSAGE_HANDLER(PluginHostMsg_URLRedirectResponse, |
| 450 OnURLRedirectResponse) | 387 OnURLRedirectResponse) |
| 451 IPC_MESSAGE_HANDLER(PluginHostMsg_CheckIfRunInsecureContent, | 388 IPC_MESSAGE_HANDLER(PluginHostMsg_CheckIfRunInsecureContent, |
| 452 OnCheckIfRunInsecureContent) | 389 OnCheckIfRunInsecureContent) |
| 453 #if defined(OS_WIN) | 390 #if defined(OS_WIN) |
| 454 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindowlessData, OnSetWindowlessData) | 391 IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindowlessData, OnSetWindowlessData) |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 // Return a dummy NPP for WebKit to use to identify this plugin. | 671 // Return a dummy NPP for WebKit to use to identify this plugin. |
| 735 return npp_.get(); | 672 return npp_.get(); |
| 736 } | 673 } |
| 737 | 674 |
| 738 bool WebPluginDelegateProxy::GetFormValue(base::string16* value) { | 675 bool WebPluginDelegateProxy::GetFormValue(base::string16* value) { |
| 739 bool success = false; | 676 bool success = false; |
| 740 Send(new PluginMsg_GetFormValue(instance_id_, value, &success)); | 677 Send(new PluginMsg_GetFormValue(instance_id_, value, &success)); |
| 741 return success; | 678 return success; |
| 742 } | 679 } |
| 743 | 680 |
| 744 void WebPluginDelegateProxy::DidFinishLoadWithReason( | |
| 745 const GURL& url, NPReason reason, int notify_id) { | |
| 746 Send(new PluginMsg_DidFinishLoadWithReason( | |
| 747 instance_id_, url, reason, notify_id)); | |
| 748 } | |
| 749 | |
| 750 void WebPluginDelegateProxy::SetFocus(bool focused) { | 681 void WebPluginDelegateProxy::SetFocus(bool focused) { |
| 751 Send(new PluginMsg_SetFocus(instance_id_, focused)); | 682 Send(new PluginMsg_SetFocus(instance_id_, focused)); |
| 752 #if defined(OS_WIN) | 683 #if defined(OS_WIN) |
| 753 if (render_view_) | 684 if (render_view_) |
| 754 render_view_->PluginFocusChanged(focused, instance_id_); | 685 render_view_->PluginFocusChanged(focused, instance_id_); |
| 755 #endif | 686 #endif |
| 756 } | 687 } |
| 757 | 688 |
| 758 bool WebPluginDelegateProxy::HandleInputEvent( | 689 bool WebPluginDelegateProxy::HandleInputEvent( |
| 759 const WebInputEvent& event, | 690 const WebInputEvent& event, |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 front_buffer_diff_ = rect; | 989 front_buffer_diff_ = rect; |
| 1059 } else { | 990 } else { |
| 1060 // Back-buffer contains the latest content for "rect" but the front-buffer | 991 // Back-buffer contains the latest content for "rect" but the front-buffer |
| 1061 // contains the latest content for some other areas (or buffer flipping not | 992 // contains the latest content for some other areas (or buffer flipping not |
| 1062 // allowed); fall back to copying the data. | 993 // allowed); fall back to copying the data. |
| 1063 CopyFromBackBufferToFrontBuffer(rect); | 994 CopyFromBackBufferToFrontBuffer(rect); |
| 1064 } | 995 } |
| 1065 transport_store_painted_.Union(rect); | 996 transport_store_painted_.Union(rect); |
| 1066 } | 997 } |
| 1067 | 998 |
| 1068 void WebPluginDelegateProxy::OnHandleURLRequest( | |
| 1069 const PluginHostMsg_URLRequest_Params& params) { | |
| 1070 const char* data = NULL; | |
| 1071 if (params.buffer.size()) | |
| 1072 data = ¶ms.buffer[0]; | |
| 1073 | |
| 1074 const char* target = NULL; | |
| 1075 if (params.target.length()) | |
| 1076 target = params.target.c_str(); | |
| 1077 | |
| 1078 plugin_->HandleURLRequest( | |
| 1079 params.url.c_str(), params.method.c_str(), target, data, | |
| 1080 static_cast<unsigned int>(params.buffer.size()), params.notify_id, | |
| 1081 params.popups_allowed, params.notify_redirects); | |
| 1082 } | |
| 1083 | |
| 1084 WebPluginResourceClient* WebPluginDelegateProxy::CreateResourceClient( | |
| 1085 unsigned long resource_id, const GURL& url, int notify_id) { | |
| 1086 if (!channel_host_.get()) | |
| 1087 return NULL; | |
| 1088 | |
| 1089 ResourceClientProxy* proxy = | |
| 1090 new ResourceClientProxy(channel_host_.get(), instance_id_); | |
| 1091 proxy->Initialize(resource_id, url, notify_id); | |
| 1092 return proxy; | |
| 1093 } | |
| 1094 | |
| 1095 WebPluginResourceClient* WebPluginDelegateProxy::CreateSeekableResourceClient( | |
| 1096 unsigned long resource_id, int range_request_id) { | |
| 1097 if (!channel_host_.get()) | |
| 1098 return NULL; | |
| 1099 | |
| 1100 ResourceClientProxy* proxy = | |
| 1101 new ResourceClientProxy(channel_host_.get(), instance_id_); | |
| 1102 proxy->InitializeForSeekableStream(resource_id, range_request_id); | |
| 1103 return proxy; | |
| 1104 } | |
| 1105 | |
| 1106 void WebPluginDelegateProxy::FetchURL(unsigned long resource_id, | |
| 1107 int notify_id, | |
| 1108 const GURL& url, | |
| 1109 const GURL& first_party_for_cookies, | |
| 1110 const std::string& method, | |
| 1111 const char* buf, | |
| 1112 unsigned int len, | |
| 1113 const Referrer& referrer, | |
| 1114 bool notify_redirects, | |
| 1115 bool is_plugin_src_load, | |
| 1116 int origin_pid, | |
| 1117 int render_frame_id, | |
| 1118 int render_view_id) { | |
| 1119 PluginMsg_FetchURL_Params params; | |
| 1120 params.resource_id = resource_id; | |
| 1121 params.notify_id = notify_id; | |
| 1122 params.url = url; | |
| 1123 params.first_party_for_cookies = first_party_for_cookies; | |
| 1124 params.method = method; | |
| 1125 if (len) { | |
| 1126 params.post_data.resize(len); | |
| 1127 memcpy(¶ms.post_data.front(), buf, len); | |
| 1128 } | |
| 1129 params.referrer = referrer.url; | |
| 1130 params.referrer_policy = referrer.policy; | |
| 1131 params.notify_redirect = notify_redirects; | |
| 1132 params.is_plugin_src_load = is_plugin_src_load; | |
| 1133 params.render_frame_id = render_frame_id; | |
| 1134 Send(new PluginMsg_FetchURL(instance_id_, params)); | |
| 1135 } | |
| 1136 | |
| 1137 #if defined(OS_MACOSX) | 999 #if defined(OS_MACOSX) |
| 1138 void WebPluginDelegateProxy::OnFocusChanged(bool focused) { | 1000 void WebPluginDelegateProxy::OnFocusChanged(bool focused) { |
| 1139 if (render_view_) | 1001 if (render_view_) |
| 1140 render_view_->PluginFocusChanged(focused, instance_id_); | 1002 render_view_->PluginFocusChanged(focused, instance_id_); |
| 1141 } | 1003 } |
| 1142 | 1004 |
| 1143 void WebPluginDelegateProxy::OnStartIme() { | 1005 void WebPluginDelegateProxy::OnStartIme() { |
| 1144 if (render_view_) | 1006 if (render_view_) |
| 1145 render_view_->StartPluginIme(); | 1007 render_view_->StartPluginIme(); |
| 1146 } | 1008 } |
| 1147 #endif | 1009 #endif |
| 1148 | 1010 |
| 1149 gfx::PluginWindowHandle WebPluginDelegateProxy::GetPluginWindowHandle() { | 1011 gfx::PluginWindowHandle WebPluginDelegateProxy::GetPluginWindowHandle() { |
| 1150 return window_; | 1012 return window_; |
| 1151 } | 1013 } |
| 1152 | 1014 |
| 1153 void WebPluginDelegateProxy::OnCancelDocumentLoad() { | 1015 void WebPluginDelegateProxy::OnCancelDocumentLoad() { |
| 1154 plugin_->CancelDocumentLoad(); | 1016 plugin_->CancelDocumentLoad(); |
| 1155 } | 1017 } |
| 1156 | 1018 |
| 1157 void WebPluginDelegateProxy::OnInitiateHTTPRangeRequest( | |
| 1158 const std::string& url, | |
| 1159 const std::string& range_info, | |
| 1160 int range_request_id) { | |
| 1161 plugin_->InitiateHTTPRangeRequest( | |
| 1162 url.c_str(), range_info.c_str(), range_request_id); | |
| 1163 } | |
| 1164 | |
| 1165 void WebPluginDelegateProxy::OnDidStartLoading() { | 1019 void WebPluginDelegateProxy::OnDidStartLoading() { |
| 1166 plugin_->DidStartLoading(); | 1020 plugin_->DidStartLoading(); |
| 1167 } | 1021 } |
| 1168 | 1022 |
| 1169 void WebPluginDelegateProxy::OnDidStopLoading() { | 1023 void WebPluginDelegateProxy::OnDidStopLoading() { |
| 1170 plugin_->DidStopLoading(); | 1024 plugin_->DidStopLoading(); |
| 1171 } | 1025 } |
| 1172 | 1026 |
| 1173 void WebPluginDelegateProxy::OnDeferResourceLoading(unsigned long resource_id, | 1027 void WebPluginDelegateProxy::OnDeferResourceLoading(unsigned long resource_id, |
| 1174 bool defer) { | 1028 bool defer) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 | 1081 |
| 1228 plugin_->URLRedirectResponse(allow, resource_id); | 1082 plugin_->URLRedirectResponse(allow, resource_id); |
| 1229 } | 1083 } |
| 1230 | 1084 |
| 1231 void WebPluginDelegateProxy::OnCheckIfRunInsecureContent(const GURL& url, | 1085 void WebPluginDelegateProxy::OnCheckIfRunInsecureContent(const GURL& url, |
| 1232 bool* result) { | 1086 bool* result) { |
| 1233 *result = plugin_->CheckIfRunInsecureContent(url); | 1087 *result = plugin_->CheckIfRunInsecureContent(url); |
| 1234 } | 1088 } |
| 1235 | 1089 |
| 1236 } // namespace content | 1090 } // namespace content |
| OLD | NEW |