diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-30 22:42:58 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-30 22:42:58 +0000 |
commit | eed529ce5d09706bc2b9da5b96822eda2919a9ae (patch) | |
tree | f5afad43a1e8412ed9473fa9d7e418621373decd /webkit/glue/webplugin_impl.cc | |
parent | ee8f54a54cab5cc3eaf837622ec61b482fac8858 (diff) | |
download | chromium_src-eed529ce5d09706bc2b9da5b96822eda2919a9ae.zip chromium_src-eed529ce5d09706bc2b9da5b96822eda2919a9ae.tar.gz chromium_src-eed529ce5d09706bc2b9da5b96822eda2919a9ae.tar.bz2 |
Revert WebURLLoader landing. Too many layout test failures.
TBR=dglazkov
Review URL: http://codereview.chromium.org/115973
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17293 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/webplugin_impl.cc')
-rw-r--r-- | webkit/glue/webplugin_impl.cc | 288 |
1 files changed, 123 insertions, 165 deletions
diff --git a/webkit/glue/webplugin_impl.cc b/webkit/glue/webplugin_impl.cc index e783c0d..0441000 100644 --- a/webkit/glue/webplugin_impl.cc +++ b/webkit/glue/webplugin_impl.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "config.h" +#include "webkit/glue/webplugin_impl.h" #include "Cursor.h" #include "Document.h" @@ -48,66 +49,44 @@ #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "net/base/escape.h" -#include "webkit/api/public/WebData.h" -#include "webkit/api/public/WebHTTPBody.h" #include "webkit/api/public/WebInputEvent.h" #include "webkit/api/public/WebKit.h" #include "webkit/api/public/WebKitClient.h" #include "webkit/api/public/WebString.h" #include "webkit/api/public/WebURL.h" -#include "webkit/api/public/WebURLLoader.h" -#include "webkit/api/public/WebURLLoaderClient.h" -#include "webkit/api/public/WebURLResponse.h" #include "webkit/glue/chrome_client_impl.h" #include "webkit/glue/event_conversion.h" #include "webkit/glue/glue_util.h" #include "webkit/glue/multipart_response_delegate.h" #include "webkit/glue/webcursor.h" #include "webkit/glue/webkit_glue.h" -#include "webkit/glue/webplugin_impl.h" #include "webkit/glue/plugins/plugin_host.h" #include "webkit/glue/plugins/plugin_instance.h" #include "webkit/glue/stacking_order_iterator.h" #include "webkit/glue/webview_impl.h" #include "googleurl/src/gurl.h" -using WebKit::WebData; -using WebKit::WebHTTPBody; -using WebKit::WebInputEvent; using WebKit::WebKeyboardEvent; +using WebKit::WebInputEvent; using WebKit::WebMouseEvent; -using WebKit::WebString; -using WebKit::WebURLError; -using WebKit::WebURLLoader; -using WebKit::WebURLLoaderClient; -using WebKit::WebURLRequest; -using WebKit::WebURLResponse; -using webkit_glue::MultipartResponseDelegate; // This class handles individual multipart responses. It is instantiated when // we receive HTTP status code 206 in the HTTP response. This indicates // that the response could have multiple parts each separated by a boundary // specified in the response header. -class MultiPartResponseClient : public WebURLLoaderClient { +class MultiPartResponseClient : public WebCore::ResourceHandleClient { public: MultiPartResponseClient(WebPluginResourceClient* resource_client) : resource_client_(resource_client) { Clear(); } - virtual void willSendRequest( - WebURLLoader*, WebURLRequest&, const WebURLResponse&) {} - virtual void didSendData( - WebURLLoader*, unsigned long long, unsigned long long) {} - // Called when the multipart parser encounters an embedded multipart // response. - virtual void didReceiveResponse( - WebURLLoader*, const WebURLResponse& response) { + virtual void didReceiveResponse(WebCore::ResourceHandle* handle, + const WebCore::ResourceResponse& response) { if (!MultipartResponseDelegate::ReadContentRanges( - response, - &byte_range_lower_bound_, - &byte_range_upper_bound_)) { + response, &byte_range_lower_bound_, &byte_range_upper_bound_)) { NOTREACHED(); return; } @@ -116,23 +95,21 @@ class MultiPartResponseClient : public WebURLLoaderClient { } // Receives individual part data from a multipart response. - virtual void didReceiveData( - WebURLLoader*, const char* data, int data_size, long long) { + virtual void didReceiveData(WebCore::ResourceHandle* handle, + const char* data, int data_size, + int reserved) { resource_client_->DidReceiveData( data, data_size, byte_range_lower_bound_); } - virtual void didFinishLoading(WebURLLoader*) {} - virtual void didFail(WebURLLoader*, const WebURLError&) {} - void Clear() { - resource_response_.reset(); + resource_response_ = WebCore::ResourceResponse(); byte_range_lower_bound_ = 0; byte_range_upper_bound_ = 0; } private: - WebURLResponse resource_response_; + WebCore::ResourceResponse resource_response_; // The lower bound of the byte range. int byte_range_lower_bound_; // The upper bound of the byte range. @@ -141,32 +118,6 @@ class MultiPartResponseClient : public WebURLLoaderClient { WebPluginResourceClient* resource_client_; }; -static std::wstring GetAllHeaders(const WebCore::ResourceResponse& response) { - std::wstring result; - const WebCore::String& status = response.httpStatusText(); - if (status.isEmpty()) - return result; - - result.append(L"HTTP "); - result.append(FormatNumber(response.httpStatusCode())); - result.append(L" "); - result.append(webkit_glue::StringToStdWString(status)); - result.append(L"\n"); - - WebCore::HTTPHeaderMap::const_iterator it = - response.httpHeaderFields().begin(); - for (; it != response.httpHeaderFields().end(); ++it) { - if (!it->first.isEmpty() && !it->second.isEmpty()) { - result.append(webkit_glue::StringToStdWString(it->first)); - result.append(L": "); - result.append(webkit_glue::StringToStdWString(it->second)); - result.append(L"\n"); - } - } - - return result; -} - WebPluginContainer::WebPluginContainer(WebPluginImpl* impl) : impl_(impl), ignore_response_error_(false) { @@ -303,7 +254,7 @@ void WebPluginContainer::didReceiveResponse( impl_->delegate_->DidReceiveManualResponse( http_response_info.url, base::SysWideToNativeMB(http_response_info.mime_type), - base::SysWideToNativeMB(GetAllHeaders(response)), + base::SysWideToNativeMB(impl_->GetAllHeaders(response)), http_response_info.expected_length, http_response_info.last_modified); } @@ -464,16 +415,17 @@ bool WebPluginImpl::ExecuteScript(const std::string& url, void WebPluginImpl::CancelResource(int id) { for (size_t i = 0; i < clients_.size(); ++i) { if (clients_[i].id == id) { - if (clients_[i].loader.get()) { - clients_[i].loader->cancel(); + if (clients_[i].handle) { + clients_[i].handle->cancel(); RemoveClient(i); } + return; } } } -bool WebPluginImpl::SetPostData(WebURLRequest* request, +bool WebPluginImpl::SetPostData(WebCore::ResourceRequest* request, const char *buf, uint32 length) { std::vector<std::string> names; @@ -481,26 +433,19 @@ bool WebPluginImpl::SetPostData(WebURLRequest* request, std::vector<char> body; bool rv = NPAPI::PluginHost::SetPostData(buf, length, &names, &values, &body); - for (size_t i = 0; i < names.size(); ++i) { - request->addHTTPHeaderField(webkit_glue::StdStringToWebString(names[i]), - webkit_glue::StdStringToWebString(values[i])); - } + for (size_t i = 0; i < names.size(); ++i) + request->addHTTPHeaderField(webkit_glue::StdStringToString(names[i]), + webkit_glue::StdStringToString(values[i])); - WebString content_type_header = WebString::fromUTF8("Content-Type"); - const WebString& content_type = - request->httpHeaderField(content_type_header); - if (content_type.isEmpty()) { - request->setHTTPHeaderField( - content_type_header, - WebString::fromUTF8("application/x-www-form-urlencoded")); - } + WebCore::String content_type = request->httpContentType(); + if (content_type.isEmpty()) + request->setHTTPContentType("application/x-www-form-urlencoded"); - WebHTTPBody http_body; - if (body.size()) { - http_body.initialize(); - http_body.appendData(WebData(&body[0], body.size())); - } - request->setHTTPBody(http_body); + RefPtr<WebCore::FormData> data = WebCore::FormData::create(); + if (body.size()) + data->appendData(&body.front(), body.size()); + + request->setHTTPBody(data.release()); return rv; } @@ -552,8 +497,8 @@ RoutingStatus WebPluginImpl::RouteToFrame(const char *method, } *completeURL = webkit_glue::KURLToGURL(complete_url_kurl); - WebURLRequest request(webkit_glue::KURLToWebURL(complete_url_kurl)); - request.setHTTPMethod(WebString::fromUTF8(method)); + WebCore::ResourceRequest request(complete_url_kurl); + request.setHTTPMethod(method); if (len > 0) { if (!is_file_data) { if (!SetPostData(&request, buf, len)) { @@ -569,8 +514,7 @@ RoutingStatus WebPluginImpl::RouteToFrame(const char *method, return ROUTED; } } - WebCore::FrameLoadRequest load_request( - *webkit_glue::WebURLRequestToResourceRequest(&request)); + WebCore::FrameLoadRequest load_request(request); load_request.setFrameName(str_target); WebCore::FrameLoader *loader = frame()->loader(); // we actually don't know whether usergesture is true or false, @@ -885,10 +829,10 @@ NPObject* WebPluginImpl::GetPluginScriptableObject() { return delegate_->GetPluginScriptableObject(); } -WebPluginResourceClient* WebPluginImpl::GetClientFromLoader( - WebURLLoader* loader) { +WebPluginResourceClient* WebPluginImpl::GetClientFromHandle( + WebCore::ResourceHandle* handle) { for (size_t i = 0; i < clients_.size(); ++i) { - if (clients_[i].loader.get() == loader) + if (clients_[i].handle.get() == handle) return clients_[i].client; } @@ -897,34 +841,54 @@ WebPluginResourceClient* WebPluginImpl::GetClientFromLoader( } -void WebPluginImpl::willSendRequest(WebURLLoader* loader, - WebURLRequest& request, - const WebURLResponse&) { - WebPluginResourceClient* client = GetClientFromLoader(loader); - if (client) - client->WillSendRequest(request.url()); +void WebPluginImpl::willSendRequest(WebCore::ResourceHandle* handle, + WebCore::ResourceRequest& request, + const WebCore::ResourceResponse&) { + WebPluginResourceClient* client = GetClientFromHandle(handle); + if (client) { + GURL gurl(webkit_glue::KURLToGURL(request.url())); + client->WillSendRequest(gurl); + } } -void WebPluginImpl::didSendData(WebURLLoader* loader, - unsigned long long bytes_sent, - unsigned long long total_bytes_to_be_sent) { +std::wstring WebPluginImpl::GetAllHeaders( + const WebCore::ResourceResponse& response) { + std::wstring result; + const WebCore::String& status = response.httpStatusText(); + if (status.isEmpty()) + return result; + + result.append(L"HTTP "); + result.append(FormatNumber(response.httpStatusCode())); + result.append(L" "); + result.append(webkit_glue::StringToStdWString(status)); + result.append(L"\n"); + + WebCore::HTTPHeaderMap::const_iterator it = + response.httpHeaderFields().begin(); + for (; it != response.httpHeaderFields().end(); ++it) { + if (!it->first.isEmpty() && !it->second.isEmpty()) { + result.append(webkit_glue::StringToStdWString(it->first)); + result.append(L": "); + result.append(webkit_glue::StringToStdWString(it->second)); + result.append(L"\n"); + } + } + + return result; } -void WebPluginImpl::didReceiveResponse(WebURLLoader* loader, - const WebURLResponse& response) { +void WebPluginImpl::didReceiveResponse(WebCore::ResourceHandle* handle, + const WebCore::ResourceResponse& response) { static const int kHttpPartialResponseStatusCode = 206; static const int kHttpResponseSuccessStatusCode = 200; - WebPluginResourceClient* client = GetClientFromLoader(loader); + WebPluginResourceClient* client = GetClientFromHandle(handle); if (!client) return; - - const WebCore::ResourceResponse& resource_response = - *webkit_glue::WebURLResponseToResourceResponse(&response); WebPluginContainer::HttpResponseInfo http_response_info; - WebPluginContainer::ReadHttpResponseInfo(resource_response, - &http_response_info); + WebPluginContainer::ReadHttpResponseInfo(response, &http_response_info); bool cancel = false; bool request_is_seekable = true; @@ -942,7 +906,7 @@ void WebPluginImpl::didReceiveResponse(WebURLLoader* loader, // continue to remain valid. // 2. Create a new plugin instance and notify it about the response // received here. - if (!ReinitializePluginForResponse(loader)) { + if (!ReinitializePluginForResponse(handle)) { NOTREACHED(); return; } @@ -956,7 +920,7 @@ void WebPluginImpl::didReceiveResponse(WebURLLoader* loader, // Create a new resource client for this request. for (size_t i = 0; i < clients_.size(); ++i) { - if (clients_[i].loader.get() == loader) { + if (clients_[i].handle.get() == handle) { WebPluginResourceClient* resource_client = delegate_->CreateResourceClient(clients_[i].id, plugin_url_.spec().c_str(), @@ -973,13 +937,13 @@ void WebPluginImpl::didReceiveResponse(WebURLLoader* loader, client->DidReceiveResponse( base::SysWideToNativeMB(http_response_info.mime_type), - base::SysWideToNativeMB(GetAllHeaders(resource_response)), + base::SysWideToNativeMB(GetAllHeaders(response)), http_response_info.expected_length, http_response_info.last_modified, request_is_seekable, &cancel); if (cancel) { - loader->cancel(); - RemoveClient(loader); + handle->cancel(); + RemoveClient(handle); return; } @@ -988,41 +952,41 @@ void WebPluginImpl::didReceiveResponse(WebURLLoader* loader, // fate of the HTTP requests issued via NPN_GetURLNotify. Webkit and FF // destroy the stream and invoke the NPP_DestroyStream function on the // plugin if the HTTP request fails. - const GURL& url = response.url(); - if (url.SchemeIs("http") || url.SchemeIs("https")) { + const WebCore::String& protocol_scheme = response.url().protocol(); + if ((protocol_scheme == "http") || (protocol_scheme == "https")) { if (response.httpStatusCode() < 100 || response.httpStatusCode() >= 400) { // The plugin instance could be in the process of deletion here. // Verify if the WebPluginResourceClient instance still exists before // use. - WebPluginResourceClient* resource_client = GetClientFromLoader(loader); + WebPluginResourceClient* resource_client = GetClientFromHandle(handle); if (resource_client) { - loader->cancel(); + handle->cancel(); resource_client->DidFail(); - RemoveClient(loader); + RemoveClient(handle); } } } } -void WebPluginImpl::didReceiveData(WebURLLoader* loader, +void WebPluginImpl::didReceiveData(WebCore::ResourceHandle* handle, const char *buffer, - int length, long long) { - WebPluginResourceClient* client = GetClientFromLoader(loader); - if (!client) - return; - MultiPartResponseHandlerMap::iterator index = - multi_part_response_map_.find(client); - if (index != multi_part_response_map_.end()) { - MultipartResponseDelegate* multi_part_handler = (*index).second; - DCHECK(multi_part_handler != NULL); - multi_part_handler->OnReceivedData(buffer, length); - } else { - client->DidReceiveData(buffer, length, 0); + int length, int) { + WebPluginResourceClient* client = GetClientFromHandle(handle); + if (client) { + MultiPartResponseHandlerMap::iterator index = + multi_part_response_map_.find(client); + if (index != multi_part_response_map_.end()) { + MultipartResponseDelegate* multi_part_handler = (*index).second; + DCHECK(multi_part_handler != NULL); + multi_part_handler->OnReceivedData(buffer, length); + } else { + client->DidReceiveData(buffer, length, 0); + } } } -void WebPluginImpl::didFinishLoading(WebURLLoader* loader) { - WebPluginResourceClient* client = GetClientFromLoader(loader); +void WebPluginImpl::didFinishLoading(WebCore::ResourceHandle* handle) { + WebPluginResourceClient* client = GetClientFromHandle(handle); if (client) { MultiPartResponseHandlerMap::iterator index = multi_part_response_map_.find(client); @@ -1036,25 +1000,25 @@ void WebPluginImpl::didFinishLoading(WebURLLoader* loader) { client->DidFinishLoading(); } - RemoveClient(loader); + RemoveClient(handle); } -void WebPluginImpl::didFail(WebURLLoader* loader, - const WebURLError&) { - WebPluginResourceClient* client = GetClientFromLoader(loader); +void WebPluginImpl::didFail(WebCore::ResourceHandle* handle, + const WebCore::ResourceError&) { + WebPluginResourceClient* client = GetClientFromHandle(handle); if (client) client->DidFail(); - RemoveClient(loader); + RemoveClient(handle); } void WebPluginImpl::RemoveClient(size_t i) { clients_.erase(clients_.begin() + i); } -void WebPluginImpl::RemoveClient(WebURLLoader* loader) { +void WebPluginImpl::RemoveClient(WebCore::ResourceHandle* handle) { for (size_t i = 0; i < clients_.size(); ++i) { - if (clients_[i].loader.get() == loader) { + if (clients_[i].handle.get() == handle) { RemoveClient(i); return; } @@ -1186,19 +1150,18 @@ bool WebPluginImpl::InitiateHTTPRequest(int resource_id, return false; } + WebCore::KURL kurl = webkit_glue::GURLToKURL(url); + ClientInfo info; info.id = resource_id; info.client = client; - info.request.initialize(); - info.request.setURL(url); + info.request.setURL(kurl); info.request.setRequestorProcessID(delegate_->GetProcessId()); - info.request.setTargetType(WebURLRequest::TargetIsObject); - info.request.setHTTPMethod(WebString::fromUTF8(method)); + info.request.setTargetType(WebCore::ResourceRequest::TargetIsObject); + info.request.setHTTPMethod(method); - if (range_info) { - info.request.addHTTPHeaderField(WebString::fromUTF8("Range"), - WebString::fromUTF8(range_info)); - } + if (range_info) + info.request.addHTTPHeaderField("Range", range_info); WebCore::String referrer; // GetURL/PostURL requests initiated explicitly by plugins should specify the @@ -1209,11 +1172,8 @@ bool WebPluginImpl::InitiateHTTPRequest(int resource_id, referrer = frame()->loader()->outgoingReferrer(); } - if (!WebCore::FrameLoader::shouldHideReferrer(webkit_glue::GURLToKURL(url), - referrer)) { - info.request.setHTTPHeaderField(WebString::fromUTF8("Referer"), - webkit_glue::StringToWebString(referrer)); - } + if (!WebCore::FrameLoader::shouldHideReferrer(kurl, referrer)) + info.request.setHTTPReferrer(referrer); if (strcmp(method, "POST") == 0) { // Adds headers or form data to a request. This must be called before @@ -1224,15 +1184,13 @@ bool WebPluginImpl::InitiateHTTPRequest(int resource_id, // Sets the routing id to associate the ResourceRequest with the RenderView. WebCore::ResourceResponse response; frame()->loader()->client()->dispatchWillSendRequest( - NULL, - 0, - *webkit_glue::WebURLRequestToMutableResourceRequest(&info.request), - response); + NULL, 0, info.request, response); - info.loader.reset(WebKit::webKitClient()->createURLLoader()); - if (!info.loader.get()) + info.handle = WebCore::ResourceHandle::create( + info.request, this, NULL, false, false); + if (!info.handle) { return false; - info.loader->loadAsynchronously(info.request, this); + } clients_.push_back(info); return true; @@ -1263,7 +1221,7 @@ void WebPluginImpl::InitiateHTTPRangeRequest(const char* url, } void WebPluginImpl::HandleHttpMultipartResponse( - const WebURLResponse& response, + const WebCore::ResourceResponse& response, WebPluginResourceClient* client) { std::string multipart_boundary; if (!MultipartResponseDelegate::ReadMultipartBoundary( @@ -1286,7 +1244,7 @@ void WebPluginImpl::HandleHttpMultipartResponse( } bool WebPluginImpl::ReinitializePluginForResponse( - WebURLLoader* loader) { + WebCore::ResourceHandle* response_handle) { WebFrameImpl* web_frame = WebFrameImpl::FromFrame(frame()); if (!web_frame) return false; @@ -1298,7 +1256,7 @@ bool WebPluginImpl::ReinitializePluginForResponse( WebPluginContainer* container_widget = widget_; // Destroy the current plugin instance. - TearDownPluginInstance(loader); + TearDownPluginInstance(response_handle); widget_ = container_widget; webframe_ = web_frame; @@ -1352,7 +1310,7 @@ void WebPluginImpl::ArrayToVector(int total_values, char** values, } void WebPluginImpl::TearDownPluginInstance( - WebURLLoader* loader_to_ignore) { + WebCore::ResourceHandle* response_handle_to_ignore) { // The frame maintains a list of JSObjects which are related to this // plugin. Tell the frame we're gone so that it can invalidate all // of those sub JSObjects. @@ -1374,13 +1332,13 @@ void WebPluginImpl::TearDownPluginInstance( while (client_index != clients_.end()) { ClientInfo& client_info = *client_index; - if (loader_to_ignore == client_info.loader) { + if (response_handle_to_ignore == client_info.handle) { client_index++; continue; } - if (client_info.loader.get()) - client_info.loader->cancel(); + if (client_info.handle) + client_info.handle->cancel(); WebPluginResourceClient* resource_client = client_info.client; client_index = clients_.erase(client_index); |