Commit 1f57bbec authored by Alex Rudenko's avatar Alex Rudenko Committed by Commit Bot

Prevent crash when page_style_sheet is missing an owner document

According to the crash report, the owner document could be a nullptr.
This CL adds a check if an owner document is available and sets the
execution_context to nullptr if it's not available.
CSSStyleDeclaration::setCSSText that receives the execution context
can handle nullptr values.

Fixed: 1090899
Change-Id: I2e0b1a56e6b25e98c043f576dbd230f50c062516
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2300382Reviewed-by: default avatarSigurd Schneider <sigurds@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarMathias Bynens <mathias@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789404}
parent eb4007a0
......@@ -1112,8 +1112,10 @@ CSSRule* InspectorStyleSheet::SetStyleText(const SourceRange& range,
else
style = To<CSSKeyframeRule>(rule)->style();
Document* owner_document = page_style_sheet_->OwnerDocument();
ExecutionContext* execution_context =
page_style_sheet_->OwnerDocument()->GetExecutionContext();
owner_document ? owner_document->GetExecutionContext() : nullptr;
style->setCSSText(execution_context, text, exception_state);
ReplaceText(source_data->rule_body_range, text, new_range, old_text);
......
The test verifies functionality of protocol method CSS.setStyleTexts and DOM.undo.
==== Initial style sheet text ====
#test { color: green; }
==== Style sheet text ====
#test {color: blue;}
Dumping matched rules:
*#test* { regular
color: blue;
}
Dumping inherited rules:
==== Style sheet text after clearing the stylesheet and DOM.Undo ====
<empty>
(async function(testRunner) {
var {page, session, dp} = await testRunner.startHTML(`
<style>
#test { color: green; }
</style>
<article id='test'></article>
`, 'The test verifies functionality of protocol method CSS.setStyleTexts and DOM.undo.');
const CSSHelper = await testRunner.loadScript('../resources/css-helper.js');
const cssHelper = new CSSHelper(testRunner, dp);
let eventPromise = dp.CSS.onceStyleSheetAdded();
await dp.DOM.enable();
await dp.CSS.enable();
let event = await eventPromise;
let styleSheetId = event.params.header.styleSheetId;
const setStyleTexts = cssHelper.setStyleTexts.bind(cssHelper, styleSheetId, false);
const documentNodeId = await cssHelper.requestDocumentNodeId();
let response = await dp.CSS.getStyleSheetText({styleSheetId});
testRunner.log('==== Initial style sheet text ====');
testRunner.log(response.result.text);
await setStyleTexts([{
styleSheetId: styleSheetId,
range: { startLine: 1, startColumn: 7, endLine: 1, endColumn: 22 },
text: "color: blue;",
}]);
await cssHelper.loadAndDumpMatchingRules(documentNodeId, '#test');
eventPromise = dp.CSS.onceStyleSheetAdded();
// Clear the style content.
await session.evaluate(fontURL => {
const style = document.querySelector('style');
style.textContent = '';
});
await dp.DOM.undo();
event = await eventPromise;
styleSheetId = event.params.header.styleSheetId;
response = await dp.CSS.getStyleSheetText({styleSheetId});
testRunner.log('==== Style sheet text after clearing the stylesheet and DOM.Undo ====');
testRunner.log(response.result.text || '<empty>');
testRunner.completeTest();
})
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