Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: webkit/glue/webplugin_impl.cc

Issue 2896: This CB fixes the following issues:-... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/webplugin_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "config.h" 5 #include "config.h"
6 6
7 #pragma warning(push, 0) 7 #pragma warning(push, 0)
8 #include "Document.h" 8 #include "Document.h"
9 #include "Element.h" 9 #include "Element.h"
10 #include "Event.h" 10 #include "Event.h"
(...skipping 22 matching lines...) Expand all
33 #pragma warning(pop) 33 #pragma warning(pop)
34 #undef LOG 34 #undef LOG
35 35
36 #include "base/gfx/rect.h" 36 #include "base/gfx/rect.h"
37 #include "base/logging.h" 37 #include "base/logging.h"
38 #include "base/message_loop.h" 38 #include "base/message_loop.h"
39 #include "base/string_util.h" 39 #include "base/string_util.h"
40 #include "base/sys_string_conversions.h" 40 #include "base/sys_string_conversions.h"
41 #include "net/base/escape.h" 41 #include "net/base/escape.h"
42 #include "webkit/glue/glue_util.h" 42 #include "webkit/glue/glue_util.h"
43 #include "webkit/glue/multipart_response_delegate.h"
43 #include "webkit/glue/webkit_glue.h" 44 #include "webkit/glue/webkit_glue.h"
44 #include "webkit/glue/webplugin_impl.h" 45 #include "webkit/glue/webplugin_impl.h"
45 #include "webkit/glue/plugins/plugin_host.h" 46 #include "webkit/glue/plugins/plugin_host.h"
46 #include "webkit/glue/plugins/plugin_instance.h" 47 #include "webkit/glue/plugins/plugin_instance.h"
47 #include "webkit/glue/webview_impl.h" 48 #include "webkit/glue/webview_impl.h"
48 #include "googleurl/src/gurl.h" 49 #include "googleurl/src/gurl.h"
49 #include "webkit/port/platform/cursor.h" 50 #include "webkit/port/platform/cursor.h"
50 51
52 // This class handles invididual multipart responses. It is instantiated when
53 // we receive HTTP status code 206 in the HTTP response. This indicates
54 // that the response could have multiple parts each separated by a boundary
55 // specified in the response header.
56 class MultiPartResponseClient : public WebCore::ResourceHandleClient {
57 public:
58 MultiPartResponseClient(WebPluginResourceClient* resource_client)
59 : resource_client_(resource_client) {
60 Clear();
61 }
62
63 // Called when the multipart parser encounters an embedded multipart
64 // response.
65 virtual void didReceiveResponse(WebCore::ResourceHandle* handle,
66 const WebCore::ResourceResponse& response) {
67 if (!MultipartResponseDelegate::ReadContentRanges(
68 response, &byte_range_lower_bound_, &byte_range_upper_bound_)) {
69 NOTREACHED();
70 return;
71 }
72
73 resource_response_ = response;
74 }
75
76 // Receives individual part data from a multipart response.
77 virtual void didReceiveData(WebCore::ResourceHandle* handle,
78 const char* data, int boundary_pos,
79 int length_received) {
80 int data_length = byte_range_upper_bound_ - byte_range_lower_bound_ + 1;
81 resource_client_->DidReceiveData(
82 data, data_length, byte_range_lower_bound_);
83 }
84
85 void Clear() {
86 resource_response_ = WebCore::ResourceResponse();
87 byte_range_lower_bound_ = 0;
88 byte_range_upper_bound_ = 0;
89 }
90
91 private:
92 WebCore::ResourceResponse resource_response_;
93 // The lower bound of the byte range.
94 int byte_range_lower_bound_;
95 // The upper bound of the byte range.
96 int byte_range_upper_bound_;
97 // The handler for the data.
98 WebPluginResourceClient* resource_client_;
99 };
100
51 WebPluginContainer::WebPluginContainer(WebPluginImpl* impl) : impl_(impl) { } 101 WebPluginContainer::WebPluginContainer(WebPluginImpl* impl) : impl_(impl) { }
52 102
53 WebPluginContainer::~WebPluginContainer() { 103 WebPluginContainer::~WebPluginContainer() {
54 impl_->SetContainer(NULL); 104 impl_->SetContainer(NULL);
55 MessageLoop::current()->DeleteSoon(FROM_HERE, impl_); 105 MessageLoop::current()->DeleteSoon(FROM_HERE, impl_);
56 } 106 }
57 107
58 NPObject* WebPluginContainer::GetPluginScriptableObject() { 108 NPObject* WebPluginContainer::GetPluginScriptableObject() {
59 return impl_->GetPluginScriptableObject(); 109 return impl_->GetPluginScriptableObject();
60 } 110 }
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 result.append(std::wstring(it->second.characters(), it->second.length())); 842 result.append(std::wstring(it->second.characters(), it->second.length()));
793 result.append(L"\n"); 843 result.append(L"\n");
794 } 844 }
795 } 845 }
796 846
797 return result; 847 return result;
798 } 848 }
799 849
800 void WebPluginImpl::didReceiveResponse(WebCore::ResourceHandle* handle, 850 void WebPluginImpl::didReceiveResponse(WebCore::ResourceHandle* handle,
801 const WebCore::ResourceResponse& response) { 851 const WebCore::ResourceResponse& response) {
852 static const int kHttpPartialResponseStatusCode = 206;
853
802 WebPluginResourceClient* client = GetClientFromHandle(handle); 854 WebPluginResourceClient* client = GetClientFromHandle(handle);
803 if (!client) 855 if (!client)
804 return; 856 return;
805 857
806 WebPluginContainer::HttpResponseInfo http_response_info; 858 WebPluginContainer::HttpResponseInfo http_response_info;
807 WebPluginContainer::ReadHttpResponseInfo(response, &http_response_info); 859 WebPluginContainer::ReadHttpResponseInfo(response, &http_response_info);
808 860
809 bool cancel = false; 861 bool cancel = false;
862
863 if (response.httpStatusCode() == kHttpPartialResponseStatusCode) {
864 HandleHttpMultipartResponse(response, client);
865 return;
866 }
810 867
811 client->DidReceiveResponse( 868 client->DidReceiveResponse(
812 base::SysWideToNativeMB(http_response_info.mime_type), 869 base::SysWideToNativeMB(http_response_info.mime_type),
813 base::SysWideToNativeMB(GetAllHeaders(response)), 870 base::SysWideToNativeMB(GetAllHeaders(response)),
814 http_response_info.expected_length, 871 http_response_info.expected_length,
815 http_response_info.last_modified, &cancel); 872 http_response_info.last_modified, &cancel);
816 873
817 if (cancel) { 874 if (cancel) {
818 handle->cancel(); 875 handle->cancel();
819 RemoveClient(handle); 876 RemoveClient(handle);
(...skipping 19 matching lines...) Expand all
839 RemoveClient(handle); 896 RemoveClient(handle);
840 } 897 }
841 } 898 }
842 } 899 }
843 } 900 }
844 901
845 void WebPluginImpl::didReceiveData(WebCore::ResourceHandle* handle, 902 void WebPluginImpl::didReceiveData(WebCore::ResourceHandle* handle,
846 const char *buffer, 903 const char *buffer,
847 int length, int) { 904 int length, int) {
848 WebPluginResourceClient* client = GetClientFromHandle(handle); 905 WebPluginResourceClient* client = GetClientFromHandle(handle);
849 if (client) 906 if (client) {
850 client->DidReceiveData(buffer, length); 907 MultipartResponseDelegate* multi_part_handler =
908 multi_part_response_map_[client];
909 if (multi_part_handler) {
910 multi_part_handler->OnReceivedData(buffer, length);
911 } else {
912 client->DidReceiveData(buffer, length, 0);
913 }
914 }
851 } 915 }
852 916
853 void WebPluginImpl::didFinishLoading(WebCore::ResourceHandle* handle) { 917 void WebPluginImpl::didFinishLoading(WebCore::ResourceHandle* handle) {
854 WebPluginResourceClient* client = GetClientFromHandle(handle); 918 WebPluginResourceClient* client = GetClientFromHandle(handle);
855 if (client) 919 if (client) {
920 MultiPartResponseHandlerMap::iterator index =
921 multi_part_response_map_.find(client);
922 if (index != multi_part_response_map_.end()) {
923 delete (*index).second;
924 multi_part_response_map_.erase(index);
925 }
856 client->DidFinishLoading(); 926 client->DidFinishLoading();
927 }
857 928
858 RemoveClient(handle); 929 RemoveClient(handle);
859 } 930 }
860 931
861 void WebPluginImpl::didFail(WebCore::ResourceHandle* handle, 932 void WebPluginImpl::didFail(WebCore::ResourceHandle* handle,
862 const WebCore::ResourceError&) { 933 const WebCore::ResourceError&) {
863 WebPluginResourceClient* client = GetClientFromHandle(handle); 934 WebPluginResourceClient* client = GetClientFromHandle(handle);
864 if (client) 935 if (client)
865 client->DidFail(); 936 client->DidFail();
866 937
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 ExecuteScript(original_url, 1044 ExecuteScript(original_url,
974 webkit_glue::DeprecatedStringToStdWString(script), notify, 1045 webkit_glue::DeprecatedStringToStdWString(script), notify,
975 reinterpret_cast<int>(notify_data), popups_allowed); 1046 reinterpret_cast<int>(notify_data), popups_allowed);
976 } else { 1047 } else {
977 std::string complete_url_string; 1048 std::string complete_url_string;
978 CompleteURL(url, &complete_url_string); 1049 CompleteURL(url, &complete_url_string);
979 1050
980 int resource_id = GetNextResourceId(); 1051 int resource_id = GetNextResourceId();
981 WebPluginResourceClient* resource_client = 1052 WebPluginResourceClient* resource_client =
982 delegate_->CreateResourceClient(resource_id, complete_url_string, 1053 delegate_->CreateResourceClient(resource_id, complete_url_string,
983 notify, notify_data); 1054 notify, notify_data, NULL);
984 1055
985 // If the RouteToFrame call returned a failure then inform the result 1056 // If the RouteToFrame call returned a failure then inform the result
986 // back to the plugin asynchronously. 1057 // back to the plugin asynchronously.
987 if ((routing_status == INVALID_URL) || 1058 if ((routing_status == INVALID_URL) ||
988 (routing_status == GENERAL_FAILURE)) { 1059 (routing_status == GENERAL_FAILURE)) {
989 resource_client->DidFail(); 1060 resource_client->DidFail();
990 return; 1061 return;
991 } 1062 }
992 1063
993 InitiateHTTPRequest(resource_id, resource_client, method, buf, len, 1064 InitiateHTTPRequest(resource_id, resource_client, method, buf, len,
994 GURL(complete_url_string)); 1065 GURL(complete_url_string), NULL);
995 } 1066 }
996 } 1067 }
997 1068
998 int WebPluginImpl::GetNextResourceId() { 1069 int WebPluginImpl::GetNextResourceId() {
999 static int next_id = 0; 1070 static int next_id = 0;
1000 return ++next_id; 1071 return ++next_id;
1001 } 1072 }
1002 1073
1003 bool WebPluginImpl::InitiateHTTPRequest(int resource_id, 1074 bool WebPluginImpl::InitiateHTTPRequest(int resource_id,
1004 WebPluginResourceClient* client, 1075 WebPluginResourceClient* client,
1005 const char* method, const char* buf, 1076 const char* method, const char* buf,
1006 int buf_len, 1077 int buf_len,
1007 const GURL& complete_url_string) { 1078 const GURL& complete_url_string,
1079 const char* range_info) {
1008 if (!client) { 1080 if (!client) {
1009 NOTREACHED(); 1081 NOTREACHED();
1010 return false; 1082 return false;
1011 } 1083 }
1012 1084
1013 ClientInfo info; 1085 ClientInfo info;
1014 info.id = resource_id; 1086 info.id = resource_id;
1015 info.client = client; 1087 info.client = client;
1016 info.request.setFrame(frame()); 1088 info.request.setFrame(frame());
1017 info.request.setURL(webkit_glue::GURLToKURL(complete_url_string)); 1089 info.request.setURL(webkit_glue::GURLToKURL(complete_url_string));
1018 info.request.setOriginPid(delegate_->GetProcessId()); 1090 info.request.setOriginPid(delegate_->GetProcessId());
1019 info.request.setResourceType(ResourceType::OBJECT); 1091 info.request.setResourceType(ResourceType::OBJECT);
1020 info.request.setHTTPMethod(method); 1092 info.request.setHTTPMethod(method);
1021 1093
1094 if (range_info)
1095 info.request.addHTTPHeaderField("Range", range_info);
1096
1022 const WebCore::String& referrer = frame()->loader()->outgoingReferrer(); 1097 const WebCore::String& referrer = frame()->loader()->outgoingReferrer();
1023 if (!WebCore::FrameLoader::shouldHideReferrer( 1098 if (!WebCore::FrameLoader::shouldHideReferrer(
1024 complete_url_string.spec().c_str(), referrer)) { 1099 complete_url_string.spec().c_str(), referrer)) {
1025 info.request.setHTTPReferrer(referrer); 1100 info.request.setHTTPReferrer(referrer);
1026 } 1101 }
1027 1102
1028 if (lstrcmpA(method, "POST") == 0) { 1103 if (lstrcmpA(method, "POST") == 0) {
1029 // Adds headers or form data to a request. This must be called before 1104 // Adds headers or form data to a request. This must be called before
1030 // we initiate the actual request. 1105 // we initiate the actual request.
1031 SetPostData(&info.request, buf, buf_len); 1106 SetPostData(&info.request, buf, buf_len);
1032 } 1107 }
1033 1108
1034 info.handle = WebCore::ResourceHandle::create(info.request, this, frame(), 1109 info.handle = WebCore::ResourceHandle::create(info.request, this, frame(),
1035 false, false); 1110 false, false);
1036 if (!info.handle) { 1111 if (!info.handle) {
1037 return false; 1112 return false;
1038 } 1113 }
1039 1114
1040 clients_.push_back(info); 1115 clients_.push_back(info);
1041 return true; 1116 return true;
1042 } 1117 }
1043 1118
1119 void WebPluginImpl::CancelDocumentLoad() {
1120 frame()->loader()->stopLoading(false);
1121 }
1122
1123 void WebPluginImpl::InitiateHTTPRangeRequest(const char* url,
1124 const char* range_info,
1125 HANDLE existing_stream,
1126 bool notify_needed,
1127 HANDLE notify_data) {
1128 int resource_id = GetNextResourceId();
1129 std::string complete_url_string;
1130 CompleteURL(url, &complete_url_string);
1131
1132 WebPluginResourceClient* resource_client =
1133 delegate_->CreateResourceClient(resource_id, complete_url_string,
1134 notify_needed, notify_data,
1135 existing_stream);
1136 InitiateHTTPRequest(resource_id, resource_client, "GET", NULL, 0,
1137 GURL(complete_url_string), range_info);
1138 }
1139
1140 void WebPluginImpl::HandleHttpMultipartResponse(
1141 const WebCore::ResourceResponse& response,
1142 WebPluginResourceClient* client) {
1143 std::string multipart_boundary;
1144 if (!MultipartResponseDelegate::ReadMultipartBoundary(
1145 response, &multipart_boundary)) {
1146 NOTREACHED();
1147 return;
1148 }
1149
1150 MultiPartResponseClient* multi_part_response_client =
1151 new MultiPartResponseClient(client);
1152
1153 MultipartResponseDelegate* multi_part_response_handler =
1154 new MultipartResponseDelegate(multi_part_response_client, NULL,
1155 response,
1156 multipart_boundary);
1157 multi_part_response_map_[client] = multi_part_response_handler;
1158 }
OLDNEW
« no previous file with comments | « webkit/glue/webplugin_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698