| OLD | NEW |
| 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 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 | 8 |
| 9 MSVC_PUSH_WARNING_LEVEL(0); | 9 MSVC_PUSH_WARNING_LEVEL(0); |
| 10 #include "Cursor.h" | 10 #include "Cursor.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 251 } |
| 252 | 252 |
| 253 WebCore::Widget* WebPluginImpl::Create(const GURL& url, | 253 WebCore::Widget* WebPluginImpl::Create(const GURL& url, |
| 254 char** argn, | 254 char** argn, |
| 255 char** argv, | 255 char** argv, |
| 256 int argc, | 256 int argc, |
| 257 WebCore::Element *element, | 257 WebCore::Element *element, |
| 258 WebFrameImpl *frame, | 258 WebFrameImpl *frame, |
| 259 WebPluginDelegate* delegate, | 259 WebPluginDelegate* delegate, |
| 260 bool load_manually) { | 260 bool load_manually) { |
| 261 WebPluginImpl* webplugin = new WebPluginImpl(element, frame, delegate, url); | 261 WebPluginImpl* webplugin = new WebPluginImpl(element, frame, delegate, url, |
| 262 load_manually); |
| 262 | 263 |
| 263 if (!delegate->Initialize(url, argn, argv, argc, webplugin, load_manually)) { | 264 if (!delegate->Initialize(url, argn, argv, argc, webplugin, load_manually)) { |
| 264 delegate->PluginDestroyed(); | 265 delegate->PluginDestroyed(); |
| 265 delegate = NULL; | 266 delegate = NULL; |
| 266 delete webplugin; | 267 delete webplugin; |
| 267 return NULL; | 268 return NULL; |
| 268 } | 269 } |
| 269 | 270 |
| 270 WebPluginContainer* container = new WebPluginContainer(webplugin); | 271 WebPluginContainer* container = new WebPluginContainer(webplugin); |
| 271 webplugin->SetContainer(container); | 272 webplugin->SetContainer(container); |
| 272 return container; | 273 return container; |
| 273 } | 274 } |
| 274 | 275 |
| 275 WebPluginImpl::WebPluginImpl(WebCore::Element* element, | 276 WebPluginImpl::WebPluginImpl(WebCore::Element* element, |
| 276 WebFrameImpl* webframe, | 277 WebFrameImpl* webframe, |
| 277 WebPluginDelegate* delegate, | 278 WebPluginDelegate* delegate, |
| 278 const GURL& plugin_url) | 279 const GURL& plugin_url, |
| 280 bool load_manually) |
| 279 : windowless_(false), | 281 : windowless_(false), |
| 280 window_(NULL), | 282 window_(NULL), |
| 281 element_(element), | 283 element_(element), |
| 282 webframe_(webframe), | 284 webframe_(webframe), |
| 283 delegate_(delegate), | 285 delegate_(delegate), |
| 284 force_geometry_update_(false), | 286 force_geometry_update_(false), |
| 285 visible_(false), | 287 visible_(false), |
| 286 received_first_paint_notification_(false), | 288 received_first_paint_notification_(false), |
| 287 widget_(NULL), | 289 widget_(NULL), |
| 288 plugin_url_(plugin_url) { | 290 plugin_url_(plugin_url), |
| 291 load_manually_(load_manually), |
| 292 first_geometry_update_(true) { |
| 289 } | 293 } |
| 290 | 294 |
| 291 WebPluginImpl::~WebPluginImpl() { | 295 WebPluginImpl::~WebPluginImpl() { |
| 292 } | 296 } |
| 293 | 297 |
| 294 void WebPluginImpl::SetWindow(HWND window, HANDLE pump_messages_event) { | 298 void WebPluginImpl::SetWindow(HWND window, HANDLE pump_messages_event) { |
| 295 if (window) { | 299 if (window) { |
| 296 DCHECK(!windowless_); // Make sure not called twice. | 300 DCHECK(!windowless_); // Make sure not called twice. |
| 297 window_ = window; | 301 window_ = window; |
| 298 } else { | 302 } else { |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 delegate_->UpdateGeometry( | 642 delegate_->UpdateGeometry( |
| 639 webkit_glue::FromIntRect(window_rect), | 643 webkit_glue::FromIntRect(window_rect), |
| 640 webkit_glue::FromIntRect(clip_rect), cutout_rects, | 644 webkit_glue::FromIntRect(clip_rect), cutout_rects, |
| 641 received_first_paint_notification_? visible_ : false); | 645 received_first_paint_notification_? visible_ : false); |
| 642 | 646 |
| 643 // delegate_ can go away as a result of above call, so check it first. | 647 // delegate_ can go away as a result of above call, so check it first. |
| 644 if (force_geometry_update_ && delegate_) { | 648 if (force_geometry_update_ && delegate_) { |
| 645 force_geometry_update_ = false; | 649 force_geometry_update_ = false; |
| 646 delegate_->FlushGeometryUpdates(); | 650 delegate_->FlushGeometryUpdates(); |
| 647 } | 651 } |
| 652 |
| 653 // Initiate a download on the plugin url. This should be done for the |
| 654 // first update geometry sequence. |
| 655 if (first_geometry_update_) { |
| 656 first_geometry_update_ = false; |
| 657 // An empty url corresponds to an EMBED tag with no src attribute. |
| 658 if (!load_manually_ && plugin_url_.is_valid()) { |
| 659 HandleURLRequestInternal("GET", false, NULL, 0, NULL, false, false, |
| 660 plugin_url_.spec().c_str(), NULL, false, |
| 661 false); |
| 662 } |
| 663 } |
| 648 } | 664 } |
| 649 | 665 |
| 650 void WebPluginImpl::paint(WebCore::GraphicsContext* gc, | 666 void WebPluginImpl::paint(WebCore::GraphicsContext* gc, |
| 651 const WebCore::IntRect& damage_rect) { | 667 const WebCore::IntRect& damage_rect) { |
| 652 if (gc->paintingDisabled()) | 668 if (gc->paintingDisabled()) |
| 653 return; | 669 return; |
| 654 | 670 |
| 655 if (!parent()) | 671 if (!parent()) |
| 656 return; | 672 return; |
| 657 | 673 |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 cutout_rects->push_back(r); | 1113 cutout_rects->push_back(r); |
| 1098 } | 1114 } |
| 1099 } | 1115 } |
| 1100 | 1116 |
| 1101 void WebPluginImpl::HandleURLRequest(const char *method, | 1117 void WebPluginImpl::HandleURLRequest(const char *method, |
| 1102 bool is_javascript_url, | 1118 bool is_javascript_url, |
| 1103 const char* target, unsigned int len, | 1119 const char* target, unsigned int len, |
| 1104 const char* buf, bool is_file_data, | 1120 const char* buf, bool is_file_data, |
| 1105 bool notify, const char* url, | 1121 bool notify, const char* url, |
| 1106 void* notify_data, bool popups_allowed) { | 1122 void* notify_data, bool popups_allowed) { |
| 1123 HandleURLRequestInternal(method, is_javascript_url, target, len, buf, |
| 1124 is_file_data, notify, url, notify_data, |
| 1125 popups_allowed, true); |
| 1126 } |
| 1127 |
| 1128 void WebPluginImpl::HandleURLRequestInternal( |
| 1129 const char *method, bool is_javascript_url, const char* target, |
| 1130 unsigned int len, const char* buf, bool is_file_data, bool notify, |
| 1131 const char* url, void* notify_data, bool popups_allowed, |
| 1132 bool use_plugin_src_as_referrer) { |
| 1107 // For this request, we either route the output to a frame | 1133 // For this request, we either route the output to a frame |
| 1108 // because a target has been specified, or we handle the request | 1134 // because a target has been specified, or we handle the request |
| 1109 // here, i.e. by executing the script if it is a javascript url | 1135 // here, i.e. by executing the script if it is a javascript url |
| 1110 // or by initiating a download on the URL, etc. There is one special | 1136 // or by initiating a download on the URL, etc. There is one special |
| 1111 // case in that the request is a javascript url and the target is "_self", | 1137 // case in that the request is a javascript url and the target is "_self", |
| 1112 // in which case we route the output to the plugin rather than routing it | 1138 // in which case we route the output to the plugin rather than routing it |
| 1113 // to the plugin's frame. | 1139 // to the plugin's frame. |
| 1114 GURL complete_url; | 1140 GURL complete_url; |
| 1115 int routing_status = RouteToFrame(method, is_javascript_url, target, len, | 1141 int routing_status = RouteToFrame(method, is_javascript_url, target, len, |
| 1116 buf, is_file_data, notify, url, | 1142 buf, is_file_data, notify, url, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1146 | 1172 |
| 1147 // If the RouteToFrame call returned a failure then inform the result | 1173 // If the RouteToFrame call returned a failure then inform the result |
| 1148 // back to the plugin asynchronously. | 1174 // back to the plugin asynchronously. |
| 1149 if ((routing_status == INVALID_URL) || | 1175 if ((routing_status == INVALID_URL) || |
| 1150 (routing_status == GENERAL_FAILURE)) { | 1176 (routing_status == GENERAL_FAILURE)) { |
| 1151 resource_client->DidFail(); | 1177 resource_client->DidFail(); |
| 1152 return; | 1178 return; |
| 1153 } | 1179 } |
| 1154 | 1180 |
| 1155 InitiateHTTPRequest(resource_id, resource_client, method, buf, len, | 1181 InitiateHTTPRequest(resource_id, resource_client, method, buf, len, |
| 1156 GURL(complete_url_string), NULL); | 1182 GURL(complete_url_string), NULL, |
| 1183 use_plugin_src_as_referrer); |
| 1157 } | 1184 } |
| 1158 } | 1185 } |
| 1159 | 1186 |
| 1160 int WebPluginImpl::GetNextResourceId() { | 1187 int WebPluginImpl::GetNextResourceId() { |
| 1161 static int next_id = 0; | 1188 static int next_id = 0; |
| 1162 return ++next_id; | 1189 return ++next_id; |
| 1163 } | 1190 } |
| 1164 | 1191 |
| 1165 bool WebPluginImpl::InitiateHTTPRequest(int resource_id, | 1192 bool WebPluginImpl::InitiateHTTPRequest(int resource_id, |
| 1166 WebPluginResourceClient* client, | 1193 WebPluginResourceClient* client, |
| 1167 const char* method, const char* buf, | 1194 const char* method, const char* buf, |
| 1168 int buf_len, | 1195 int buf_len, |
| 1169 const GURL& url, | 1196 const GURL& url, |
| 1170 const char* range_info) { | 1197 const char* range_info, |
| 1198 bool use_plugin_src_as_referrer) { |
| 1171 if (!client) { | 1199 if (!client) { |
| 1172 NOTREACHED(); | 1200 NOTREACHED(); |
| 1173 return false; | 1201 return false; |
| 1174 } | 1202 } |
| 1175 | 1203 |
| 1176 WebCore::KURL kurl = webkit_glue::GURLToKURL(url); | 1204 WebCore::KURL kurl = webkit_glue::GURLToKURL(url); |
| 1177 | 1205 |
| 1178 ClientInfo info; | 1206 ClientInfo info; |
| 1179 info.id = resource_id; | 1207 info.id = resource_id; |
| 1180 info.client = client; | 1208 info.client = client; |
| 1181 info.request.setFrame(frame()); | 1209 info.request.setFrame(frame()); |
| 1182 info.request.setURL(kurl); | 1210 info.request.setURL(kurl); |
| 1183 info.request.setOriginPid(delegate_->GetProcessId()); | 1211 info.request.setOriginPid(delegate_->GetProcessId()); |
| 1184 info.request.setResourceType(ResourceType::OBJECT); | 1212 info.request.setResourceType(ResourceType::OBJECT); |
| 1185 info.request.setHTTPMethod(method); | 1213 info.request.setHTTPMethod(method); |
| 1186 | 1214 |
| 1187 if (range_info) | 1215 if (range_info) |
| 1188 info.request.addHTTPHeaderField("Range", range_info); | 1216 info.request.addHTTPHeaderField("Range", range_info); |
| 1189 | 1217 |
| 1190 WebCore::String referrer; | 1218 WebCore::String referrer; |
| 1191 // If the plugin is instantiated without a SRC URL, then use the | 1219 // GetURL/PostURL requests initiated explicitly by plugins should specify the |
| 1192 // containing frame URL as the referrer. | 1220 // plugin SRC url as the referrer if it is available. |
| 1193 if (plugin_url_.spec().empty()) { | 1221 if (use_plugin_src_as_referrer && !plugin_url_.spec().empty()) { |
| 1222 referrer = webkit_glue::StdStringToString(plugin_url_.spec()); |
| 1223 } else { |
| 1194 referrer = frame()->loader()->outgoingReferrer(); | 1224 referrer = frame()->loader()->outgoingReferrer(); |
| 1195 } else { | |
| 1196 referrer = webkit_glue::StdStringToString(plugin_url_.spec()); | |
| 1197 } | 1225 } |
| 1198 | 1226 |
| 1199 if (!WebCore::FrameLoader::shouldHideReferrer(kurl, referrer)) | 1227 if (!WebCore::FrameLoader::shouldHideReferrer(kurl, referrer)) |
| 1200 info.request.setHTTPReferrer(referrer); | 1228 info.request.setHTTPReferrer(referrer); |
| 1201 | 1229 |
| 1202 if (strcmp(method, "POST") == 0) { | 1230 if (strcmp(method, "POST") == 0) { |
| 1203 // Adds headers or form data to a request. This must be called before | 1231 // Adds headers or form data to a request. This must be called before |
| 1204 // we initiate the actual request. | 1232 // we initiate the actual request. |
| 1205 SetPostData(&info.request, buf, buf_len); | 1233 SetPostData(&info.request, buf, buf_len); |
| 1206 } | 1234 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1226 HANDLE notify_data) { | 1254 HANDLE notify_data) { |
| 1227 int resource_id = GetNextResourceId(); | 1255 int resource_id = GetNextResourceId(); |
| 1228 std::string complete_url_string; | 1256 std::string complete_url_string; |
| 1229 CompleteURL(url, &complete_url_string); | 1257 CompleteURL(url, &complete_url_string); |
| 1230 | 1258 |
| 1231 WebPluginResourceClient* resource_client = | 1259 WebPluginResourceClient* resource_client = |
| 1232 delegate_->CreateResourceClient(resource_id, complete_url_string, | 1260 delegate_->CreateResourceClient(resource_id, complete_url_string, |
| 1233 notify_needed, notify_data, | 1261 notify_needed, notify_data, |
| 1234 existing_stream); | 1262 existing_stream); |
| 1235 InitiateHTTPRequest(resource_id, resource_client, "GET", NULL, 0, | 1263 InitiateHTTPRequest(resource_id, resource_client, "GET", NULL, 0, |
| 1236 GURL(complete_url_string), range_info); | 1264 GURL(complete_url_string), range_info, true); |
| 1237 } | 1265 } |
| 1238 | 1266 |
| 1239 void WebPluginImpl::HandleHttpMultipartResponse( | 1267 void WebPluginImpl::HandleHttpMultipartResponse( |
| 1240 const WebCore::ResourceResponse& response, | 1268 const WebCore::ResourceResponse& response, |
| 1241 WebPluginResourceClient* client) { | 1269 WebPluginResourceClient* client) { |
| 1242 std::string multipart_boundary; | 1270 std::string multipart_boundary; |
| 1243 if (!MultipartResponseDelegate::ReadMultipartBoundary( | 1271 if (!MultipartResponseDelegate::ReadMultipartBoundary( |
| 1244 response, &multipart_boundary)) { | 1272 response, &multipart_boundary)) { |
| 1245 NOTREACHED(); | 1273 NOTREACHED(); |
| 1246 return; | 1274 return; |
| 1247 } | 1275 } |
| 1248 | 1276 |
| 1249 MultiPartResponseClient* multi_part_response_client = | 1277 MultiPartResponseClient* multi_part_response_client = |
| 1250 new MultiPartResponseClient(client); | 1278 new MultiPartResponseClient(client); |
| 1251 | 1279 |
| 1252 MultipartResponseDelegate* multi_part_response_handler = | 1280 MultipartResponseDelegate* multi_part_response_handler = |
| 1253 new MultipartResponseDelegate(multi_part_response_client, NULL, | 1281 new MultipartResponseDelegate(multi_part_response_client, NULL, |
| 1254 response, | 1282 response, |
| 1255 multipart_boundary); | 1283 multipart_boundary); |
| 1256 multi_part_response_map_[client] = multi_part_response_handler; | 1284 multi_part_response_map_[client] = multi_part_response_handler; |
| 1257 } | 1285 } |
| OLD | NEW |