Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp

Issue 2916283002: Revert of DevTools: require enabling CSS domain before running CSS.* commands. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/inspector/InspectorCSSAgent.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 if (!state_->booleanProperty(CSSAgentState::kCssAgentEnabled, false)) { 750 if (!state_->booleanProperty(CSSAgentState::kCssAgentEnabled, false)) {
751 // We were disabled while fetching resources. 751 // We were disabled while fetching resources.
752 return; 752 return;
753 } 753 }
754 754
755 instrumenting_agents_->addInspectorCSSAgent(this); 755 instrumenting_agents_->addInspectorCSSAgent(this);
756 dom_agent_->SetDOMListener(this); 756 dom_agent_->SetDOMListener(this);
757 HeapVector<Member<Document>> documents = dom_agent_->Documents(); 757 HeapVector<Member<Document>> documents = dom_agent_->Documents();
758 for (Document* document : documents) 758 for (Document* document : documents)
759 UpdateActiveStyleSheets(document); 759 UpdateActiveStyleSheets(document);
760 was_enabled_ = true;
761 } 760 }
762 761
763 Response InspectorCSSAgent::disable() { 762 Response InspectorCSSAgent::disable() {
764 Reset(); 763 Reset();
765 dom_agent_->SetDOMListener(nullptr); 764 dom_agent_->SetDOMListener(nullptr);
766 instrumenting_agents_->removeInspectorCSSAgent(this); 765 instrumenting_agents_->removeInspectorCSSAgent(this);
767 state_->setBoolean(CSSAgentState::kCssAgentEnabled, false); 766 state_->setBoolean(CSSAgentState::kCssAgentEnabled, false);
768 was_enabled_ = false;
769 resource_content_loader_->Cancel(resource_content_loader_client_id_); 767 resource_content_loader_->Cancel(resource_content_loader_client_id_);
770 state_->setBoolean(CSSAgentState::kRuleRecordingEnabled, false); 768 state_->setBoolean(CSSAgentState::kRuleRecordingEnabled, false);
771 SetCoverageEnabled(false); 769 SetCoverageEnabled(false);
772 return Response::OK(); 770 return Response::OK();
773 } 771 }
774 772
775 void InspectorCSSAgent::DidCommitLoadForLocalFrame(LocalFrame* frame) { 773 void InspectorCSSAgent::DidCommitLoadForLocalFrame(LocalFrame* frame) {
776 if (frame == inspected_frames_->Root()) 774 if (frame == inspected_frames_->Root())
777 Reset(); 775 Reset();
778 } 776 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 int node_id, 908 int node_id,
911 Maybe<protocol::CSS::CSSStyle>* inline_style, 909 Maybe<protocol::CSS::CSSStyle>* inline_style,
912 Maybe<protocol::CSS::CSSStyle>* attributes_style, 910 Maybe<protocol::CSS::CSSStyle>* attributes_style,
913 Maybe<protocol::Array<protocol::CSS::RuleMatch>>* matched_css_rules, 911 Maybe<protocol::Array<protocol::CSS::RuleMatch>>* matched_css_rules,
914 Maybe<protocol::Array<protocol::CSS::PseudoElementMatches>>* 912 Maybe<protocol::Array<protocol::CSS::PseudoElementMatches>>*
915 pseudo_id_matches, 913 pseudo_id_matches,
916 Maybe<protocol::Array<protocol::CSS::InheritedStyleEntry>>* 914 Maybe<protocol::Array<protocol::CSS::InheritedStyleEntry>>*
917 inherited_entries, 915 inherited_entries,
918 Maybe<protocol::Array<protocol::CSS::CSSKeyframesRule>>* 916 Maybe<protocol::Array<protocol::CSS::CSSKeyframesRule>>*
919 css_keyframes_rules) { 917 css_keyframes_rules) {
920 Response response = AssertEnabled(); 918 Element* element = nullptr;
919 Response response = dom_agent_->AssertElement(node_id, element);
921 if (!response.isSuccess()) 920 if (!response.isSuccess())
922 return response; 921 return response;
923 922
924 Element* element = nullptr;
925 response = dom_agent_->AssertElement(node_id, element);
926 if (!response.isSuccess())
927 return response;
928
929 Element* original_element = element; 923 Element* original_element = element;
930 PseudoId element_pseudo_id = element->GetPseudoId(); 924 PseudoId element_pseudo_id = element->GetPseudoId();
931 if (element_pseudo_id) { 925 if (element_pseudo_id) {
932 element = element->ParentOrShadowHostElement(); 926 element = element->ParentOrShadowHostElement();
933 if (!element) 927 if (!element)
934 return Response::Error("Pseudo element has no parent"); 928 return Response::Error("Pseudo element has no parent");
935 } 929 }
936 930
937 Document* owner_document = element->ownerDocument(); 931 Document* owner_document = element->ownerDocument();
938 // A non-active document has no styles. 932 // A non-active document has no styles.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 .setKeyframes(std::move(keyframes)) 1085 .setKeyframes(std::move(keyframes))
1092 .build()); 1086 .build());
1093 } 1087 }
1094 return css_keyframes_rules; 1088 return css_keyframes_rules;
1095 } 1089 }
1096 1090
1097 Response InspectorCSSAgent::getInlineStylesForNode( 1091 Response InspectorCSSAgent::getInlineStylesForNode(
1098 int node_id, 1092 int node_id,
1099 Maybe<protocol::CSS::CSSStyle>* inline_style, 1093 Maybe<protocol::CSS::CSSStyle>* inline_style,
1100 Maybe<protocol::CSS::CSSStyle>* attributes_style) { 1094 Maybe<protocol::CSS::CSSStyle>* attributes_style) {
1101 Response response = AssertEnabled();
1102 if (!response.isSuccess())
1103 return response;
1104 Element* element = nullptr; 1095 Element* element = nullptr;
1105 response = dom_agent_->AssertElement(node_id, element); 1096 Response response = dom_agent_->AssertElement(node_id, element);
1106 if (!response.isSuccess()) 1097 if (!response.isSuccess())
1107 return response; 1098 return response;
1108 1099
1109 InspectorStyleSheetForInlineStyle* style_sheet = 1100 InspectorStyleSheetForInlineStyle* style_sheet =
1110 AsInspectorStyleSheet(element); 1101 AsInspectorStyleSheet(element);
1111 if (!style_sheet) 1102 if (!style_sheet)
1112 return Response::Error("Element is not a style sheet"); 1103 return Response::Error("Element is not a style sheet");
1113 1104
1114 *inline_style = style_sheet->BuildObjectForStyle(element->style()); 1105 *inline_style = style_sheet->BuildObjectForStyle(element->style());
1115 *attributes_style = BuildObjectForAttributesStyle(element); 1106 *attributes_style = BuildObjectForAttributesStyle(element);
1116 return Response::OK(); 1107 return Response::OK();
1117 } 1108 }
1118 1109
1119 Response InspectorCSSAgent::getComputedStyleForNode( 1110 Response InspectorCSSAgent::getComputedStyleForNode(
1120 int node_id, 1111 int node_id,
1121 std::unique_ptr<protocol::Array<protocol::CSS::CSSComputedStyleProperty>>* 1112 std::unique_ptr<protocol::Array<protocol::CSS::CSSComputedStyleProperty>>*
1122 style) { 1113 style) {
1123 Response response = AssertEnabled();
1124 if (!response.isSuccess())
1125 return response;
1126 Node* node = nullptr; 1114 Node* node = nullptr;
1127 response = dom_agent_->AssertNode(node_id, node); 1115 Response response = dom_agent_->AssertNode(node_id, node);
1128 if (!response.isSuccess()) 1116 if (!response.isSuccess())
1129 return response; 1117 return response;
1130 1118
1131 CSSComputedStyleDeclaration* computed_style_info = 1119 CSSComputedStyleDeclaration* computed_style_info =
1132 CSSComputedStyleDeclaration::Create(node, true); 1120 CSSComputedStyleDeclaration::Create(node, true);
1133 *style = protocol::Array<protocol::CSS::CSSComputedStyleProperty>::create(); 1121 *style = protocol::Array<protocol::CSS::CSSComputedStyleProperty>::create();
1134 for (int id = firstCSSProperty; id <= lastCSSProperty; ++id) { 1122 for (int id = firstCSSProperty; id <= lastCSSProperty; ++id) {
1135 CSSPropertyID property_id = static_cast<CSSPropertyID>(id); 1123 CSSPropertyID property_id = static_cast<CSSPropertyID>(id);
1136 if (!CSSPropertyMetadata::IsEnabledProperty(property_id) || 1124 if (!CSSPropertyMetadata::IsEnabledProperty(property_id) ||
1137 isShorthandProperty(property_id) || 1125 isShorthandProperty(property_id) ||
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 std::make_pair(simple_font_data->IsCustomFont() ? 1 : 0, family_name), 1171 std::make_pair(simple_font_data->IsCustomFont() ? 1 : 0, family_name),
1184 run_font_data.glyph_count_); 1172 run_font_data.glyph_count_);
1185 } 1173 }
1186 } 1174 }
1187 } 1175 }
1188 1176
1189 Response InspectorCSSAgent::getPlatformFontsForNode( 1177 Response InspectorCSSAgent::getPlatformFontsForNode(
1190 int node_id, 1178 int node_id,
1191 std::unique_ptr<protocol::Array<protocol::CSS::PlatformFontUsage>>* 1179 std::unique_ptr<protocol::Array<protocol::CSS::PlatformFontUsage>>*
1192 platform_fonts) { 1180 platform_fonts) {
1193 Response response = AssertEnabled();
1194 if (!response.isSuccess())
1195 return response;
1196 Node* node = nullptr; 1181 Node* node = nullptr;
1197 response = dom_agent_->AssertNode(node_id, node); 1182 Response response = dom_agent_->AssertNode(node_id, node);
1198 if (!response.isSuccess()) 1183 if (!response.isSuccess())
1199 return response; 1184 return response;
1200 1185
1201 HashCountedSet<std::pair<int, String>> font_stats; 1186 HashCountedSet<std::pair<int, String>> font_stats;
1202 LayoutObject* root = node->GetLayoutObject(); 1187 LayoutObject* root = node->GetLayoutObject();
1203 if (root) { 1188 if (root) {
1204 CollectPlatformFontsForLayoutObject(root, &font_stats); 1189 CollectPlatformFontsForLayoutObject(root, &font_stats);
1205 // Iterate upto two layers deep. 1190 // Iterate upto two layers deep.
1206 for (LayoutObject* child = root->SlowFirstChild(); child; 1191 for (LayoutObject* child = root->SlowFirstChild(); child;
1207 child = child->NextSibling()) { 1192 child = child->NextSibling()) {
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 return InspectorDOMAgent::ToResponse(exception_state); 1558 return InspectorDOMAgent::ToResponse(exception_state);
1574 1559
1575 CSSStyleRule* rule = action->TakeRule(); 1560 CSSStyleRule* rule = action->TakeRule();
1576 *result = BuildObjectForRule(rule); 1561 *result = BuildObjectForRule(rule);
1577 return Response::OK(); 1562 return Response::OK();
1578 } 1563 }
1579 1564
1580 Response InspectorCSSAgent::forcePseudoState( 1565 Response InspectorCSSAgent::forcePseudoState(
1581 int node_id, 1566 int node_id,
1582 std::unique_ptr<protocol::Array<String>> forced_pseudo_classes) { 1567 std::unique_ptr<protocol::Array<String>> forced_pseudo_classes) {
1583 Response response = AssertEnabled();
1584 if (!response.isSuccess())
1585 return response;
1586 Element* element = nullptr; 1568 Element* element = nullptr;
1587 response = dom_agent_->AssertElement(node_id, element); 1569 Response response = dom_agent_->AssertElement(node_id, element);
1588 if (!response.isSuccess()) 1570 if (!response.isSuccess())
1589 return response; 1571 return response;
1590 1572
1591 unsigned forced_pseudo_state = 1573 unsigned forced_pseudo_state =
1592 ComputePseudoClassMask(std::move(forced_pseudo_classes)); 1574 ComputePseudoClassMask(std::move(forced_pseudo_classes));
1593 NodeIdToForcedPseudoState::iterator it = 1575 NodeIdToForcedPseudoState::iterator it =
1594 node_id_to_forced_pseudo_state_.find(node_id); 1576 node_id_to_forced_pseudo_state_.find(node_id);
1595 unsigned current_forced_pseudo_state = 1577 unsigned current_forced_pseudo_state =
1596 it == node_id_to_forced_pseudo_state_.end() ? 0 : it->value; 1578 it == node_id_to_forced_pseudo_state_.end() ? 0 : it->value;
1597 bool need_style_recalc = forced_pseudo_state != current_forced_pseudo_state; 1579 bool need_style_recalc = forced_pseudo_state != current_forced_pseudo_state;
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 return nullptr; 1884 return nullptr;
1903 1885
1904 CSSStyleSheet& inspector_sheet = 1886 CSSStyleSheet& inspector_sheet =
1905 document->GetStyleEngine().EnsureInspectorStyleSheet(); 1887 document->GetStyleEngine().EnsureInspectorStyleSheet();
1906 1888
1907 FlushPendingProtocolNotifications(); 1889 FlushPendingProtocolNotifications();
1908 1890
1909 return css_style_sheet_to_inspector_style_sheet_.at(&inspector_sheet); 1891 return css_style_sheet_to_inspector_style_sheet_.at(&inspector_sheet);
1910 } 1892 }
1911 1893
1912 Response InspectorCSSAgent::AssertEnabled() {
1913 return was_enabled_ ? Response::OK()
1914 : Response::Error("CSS agent was not enabled");
1915 }
1916
1917 Response InspectorCSSAgent::AssertInspectorStyleSheetForId( 1894 Response InspectorCSSAgent::AssertInspectorStyleSheetForId(
1918 const String& style_sheet_id, 1895 const String& style_sheet_id,
1919 InspectorStyleSheet*& result) { 1896 InspectorStyleSheet*& result) {
1920 Response response = AssertEnabled();
1921 if (!response.isSuccess())
1922 return response;
1923 IdToInspectorStyleSheet::iterator it = 1897 IdToInspectorStyleSheet::iterator it =
1924 id_to_inspector_style_sheet_.find(style_sheet_id); 1898 id_to_inspector_style_sheet_.find(style_sheet_id);
1925 if (it == id_to_inspector_style_sheet_.end()) 1899 if (it == id_to_inspector_style_sheet_.end())
1926 return Response::Error("No style sheet with given id found"); 1900 return Response::Error("No style sheet with given id found");
1927 result = it->value.Get(); 1901 result = it->value.Get();
1928 return Response::OK(); 1902 return Response::OK();
1929 } 1903 }
1930 1904
1931 Response InspectorCSSAgent::AssertStyleSheetForId( 1905 Response InspectorCSSAgent::AssertStyleSheetForId(
1932 const String& style_sheet_id, 1906 const String& style_sheet_id,
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
2562 visitor->Trace(css_style_sheet_to_inspector_style_sheet_); 2536 visitor->Trace(css_style_sheet_to_inspector_style_sheet_);
2563 visitor->Trace(document_to_css_style_sheets_); 2537 visitor->Trace(document_to_css_style_sheets_);
2564 visitor->Trace(invalidated_documents_); 2538 visitor->Trace(invalidated_documents_);
2565 visitor->Trace(node_to_inspector_style_sheet_); 2539 visitor->Trace(node_to_inspector_style_sheet_);
2566 visitor->Trace(inspector_user_agent_style_sheet_); 2540 visitor->Trace(inspector_user_agent_style_sheet_);
2567 visitor->Trace(tracker_); 2541 visitor->Trace(tracker_);
2568 InspectorBaseAgent::Trace(visitor); 2542 InspectorBaseAgent::Trace(visitor);
2569 } 2543 }
2570 2544
2571 } // namespace blink 2545 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/inspector/InspectorCSSAgent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698