Commit 9cfe83f2 authored by Rob Paveza's avatar Rob Paveza Committed by Commit Bot

DevTools: Hide not-found sourcemap refs

When a JS source file refers to a sourcemap, which then refers to a file
that is not found on the file system (file://), the underlying request
handler doesn't return any headers. With no headers, the DevTools UI
bindings component presumes that the response is equivalent to a 200 OK
and returns a blank file. Instead, we're going to return a 404, which
will then prevent DevTools from surfacing the not-found file altogether.

Bug: 941035
Change-Id: Icf92bdcfb415f0381217547dac9037d53915e3fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1847833Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Robert Paveza <Rob.Paveza@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#704396}
parent 5f06901f
...@@ -200,9 +200,17 @@ InfoBarService* DefaultBindingsDelegate::GetInfoBarService() { ...@@ -200,9 +200,17 @@ InfoBarService* DefaultBindingsDelegate::GetInfoBarService() {
} }
std::unique_ptr<base::DictionaryValue> BuildObjectForResponse( std::unique_ptr<base::DictionaryValue> BuildObjectForResponse(
const net::HttpResponseHeaders* rh) { const net::HttpResponseHeaders* rh,
bool success) {
auto response = std::make_unique<base::DictionaryValue>(); auto response = std::make_unique<base::DictionaryValue>();
response->SetInteger("statusCode", rh ? rh->response_code() : 200); int responseCode = 200;
if (rh) {
responseCode = rh->response_code();
} else if (!success) {
// In case of no headers, assume file:// URL and failed to load
responseCode = 404;
}
response->SetInteger("statusCode", responseCode);
auto headers = std::make_unique<base::DictionaryValue>(); auto headers = std::make_unique<base::DictionaryValue>();
size_t iterator = 0; size_t iterator = 0;
...@@ -419,7 +427,7 @@ class DevToolsUIBindings::NetworkResourceLoader ...@@ -419,7 +427,7 @@ class DevToolsUIBindings::NetworkResourceLoader
} }
void OnComplete(bool success) override { void OnComplete(bool success) override {
auto response = BuildObjectForResponse(response_headers_.get()); auto response = BuildObjectForResponse(response_headers_.get(), success);
callback_.Run(response.get()); callback_.Run(response.get());
bindings_->loaders_.erase(bindings_->loaders_.find(this)); bindings_->loaders_.erase(bindings_->loaders_.find(this));
......
...@@ -55,9 +55,17 @@ std::vector<ShellDevToolsBindings*>* GetShellDevtoolsBindingsInstances() { ...@@ -55,9 +55,17 @@ std::vector<ShellDevToolsBindings*>* GetShellDevtoolsBindingsInstances() {
} }
std::unique_ptr<base::DictionaryValue> BuildObjectForResponse( std::unique_ptr<base::DictionaryValue> BuildObjectForResponse(
const net::HttpResponseHeaders* rh) { const net::HttpResponseHeaders* rh,
bool success) {
auto response = std::make_unique<base::DictionaryValue>(); auto response = std::make_unique<base::DictionaryValue>();
response->SetInteger("statusCode", rh ? rh->response_code() : 200); int responseCode = 200;
if (rh) {
responseCode = rh->response_code();
} else if (!success) {
// In case of no headers, assume file:// URL and failed to load
responseCode = 404;
}
response->SetInteger("statusCode", responseCode);
auto headers = std::make_unique<base::DictionaryValue>(); auto headers = std::make_unique<base::DictionaryValue>();
size_t iterator = 0; size_t iterator = 0;
...@@ -118,7 +126,7 @@ class ShellDevToolsBindings::NetworkResourceLoader ...@@ -118,7 +126,7 @@ class ShellDevToolsBindings::NetworkResourceLoader
} }
void OnComplete(bool success) override { void OnComplete(bool success) override {
auto response = BuildObjectForResponse(response_headers_.get()); auto response = BuildObjectForResponse(response_headers_.get(), success);
bindings_->SendMessageAck(request_id_, response.get()); bindings_->SendMessageAck(request_id_, response.get());
bindings_->loaders_.erase(bindings_->loaders_.find(this)); bindings_->loaders_.erase(bindings_->loaders_.find(this));
} }
......
...@@ -1437,6 +1437,7 @@ ...@@ -1437,6 +1437,7 @@
baseURL + 'echoheader?Cookie', undefined, 200, ['cache-control'], 'devtools-test-cookie=same-site-cookie'); baseURL + 'echoheader?Cookie', undefined, 200, ['cache-control'], 'devtools-test-cookie=same-site-cookie');
await testCase('data:text/html,<body>hello</body>', undefined, 200, [], '<body>hello</body>'); await testCase('data:text/html,<body>hello</body>', undefined, 200, [], '<body>hello</body>');
await testCase(fileURL, undefined, 200, [], '<html>\n<body>\nDummy page.\n</body>\n</html>\n'); await testCase(fileURL, undefined, 200, [], '<html>\n<body>\nDummy page.\n</body>\n</html>\n');
await testCase(fileURL + 'thisfileshouldnotbefound', undefined, 404, [], '');
this.releaseControl(); this.releaseControl();
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment