Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit e1e37a4

Browse files
author
Raymes Khoury
committed
Ensure MimeHandlerView plugins load properly with long URLs
Currently if a URL which is handled by a MimeHandlerView is too long, mojo will refuse to send the string inside the StreamDetails which are sent to the renderer. In these cases we truncate the URL which gets sent. BUG=478389 Review URL: https://codereview.chromium.org/1062283003 Cr-Commit-Position: refs/heads/master@{#326468} (cherry picked from commit b9a01b5) Review URL: https://codereview.chromium.org/1109693002 Cr-Commit-Position: refs/branch-heads/2357@{#234} Cr-Branched-From: 59d4494-refs/heads/master@{#323860}
1 parent d5f7c7d commit e1e37a4

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

chrome/test/data/extensions/api_test/mime_handler_view/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ function expectSuccessfulRead(response) {
3838
chrome.test.assertEq('content to read\n', response.data);
3939
}
4040

41+
function expectSuccessfulReadLong(response) {
42+
chrome.test.assertEq(200, response.status);
43+
chrome.test.assertTrue(response.data.indexOf('content to read\n') === 0);
44+
}
45+
4146
function checkStreamDetails(name, embedded) {
4247
checkStreamDetailsNoFile();
4348
chrome.test.assertEq(embedded, streamDetails.embedded);
@@ -128,6 +133,13 @@ var tests = [
128133
fetchUrl(streamDetails.streamUrl)
129134
.then(expectSuccessfulRead)
130135
.then(chrome.test.succeed);
136+
},
137+
138+
function testDataUrlLong() {
139+
checkStreamDetailsNoFile();
140+
fetchUrl(streamDetails.streamUrl)
141+
.then(expectSuccessfulReadLong)
142+
.then(chrome.test.succeed);
131143
}
132144
];
133145

@@ -153,6 +165,10 @@ chrome.mimeHandlerPrivate.getStreamInfo(function(streamInfo) {
153165
// Run the test for data URLs.
154166
if (streamInfo.originalUrl.indexOf("data:") === 0) {
155167
window.removeEventListener('message', queueMessage);
156-
chrome.test.runTests([testsByName['testDataUrl']]);
168+
// Long data URLs get truncated.
169+
if (streamInfo.originalUrl == "data:")
170+
chrome.test.runTests([testsByName['testDataUrlLong']]);
171+
else
172+
chrome.test.runTests([testsByName['testDataUrl']]);
157173
}
158174
});

chrome/test/data/extensions/api_test/mime_handler_view/test_embedded_data_url_long.html

Lines changed: 5 additions & 0 deletions
Large diffs are not rendered by default.

extensions/browser/api/mime_handler_private/mime_handler_private.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "base/strings/string_util.h"
88
#include "content/public/browser/stream_handle.h"
99
#include "content/public/browser/stream_info.h"
10+
#include "content/public/common/content_constants.h"
1011
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
1112
#include "extensions/common/constants.h"
1213
#include "net/http/http_response_headers.h"
@@ -99,7 +100,18 @@ extensions::mime_handler::StreamInfoPtr TypeConverter<
99100
result->tab_id = stream.tab_id();
100101
const content::StreamInfo* info = stream.stream_info();
101102
result->mime_type = info->mime_type;
102-
result->original_url = info->original_url.spec();
103+
104+
// If the URL is too long, mojo will give up on sending the URL. In these
105+
// cases truncate it. Only data: URLs should ever really suffer this problem
106+
// so only worry about those for now.
107+
// TODO(raymes): This appears to be a bug in mojo somewhere. crbug.com/480099.
108+
if (info->original_url.SchemeIs(url::kDataScheme) &&
109+
info->original_url.spec().size() > content::kMaxURLDisplayChars) {
110+
result->original_url = info->original_url.scheme() + ":";
111+
} else {
112+
result->original_url = info->original_url.spec();
113+
}
114+
103115
result->stream_url = info->handle->GetURL().spec();
104116
result->response_headers =
105117
extensions::CreateResponseHeadersMap(info->response_headers.get());

extensions/browser/guest_view/mime_handler_view/mime_handler_view_browsertest.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,7 @@ IN_PROC_BROWSER_TEST_F(MimeHandlerViewTest, EmbeddedDataUrlObject) {
8686
IN_PROC_BROWSER_TEST_F(MimeHandlerViewTest, EmbeddedDataUrlEmbed) {
8787
RunTest("test_embedded_data_url_embed.html");
8888
}
89+
90+
IN_PROC_BROWSER_TEST_F(MimeHandlerViewTest, EmbeddedDataUrlLong) {
91+
RunTest("test_embedded_data_url_long.html");
92+
}

0 commit comments

Comments
 (0)