Commit bb156c20 authored by Alex Rudenko's avatar Alex Rudenko Committed by Commit Bot

Fix resource lookups in inspector stylesheet

The method ResourceStyleSheetText was using stylesheet's href
attribute to look up resources stored in the resource_container_.
It only worked when the href attribute and the FinalURL() were
the same because FinalURL() is used to store resources in the
resource_container_. This CL changes ResourceStyleSheetText to
use FinalURL() when looking up resources. FinalURL() is the
actual URL where stylesheet was loaded from (e.g., after
redirects).

Fixed: 1128360
Change-Id: Ib2dff7d2c86af582a857493a73f3f9fe27307e36
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414213Reviewed-by: default avatarSigurd Schneider <sigurds@chromium.org>
Reviewed-by: default avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808267}
parent babe1d8f
......@@ -1924,14 +1924,22 @@ bool InspectorStyleSheet::ResourceStyleSheetText(String* result) {
if (!page_style_sheet_->OwnerDocument())
return false;
KURL url(page_style_sheet_->href());
if (page_style_sheet_->href() &&
resource_container_->LoadStyleSheetContent(url, result))
// Original URL defined in CSS.
String href = page_style_sheet_->href();
// Not a resource style sheet.
if (!href)
return false;
// FinalURL() is a URL after redirects, whereas, href is not.
// FinalURL() is used to call resource_container_->StoreStyleSheetContent
// so it has to be used for lookups.
if (resource_container_->LoadStyleSheetContent(KURL(FinalURL()), result))
return true;
bool base64_encoded;
bool success = network_agent_->FetchResourceContent(
page_style_sheet_->OwnerDocument(), url, result, &base64_encoded);
page_style_sheet_->OwnerDocument(), KURL(href), result, &base64_encoded);
return success && !base64_encoded;
}
......
Test disabling of style rules for external CSS files served via a redirect.
CSS text for #target before disabling a style:
color: blue;
CSS text for #target after disabling a style:
/* color: blue; */
(async function(testRunner) {
const {dp} = await testRunner.startHTML(`
<link rel="stylesheet" href="${testRunner.url('../resources/css-redirect.php')}">
<div id="target">
Text
</div>
`, 'Test disabling of style rules for external CSS files served via a redirect.');
await dp.DOM.enable();
await dp.CSS.enable();
async function requestDocumentNodeId() {
const {result} = await dp.DOM.getDocument({});
return result.root.nodeId;
}
async function requestNodeId(nodeId, selector) {
const {result} = await dp.DOM.querySelector({nodeId, selector});
return result.nodeId;
}
const documentNodeId = await requestDocumentNodeId();
const nodeId = await requestNodeId(documentNodeId, '#target');
async function getMatchedRule() {
const { result } = await dp.CSS.getMatchedStylesForNode({ nodeId });
const matchedRule = result.matchedCSSRules.find(match => match.rule.selectorList.text === '#target');
if (!matchedRule) {
return 'default';
}
return matchedRule;
}
let rule = await getMatchedRule();
testRunner.log("CSS text for #target before disabling a style:");
testRunner.log(rule.rule.style.cssText.trim());
const styleSheetId = rule.rule.style.styleSheetId;
const response = await dp.CSS.setStyleTexts({
edits: [
{
"styleSheetId":styleSheetId,
"range": {
"startLine": 0,
"startColumn": 9,
"endLine": 2,
"endColumn": 0
},
"text":"\n\t/* color: blue; */\n"
}
]
});
rule = await getMatchedRule();
testRunner.log("CSS text for #target after disabling a style:");
testRunner.log(rule.rule.style.cssText.trim());
testRunner.completeTest();
});
<?php
header('HTTP/1.1 307 Temporary Redirect');
header('Location: css-edit-redirected-css.css');
?>
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