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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 // Return a dummy NPP for WebKit to use to identify this plugin. | 672 // Return a dummy NPP for WebKit to use to identify this plugin. |
736 return npp_.get(); | 673 return npp_.get(); |
737 } | 674 } |
738 | 675 |
739 bool WebPluginDelegateProxy::GetFormValue(base::string16* value) { | 676 bool WebPluginDelegateProxy::GetFormValue(base::string16* value) { |
740 bool success = false; | 677 bool success = false; |
741 Send(new PluginMsg_GetFormValue(instance_id_, value, &success)); | 678 Send(new PluginMsg_GetFormValue(instance_id_, value, &success)); |
742 return success; | 679 return success; |
743 } | 680 } |
744 | 681 |
745 void WebPluginDelegateProxy::DidFinishLoadWithReason( | |
746 const GURL& url, NPReason reason, int notify_id) { | |
747 Send(new PluginMsg_DidFinishLoadWithReason( | |
748 instance_id_, url, reason, notify_id)); | |
749 } | |
750 | |
751 void WebPluginDelegateProxy::SetFocus(bool focused) { | 682 void WebPluginDelegateProxy::SetFocus(bool focused) { |
752 Send(new PluginMsg_SetFocus(instance_id_, focused)); | 683 Send(new PluginMsg_SetFocus(instance_id_, focused)); |
753 #if defined(OS_WIN) | 684 #if defined(OS_WIN) |
754 if (render_view_) | 685 if (render_view_) |
755 render_view_->PluginFocusChanged(focused, instance_id_); | 686 render_view_->PluginFocusChanged(focused, instance_id_); |
756 #endif | 687 #endif |
757 } | 688 } |
758 | 689 |
759 bool WebPluginDelegateProxy::HandleInputEvent( | 690 bool WebPluginDelegateProxy::HandleInputEvent( |
760 const WebInputEvent& event, | 691 const WebInputEvent& event, |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 front_buffer_diff_ = rect; | 990 front_buffer_diff_ = rect; |
1060 } else { | 991 } else { |
1061 // Back-buffer contains the latest content for "rect" but the front-buffer | 992 // Back-buffer contains the latest content for "rect" but the front-buffer |
1062 // contains the latest content for some other areas (or buffer flipping not | 993 // contains the latest content for some other areas (or buffer flipping not |
1063 // allowed); fall back to copying the data. | 994 // allowed); fall back to copying the data. |
1064 CopyFromBackBufferToFrontBuffer(rect); | 995 CopyFromBackBufferToFrontBuffer(rect); |
1065 } | 996 } |
1066 transport_store_painted_.Union(rect); | 997 transport_store_painted_.Union(rect); |
1067 } | 998 } |
1068 | 999 |
1069 void WebPluginDelegateProxy::OnHandleURLRequest( | |
1070 const PluginHostMsg_URLRequest_Params& params) { | |
1071 const char* data = NULL; | |
1072 if (params.buffer.size()) | |
1073 data = ¶ms.buffer[0]; | |
1074 | |
1075 const char* target = NULL; | |
1076 if (params.target.length()) | |
1077 target = params.target.c_str(); | |
1078 | |
1079 plugin_->HandleURLRequest( | |
1080 params.url.c_str(), params.method.c_str(), target, data, | |
1081 static_cast<unsigned int>(params.buffer.size()), params.notify_id, | |
1082 params.popups_allowed, params.notify_redirects); | |
1083 } | |
1084 | |
1085 WebPluginResourceClient* WebPluginDelegateProxy::CreateResourceClient( | |
1086 unsigned long resource_id, const GURL& url, int notify_id) { | |
1087 if (!channel_host_.get()) | |
1088 return NULL; | |
1089 | |
1090 ResourceClientProxy* proxy = | |
1091 new ResourceClientProxy(channel_host_.get(), instance_id_); | |
1092 proxy->Initialize(resource_id, url, notify_id); | |
1093 return proxy; | |
1094 } | |
1095 | |
1096 WebPluginResourceClient* WebPluginDelegateProxy::CreateSeekableResourceClient( | |
1097 unsigned long resource_id, int range_request_id) { | |
1098 if (!channel_host_.get()) | |
1099 return NULL; | |
1100 | |
1101 ResourceClientProxy* proxy = | |
1102 new ResourceClientProxy(channel_host_.get(), instance_id_); | |
1103 proxy->InitializeForSeekableStream(resource_id, range_request_id); | |
1104 return proxy; | |
1105 } | |
1106 | |
1107 void WebPluginDelegateProxy::FetchURL(unsigned long resource_id, | |
1108 int notify_id, | |
1109 const GURL& url, | |
1110 const GURL& first_party_for_cookies, | |
1111 const std::string& method, | |
1112 const char* buf, | |
1113 unsigned int len, | |
1114 const Referrer& referrer, | |
1115 bool notify_redirects, | |
1116 bool is_plugin_src_load, | |
1117 int origin_pid, | |
1118 int render_frame_id, | |
1119 int render_view_id) { | |
1120 PluginMsg_FetchURL_Params params; | |
1121 params.resource_id = resource_id; | |
1122 params.notify_id = notify_id; | |
1123 params.url = url; | |
1124 params.first_party_for_cookies = first_party_for_cookies; | |
1125 params.method = method; | |
1126 if (len) { | |
1127 params.post_data.resize(len); | |
1128 memcpy(¶ms.post_data.front(), buf, len); | |
1129 } | |
1130 params.referrer = referrer.url; | |
1131 params.referrer_policy = referrer.policy; | |
1132 params.notify_redirect = notify_redirects; | |
1133 params.is_plugin_src_load = is_plugin_src_load; | |
1134 params.render_frame_id = render_frame_id; | |
1135 Send(new PluginMsg_FetchURL(instance_id_, params)); | |
1136 } | |
1137 | |
1138 #if defined(OS_MACOSX) | 1000 #if defined(OS_MACOSX) |
1139 void WebPluginDelegateProxy::OnFocusChanged(bool focused) { | 1001 void WebPluginDelegateProxy::OnFocusChanged(bool focused) { |
1140 if (render_view_) | 1002 if (render_view_) |
1141 render_view_->PluginFocusChanged(focused, instance_id_); | 1003 render_view_->PluginFocusChanged(focused, instance_id_); |
1142 } | 1004 } |
1143 | 1005 |
1144 void WebPluginDelegateProxy::OnStartIme() { | 1006 void WebPluginDelegateProxy::OnStartIme() { |
1145 if (render_view_) | 1007 if (render_view_) |
1146 render_view_->StartPluginIme(); | 1008 render_view_->StartPluginIme(); |
1147 } | 1009 } |
1148 #endif | 1010 #endif |
1149 | 1011 |
1150 gfx::PluginWindowHandle WebPluginDelegateProxy::GetPluginWindowHandle() { | 1012 gfx::PluginWindowHandle WebPluginDelegateProxy::GetPluginWindowHandle() { |
1151 return window_; | 1013 return window_; |
1152 } | 1014 } |
1153 | 1015 |
1154 void WebPluginDelegateProxy::OnCancelDocumentLoad() { | 1016 void WebPluginDelegateProxy::OnCancelDocumentLoad() { |
1155 plugin_->CancelDocumentLoad(); | 1017 plugin_->CancelDocumentLoad(); |
1156 } | 1018 } |
1157 | 1019 |
1158 void WebPluginDelegateProxy::OnInitiateHTTPRangeRequest( | |
1159 const std::string& url, | |
1160 const std::string& range_info, | |
1161 int range_request_id) { | |
1162 plugin_->InitiateHTTPRangeRequest( | |
1163 url.c_str(), range_info.c_str(), range_request_id); | |
1164 } | |
1165 | |
1166 void WebPluginDelegateProxy::OnDidStartLoading() { | 1020 void WebPluginDelegateProxy::OnDidStartLoading() { |
1167 plugin_->DidStartLoading(); | 1021 plugin_->DidStartLoading(); |
1168 } | 1022 } |
1169 | 1023 |
1170 void WebPluginDelegateProxy::OnDidStopLoading() { | 1024 void WebPluginDelegateProxy::OnDidStopLoading() { |
1171 plugin_->DidStopLoading(); | 1025 plugin_->DidStopLoading(); |
1172 } | 1026 } |
1173 | 1027 |
1174 void WebPluginDelegateProxy::OnDeferResourceLoading(unsigned long resource_id, | 1028 void WebPluginDelegateProxy::OnDeferResourceLoading(unsigned long resource_id, |
1175 bool defer) { | 1029 bool defer) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 | 1082 |
1229 plugin_->URLRedirectResponse(allow, resource_id); | 1083 plugin_->URLRedirectResponse(allow, resource_id); |
1230 } | 1084 } |
1231 | 1085 |
1232 void WebPluginDelegateProxy::OnCheckIfRunInsecureContent(const GURL& url, | 1086 void WebPluginDelegateProxy::OnCheckIfRunInsecureContent(const GURL& url, |
1233 bool* result) { | 1087 bool* result) { |
1234 *result = plugin_->CheckIfRunInsecureContent(url); | 1088 *result = plugin_->CheckIfRunInsecureContent(url); |
1235 } | 1089 } |
1236 | 1090 |
1237 } // namespace content | 1091 } // namespace content |
OLD | NEW |