DevTools: fix CSS.addRule protocol method for file:// urls
The previous attempt to fix the bug was in crrev.com/539166: the patch allowed adding rules to the inspector style sheets. However, it didn't take into account adding rules into the already-existing style sheets. This patch fixes CSS.addRule altogether, allowing CSSOM access if the operation is happenning from-inside InspectorMutationScope. Our tests didn't catch the regression since we run with --allow-file-access-from-files flag. BUG=818518 R=dgozman Change-Id: Ic6b198a5ef7abbabcef671edbefb5a9b14fde531 Reviewed-on: https://chromium-review.googlesource.com/1018526 Commit-Queue: Andrey Lushnikov <lushnikov@chromium.org> Reviewed-by: Dmitry Gozman <dgozman@chromium.org> Reviewed-by: Rune Lillesveen <futhark@chromium.org> Cr-Commit-Position: refs/heads/master@{#552161}
This commit is contained in:

committed by
Commit Bot

parent
881ffae181
commit
85535060d2
third_party/blink/renderer/core
@ -238,6 +238,23 @@ void CSSStyleSheet::DidMutate() {
|
||||
ownerNode()->GetTreeScope());
|
||||
}
|
||||
|
||||
void CSSStyleSheet::EnableRuleAccessForInspector() {
|
||||
enable_rule_access_for_inspector_ = true;
|
||||
}
|
||||
void CSSStyleSheet::DisableRuleAccessForInspector() {
|
||||
enable_rule_access_for_inspector_ = false;
|
||||
}
|
||||
|
||||
CSSStyleSheet::InspectorMutationScope::InspectorMutationScope(
|
||||
CSSStyleSheet* sheet)
|
||||
: style_sheet_(sheet) {
|
||||
style_sheet_->EnableRuleAccessForInspector();
|
||||
}
|
||||
|
||||
CSSStyleSheet::InspectorMutationScope::~InspectorMutationScope() {
|
||||
style_sheet_->DisableRuleAccessForInspector();
|
||||
}
|
||||
|
||||
void CSSStyleSheet::ReattachChildRuleCSSOMWrappers() {
|
||||
for (unsigned i = 0; i < child_rule_cssom_wrappers_.size(); ++i) {
|
||||
if (!child_rule_cssom_wrappers_[i])
|
||||
@ -299,6 +316,8 @@ void CSSStyleSheet::ClearOwnerNode() {
|
||||
}
|
||||
|
||||
bool CSSStyleSheet::CanAccessRules() const {
|
||||
if (enable_rule_access_for_inspector_)
|
||||
return true;
|
||||
if (is_inline_stylesheet_)
|
||||
return true;
|
||||
KURL base_url = contents_->BaseURL();
|
||||
@ -307,8 +326,6 @@ bool CSSStyleSheet::CanAccessRules() const {
|
||||
Document* document = OwnerDocument();
|
||||
if (!document)
|
||||
return true;
|
||||
if (document->GetStyleEngine().InspectorStyleSheet() == this)
|
||||
return true;
|
||||
if (document->GetSecurityOrigin()->CanReadContent(base_url))
|
||||
return true;
|
||||
if (allow_rule_access_from_origin_ &&
|
||||
|
@ -152,6 +152,21 @@ class CORE_EXPORT CSSStyleSheet final : public StyleSheet {
|
||||
void DidMutateRules();
|
||||
void DidMutate();
|
||||
|
||||
class InspectorMutationScope {
|
||||
STACK_ALLOCATED();
|
||||
|
||||
public:
|
||||
explicit InspectorMutationScope(CSSStyleSheet*);
|
||||
~InspectorMutationScope();
|
||||
|
||||
private:
|
||||
Member<CSSStyleSheet> style_sheet_;
|
||||
DISALLOW_COPY_AND_ASSIGN(InspectorMutationScope);
|
||||
};
|
||||
|
||||
void EnableRuleAccessForInspector();
|
||||
void DisableRuleAccessForInspector();
|
||||
|
||||
StyleSheetContents* Contents() const { return contents_.Get(); }
|
||||
|
||||
bool IsInline() const { return is_inline_stylesheet_; }
|
||||
@ -199,6 +214,7 @@ class CORE_EXPORT CSSStyleSheet final : public StyleSheet {
|
||||
// This alternate variable is only used for constructed CSSStyleSheet.
|
||||
// For other CSSStyleSheet, consult the alternate attribute.
|
||||
bool alternate_from_constructor_ = false;
|
||||
bool enable_rule_access_for_inspector_ = false;
|
||||
String title_;
|
||||
scoped_refptr<MediaQuerySet> media_queries_;
|
||||
MediaQueryResultList viewport_dependent_media_query_results_;
|
||||
@ -219,8 +235,7 @@ class CORE_EXPORT CSSStyleSheet final : public StyleSheet {
|
||||
|
||||
inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSStyleSheet* sheet)
|
||||
: style_sheet_(sheet) {
|
||||
if (style_sheet_)
|
||||
style_sheet_->WillMutateRules();
|
||||
style_sheet_->WillMutateRules();
|
||||
}
|
||||
|
||||
inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSRule* rule)
|
||||
|
@ -622,10 +622,12 @@ class InspectorCSSAgent::AddRuleAction final
|
||||
}
|
||||
|
||||
bool Undo(ExceptionState& exception_state) override {
|
||||
CSSStyleSheet::InspectorMutationScope scope(style_sheet_->PageStyleSheet());
|
||||
return style_sheet_->DeleteRule(added_range_, exception_state);
|
||||
}
|
||||
|
||||
bool Redo(ExceptionState& exception_state) override {
|
||||
CSSStyleSheet::InspectorMutationScope scope(style_sheet_->PageStyleSheet());
|
||||
css_rule_ = style_sheet_->AddRule(rule_text_, location_, &added_range_,
|
||||
exception_state);
|
||||
if (exception_state.HadException())
|
||||
|
Reference in New Issue
Block a user