Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
is an issue with the shockwave game not loading.

The plugin issues a number of geturlnotify requests. Some of these requests
come in with response headers without the content length. We would pass in -1
in the NPStream passed down to the plugin. As the end field in the NPStream
structure is an unsigned integer, the plugin would expect more data to arrive
and hence the issue.

The fix is to emulate Safari behavior and set the end field to 0 if the length
is -1.

Bug=643

Review URL: http://codereview.chromium.org/1676

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1958 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
iyengar@google.com committed Sep 10, 2008
1 parent 11b901e commit cc6cd34
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 35 deletions.
76 changes: 41 additions & 35 deletions webkit/glue/webplugin_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,16 @@ void WebPluginContainer::detachFromWindow() {

void WebPluginContainer::didReceiveResponse(
const WebCore::ResourceResponse& response) {

std::wstring url = webkit_glue::StringToStdWString(response.url().string());
std::string ascii_url = WideToASCII(url);

std::wstring mime_type(webkit_glue::StringToStdWString(response.mimeType()));

uint32 last_modified = static_cast<uint32>(response.lastModifiedDate());
uint32 expected_length =
static_cast<uint32>(response.expectedContentLength());
WebCore::String content_encoding =
response.httpHeaderField("Content-Encoding");
if (!content_encoding.isNull() && content_encoding != "identity") {
// Don't send the compressed content length to the plugin, which only
// cares about the decoded length.
expected_length = 0;
}

HttpResponseInfo http_response_info;
ReadHttpResponseInfo(response, &http_response_info);

impl_->delegate_->DidReceiveManualResponse(
ascii_url, base::SysWideToNativeMB(mime_type),
http_response_info.url,
base::SysWideToNativeMB(http_response_info.mime_type),
base::SysWideToNativeMB(impl_->GetAllHeaders(response)),
expected_length, last_modified);
http_response_info.expected_length,
http_response_info.last_modified);
}

void WebPluginContainer::didReceiveData(const char *buffer, int length) {
Expand All @@ -165,6 +154,31 @@ void WebPluginContainer::didFail(const WebCore::ResourceError&) {
impl_->delegate_->DidManualLoadFail();
}

void WebPluginContainer::ReadHttpResponseInfo(
const WebCore::ResourceResponse& response,
HttpResponseInfo* http_response) {
std::wstring url = webkit_glue::StringToStdWString(response.url().string());
http_response->url = WideToASCII(url);

http_response->mime_type =
webkit_glue::StringToStdWString(response.mimeType());

http_response->last_modified =
static_cast<uint32>(response.lastModifiedDate());
// If the length comes in as -1, then it indicates that it was not
// read off the HTTP headers. We replicate Safari webkit behavior here,
// which is to set it to 0.
http_response->expected_length =
static_cast<uint32>(std::max(response.expectedContentLength(), 0LL));
WebCore::String content_encoding =
response.httpHeaderField("Content-Encoding");
if (!content_encoding.isNull() && content_encoding != "identity") {
// Don't send the compressed content length to the plugin, which only
// cares about the decoded length.
http_response->expected_length = 0;
}
}

WebCore::Widget* WebPluginImpl::Create(const GURL& url,
char** argn,
char** argv,
Expand Down Expand Up @@ -789,25 +803,17 @@ void WebPluginImpl::didReceiveResponse(WebCore::ResourceHandle* handle,
if (!client)
return;

WebPluginContainer::HttpResponseInfo http_response_info;
WebPluginContainer::ReadHttpResponseInfo(response, &http_response_info);

bool cancel = false;
std::wstring mime_type(webkit_glue::StringToStdWString(response.mimeType()));

uint32 last_modified = static_cast<uint32>(response.lastModifiedDate());
uint32 expected_length =
static_cast<uint32>(response.expectedContentLength());
WebCore::String content_encoding =
response.httpHeaderField("Content-Encoding");
if (!content_encoding.isNull() && content_encoding != "identity") {
// Don't send the compressed content length to the plugin, which only
// cares about the decoded length.
expected_length = 0;
}
client->DidReceiveResponse(
base::SysWideToNativeMB(http_response_info.mime_type),
base::SysWideToNativeMB(GetAllHeaders(response)),
http_response_info.expected_length,
http_response_info.last_modified, &cancel);

client->DidReceiveResponse(base::SysWideToNativeMB(mime_type),
base::SysWideToNativeMB(GetAllHeaders(response)),
expected_length,
last_modified,
&cancel);
if (cancel) {
handle->cancel();
RemoveClient(handle);
Expand Down Expand Up @@ -1013,7 +1019,7 @@ bool WebPluginImpl::InitiateHTTPRequest(int resource_id,
info.request.setResourceType(ResourceType::OBJECT);
info.request.setHTTPMethod(method);

const WebCore::String& referrer = frame()->loader()->outgoingReferrer();
const WebCore::String& referrer = frame()->loader()->outgoingReferrer();
if (!WebCore::FrameLoader::shouldHideReferrer(
complete_url_string.spec().c_str(), referrer)) {
info.request.setHTTPReferrer(referrer);
Expand Down
11 changes: 11 additions & 0 deletions webkit/glue/webplugin_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ class WebPluginContainer : public WebCore::Widget {
void didFinishLoading();
void didFail(const WebCore::ResourceError&);

struct HttpResponseInfo {
std::string url;
std::wstring mime_type;
uint32 last_modified;
uint32 expected_length;
};
// Helper function to read fields in a HTTP response structure.
// These fields are written to the HttpResponseInfo structure passed in.
static void ReadHttpResponseInfo(const WebCore::ResourceResponse& response,
HttpResponseInfo* http_response);

private:
WebPluginImpl* impl_;
};
Expand Down

0 comments on commit cc6cd34

Please sign in to comment.