diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-06 12:48:11 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:33:43 +0000 |
commit | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (patch) | |
tree | fa14ba0ca8d2683ba2efdabd246dc9b18a1229c6 /chromium/third_party/blink/renderer/core/inspector | |
parent | 79b4f909db1049fca459c07cca55af56a9b54fe3 (diff) | |
download | qtwebengine-chromium-7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3.tar.gz |
BASELINE: Update Chromium to 84.0.4147.141
Change-Id: Ib85eb4cfa1cbe2b2b81e5022c8cad5c493969535
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/core/inspector')
38 files changed, 1514 insertions, 476 deletions
diff --git a/chromium/third_party/blink/renderer/core/inspector/BUILD.gn b/chromium/third_party/blink/renderer/core/inspector/BUILD.gn index a61b241165b..e8a912f1766 100644 --- a/chromium/third_party/blink/renderer/core/inspector/BUILD.gn +++ b/chromium/third_party/blink/renderer/core/inspector/BUILD.gn @@ -28,6 +28,8 @@ blink_core_sources("inspector") { "dom_editor.h", "dom_patch_support.cc", "dom_patch_support.h", + "dom_traversal_utils.cc", + "dom_traversal_utils.h", "identifiers_factory.cc", "identifiers_factory.h", "inspect_tools.cc", diff --git a/chromium/third_party/blink/renderer/core/inspector/dom_traversal_utils.cc b/chromium/third_party/blink/renderer/core/inspector/dom_traversal_utils.cc new file mode 100644 index 00000000000..71a752e0ed9 --- /dev/null +++ b/chromium/third_party/blink/renderer/core/inspector/dom_traversal_utils.cc @@ -0,0 +1,46 @@ +#include "third_party/blink/renderer/core/inspector/dom_traversal_utils.h" + +#include "third_party/blink/renderer/core/dom/flat_tree_traversal.h" +#include "third_party/blink/renderer/core/dom/node.h" +#include "third_party/blink/renderer/core/dom/shadow_root.h" + +namespace blink { +namespace dom_traversal_utils { + +Node* FirstChild(const Node& node, bool include_user_agent_shadow_tree) { + DCHECK(include_user_agent_shadow_tree || !node.IsInUserAgentShadowRoot()); + if (!include_user_agent_shadow_tree) { + ShadowRoot* shadow_root = node.GetShadowRoot(); + if (shadow_root && shadow_root->GetType() == ShadowRootType::kUserAgent) { + Node* child = node.firstChild(); + while (child && !child->CanParticipateInFlatTree()) + child = child->nextSibling(); + return child; + } + } + return FlatTreeTraversal::FirstChild(node); +} + +// static +bool HasChildren(const Node& node, bool include_user_agent_shadow_tree) { + return FirstChild(node, include_user_agent_shadow_tree); +} + +// static +Node* NextSibling(const Node& node, bool include_user_agent_shadow_tree) { + DCHECK(include_user_agent_shadow_tree || !node.IsInUserAgentShadowRoot()); + if (!include_user_agent_shadow_tree) { + if (node.ParentElementShadowRoot() && + node.ParentElementShadowRoot()->GetType() == + ShadowRootType::kUserAgent) { + Node* sibling = node.nextSibling(); + while (sibling && !sibling->CanParticipateInFlatTree()) + sibling = sibling->nextSibling(); + return sibling; + } + } + return FlatTreeTraversal::NextSibling(node); +} + +} // namespace dom_traversal_utils +} // namespace blink diff --git a/chromium/third_party/blink/renderer/core/inspector/dom_traversal_utils.h b/chromium/third_party/blink/renderer/core/inspector/dom_traversal_utils.h new file mode 100644 index 00000000000..d4a52a40844 --- /dev/null +++ b/chromium/third_party/blink/renderer/core/inspector/dom_traversal_utils.h @@ -0,0 +1,22 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_DOM_TRAVERSAL_UTILS_H_ +#define THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_DOM_TRAVERSAL_UTILS_H_ + +namespace blink { + +class Node; + +namespace dom_traversal_utils { + +// These are deprecated, do not use in new code. Use FlatTreeTraversal directly. +Node* FirstChild(const Node& node, bool include_user_agent_shadow_tree); +bool HasChildren(const Node& node, bool include_user_agent_shadow_tree); +Node* NextSibling(const Node& node, bool include_user_agent_shadow_tree); + +} // namespace dom_traversal_utils +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_DOM_TRAVERSAL_UTILS_H_ diff --git a/chromium/third_party/blink/renderer/core/inspector/inspect_tool_highlight.html b/chromium/third_party/blink/renderer/core/inspector/inspect_tool_highlight.html index 2f9157c4a22..b5c7dbdb50f 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspect_tool_highlight.html +++ b/chromium/third_party/blink/renderer/core/inspector/inspect_tool_highlight.html @@ -66,7 +66,7 @@ body { border-radius: 3px; box-sizing: border-box; min-width: 100px; - max-width: 300px; + max-width: min(300px, 100% - 4px); z-index: 1; background-clip: padding-box; will-change: transform; @@ -87,6 +87,20 @@ body { visibility: var(--arrow-visibility); } +.element-info-section { + margin-top: 12px; + margin-bottom: 6px; +} + +.section-name { + color: #333; + font-weight: 500; + font-size: 10px; + text-transform: uppercase; + letter-spacing: .05em; + line-height: 12px; +} + .element-info { display: flex; flex-direction: column; @@ -109,13 +123,20 @@ body { line-height: 19px; } -.element-info-contrast-row { +.separator-container { + display: flex; + align-items: center; + flex: auto; + margin-left: 7px; +} + +.separator { border-top: 1px solid #ddd; - padding-top: 5px; - margin-top: 5px; + width: 100%; } .element-info-name { + flex-shrink: 0; color: #666; } @@ -132,11 +153,21 @@ body { .element-info-value-contrast { display: flex; + align-items: center; text-align: right; color: rgb(48, 57, 66); margin-left: 10px; } +.element-info-value-contrast .a11y-icon { + margin-left: 8px; +} + +.element-info-value-icon { + display: flex; + align-items: center; +} + .element-info-value-text { text-align: right; color: rgb(48, 57, 66); @@ -205,16 +236,20 @@ body { .a11y-icon { width: 16px; height: 16px; - margin-left: 2px; background-repeat: no-repeat; + display: inline-block; +} + +.a11y-icon-not-ok { + background-image: url('data:image/svg+xml,<svg fill="none" viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg"><path d="m9 1.5c-4.14 0-7.5 3.36-7.5 7.5s3.36 7.5 7.5 7.5 7.5-3.36 7.5-7.5-3.36-7.5-7.5-7.5zm0 13.5c-3.315 0-6-2.685-6-6 0-1.3875.4725-2.6625 1.2675-3.675l8.4075 8.4075c-1.0125.795-2.2875 1.2675-3.675 1.2675zm4.7325-2.325-8.4075-8.4075c1.0125-.795 2.2875-1.2675 3.675-1.2675 3.315 0 6 2.685 6 6 0 1.3875-.4725 2.6625-1.2675 3.675z" fill="%239e9e9e"/></svg>'); } .a11y-icon-warning { - background-image: url("data:image/svg+xml;charset=UTF-8, %3csvg xmlns='http://www.w3.org/2000/svg' width='16px' height='16px' viewBox='0 0 18 18' fill='%23ffc107'%3e%3cpath d='M0 0h18v18H0z' fill='none'/%3e%3cpath d='M.5 16h17L9 1 .5 16zm9.5-2H8v-2h2v2zm0-3H8V7h2v4z'/%3e%3c/svg%3e "); + background-image: url('data:image/svg+xml,<svg fill="none" viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg"><path d="m8.25 11.25h1.5v1.5h-1.5zm0-6h1.5v4.5h-1.5zm.7425-3.75c-4.14 0-7.4925 3.36-7.4925 7.5s3.3525 7.5 7.4925 7.5c4.1475 0 7.5075-3.36 7.5075-7.5s-3.36-7.5-7.5075-7.5zm.0075 13.5c-3.315 0-6-2.685-6-6s2.685-6 6-6 6 2.685 6 6-2.685 6-6 6z" fill="%23e37400"/></svg>'); } .a11y-icon-ok { - background-image: url("data:image/svg+xml;charset=UTF-8, %3csvg xmlns='http://www.w3.org/2000/svg' width='16px' height='16px' viewBox='0 0 48 48' fill='%2300a000'%3e%3cpath d='M0 0h48v48H0z' fill='none'/%3e%3cpath d='M18 32.34L9.66 24l-2.83 2.83L18 38l24-24-2.83-2.83z'/%3e%3c/svg%3e"); + background-image: url('data:image/svg+xml,<svg fill="none" viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg"><path d="m9 1.5c-4.14 0-7.5 3.36-7.5 7.5s3.36 7.5 7.5 7.5 7.5-3.36 7.5-7.5-3.36-7.5-7.5-7.5zm0 13.5c-3.3075 0-6-2.6925-6-6s2.6925-6 6-6 6 2.6925 6 6-2.6925 6-6 6zm-1.5-4.35-1.95-1.95-1.05 1.05 3 3 6-6-1.05-1.05z" fill="%230ca40c"/></svg>'); } @media (forced-colors: active) { @@ -233,13 +268,14 @@ body { } .color-swatch-inner, .contrast-text, - .element-info-contrast-row { + .separator { border-color: Highlight; } .dimensions, .element-info-name, .element-info-value-color, .element-info-value-contrast, + .element-info-value-icon, .element-info-value-text, .material-tag-name, .material-class-name, @@ -407,14 +443,68 @@ function parseHexa(hexa) { } /** - * @param {!String} hexa + * TODO(alexrudenko): import this and other color helpers from DevTools + * @param {!Array<number>} rgba * @return {!Array<number>} */ -function normalizeColorString(hexa) { - if (hexa.endsWith("FF")) +function rgbaToHsla(rgba) { + const [r, g, b] = rgba; + const max = Math.max(r, g, b); + const min = Math.min(r, g, b); + const diff = max - min; + const sum = max + min; + + let h; + if (min === max) { + h = 0; + } else if (r === max) { + h = ((1 / 6 * (g - b) / diff) + 1) % 1; + } else if (g === max) { + h = (1 / 6 * (b - r) / diff) + 1 / 3; + } else { + h = (1 / 6 * (r - g) / diff) + 2 / 3; + } + + const l = 0.5 * sum; + + let s; + if (l === 0) { + s = 0; + } else if (l === 1) { + s = 0; + } else if (l <= 0.5) { + s = diff / sum; + } else { + s = diff / (2 - sum); + } + + return [h, s, l, rgba[3]]; +} + +/** + * @param {!String} hexa + * @param {!String} colorFormat + * @return {!String} + */ +function formatColor(hexa, colorFormat) { + if (colorFormat === 'rgb') { + const [r, g, b, a] = parseHexa(hexa); + // rgb(r g b [ / a]) + return `rgb(${(r * 255).toFixed()} ${(g * 255).toFixed()} ${(b * 255).toFixed()}${a === 1 ? '' : ' / ' + Math.round(a * 100) / 100})`; + } + + if (colorFormat === 'hsl') { + const [h, s, l, a] = rgbaToHsla(parseHexa(hexa)); + // hsl(hdeg s l [ / a]) + return `hsl(${Math.round(h * 360)}deg ${Math.round(s * 100)} ${Math.round(l * 100)}${a === 1 ? '' : ' / ' + Math.round(a * 100) / 100})`; + } + + if (hexa.endsWith("FF")) { + // short hex if no alpha return hexa.substr(0, 7); - const [r, g, b, a] = parseHexa(hexa); - return `rgba(${(r * 255).toFixed()}, ${(g * 255).toFixed()}, ${(b * 255).toFixed()}, ${Math.round(a * 100) / 100})`; + } + + return hexa; } /** @@ -484,7 +574,7 @@ function computeIsLargeFont(contrast) { return fontSizePt >= 18; } -function _createElementDescription(elementInfo) +function _createElementDescription(elementInfo, colorFormat) { const elementInfoElement = createElement("div", "element-info"); const elementInfoHeaderElement = elementInfoElement.createChild("div", "element-info-header"); @@ -513,7 +603,7 @@ function _createElementDescription(elementInfo) const color = style["color"]; if (color && color !== "#00000000") - addColorRow("Color", color); + addColorRow("Color", color, colorFormat); const fontFamily = style["font-family"]; const fontSize = style["font-size"]; @@ -522,7 +612,7 @@ function _createElementDescription(elementInfo) const bgcolor = style["background-color"]; if (bgcolor && bgcolor !== "#00000000") - addColorRow("Background", bgcolor); + addColorRow("Background", bgcolor, colorFormat); const margin = style["margin"]; if (margin && margin !== "0px") @@ -533,12 +623,36 @@ function _createElementDescription(elementInfo) addTextRow("Padding", padding); const cbgColor = elementInfo.contrast ? elementInfo.contrast.backgroundColor : null; - if (color && color !== "#00000000" && cbgColor && cbgColor !== "#00000000") - addContrastRow(style["color"], elementInfo.contrast); + const hasContrastInfo = color && color !== "#00000000" && cbgColor && cbgColor !== "#00000000"; - function addRow(name, rowClassName, valueClassName) { + if (elementInfo.showAccessibilityInfo) { + addSection("Accessibility"); + + if (hasContrastInfo) + addContrastRow(style["color"], elementInfo.contrast); + + addTextRow("Name", elementInfo.accessibleName); + addTextRow("Role", elementInfo.accessibleRole); + addIconRow("Keyboard-focusable", elementInfo.isKeyboardFocusable ? "a11y-icon a11y-icon-ok" : "a11y-icon a11y-icon-not-ok"); + } + + function ensureElementInfoBody() { if (!elementInfoBodyElement) elementInfoBodyElement = elementInfoElement.createChild("div", "element-info-body") + } + + function addSection(name) { + ensureElementInfoBody(); + const rowElement = elementInfoBodyElement.createChild("div", "element-info-row element-info-section"); + const nameElement = rowElement.createChild("div", "section-name"); + nameElement.textContent = name; + const separatorElement = rowElement + .createChild("div", "separator-container") + .createChild("div", "separator"); + } + + function addRow(name, rowClassName, valueClassName) { + ensureElementInfoBody(); const rowElement = elementInfoBodyElement.createChild("div", "element-info-row"); if (rowClassName) rowElement.classList.add(rowClassName); @@ -548,22 +662,26 @@ function _createElementDescription(elementInfo) return rowElement.createChild("div", valueClassName || ""); } + function addIconRow(name, value) { + addRow(name, "", "element-info-value-icon").createChild('div', value); + } + function addTextRow(name, value) { addRow(name, "", "element-info-value-text").createTextChild(value); } - function addColorRow(name, color) { + function addColorRow(name, color, colorFormat) { const valueElement = addRow(name, "", "element-info-value-color"); const swatch = valueElement.createChild("div", "color-swatch"); const inner = swatch.createChild("div", "color-swatch-inner"); inner.style.backgroundColor = color; - valueElement.createTextChild(normalizeColorString(color)); + valueElement.createTextChild(formatColor(color, colorFormat)); } function addContrastRow(fgColor, contrast) { const ratio = contrastRatio(parseHexa(fgColor), parseHexa(contrast.backgroundColor)); const threshold = computeIsLargeFont(contrast) ? 3.0 : 4.5; - const valueElement = addRow("Contrast", "element-info-contrast-row", "element-info-value-contrast"); + const valueElement = addRow("Contrast", "", "element-info-value-contrast"); const sampleText = valueElement.createChild("div", "contrast-text"); sampleText.style.color = fgColor; sampleText.style.backgroundColor = contrast.backgroundColor; @@ -576,11 +694,11 @@ function _createElementDescription(elementInfo) return elementInfoElement; } -function _drawElementTitle(elementInfo, bounds) +function _drawElementTitle(elementInfo, bounds, colorFormat) { const tooltipContainer = document.getElementById("tooltip-container"); tooltipContainer.removeChildren(); - _createMaterialTooltip(tooltipContainer, bounds, _createElementDescription(elementInfo), true); + _createMaterialTooltip(tooltipContainer, bounds, _createElementDescription(elementInfo, colorFormat), true); } function _createMaterialTooltip(parentElement, bounds, contentElement, withArrow) @@ -651,14 +769,17 @@ function _createMaterialTooltip(parentElement, bounds, contentElement, withArrow tooltipContent.style.setProperty('--arrow-left', (arrowX - boxX) + 'px'); } -function _drawRulers(context, bounds, rulerAtRight, rulerAtBottom) +function _drawRulers(context, bounds, rulerAtRight, rulerAtBottom, color, dash) { context.save(); var width = canvasWidth; var height = canvasHeight; - context.strokeStyle = "rgba(128, 128, 128, 0.3)"; + context.strokeStyle = color || "rgba(128, 128, 128, 0.3)"; context.lineWidth = 1; context.translate(0.5, 0.5); + if (dash) { + context.setLineDash([3, 3]); + } if (rulerAtRight) { for (var y in bounds.rightmostXForY) { @@ -779,22 +900,150 @@ function emptyBounds() function _drawLayoutGridHighlight(highlight, context) { + // Draw Grid border + if (highlight.gridHighlightConfig.gridBorderColor) { + context.save(); + context.translate(0.5, 0.5); + context.lineWidth = 0; + if (highlight.gridHighlightConfig.gridBorderDash) { + context.setLineDash([3, 3]); + } + context.strokeStyle = highlight.gridHighlightConfig.gridBorderColor; + context.stroke(buildPath(highlight.gridBorder, emptyBounds())); + context.restore(); + } + + // Draw Cell Border + if (highlight.gridHighlightConfig.cellBorderColor) { + const rowBounds = emptyBounds(); + const columnBounds = emptyBounds(); + const rowPath = buildPath(highlight.rows, rowBounds); + const columnPath = buildPath(highlight.columns, columnBounds); + context.save(); + context.translate(0.5, 0.5); + if (highlight.gridHighlightConfig.cellBorderDash) { + context.setLineDash([3, 3]); + } + context.lineWidth = 0; + context.strokeStyle = highlight.gridHighlightConfig.cellBorderColor; + + context.save(); + context.clip(columnPath); + context.stroke(rowPath); + context.restore(); + + context.save(); + context.clip(rowPath); + context.stroke(columnPath); + context.restore(); + + context.restore(); + + if (highlight.gridHighlightConfig.showGridExtensionLines) { + // Extend row gap lines left/up. + _drawRulers(context, rowBounds, /* rulerAtRight */ false, /* rulerAtBottom */ false, highlight.gridHighlightConfig.cellBorderColor, highlight.gridHighlightConfig.cellBorderDash); + // Extend row gap right/down. + _drawRulers(context, rowBounds, /* rulerAtRight */ true, /* rulerAtBottom */ true, highlight.gridHighlightConfig.cellBorderColor, highlight.gridHighlightConfig.cellBorderDash); + // Extend column lines left/up. + _drawRulers(context, columnBounds, /* rulerAtRight */ false, /* rulerAtBottom */ false, highlight.gridHighlightConfig.cellBorderColor, highlight.gridHighlightConfig.cellBorderDash); + // Extend column right/down. + _drawRulers(context, columnBounds, /* rulerAtRight */ true, /* rulerAtBottom */ true, highlight.gridHighlightConfig.cellBorderColor, highlight.gridHighlightConfig.cellBorderDash); + } + } + + // Row Gaps + if (highlight.gridHighlightConfig.rowGapColor) { + context.save(); + context.translate(0.5, 0.5); + context.lineWidth = 0; + context.fillStyle = highlight.gridHighlightConfig.rowGapColor; + let bounds = emptyBounds(); + const path = buildPath(highlight.rowGaps, bounds); + if (highlight.gridHighlightConfig.rowHatchColor) { + hatchFillPath(context, path, bounds, 10, highlight.gridHighlightConfig.rowHatchColor, /* flipDirection */ true); + } + context.fill(path); + context.restore(); + } + + // Column Gaps + if (highlight.gridHighlightConfig.columnGapColor) { + context.save(); + context.translate(0.5, 0.5); + context.lineWidth = 0; + context.fillStyle = highlight.gridHighlightConfig.columnGapColor; + let bounds = emptyBounds(); + const path = buildPath(highlight.columnGaps, bounds); + if (highlight.gridHighlightConfig.columnHatchColor) { + hatchFillPath(context, path, bounds, 10, highlight.gridHighlightConfig.columnHatchColor); + } + context.fill(path); + context.restore(); + } +} + +/** + * Draw line hatching at a 45 degree angle for a given + * path. + * __________ + * |\ \ \ | + * | \ \ \| + * | \ \ | + * |\ \ \ | + * ********** + * + * @param {CanvasRenderingContext2D} context + * @param {Path2D} path + * @param {Object} bounds + * @param {delta} delta - vertical gap between hatching lines in pixels + * @param {string} color + * @param {boolean=} flipDirection - lines are drawn from top right to bottom left + * + */ +function hatchFillPath(context, path, bounds, delta, color, flipDirection) { + const dx = bounds.maxX - bounds.minX; + const dy = bounds.maxY - bounds.minY; + context.rect(bounds.minX, bounds.minY, dx, dy); context.save(); - context.translate(0.5, 0.5); - context.setLineDash([3, 3]); - context.lineWidth = 0; - context.strokeStyle = highlight.color; - context.stroke(buildPath(highlight.cells, emptyBounds())); + context.clip(path); + context.setLineDash([5, 3]); + const majorAxis = Math.max(dx, dy); + context.strokeStyle = color; + if (flipDirection) { + for (let i = -majorAxis; i < majorAxis; i += delta) { + context.beginPath(); + context.moveTo(bounds.maxX - i , bounds.minY); + context.lineTo(bounds.maxX - dy - i, bounds.maxY); + context.stroke(); + } + } else { + for (let i = -majorAxis; i < majorAxis; i += delta) { + context.beginPath(); + context.moveTo(i + bounds.minX, bounds.minY); + context.lineTo(dy + i + bounds.minX, bounds.maxY); + context.stroke(); + } + } context.restore(); } -function clipLayoutGridCells(highlight) { +function clipLayoutGridCells(highlight, context) { + // It may seem simpler to, before drawing the desired path, call context.clip() + // with the rows and then with the columns. However, the 2nd context.clip() call + // would try to find the intersection of the rows and columns, which is way too + // expensive if the grid is huge, e.g. a 1000x1000 grid has 1M cells. + // Therefore, it's better to draw the path first, set the globalCompositeOperation + // so that the existing canvas content is kept where it overlaps with new content, + // and then draw the rows and columns. if (highlight.gridInfo) { for (const grid of highlight.gridInfo) { if (!grid.isPrimaryGrid) continue; - const path = buildPath(grid.cells, emptyBounds()); - context.clip(path); + context.save(); + context.globalCompositeOperation = "destination-in"; + drawPath(context, grid.rows, "red", null, emptyBounds()); + drawPath(context, grid.columns, "red", null, emptyBounds()); + context.restore(); } } } @@ -808,15 +1057,15 @@ function drawHighlight(highlight, context) for (var paths = highlight.paths.slice(); paths.length;) { var path = paths.pop(); - // Clip content quad using the data grid cells info to create white stripes. context.save(); - if (path.name === "content") - clipLayoutGridCells(highlight); drawPath(context, path.path, path.fillColor, path.outlineColor, bounds); if (paths.length) { context.globalCompositeOperation = "destination-out"; drawPath(context, paths[paths.length - 1].path, "red", null, bounds); } + // Clip content quad using the data grid cells info to create white stripes. + if (path.name === "content") + clipLayoutGridCells(highlight, context); context.restore(); } context.restore(); @@ -834,7 +1083,7 @@ function drawHighlight(highlight, context) _drawRulers(context, bounds, rulerAtRight, rulerAtBottom); if (highlight.elementInfo) - _drawElementTitle(highlight.elementInfo, bounds); + _drawElementTitle(highlight.elementInfo, bounds, highlight.colorFormat); } if (highlight.gridInfo) { for (var grid of highlight.gridInfo) @@ -851,7 +1100,7 @@ function test() { drawHighlight( {"paths":[{"path":["M",122,133.796875,"L",822,133.796875,"L",822,208.796875,"L",122,208.796875,"Z"], "fillColor":"rgba(111, 168, 220, 0.658823529411765)","name":"content"}, {"path":["M",122,113.796875,"L",822,113.796875,"L",822,228.796875,"L",122,228.796875,"Z"],"fillColor":"rgba(246, 178, 107, 0.66)","name":"margin"}],"showRulers":false,"showExtensionLines":false, - "elementInfo":{"tagName":"button","className":"class.name", "idValue":"download-hero","nodeWidth":"700","nodeHeight":"75","style":{"color":"#FFFFFFFF","font-family":"\"Product Sans\", \"Open Sans\", Roboto, Arial, \"Product Sans\", \"Open Sans\", Roboto, Arial","font-size":"20px","line-height":"25px","padding":"0px","margin":"20px 0px","background-color":"#00000000"},"contrast":{"fontSize":"20px","fontWeight":"400","backgroundColor":"#F9B826BF"}}, showExtensionLines: true, showRulers: true}); + "elementInfo":{"tagName":"button","className":"class.name", "idValue":"download-hero","nodeWidth":"700","nodeHeight":"75","style":{"color":"#FFFFFFFF","font-family":"\"Product Sans\", \"Open Sans\", Roboto, Arial, \"Product Sans\", \"Open Sans\", Roboto, Arial","font-size":"20px","line-height":"25px","padding":"0px","margin":"20px 0px","background-color":"#00000000"},"contrast":{"fontSize":"20px","fontWeight":"400","backgroundColor":"#F9B826BF"},"isKeyboardFocusable":false,"accessibleName":"name","accessibleRole":"role","showAccessibilityInfo":true}, showExtensionLines: true, showRulers: true, colorFormat: "hsl"}); } </script> diff --git a/chromium/third_party/blink/renderer/core/inspector/inspect_tools.cc b/chromium/third_party/blink/renderer/core/inspector/inspect_tools.cc index 866afa057bf..502c7676fca 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspect_tools.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspect_tools.cc @@ -142,8 +142,8 @@ void SearchingForNodeTool::Draw(float scale) { bool SearchingForNodeTool::HandleInputEvent(LocalFrameView* frame_view, const WebInputEvent& input_event, bool* swallow_next_mouse_up) { - if (input_event.GetType() == WebInputEvent::kGestureScrollBegin || - input_event.GetType() == WebInputEvent::kGestureScrollUpdate) { + if (input_event.GetType() == WebInputEvent::Type::kGestureScrollBegin || + input_event.GetType() == WebInputEvent::Type::kGestureScrollUpdate) { hovered_node_.Clear(); event_target_node_.Clear(); overlay_->ScheduleUpdate(); @@ -297,6 +297,10 @@ bool NodeHighlightTool::HideOnHideHighlight() { return true; } +bool NodeHighlightTool::HideOnMouseMove() { + return true; +} + void NodeHighlightTool::Draw(float scale) { DrawNode(); DrawMatchingSelector(); diff --git a/chromium/third_party/blink/renderer/core/inspector/inspect_tools.h b/chromium/third_party/blink/renderer/core/inspector/inspect_tools.h index 5117ebd7760..3d19e9ada1b 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspect_tools.h +++ b/chromium/third_party/blink/renderer/core/inspector/inspect_tools.h @@ -75,6 +75,7 @@ class NodeHighlightTool : public InspectTool { private: bool ForwardEventsToOverlay() override; + bool HideOnMouseMove() override; bool HideOnHideHighlight() override; void Draw(float scale) override; void DrawNode(); diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_animation_agent.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_animation_agent.cc index 786c300e858..734a3349e14 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_animation_agent.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_animation_agent.cc @@ -193,7 +193,7 @@ InspectorAnimationAgent::BuildObjectForAnimation(blink::Animation& animation) { .setPlayState(animation.PlayStateString()) .setPlaybackRate(animation.playbackRate()) .setStartTime(NormalizedStartTime(animation)) - .setCurrentTime(animation.currentTime()) + .setCurrentTime(animation.currentTime().value_or(Timing::NullValue())) .setType(animation_type) .build(); if (animation_type != AnimationType::WebAnimation) @@ -225,10 +225,10 @@ Response InspectorAnimationAgent::getCurrentTime(const String& id, animation = id_to_animation_clone_.at(id); if (animation->Paused() || !animation->timeline()->IsActive()) { - *current_time = animation->currentTime(); + *current_time = animation->currentTime().value_or(Timing::NullValue()); } else { // Use startTime where possible since currentTime is limited. - base::Optional<double> timeline_time = animation->timeline()->CurrentTime(); + base::Optional<double> timeline_time = animation->timeline()->currentTime(); // TODO(crbug.com/916117): Handle NaN values for scroll linked animations. *current_time = timeline_time ? timeline_time.value() - @@ -253,9 +253,9 @@ Response InspectorAnimationAgent::setPaused( // Ensure we restore a current time if the animation is limited. double current_time = 0; if (!clone->timeline()->IsActive()) { - current_time = clone->currentTime(); + current_time = clone->currentTime().value_or(Timing::NullValue()); } else { - base::Optional<double> timeline_time = clone->timeline()->CurrentTime(); + base::Optional<double> timeline_time = clone->timeline()->currentTime(); // TODO(crbug.com/916117): Handle NaN values. current_time = timeline_time ? timeline_time.value() - @@ -263,7 +263,7 @@ Response InspectorAnimationAgent::setPaused( : Timing::NullValue(); } clone->pause(); - clone->setCurrentTime(current_time, false); + clone->setCurrentTime(current_time); } else if (!paused && clone->Paused()) { clone->Unpause(); } @@ -310,8 +310,7 @@ blink::Animation* InspectorAnimationAgent::AnimationClone( id_to_animation_clone_.Set(id, clone); id_to_animation_.Set(String::Number(clone->SequenceNumber()), clone); clone->play(); - clone->setStartTime(animation->startTime().value_or(Timing::NullValue()), - false); + clone->setStartTime(animation->startTime().value_or(Timing::NullValue())); animation->SetEffectSuppressed(true); } @@ -331,7 +330,7 @@ Response InspectorAnimationAgent::seekAnimations( return Response::ServerError("Failed to clone a detached animation."); if (!clone->Paused()) clone->play(); - clone->setCurrentTime(current_time, false); + clone->setCurrentTime(current_time); } return Response::Success(); } @@ -515,7 +514,8 @@ double InspectorAnimationAgent::NormalizedStartTime( if (document_timeline) { if (ReferenceTimeline().PlaybackRate() == 0) { time_ms += - ReferenceTimeline().currentTime() - document_timeline->currentTime(); + ReferenceTimeline().currentTime().value_or(Timing::NullValue()) - + document_timeline->currentTime().value_or(Timing::NullValue()); } else { time_ms += (document_timeline->ZeroTime() - ReferenceTimeline().ZeroTime()) diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_audits_agent.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_audits_agent.cc index 7dfae515abc..de81a8e3df5 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_audits_agent.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_audits_agent.cc @@ -153,31 +153,43 @@ void InspectorAuditsAgent::InnerEnable() { } namespace { -std::unique_ptr<protocol::Array<protocol::Audits::AffectedCookie>> BuildCookies( - const WTF::Vector<mojom::blink::AffectedCookiePtr>& cookies) { - auto result = - std::make_unique<protocol::Array<protocol::Audits::AffectedCookie>>(); - for (const auto& cookie : cookies) { - auto protocol_cookie = std::move(protocol::Audits::AffectedCookie::create() - .setName(cookie->name) - .setPath(cookie->path) - .setDomain(cookie->domain)); - if (cookie->site_for_cookies) { - protocol_cookie.setSiteForCookies(*cookie->site_for_cookies); - } - result->push_back(protocol_cookie.build()); +std::unique_ptr<protocol::Audits::AffectedCookie> BuildAffectedCookie( + const mojom::blink::AffectedCookiePtr& cookie) { + auto protocol_cookie = std::move(protocol::Audits::AffectedCookie::create() + .setName(cookie->name) + .setPath(cookie->path) + .setDomain(cookie->domain)); + return protocol_cookie.build(); +} + +std::unique_ptr<protocol::Audits::AffectedRequest> BuildAffectedRequest( + const mojom::blink::AffectedRequestPtr& request) { + auto protocol_request = protocol::Audits::AffectedRequest::create() + .setRequestId(request->request_id) + .build(); + if (!request->url.IsEmpty()) { + protocol_request->setUrl(request->url); } - return result; + return protocol_request; +} + +std::unique_ptr<protocol::Audits::AffectedFrame> BuildAffectedFrame( + const mojom::blink::AffectedFramePtr& frame) { + return protocol::Audits::AffectedFrame::create() + .setFrameId(frame->frame_id) + .build(); } + blink::protocol::String InspectorIssueCodeValue( mojom::blink::InspectorIssueCode code) { switch (code) { case mojom::blink::InspectorIssueCode::kSameSiteCookieIssue: return protocol::Audits::InspectorIssueCodeEnum::SameSiteCookieIssue; + case mojom::blink::InspectorIssueCode::kMixedContentIssue: + return protocol::Audits::InspectorIssueCodeEnum::MixedContentIssue; } - NOTREACHED(); - return "unknown"; } + protocol::String BuildCookieExclusionReason( mojom::blink::SameSiteCookieExclusionReason exclusion_reason) { switch (exclusion_reason) { @@ -190,9 +202,8 @@ protocol::String BuildCookieExclusionReason( return protocol::Audits::SameSiteCookieExclusionReasonEnum:: ExcludeSameSiteNoneInsecure; } - NOTREACHED(); - return "unknown"; } + std::unique_ptr<std::vector<blink::protocol::String>> BuildCookieExclusionReasons( const WTF::Vector<mojom::blink::SameSiteCookieExclusionReason>& @@ -204,6 +215,7 @@ BuildCookieExclusionReasons( } return protocol_exclusion_reasons; } + protocol::String BuildCookieWarningReason( mojom::blink::SameSiteCookieWarningReason warning_reason) { switch (warning_reason) { @@ -220,33 +232,28 @@ protocol::String BuildCookieWarningReason( return protocol::Audits::SameSiteCookieWarningReasonEnum:: WarnSameSiteUnspecifiedLaxAllowUnsafe; case blink::mojom::blink::SameSiteCookieWarningReason:: - WarnSameSiteCrossSchemeSecureUrlMethodUnsafe: - return protocol::Audits::SameSiteCookieWarningReasonEnum:: - WarnSameSiteCrossSchemeSecureUrlMethodUnsafe; - case blink::mojom::blink::SameSiteCookieWarningReason:: - WarnSameSiteCrossSchemeSecureUrlLax: + WarnSameSiteStrictLaxDowngradeStrict: return protocol::Audits::SameSiteCookieWarningReasonEnum:: - WarnSameSiteCrossSchemeSecureUrlLax; + WarnSameSiteStrictLaxDowngradeStrict; case blink::mojom::blink::SameSiteCookieWarningReason:: - WarnSameSiteCrossSchemeSecureUrlStrict: + WarnSameSiteStrictCrossDowngradeStrict: return protocol::Audits::SameSiteCookieWarningReasonEnum:: - WarnSameSiteCrossSchemeSecureUrlStrict; + WarnSameSiteStrictCrossDowngradeStrict; case blink::mojom::blink::SameSiteCookieWarningReason:: - WarnSameSiteCrossSchemeInsecureUrlMethodUnsafe: + WarnSameSiteStrictCrossDowngradeLax: return protocol::Audits::SameSiteCookieWarningReasonEnum:: - WarnSameSiteCrossSchemeInsecureUrlMethodUnsafe; + WarnSameSiteStrictCrossDowngradeLax; case blink::mojom::blink::SameSiteCookieWarningReason:: - WarnSameSiteCrossSchemeInsecureUrlLax: + WarnSameSiteLaxCrossDowngradeStrict: return protocol::Audits::SameSiteCookieWarningReasonEnum:: - WarnSameSiteCrossSchemeInsecureUrlLax; + WarnSameSiteLaxCrossDowngradeStrict; case blink::mojom::blink::SameSiteCookieWarningReason:: - WarnSameSiteCrossSchemeInsecureUrlStrict: + WarnSameSiteLaxCrossDowngradeLax: return protocol::Audits::SameSiteCookieWarningReasonEnum:: - WarnSameSiteCrossSchemeInsecureUrlStrict; + WarnSameSiteLaxCrossDowngradeLax; } - NOTREACHED(); - return "unknown"; } + std::unique_ptr<std::vector<blink::protocol::String>> BuildCookieWarningReasons( const WTF::Vector<mojom::blink::SameSiteCookieWarningReason>& warning_reasons) { @@ -257,32 +264,154 @@ std::unique_ptr<std::vector<blink::protocol::String>> BuildCookieWarningReasons( } return protocol_warning_reasons; } +protocol::String BuildCookieOperation( + mojom::blink::SameSiteCookieOperation operation) { + switch (operation) { + case blink::mojom::blink::SameSiteCookieOperation::SetCookie: + return protocol::Audits::SameSiteCookieOperationEnum::SetCookie; + case blink::mojom::blink::SameSiteCookieOperation::ReadCookie: + return protocol::Audits::SameSiteCookieOperationEnum::ReadCookie; + } +} + +protocol::String BuildMixedContentResolutionStatus( + mojom::blink::MixedContentResolutionStatus resolution_type) { + switch (resolution_type) { + case blink::mojom::blink::MixedContentResolutionStatus::MixedContentBlocked: + return protocol::Audits::MixedContentResolutionStatusEnum:: + MixedContentBlocked; + case blink::mojom::blink::MixedContentResolutionStatus:: + MixedContentAutomaticallyUpgraded: + return protocol::Audits::MixedContentResolutionStatusEnum:: + MixedContentAutomaticallyUpgraded; + case blink::mojom::blink::MixedContentResolutionStatus::MixedContentWarning: + return protocol::Audits::MixedContentResolutionStatusEnum:: + MixedContentWarning; + } +} + +protocol::String BuildMixedContentResourceType( + mojom::blink::RequestContextType request_context) { + switch (request_context) { + case blink::mojom::blink::RequestContextType::AUDIO: + return protocol::Audits::MixedContentResourceTypeEnum::Audio; + case blink::mojom::blink::RequestContextType::BEACON: + return protocol::Audits::MixedContentResourceTypeEnum::Beacon; + case blink::mojom::blink::RequestContextType::CSP_REPORT: + return protocol::Audits::MixedContentResourceTypeEnum::CSPReport; + case blink::mojom::blink::RequestContextType::DOWNLOAD: + return protocol::Audits::MixedContentResourceTypeEnum::Download; + case blink::mojom::blink::RequestContextType::EMBED: + return protocol::Audits::MixedContentResourceTypeEnum::PluginResource; + case blink::mojom::blink::RequestContextType::EVENT_SOURCE: + return protocol::Audits::MixedContentResourceTypeEnum::EventSource; + case blink::mojom::blink::RequestContextType::FAVICON: + return protocol::Audits::MixedContentResourceTypeEnum::Favicon; + case blink::mojom::blink::RequestContextType::FETCH: + return protocol::Audits::MixedContentResourceTypeEnum::Resource; + case blink::mojom::blink::RequestContextType::FONT: + return protocol::Audits::MixedContentResourceTypeEnum::Font; + case blink::mojom::blink::RequestContextType::FORM: + return protocol::Audits::MixedContentResourceTypeEnum::Form; + case blink::mojom::blink::RequestContextType::FRAME: + return protocol::Audits::MixedContentResourceTypeEnum::Frame; + case blink::mojom::blink::RequestContextType::HYPERLINK: + return protocol::Audits::MixedContentResourceTypeEnum::Resource; + case blink::mojom::blink::RequestContextType::IFRAME: + return protocol::Audits::MixedContentResourceTypeEnum::Frame; + case blink::mojom::blink::RequestContextType::IMAGE: + return protocol::Audits::MixedContentResourceTypeEnum::Image; + case blink::mojom::blink::RequestContextType::IMAGE_SET: + return protocol::Audits::MixedContentResourceTypeEnum::Image; + case blink::mojom::blink::RequestContextType::IMPORT: + return protocol::Audits::MixedContentResourceTypeEnum::Import; + case blink::mojom::blink::RequestContextType::INTERNAL: + return protocol::Audits::MixedContentResourceTypeEnum::Resource; + case blink::mojom::blink::RequestContextType::LOCATION: + return protocol::Audits::MixedContentResourceTypeEnum::Resource; + case blink::mojom::blink::RequestContextType::MANIFEST: + return protocol::Audits::MixedContentResourceTypeEnum::Manifest; + case blink::mojom::blink::RequestContextType::OBJECT: + return protocol::Audits::MixedContentResourceTypeEnum::PluginResource; + case blink::mojom::blink::RequestContextType::PING: + return protocol::Audits::MixedContentResourceTypeEnum::Ping; + case blink::mojom::blink::RequestContextType::PLUGIN: + return protocol::Audits::MixedContentResourceTypeEnum::PluginData; + case blink::mojom::blink::RequestContextType::PREFETCH: + return protocol::Audits::MixedContentResourceTypeEnum::Prefetch; + case blink::mojom::blink::RequestContextType::SCRIPT: + return protocol::Audits::MixedContentResourceTypeEnum::Script; + case blink::mojom::blink::RequestContextType::SERVICE_WORKER: + return protocol::Audits::MixedContentResourceTypeEnum::ServiceWorker; + case blink::mojom::blink::RequestContextType::SHARED_WORKER: + return protocol::Audits::MixedContentResourceTypeEnum::SharedWorker; + case blink::mojom::blink::RequestContextType::STYLE: + return protocol::Audits::MixedContentResourceTypeEnum::Stylesheet; + case blink::mojom::blink::RequestContextType::SUBRESOURCE: + return protocol::Audits::MixedContentResourceTypeEnum::Resource; + case blink::mojom::blink::RequestContextType::TRACK: + return protocol::Audits::MixedContentResourceTypeEnum::Track; + case blink::mojom::blink::RequestContextType::UNSPECIFIED: + return protocol::Audits::MixedContentResourceTypeEnum::Resource; + case blink::mojom::blink::RequestContextType::VIDEO: + return protocol::Audits::MixedContentResourceTypeEnum::Video; + case blink::mojom::blink::RequestContextType::WORKER: + return protocol::Audits::MixedContentResourceTypeEnum::Worker; + case blink::mojom::blink::RequestContextType::XML_HTTP_REQUEST: + return protocol::Audits::MixedContentResourceTypeEnum::XMLHttpRequest; + case blink::mojom::blink::RequestContextType::XSLT: + return protocol::Audits::MixedContentResourceTypeEnum::XSLT; + } +} + } // namespace void InspectorAuditsAgent::InspectorIssueAdded(InspectorIssue* issue) { auto issueDetails = protocol::Audits::InspectorIssueDetails::create(); - if (issue->Details()->sameSiteCookieIssueDetails) { + if (const auto* d = issue->Details()->sameSiteCookieIssueDetails.get()) { auto sameSiteCookieDetails = - protocol::Audits::SameSiteCookieIssueDetails::create() - .setCookieExclusionReasons(BuildCookieExclusionReasons( - issue->Details()->sameSiteCookieIssueDetails->exclusionReason)) - .setCookieWarningReasons(BuildCookieWarningReasons( - issue->Details()->sameSiteCookieIssueDetails->warningReason)) - .build(); - issueDetails.setSameSiteCookieIssueDetails( - std::move(sameSiteCookieDetails)); + std::move(protocol::Audits::SameSiteCookieIssueDetails::create() + .setCookie(BuildAffectedCookie(d->cookie)) + .setCookieExclusionReasons( + BuildCookieExclusionReasons(d->exclusionReason)) + .setCookieWarningReasons( + BuildCookieWarningReasons(d->warningReason)) + .setOperation(BuildCookieOperation(d->operation))); + + if (d->site_for_cookies) { + sameSiteCookieDetails.setSiteForCookies(*d->site_for_cookies); + } + if (d->cookie_url) { + sameSiteCookieDetails.setCookieUrl(*d->cookie_url); + } + if (d->request) { + sameSiteCookieDetails.setRequest(BuildAffectedRequest(d->request)); + } + issueDetails.setSameSiteCookieIssueDetails(sameSiteCookieDetails.build()); } - auto affectedResources = - protocol::Audits::AffectedResources::create() - .setCookies(BuildCookies(issue->Resources()->cookies)) - .build(); + if (const auto* d = issue->Details()->mixed_content_issue_details.get()) { + auto mixedContentDetails = + protocol::Audits::MixedContentIssueDetails::create() + .setResourceType(BuildMixedContentResourceType(d->request_context)) + .setResolutionStatus( + BuildMixedContentResolutionStatus(d->resolution_status)) + .setInsecureURL(d->insecure_url) + .setMainResourceURL(d->main_resource_url) + .build(); + if (d->request) { + mixedContentDetails->setRequest(BuildAffectedRequest(d->request)); + } + if (d->frame) { + mixedContentDetails->setFrame(BuildAffectedFrame(d->frame)); + } + issueDetails.setMixedContentIssueDetails(std::move(mixedContentDetails)); + } auto inspector_issue = protocol::Audits::InspectorIssue::create() .setCode(InspectorIssueCodeValue(issue->Code())) .setDetails(issueDetails.build()) - .setResources(std::move(affectedResources)) .build(); GetFrontend()->issueAdded(std::move(inspector_issue)); diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_css_agent.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_css_agent.cc index b7637eadd7e..ef7c1ca3a0a 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_css_agent.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_css_agent.cc @@ -60,6 +60,7 @@ #include "third_party/blink/renderer/core/display_lock/display_lock_utilities.h" #include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/dom/dom_node_ids.h" +#include "third_party/blink/renderer/core/dom/flat_tree_traversal.h" #include "third_party/blink/renderer/core/dom/node.h" #include "third_party/blink/renderer/core/dom/text.h" #include "third_party/blink/renderer/core/frame/local_frame.h" @@ -860,6 +861,19 @@ void InspectorCSSAgent::ForcePseudoState(Element* element, if (!node_id) return; + // First check whether focus-within was set because focus or focus-within was + // forced for a child node. + NodeIdToNumberFocusedChildren::iterator focused_it = + node_id_to_number_focused_children_.find(node_id); + unsigned focused_count = + focused_it == node_id_to_number_focused_children_.end() + ? 0 + : focused_it->value; + if (pseudo_type == CSSSelector::kPseudoFocusWithin && focused_count > 0) { + *result = true; + return; + } + NodeIdToForcedPseudoState::iterator it = node_id_to_forced_pseudo_state_.find(node_id); if (it == node_id_to_forced_pseudo_state_.end()) @@ -867,6 +881,7 @@ void InspectorCSSAgent::ForcePseudoState(Element* element, bool force = false; unsigned forced_pseudo_state = it->value; + switch (pseudo_type) { case CSSSelector::kPseudoActive: force = forced_pseudo_state & kPseudoActive; @@ -1637,11 +1652,65 @@ Response InspectorCSSAgent::forcePseudoState( node_id_to_forced_pseudo_state_.Set(node_id, forced_pseudo_state); else node_id_to_forced_pseudo_state_.erase(node_id); + + // When adding focus or focus-within, we force focus-within for ancestor + // nodes to emulate real focus for user convenience. + + // Flips from no forced focus to the forced focus (:focus or :focus-within). + if (((forced_pseudo_state & kPseudoFocus) == kPseudoFocus && + (current_forced_pseudo_state & kPseudoFocus) == 0) || + ((forced_pseudo_state & kPseudoFocusWithin) == kPseudoFocusWithin && + (current_forced_pseudo_state & kPseudoFocusWithin) == 0)) { + IncrementFocusedCountForAncestors(element); + } + + // Flips from the forced focus (:focus or :focus-within) to no focus. + if (((forced_pseudo_state & kPseudoFocus) == 0 && + (current_forced_pseudo_state & kPseudoFocus) == kPseudoFocus) || + ((forced_pseudo_state & kPseudoFocusWithin) == 0 && + (current_forced_pseudo_state & kPseudoFocusWithin) == + kPseudoFocusWithin)) { + DecrementFocusedCountForAncestors(element); + } + element->ownerDocument()->GetStyleEngine().MarkAllElementsForStyleRecalc( StyleChangeReasonForTracing::Create(style_change_reason::kInspector)); return Response::Success(); } +void InspectorCSSAgent::IncrementFocusedCountForAncestors(Element* element) { + for (Node& ancestor : FlatTreeTraversal::AncestorsOf(*element)) { + int node_id = dom_agent_->BoundNodeId(&ancestor); + if (!node_id) + continue; + NodeIdToNumberFocusedChildren::iterator it = + node_id_to_number_focused_children_.find(node_id); + unsigned count = + it == node_id_to_number_focused_children_.end() ? 0 : it->value; + node_id_to_number_focused_children_.Set(node_id, count + 1); + } +} + +void InspectorCSSAgent::DecrementFocusedCountForAncestors(Element* element) { + for (Node& ancestor : FlatTreeTraversal::AncestorsOf(*element)) { + int node_id = dom_agent_->BoundNodeId(&ancestor); + if (!node_id) + continue; + NodeIdToNumberFocusedChildren::iterator it = + node_id_to_number_focused_children_.find(node_id); + unsigned count = + it == node_id_to_number_focused_children_.end() ? 1 : it->value; + if (count <= 1) { + // If `count - 1` is zero or overflows, erase the node_id + // from the map to save memory. If there is zero focused child + // elements, :focus-within should not be forced. + node_id_to_number_focused_children_.erase(node_id); + } else { + node_id_to_number_focused_children_.Set(node_id, count - 1); + } + } +} + std::unique_ptr<protocol::CSS::CSSMedia> InspectorCSSAgent::BuildMediaObject( const MediaList* media, MediaListSource media_list_source, @@ -2154,7 +2223,14 @@ void InspectorCSSAgent::ResetPseudoStates() { documents_to_change.insert(element->ownerDocument()); } + for (auto& count : node_id_to_number_focused_children_) { + auto* element = To<Element>(dom_agent_->NodeForId(count.key)); + if (element && element->ownerDocument()) + documents_to_change.insert(element->ownerDocument()); + } + node_id_to_forced_pseudo_state_.clear(); + node_id_to_number_focused_children_.clear(); for (auto& document : documents_to_change) { document->GetStyleEngine().MarkAllElementsForStyleRecalc( StyleChangeReasonForTracing::Create(style_change_reason::kInspector)); diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_css_agent.h b/chromium/third_party/blink/renderer/core/inspector/inspector_css_agent.h index 5815c86fbdb..449b85ea315 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_css_agent.h +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_css_agent.h @@ -245,6 +245,7 @@ class CORE_EXPORT InspectorCSSAgent final NodeToInspectorStyleSheet; // bogus "stylesheets" with elements' inline // styles typedef HashMap<int, unsigned> NodeIdToForcedPseudoState; + typedef HashMap<int, unsigned> NodeIdToNumberFocusedChildren; void ResourceContentLoaded(std::unique_ptr<EnableCallback>); void CompleteEnabled(); @@ -303,6 +304,9 @@ class CORE_EXPORT InspectorCSSAgent final void ResetPseudoStates(); + void IncrementFocusedCountForAncestors(Element*); + void DecrementFocusedCountForAncestors(Element*); + Member<InspectorDOMAgent> dom_agent_; Member<InspectedFrames> inspected_frames_; Member<InspectorNetworkAgent> network_agent_; @@ -322,6 +326,7 @@ class CORE_EXPORT InspectorCSSAgent final NodeToInspectorStyleSheet node_to_inspector_style_sheet_; NodeIdToForcedPseudoState node_id_to_forced_pseudo_state_; + NodeIdToNumberFocusedChildren node_id_to_number_focused_children_; Member<StyleRuleUsageTracker> tracker_; diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_dom_agent.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_dom_agent.cc index ce49bb82a00..bcf226243cf 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_dom_agent.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_dom_agent.cc @@ -1541,9 +1541,13 @@ std::unique_ptr<protocol::DOM::Node> InspectorDOMAgent::BuildObjectForNode( } if (auto* template_element = DynamicTo<HTMLTemplateElement>(*element)) { - value->setTemplateContent(BuildObjectForNode( - template_element->content(), 0, pierce, nodes_map, flatten_result)); - force_push_children = true; + // The inspector should not try to access the .content() property of + // declarative Shadow DOM <template> elements, because it will be null. + if (!template_element->IsDeclarativeShadowRoot()) { + value->setTemplateContent(BuildObjectForNode( + template_element->content(), 0, pierce, nodes_map, flatten_result)); + force_push_children = true; + } } if (element->GetPseudoId()) { diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_dom_snapshot_agent.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_dom_snapshot_agent.cc index 85e99a901d4..42755c8a650 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_dom_snapshot_agent.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_dom_snapshot_agent.cc @@ -141,6 +141,63 @@ String GetOriginUrl(const Node* node) { return node->GetDocument().Url().GetString(); } +class DOMTreeIterator { + STACK_ALLOCATED(); + + public: + DOMTreeIterator(Node* root, int root_node_id) + : current_(root), path_to_current_node_({root_node_id}) { + DCHECK(current_); + } + + void Advance(int next_node_id) { + DCHECK(current_); + const bool skip_shadow_root = + current_->GetShadowRoot() && current_->GetShadowRoot()->IsUserAgent(); + if (Node* first_child = skip_shadow_root + ? FirstFlatTreeSibling(current_->firstChild()) + : FlatTreeTraversal::FirstChild(*current_)) { + current_ = first_child; + path_to_current_node_.push_back(next_node_id); + return; + } + // No children, let's try siblings, then ancestor siblings. + while (current_) { + const bool in_ua_shadow_tree = + current_->ParentElementShadowRoot() && + current_->ParentElementShadowRoot()->IsUserAgent(); + if (Node* node = in_ua_shadow_tree + ? FirstFlatTreeSibling(current_->nextSibling()) + : FlatTreeTraversal::NextSibling(*current_)) { + path_to_current_node_.back() = next_node_id; + current_ = node; + return; + } + current_ = in_ua_shadow_tree ? current_->parentNode() + : FlatTreeTraversal::Parent(*current_); + path_to_current_node_.pop_back(); + } + DCHECK(path_to_current_node_.IsEmpty()); + } + + Node* CurrentNode() const { return current_; } + + int ParentNodeId() const { + return path_to_current_node_.size() > 1 + ? *(path_to_current_node_.rbegin() + 1) + : -1; + } + + private: + static Node* FirstFlatTreeSibling(Node* node) { + while (node && !node->CanParticipateInFlatTree()) + node = node->nextSibling(); + return node; + } + Node* current_; + WTF::Vector<int> path_to_current_node_; +}; + } // namespace // Returns |layout_object|'s bounding box in document coordinates. @@ -417,11 +474,16 @@ void InspectorDOMSnapshotAgent::VisitDocument(Document* document) { std::make_unique<protocol::Array<protocol::Array<double>>>()); } - VisitNode(document, -1); + auto* node_names = document_->getNodes()->getNodeName(nullptr); + for (DOMTreeIterator it(document, node_names->size()); it.CurrentNode(); + it.Advance(node_names->size())) { + DCHECK(!it.CurrentNode()->IsInUserAgentShadowRoot()); + VisitNode(it.CurrentNode(), it.ParentNodeId()); + } documents_->emplace_back(std::move(document_)); } -int InspectorDOMSnapshotAgent::VisitNode(Node* node, int parent_index) { +void InspectorDOMSnapshotAgent::VisitNode(Node* node, int parent_index) { String node_value; switch (node->getNodeType()) { case Node::kTextNode: @@ -508,62 +570,6 @@ int InspectorDOMSnapshotAgent::VisitNode(Node* node, int parent_index) { image_element->currentSrc()); } } - if (node->IsContainerNode()) - VisitContainerChildren(node, index); - return index; -} - -// static -Node* InspectorDOMSnapshotAgent::FirstChild( - const Node& node, - bool include_user_agent_shadow_tree) { - DCHECK(include_user_agent_shadow_tree || !node.IsInUserAgentShadowRoot()); - if (!include_user_agent_shadow_tree) { - ShadowRoot* shadow_root = node.GetShadowRoot(); - if (shadow_root && shadow_root->GetType() == ShadowRootType::kUserAgent) { - Node* child = node.firstChild(); - while (child && !child->CanParticipateInFlatTree()) - child = child->nextSibling(); - return child; - } - } - return FlatTreeTraversal::FirstChild(node); -} - -// static -bool InspectorDOMSnapshotAgent::HasChildren( - const Node& node, - bool include_user_agent_shadow_tree) { - return FirstChild(node, include_user_agent_shadow_tree); -} - -// static -Node* InspectorDOMSnapshotAgent::NextSibling( - const Node& node, - bool include_user_agent_shadow_tree) { - DCHECK(include_user_agent_shadow_tree || !node.IsInUserAgentShadowRoot()); - if (!include_user_agent_shadow_tree) { - if (node.ParentElementShadowRoot() && - node.ParentElementShadowRoot()->GetType() == - ShadowRootType::kUserAgent) { - Node* sibling = node.nextSibling(); - while (sibling && !sibling->CanParticipateInFlatTree()) - sibling = sibling->nextSibling(); - return sibling; - } - } - return FlatTreeTraversal::NextSibling(node); -} - -void InspectorDOMSnapshotAgent::VisitContainerChildren(Node* container, - int parent_index) { - if (!HasChildren(*container, false)) - return; - - for (Node* child = FirstChild(*container, false); child; - child = NextSibling(*child, false)) { - VisitNode(child, parent_index); - } } void InspectorDOMSnapshotAgent::VisitPseudoElements(Element* parent, diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_dom_snapshot_agent.h b/chromium/third_party/blink/renderer/core/inspector/inspector_dom_snapshot_agent.h index 8587c6147a9..d5ef9a5cee7 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_dom_snapshot_agent.h +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_dom_snapshot_agent.h @@ -57,14 +57,6 @@ class CORE_EXPORT InspectorDOMSnapshotAgent final void CharacterDataModified(CharacterData*); void DidInsertDOMNode(Node*); - // Helpers for traversal. - static bool HasChildren(const Node& node, - bool include_user_agent_shadow_tree); - static Node* FirstChild(const Node& node, - bool include_user_agent_shadow_tree); - static Node* NextSibling(const Node& node, - bool include_user_agent_shadow_tree); - // Helpers for rects static PhysicalRect RectInDocument(const LayoutObject* layout_object); static PhysicalRect TextFragmentRectInDocument( @@ -88,7 +80,8 @@ class CORE_EXPORT InspectorDOMSnapshotAgent final const String& value); void SetRare(protocol::DOMSnapshot::RareBooleanData* data, int index); void VisitDocument(Document*); - int VisitNode(Node*, int parent_index); + + void VisitNode(Node*, int parent_index); void VisitContainerChildren(Node* container, int parent_index); void VisitPseudoElements(Element* parent, int parent_index); std::unique_ptr<protocol::Array<int>> BuildArrayForElementAttributes(Node*); @@ -127,6 +120,7 @@ class CORE_EXPORT InspectorDOMSnapshotAgent final Member<InspectedFrames> inspected_frames_; Member<InspectorDOMDebuggerAgent> dom_debugger_agent_; InspectorAgentState::Boolean enabled_; + DISALLOW_COPY_AND_ASSIGN(InspectorDOMSnapshotAgent); }; diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_emulation_agent.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_emulation_agent.cc index 39b3efb5d0f..843b8c340dd 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_emulation_agent.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_emulation_agent.cc @@ -45,6 +45,8 @@ InspectorEmulationAgent::InspectorEmulationAgent( navigator_platform_override_(&agent_state_, /*default_value=*/WTF::String()), user_agent_override_(&agent_state_, /*default_value=*/WTF::String()), + serialized_ua_metadata_override_(&agent_state_, + /*default_value=*/WTF::String()), accept_language_override_(&agent_state_, /*default_value=*/WTF::String()), locale_override_(&agent_state_, /*default_value=*/WTF::String()), @@ -77,9 +79,19 @@ std::unique_ptr<protocol::DOM::RGBA> ParseRGBA( } // namespace void InspectorEmulationAgent::Restore() { - setUserAgentOverride(user_agent_override_.Get(), - accept_language_override_.Get(), - navigator_platform_override_.Get()); + // Since serialized_ua_metadata_override_ can't directly be converted back + // to appropriate protocol message, we initially pass null and decode it + // directly. + WTF::String save_serialized_ua_metadata_override = + serialized_ua_metadata_override_.Get(); + setUserAgentOverride( + user_agent_override_.Get(), accept_language_override_.Get(), + navigator_platform_override_.Get(), + protocol::Maybe<protocol::Emulation::UserAgentMetadata>()); + ua_metadata_override_ = blink::UserAgentMetadata::Demarshal( + save_serialized_ua_metadata_override.Latin1()); + serialized_ua_metadata_override_.Set(save_serialized_ua_metadata_override); + if (!locale_override_.Get().IsEmpty()) setLocaleOverride(locale_override_.Get()); if (!web_local_frame_) @@ -155,8 +167,10 @@ Response InspectorEmulationAgent::disable() { instrumenting_agents_->RemoveInspectorEmulationAgent(this); enabled_ = false; } - setUserAgentOverride(String(), protocol::Maybe<String>(), - protocol::Maybe<String>()); + + setUserAgentOverride( + String(), protocol::Maybe<String>(), protocol::Maybe<String>(), + protocol::Maybe<protocol::Emulation::UserAgentMetadata>()); if (!locale_override_.Get().IsEmpty()) setLocaleOverride(String()); if (!web_local_frame_) @@ -530,7 +544,9 @@ Response InspectorEmulationAgent::clearDeviceMetricsOverride() { Response InspectorEmulationAgent::setUserAgentOverride( const String& user_agent, protocol::Maybe<String> accept_language, - protocol::Maybe<String> platform) { + protocol::Maybe<String> platform, + protocol::Maybe<protocol::Emulation::UserAgentMetadata> + ua_metadata_override) { if (!user_agent.IsEmpty() || accept_language.isJust() || platform.isJust()) InnerEnable(); user_agent_override_.Set(user_agent); @@ -540,6 +556,43 @@ Response InspectorEmulationAgent::setUserAgentOverride( GetWebViewImpl()->GetPage()->GetSettings().SetNavigatorPlatformOverride( navigator_platform_override_.Get()); } + + if (ua_metadata_override.isJust()) { + if (user_agent.IsEmpty()) { + ua_metadata_override_ = base::nullopt; + serialized_ua_metadata_override_.Set(WTF::String()); + return Response::InvalidParams( + "Can't specify UserAgentMetadata but no UA string"); + } + std::unique_ptr<protocol::Emulation::UserAgentMetadata> ua_metadata = + ua_metadata_override.takeJust(); + ua_metadata_override_.emplace(); + if (ua_metadata->getBrands()) { + for (const auto& bv : *ua_metadata->getBrands()) { + blink::UserAgentBrandVersion out_bv; + out_bv.brand = bv->getBrand().Ascii(); + out_bv.major_version = bv->getVersion().Ascii(); + ua_metadata_override_->brand_version_list.push_back(std::move(out_bv)); + } + } + ua_metadata_override_->full_version = ua_metadata->getFullVersion().Ascii(); + ua_metadata_override_->platform = ua_metadata->getPlatform().Ascii(); + ua_metadata_override_->platform_version = + ua_metadata->getPlatformVersion().Ascii(); + ua_metadata_override_->architecture = + ua_metadata->getArchitecture().Ascii(); + ua_metadata_override_->model = ua_metadata->getModel().Ascii(); + ua_metadata_override_->mobile = ua_metadata->getMobile(); + } else { + ua_metadata_override_ = base::nullopt; + } + + std::string marshalled = + blink::UserAgentMetadata::Marshal(ua_metadata_override_) + .value_or(std::string()); + serialized_ua_metadata_override_.Set( + WTF::String(marshalled.data(), marshalled.size())); + return Response::Success(); } @@ -587,6 +640,14 @@ void InspectorEmulationAgent::ApplyUserAgentOverride(String* user_agent) { *user_agent = user_agent_override_.Get(); } +void InspectorEmulationAgent::ApplyUserAgentMetadataOverride( + base::Optional<blink::UserAgentMetadata>* ua_metadata) { + // This applies when UA override is set. + if (!user_agent_override_.Get().IsEmpty()) { + *ua_metadata = ua_metadata_override_; + } +} + void InspectorEmulationAgent::InnerEnable() { if (enabled_) return; diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_emulation_agent.h b/chromium/third_party/blink/renderer/core/inspector/inspector_emulation_agent.h index 4c7739644aa..e87627062f5 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_emulation_agent.h +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_emulation_agent.h @@ -7,6 +7,7 @@ #include "base/macros.h" #include "base/optional.h" +#include "third_party/blink/public/common/user_agent/user_agent_metadata.h" #include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/inspector/inspector_base_agent.h" #include "third_party/blink/renderer/core/inspector/protocol/Emulation.h" @@ -79,12 +80,16 @@ class CORE_EXPORT InspectorEmulationAgent final protocol::Response setUserAgentOverride( const String& user_agent, protocol::Maybe<String> accept_language, - protocol::Maybe<String> platform) override; + protocol::Maybe<String> platform, + protocol::Maybe<protocol::Emulation::UserAgentMetadata> + ua_metadata_override) override; protocol::Response setLocaleOverride(protocol::Maybe<String>) override; // InspectorInstrumentation API void ApplyAcceptLanguageOverride(String* accept_lang); void ApplyUserAgentOverride(String* user_agent); + void ApplyUserAgentMetadataOverride( + base::Optional<blink::UserAgentMetadata>* ua_metadata); void FrameStartedLoading(LocalFrame*); void PrepareRequest(DocumentLoader*, ResourceRequest&, @@ -131,6 +136,8 @@ class CORE_EXPORT InspectorEmulationAgent final InspectorAgentState::String emulated_vision_deficiency_; InspectorAgentState::String navigator_platform_override_; InspectorAgentState::String user_agent_override_; + InspectorAgentState::String serialized_ua_metadata_override_; + base::Optional<blink::UserAgentMetadata> ua_metadata_override_; InspectorAgentState::String accept_language_override_; InspectorAgentState::String locale_override_; InspectorAgentState::Double virtual_time_budget_; diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_highlight.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_highlight.cc index 379b7ccf045..e0b532a2b7b 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_highlight.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_highlight.cc @@ -13,8 +13,8 @@ #include "third_party/blink/renderer/core/frame/local_frame_view.h" #include "third_party/blink/renderer/core/frame/visual_viewport.h" #include "third_party/blink/renderer/core/geometry/dom_rect.h" +#include "third_party/blink/renderer/core/inspector/dom_traversal_utils.h" #include "third_party/blink/renderer/core/inspector/inspector_dom_agent.h" -#include "third_party/blink/renderer/core/inspector/inspector_dom_snapshot_agent.h" #include "third_party/blink/renderer/core/layout/adjust_for_absolute_zoom.h" #include "third_party/blink/renderer/core/layout/layout_box.h" #include "third_party/blink/renderer/core/layout/layout_grid.h" @@ -308,6 +308,12 @@ std::unique_ptr<protocol::DictionaryValue> BuildElementInfo(Element* element) { DOMRect* bounding_box = element->getBoundingClientRect(); element_info->setString("nodeWidth", String::Number(bounding_box->width())); element_info->setString("nodeHeight", String::Number(bounding_box->height())); + + element_info->setBoolean("showAccessibilityInfo", true); + element_info->setBoolean("isKeyboardFocusable", + element->IsKeyboardFocusable()); + element_info->setString("accessibleName", element->computedName()); + element_info->setString("accessibleRole", element->computedRole()); return element_info; } @@ -322,13 +328,50 @@ std::unique_ptr<protocol::DictionaryValue> BuildTextNodeInfo(Text* text_node) { text_info->setString("nodeWidth", bounding_box.Width().ToString()); text_info->setString("nodeHeight", bounding_box.Height().ToString()); text_info->setString("tagName", "#text"); + text_info->setBoolean("showAccessibilityInfo", false); return text_info; } +std::unique_ptr<protocol::DictionaryValue> BuildGridHighlightConfigInfo( + const InspectorGridHighlightConfig& grid_config) { + std::unique_ptr<protocol::DictionaryValue> grid_config_info = + protocol::DictionaryValue::create(); + grid_config_info->setBoolean("gridBorderDash", grid_config.grid_border_dash); + grid_config_info->setBoolean("cellBorderDash", grid_config.cell_border_dash); + grid_config_info->setBoolean("showGridExtensionLines", + grid_config.show_grid_extension_lines); + + if (grid_config.grid_color != Color::kTransparent) { + grid_config_info->setString("gridBorderColor", + grid_config.grid_color.Serialized()); + } + if (grid_config.cell_color != Color::kTransparent) { + grid_config_info->setString("cellBorderColor", + grid_config.cell_color.Serialized()); + } + if (grid_config.row_gap_color != Color::kTransparent) { + grid_config_info->setString("rowGapColor", + grid_config.row_gap_color.Serialized()); + } + if (grid_config.column_gap_color != Color::kTransparent) { + grid_config_info->setString("columnGapColor", + grid_config.column_gap_color.Serialized()); + } + if (grid_config.row_hatch_color != Color::kTransparent) { + grid_config_info->setString("rowHatchColor", + grid_config.row_hatch_color.Serialized()); + } + if (grid_config.column_hatch_color != Color::kTransparent) { + grid_config_info->setString("columnHatchColor", + grid_config.column_hatch_color.Serialized()); + } + return grid_config_info; +} + std::unique_ptr<protocol::DictionaryValue> BuildGridInfo( LocalFrameView* containing_view, LayoutGrid* layout_grid, - Color color, + const InspectorHighlightConfig& highlight_config, float scale, bool isPrimary) { std::unique_ptr<protocol::DictionaryValue> grid_info = @@ -337,29 +380,88 @@ std::unique_ptr<protocol::DictionaryValue> BuildGridInfo( const auto& rows = layout_grid->RowPositions(); const auto& columns = layout_grid->ColumnPositions(); - PathBuilder cell_builder; auto row_gap = layout_grid->GridGap(kForRows) + layout_grid->GridItemOffset(kForRows); auto column_gap = layout_grid->GridGap(kForColumns) + layout_grid->GridItemOffset(kForColumns); + PathBuilder row_builder; + PathBuilder row_gap_builder; + LayoutUnit row_left = columns.front(); + LayoutUnit row_width = columns.back() - columns.front(); for (size_t i = 1; i < rows.size(); ++i) { - for (size_t j = 1; j < columns.size(); ++j) { - PhysicalOffset position(columns.at(j - 1), rows.at(i - 1)); - PhysicalSize size(columns.at(j) - columns.at(j - 1), - rows.at(i) - rows.at(i - 1)); - if (i != rows.size() - 1) - size.height -= row_gap; - if (j != columns.size() - 1) - size.width -= column_gap; - PhysicalRect cell(position, size); - FloatQuad cell_quad = layout_grid->LocalRectToAbsoluteQuad(cell); - FrameQuadToViewport(containing_view, cell_quad); - cell_builder.AppendPath(QuadToPath(cell_quad), scale); + // Rows + PhysicalOffset position(row_left, rows.at(i - 1)); + PhysicalSize size(row_width, rows.at(i) - rows.at(i - 1)); + if (i != rows.size() - 1) + size.height -= row_gap; + PhysicalRect row(position, size); + FloatQuad row_quad = layout_grid->LocalRectToAbsoluteQuad(row); + FrameQuadToViewport(containing_view, row_quad); + row_builder.AppendPath(QuadToPath(row_quad), scale); + // Row Gaps + if (i != rows.size() - 1) { + PhysicalOffset gap_position(row_left, rows.at(i) - row_gap); + PhysicalSize gap_size(row_width, row_gap); + PhysicalRect gap(gap_position, gap_size); + FloatQuad gap_quad = layout_grid->LocalRectToAbsoluteQuad(gap); + FrameQuadToViewport(containing_view, gap_quad); + row_gap_builder.AppendPath(QuadToPath(gap_quad), scale); + } + } + grid_info->setValue("rows", row_builder.Release()); + grid_info->setValue("rowGaps", row_gap_builder.Release()); + + PathBuilder column_builder; + PathBuilder column_gap_builder; + LayoutUnit column_top = rows.front(); + LayoutUnit column_height = rows.back() - rows.front(); + for (size_t i = 1; i < columns.size(); ++i) { + PhysicalOffset position(columns.at(i - 1), column_top); + PhysicalSize size(columns.at(i) - columns.at(i - 1), column_height); + if (i != columns.size() - 1) + size.width -= column_gap; + PhysicalRect column(position, size); + FloatQuad column_quad = layout_grid->LocalRectToAbsoluteQuad(column); + FrameQuadToViewport(containing_view, column_quad); + column_builder.AppendPath(QuadToPath(column_quad), scale); + // Column Gaps + if (i != columns.size() - 1) { + PhysicalOffset gap_position(columns.at(i) - column_gap, column_top); + PhysicalSize gap_size(column_gap, column_height); + PhysicalRect gap(gap_position, gap_size); + FloatQuad gap_quad = layout_grid->LocalRectToAbsoluteQuad(gap); + FrameQuadToViewport(containing_view, gap_quad); + column_gap_builder.AppendPath(QuadToPath(gap_quad), scale); } } - grid_info->setValue("cells", cell_builder.Release()); - grid_info->setString("color", color.Serialized()); + grid_info->setValue("columns", column_builder.Release()); + grid_info->setValue("columnGaps", column_gap_builder.Release()); + + // Grid border + PathBuilder grid_border_builder; + PhysicalOffset grid_position(row_left, column_top); + PhysicalSize grid_size(row_width, column_height); + PhysicalRect grid_rect(grid_position, grid_size); + FloatQuad grid_quad = layout_grid->LocalRectToAbsoluteQuad(grid_rect); + FrameQuadToViewport(containing_view, grid_quad); + grid_border_builder.AppendPath(QuadToPath(grid_quad), scale); + grid_info->setValue("gridBorder", grid_border_builder.Release()); + + if (highlight_config.css_grid != Color::kTransparent) { + // Legacy support for highlight_config.css_grid + std::unique_ptr<protocol::DictionaryValue> grid_config_info = + protocol::DictionaryValue::create(); + grid_config_info->setString("cellBorderColor", + highlight_config.css_grid.Serialized()); + grid_config_info->setBoolean("cellBorderDash", true); + grid_info->setValue("gridHighlightConfig", grid_config_info->clone()); + } else { + grid_info->setValue( + "gridHighlightConfig", + BuildGridHighlightConfigInfo(*highlight_config.grid_highlight_config)); + } + grid_info->setBoolean("isPrimaryGrid", isPrimary); return grid_info; } @@ -425,17 +527,24 @@ PhysicalRect TextFragmentRectInRootFrame( } // namespace +InspectorHighlightConfig::InspectorHighlightConfig() + : show_info(false), + show_styles(false), + show_rulers(false), + show_extension_lines(false), + color_format(ColorFormat::HEX) {} + InspectorHighlight::InspectorHighlight(float scale) : highlight_paths_(protocol::ListValue::create()), show_rulers_(false), show_extension_lines_(false), - scale_(scale) {} + scale_(scale), + color_format_(ColorFormat::HEX) {} -InspectorHighlightConfig::InspectorHighlightConfig() - : show_info(false), - show_styles(false), - show_rulers(false), - show_extension_lines(false) {} +InspectorGridHighlightConfig::InspectorGridHighlightConfig() + : show_grid_extension_lines(false), + grid_border_dash(false), + cell_border_dash(false) {} InspectorHighlight::InspectorHighlight( Node* node, @@ -447,7 +556,8 @@ InspectorHighlight::InspectorHighlight( : highlight_paths_(protocol::ListValue::create()), show_rulers_(highlight_config.show_rulers), show_extension_lines_(highlight_config.show_extension_lines), - scale_(1.f) { + scale_(1.f), + color_format_(highlight_config.color_format) { DCHECK(!DisplayLockUtilities::NearestLockedExclusiveAncestor(*node)); LocalFrameView* frame_view = node->GetDocument().View(); if (frame_view) { @@ -495,10 +605,7 @@ void InspectorHighlight::AppendDistanceInfo(Node* node) { continue; if (value->IsColorValue()) { Color color = static_cast<const cssvalue::CSSColorValue*>(value)->Value(); - String hex_color = - String::Format("#%02X%02X%02X%02X", color.Red(), color.Green(), - color.Blue(), color.Alpha()); - computed_style_->setString(name, hex_color); + computed_style_->setString(name, ToHEXA(color)); } else { computed_style_->setString(name, value->CssText()); } @@ -532,10 +639,10 @@ void InspectorHighlight::VisitAndCollectDistanceInfo(Node* node) { if (!node->IsContainerNode()) return; - Node* first_child = InspectorDOMSnapshotAgent::FirstChild(*node, false); - for (Node* child = first_child; child; - child = InspectorDOMSnapshotAgent::NextSibling(*child, false)) + for (Node* child = blink::dom_traversal_utils::FirstChild(*node, false); + child; child = blink::dom_traversal_utils::NextSibling(*child, false)) { VisitAndCollectDistanceInfo(child); + } } void InspectorHighlight::VisitAndCollectDistanceInfo( @@ -653,22 +760,24 @@ void InspectorHighlight::AppendNodeHighlight( AppendQuad(border, highlight_config.border, Color::kTransparent, "border"); AppendQuad(margin, highlight_config.margin, Color::kTransparent, "margin"); - if (highlight_config.css_grid == Color::kTransparent) + if (highlight_config.css_grid == Color::kTransparent && + !highlight_config.grid_highlight_config) { return; + } grid_info_ = protocol::ListValue::create(); if (layout_object->IsLayoutGrid()) { - grid_info_->pushValue( - BuildGridInfo(node->GetDocument().View(), ToLayoutGrid(layout_object), - highlight_config.css_grid, scale_, true)); + grid_info_->pushValue(BuildGridInfo(node->GetDocument().View(), + ToLayoutGrid(layout_object), + highlight_config, scale_, true)); } LayoutObject* parent = layout_object->Parent(); if (!parent || !parent->IsLayoutGrid()) return; if (!BuildNodeQuads(parent->GetNode(), &content, &padding, &border, &margin)) return; - grid_info_->pushValue( - BuildGridInfo(node->GetDocument().View(), ToLayoutGrid(parent), - highlight_config.css_grid, scale_, false)); + grid_info_->pushValue(BuildGridInfo(node->GetDocument().View(), + ToLayoutGrid(parent), highlight_config, + scale_, false)); } std::unique_ptr<protocol::DictionaryValue> InspectorHighlight::AsProtocolValue() @@ -678,6 +787,18 @@ std::unique_ptr<protocol::DictionaryValue> InspectorHighlight::AsProtocolValue() object->setValue("paths", highlight_paths_->clone()); object->setBoolean("showRulers", show_rulers_); object->setBoolean("showExtensionLines", show_extension_lines_); + switch (color_format_) { + case ColorFormat::RGB: + object->setString("colorFormat", "rgb"); + break; + case ColorFormat::HSL: + object->setString("colorFormat", "hsl"); + break; + case ColorFormat::HEX: + object->setString("colorFormat", "hex"); + break; + } + if (model_) { std::unique_ptr<protocol::DictionaryValue> distance_info = protocol::DictionaryValue::create(); @@ -929,7 +1050,25 @@ InspectorHighlightConfig InspectorHighlight::DefaultConfig() { config.show_styles = false; config.show_rulers = true; config.show_extension_lines = true; - config.css_grid = Color(128, 128, 128, 0); + config.css_grid = Color::kTransparent; + config.color_format = ColorFormat::HEX; + config.grid_highlight_config = std::make_unique<InspectorGridHighlightConfig>( + InspectorHighlight::DefaultGridConfig()); + return config; +} + +// static +InspectorGridHighlightConfig InspectorHighlight::DefaultGridConfig() { + InspectorGridHighlightConfig config; + config.grid_color = Color(255, 0, 0, 0); + config.cell_color = Color(128, 0, 0, 0); + config.row_gap_color = Color(0, 255, 0, 0); + config.column_gap_color = Color(0, 0, 255, 0); + config.row_hatch_color = Color(255, 255, 255, 0); + config.column_hatch_color = Color(128, 128, 128, 0); + config.show_grid_extension_lines = true; + config.grid_border_dash = false; + config.cell_border_dash = true; return config; } diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_highlight.h b/chromium/third_party/blink/renderer/core/inspector/inspector_highlight.h index 5ca5060888f..9625b3941cd 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_highlight.h +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_highlight.h @@ -17,6 +17,25 @@ namespace blink { class Color; +enum class ColorFormat { RGB, HEX, HSL }; +struct CORE_EXPORT InspectorGridHighlightConfig { + USING_FAST_MALLOC(InspectorGridHighlightConfig); + + public: + InspectorGridHighlightConfig(); + + Color grid_color; + Color cell_color; + Color row_gap_color; + Color column_gap_color; + Color row_hatch_color; + Color column_hatch_color; + + bool show_grid_extension_lines; + bool grid_border_dash; + bool cell_border_dash; +}; + struct CORE_EXPORT InspectorHighlightConfig { USING_FAST_MALLOC(InspectorHighlightConfig); @@ -39,6 +58,9 @@ struct CORE_EXPORT InspectorHighlightConfig { bool show_extension_lines; String selector_list; + ColorFormat color_format; + + std::unique_ptr<InspectorGridHighlightConfig> grid_highlight_config; }; struct InspectorHighlightContrastInfo { @@ -67,6 +89,7 @@ class CORE_EXPORT InspectorHighlight { Node*, std::unique_ptr<protocol::Array<protocol::Array<double>>>*); static InspectorHighlightConfig DefaultConfig(); + static InspectorGridHighlightConfig DefaultGridConfig(); void AppendPath(std::unique_ptr<protocol::ListValue> path, const Color& fill_color, @@ -106,6 +129,7 @@ class CORE_EXPORT InspectorHighlight { bool show_rulers_; bool show_extension_lines_; float scale_; + ColorFormat color_format_; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_issue.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_issue.cc index 93749ebb4e0..3ae80a29047 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_issue.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_issue.cc @@ -9,20 +9,15 @@ #include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/public/platform/web_string.h" -#include "third_party/blink/public/web/web_inspector_issue.h" #include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/platform/wtf/vector.h" namespace blink { InspectorIssue::InspectorIssue(mojom::blink::InspectorIssueCode code, - mojom::blink::InspectorIssueDetailsPtr details, - mojom::blink::AffectedResourcesPtr resources) - : code_(code), - details_(std::move(details)), - resources_(std::move(resources)) { + mojom::blink::InspectorIssueDetailsPtr details) + : code_(code), details_(std::move(details)) { DCHECK(details_); - DCHECK(resources_); } InspectorIssue::~InspectorIssue() = default; @@ -30,9 +25,8 @@ InspectorIssue::~InspectorIssue() = default; InspectorIssue* InspectorIssue::Create( mojom::blink::InspectorIssueInfoPtr info) { DCHECK(info->details); - DCHECK(info->resources); - return MakeGarbageCollected<InspectorIssue>( - info->code, std::move(info->details), std::move(info->resources)); + return MakeGarbageCollected<InspectorIssue>(info->code, + std::move(info->details)); } mojom::blink::InspectorIssueCode InspectorIssue::Code() const { @@ -43,10 +37,6 @@ const mojom::blink::InspectorIssueDetailsPtr& InspectorIssue::Details() const { return details_; } -const mojom::blink::AffectedResourcesPtr& InspectorIssue::Resources() const { - return resources_; -} - void InspectorIssue::Trace(blink::Visitor* visitor) {} } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_issue.h b/chromium/third_party/blink/renderer/core/inspector/inspector_issue.h index a97cd2ba467..3dc9037fa4d 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_issue.h +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_issue.h @@ -19,22 +19,19 @@ class CORE_EXPORT InspectorIssue final InspectorIssue() = delete; InspectorIssue(mojom::blink::InspectorIssueCode code, - mojom::blink::InspectorIssueDetailsPtr details, - mojom::blink::AffectedResourcesPtr resources); + mojom::blink::InspectorIssueDetailsPtr details); ~InspectorIssue(); static InspectorIssue* Create(mojom::blink::InspectorIssueInfoPtr info); mojom::blink::InspectorIssueCode Code() const; const mojom::blink::InspectorIssueDetailsPtr& Details() const; - const mojom::blink::AffectedResourcesPtr& Resources() const; void Trace(Visitor*); private: mojom::blink::InspectorIssueCode code_; mojom::blink::InspectorIssueDetailsPtr details_; - mojom::blink::AffectedResourcesPtr resources_; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_issue_storage.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_issue_storage.cc index dd081bbbbe3..803b7775cfd 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_issue_storage.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_issue_storage.cc @@ -23,6 +23,12 @@ void InspectorIssueStorage::AddInspectorIssue(ExecutionContext* context, issues_.push_back(issue); } +void InspectorIssueStorage::AddInspectorIssue( + ExecutionContext* context, + mojom::blink::InspectorIssueInfoPtr info) { + AddInspectorIssue(context, InspectorIssue::Create(std::move(info))); +} + void InspectorIssueStorage::Clear() { issues_.clear(); } diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_issue_storage.h b/chromium/third_party/blink/renderer/core/inspector/inspector_issue_storage.h index d318c96d654..3a99f74185c 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_issue_storage.h +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_issue_storage.h @@ -6,6 +6,7 @@ #define THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECTOR_ISSUE_STORAGE_H_ #include "base/macros.h" +#include "third_party/blink/public/mojom/devtools/inspector_issue.mojom-blink-forward.h" #include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/wtf/forward.h" @@ -21,6 +22,8 @@ class CORE_EXPORT InspectorIssueStorage InspectorIssueStorage(); void AddInspectorIssue(ExecutionContext*, InspectorIssue*); + void AddInspectorIssue(ExecutionContext*, + mojom::blink::InspectorIssueInfoPtr); void Clear(); wtf_size_t size() const; InspectorIssue* at(wtf_size_t index) const; diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_media_agent.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_media_agent.cc index 16a634f9f44..40e9ae5054b 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_media_agent.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_media_agent.cc @@ -13,35 +13,67 @@ namespace blink { namespace { -std::unique_ptr<protocol::Media::PlayerEvent> ConvertInspectorPlayerEvent( - const InspectorPlayerEvent& event) { - protocol::Media::PlayerEventType event_type; - switch (event.type) { - case InspectorPlayerEvent::ERROR_EVENT: - event_type = protocol::Media::PlayerEventTypeEnum::ErrorEvent; - break; - case InspectorPlayerEvent::TRIGGERED_EVENT: - event_type = protocol::Media::PlayerEventTypeEnum::TriggeredEvent; - break; - case InspectorPlayerEvent::MESSAGE_EVENT: - event_type = protocol::Media::PlayerEventTypeEnum::MessageEvent; - break; +const char* ConvertMessageLevelEnum(InspectorPlayerMessage::Level level) { + switch (level) { + case InspectorPlayerMessage::Level::kError: + return protocol::Media::PlayerMessage::LevelEnum::Error; + case InspectorPlayerMessage::Level::kWarning: + return protocol::Media::PlayerMessage::LevelEnum::Warning; + case InspectorPlayerMessage::Level::kInfo: + return protocol::Media::PlayerMessage::LevelEnum::Info; + case InspectorPlayerMessage::Level::kDebug: + return protocol::Media::PlayerMessage::LevelEnum::Debug; + } +} + +const char* ConvertErrorTypeEnum(InspectorPlayerError::Type level) { + switch (level) { + case InspectorPlayerError::Type::kPipelineError: + return protocol::Media::PlayerError::TypeEnum::Pipeline_error; + case InspectorPlayerError::Type::kMediaStatus: + return protocol::Media::PlayerError::TypeEnum::Media_error; } +} + +std::unique_ptr<protocol::Media::PlayerEvent> ConvertToProtocolType( + const InspectorPlayerEvent& event) { return protocol::Media::PlayerEvent::create() - .setType(event_type) .setTimestamp(event.timestamp.since_origin().InSecondsF()) - .setName(event.key) .setValue(event.value) .build(); } -std::unique_ptr<protocol::Media::PlayerProperty> ConvertInspectorPlayerProperty( +std::unique_ptr<protocol::Media::PlayerProperty> ConvertToProtocolType( const InspectorPlayerProperty& property) { - auto builder = std::move( - protocol::Media::PlayerProperty::create().setName(property.name)); - if (property.value.has_value()) - builder.setValue(property.value.value()); - return builder.build(); + return protocol::Media::PlayerProperty::create() + .setName(property.name) + .setValue(property.value) + .build(); +} + +std::unique_ptr<protocol::Media::PlayerMessage> ConvertToProtocolType( + const InspectorPlayerMessage& message) { + return protocol::Media::PlayerMessage::create() + .setLevel(ConvertMessageLevelEnum(message.level)) + .setMessage(message.message) + .build(); +} + +std::unique_ptr<protocol::Media::PlayerError> ConvertToProtocolType( + const InspectorPlayerError& error) { + return protocol::Media::PlayerError::create() + .setType(ConvertErrorTypeEnum(error.type)) + .setErrorCode(error.errorCode) + .build(); +} + +template <typename To, typename From> +std::unique_ptr<protocol::Array<To>> ConvertVector(const Vector<From>& from) { + auto result = std::make_unique<protocol::Array<To>>(); + result->reserve(from.size()); + for (const From& each : from) + result->push_back(ConvertToProtocolType(each)); + return result; } } // namespace @@ -60,13 +92,19 @@ void InspectorMediaAgent::Restore() { void InspectorMediaAgent::RegisterAgent() { instrumenting_agents_->AddInspectorMediaAgent(this); - auto* cache = MediaInspectorContextImpl::FromLocalFrame(local_frame_); - Vector<WebString> players = cache->GetAllPlayerIds(); + auto* cache = MediaInspectorContextImpl::From(*local_frame_->DomWindow()); + Vector<WebString> players = cache->AllPlayerIds(); PlayersCreated(players); for (const auto& player_id : players) { - auto props_events = cache->GetPropertiesAndEvents(player_id); - PlayerPropertiesChanged(player_id, props_events.first); - PlayerEventsAdded(player_id, props_events.second); + const auto& media_player = cache->MediaPlayerFromId(player_id); + Vector<InspectorPlayerProperty> properties; + properties.AppendRange(media_player.properties.Values().begin(), + media_player.properties.Values().end()); + + PlayerPropertiesChanged(player_id, properties); + PlayerMessagesLogged(player_id, media_player.messages); + PlayerEventsAdded(player_id, media_player.events); + PlayerErrorsRaised(player_id, media_player.errors); } } @@ -89,23 +127,29 @@ protocol::Response InspectorMediaAgent::disable() { void InspectorMediaAgent::PlayerPropertiesChanged( const WebString& playerId, const Vector<InspectorPlayerProperty>& properties) { - auto protocol_props = - std::make_unique<protocol::Array<protocol::Media::PlayerProperty>>(); - protocol_props->reserve(properties.size()); - for (const auto& property : properties) - protocol_props->push_back(ConvertInspectorPlayerProperty(property)); - GetFrontend()->playerPropertiesChanged(playerId, std::move(protocol_props)); + GetFrontend()->playerPropertiesChanged( + playerId, ConvertVector<protocol::Media::PlayerProperty>(properties)); } void InspectorMediaAgent::PlayerEventsAdded( const WebString& playerId, const Vector<InspectorPlayerEvent>& events) { - auto protocol_events = - std::make_unique<protocol::Array<protocol::Media::PlayerEvent>>(); - protocol_events->reserve(events.size()); - for (const auto& event : events) - protocol_events->push_back(ConvertInspectorPlayerEvent(event)); - GetFrontend()->playerEventsAdded(playerId, std::move(protocol_events)); + GetFrontend()->playerEventsAdded( + playerId, ConvertVector<protocol::Media::PlayerEvent>(events)); +} + +void InspectorMediaAgent::PlayerErrorsRaised( + const WebString& playerId, + const Vector<InspectorPlayerError>& errors) { + GetFrontend()->playerErrorsRaised( + playerId, ConvertVector<protocol::Media::PlayerError>(errors)); +} + +void InspectorMediaAgent::PlayerMessagesLogged( + const WebString& playerId, + const Vector<InspectorPlayerMessage>& messages) { + GetFrontend()->playerMessagesLogged( + playerId, ConvertVector<protocol::Media::PlayerMessage>(messages)); } void InspectorMediaAgent::PlayersCreated(const Vector<WebString>& player_ids) { diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_media_agent.h b/chromium/third_party/blink/renderer/core/inspector/inspector_media_agent.h index e7292fa4c51..b65460cf07f 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_media_agent.h +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_media_agent.h @@ -30,9 +30,13 @@ class CORE_EXPORT InspectorMediaAgent final protocol::Response disable() override; // Protocol send messages. + void PlayerErrorsRaised(const WebString&, + const Vector<InspectorPlayerError>&); + void PlayerEventsAdded(const WebString&, const Vector<InspectorPlayerEvent>&); + void PlayerMessagesLogged(const WebString&, + const Vector<InspectorPlayerMessage>&); void PlayerPropertiesChanged(const WebString&, const Vector<InspectorPlayerProperty>&); - void PlayerEventsAdded(const WebString&, const Vector<InspectorPlayerEvent>&); void PlayersCreated(const Vector<WebString>&); // blink-gc methods. diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_media_context_impl.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_media_context_impl.cc index 445786bfedb..a172dc6d697 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_media_context_impl.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_media_context_impl.cc @@ -8,9 +8,7 @@ #include <utility> #include "base/unguessable_token.h" -#include "third_party/blink/renderer/core/dom/document.h" -#include "third_party/blink/renderer/core/html/media/html_media_element.h" -#include "third_party/blink/renderer/core/inspector/inspected_frames.h" +#include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/probe/core_probes.h" namespace blink { @@ -18,40 +16,37 @@ namespace blink { const char MediaInspectorContextImpl::kSupplementName[] = "MediaInspectorContextImpl"; -// static -void MediaInspectorContextImpl::ProvideToLocalFrame(LocalFrame& frame) { - frame.ProvideSupplement( - MakeGarbageCollected<MediaInspectorContextImpl>(frame)); -} // static -MediaInspectorContextImpl* MediaInspectorContextImpl::FromLocalFrame( - LocalFrame* frame) { - return Supplement<LocalFrame>::From<MediaInspectorContextImpl>(frame); +MediaInspectorContextImpl* MediaInspectorContextImpl::From( + LocalDOMWindow& window) { + auto* context = + Supplement<LocalDOMWindow>::From<MediaInspectorContextImpl>(window); + if (!context) { + context = MakeGarbageCollected<MediaInspectorContextImpl>(window); + Supplement<LocalDOMWindow>::ProvideTo(window, context); + } + return context; } -// static -MediaInspectorContextImpl* MediaInspectorContextImpl::FromDocument( - const Document& document) { - return MediaInspectorContextImpl::FromLocalFrame(document.GetFrame()); -} +MediaInspectorContextImpl::MediaInspectorContextImpl(LocalDOMWindow& frame) + : Supplement<LocalDOMWindow>(frame) {} -// static -MediaInspectorContextImpl* MediaInspectorContextImpl::FromHtmlMediaElement( - const HTMLMediaElement& element) { - return MediaInspectorContextImpl::FromDocument(element.GetDocument()); +// Local to cc file for converting +template <typename T, typename Iterable> +static Vector<T> Iter2Vector(const Iterable& iterable) { + Vector<T> result; + result.AppendRange(iterable.begin(), iterable.end()); + return result; } -MediaInspectorContextImpl::MediaInspectorContextImpl(LocalFrame& frame) - : Supplement<LocalFrame>(frame) {} - // Garbage collection method. void MediaInspectorContextImpl::Trace(Visitor* visitor) { - Supplement<LocalFrame>::Trace(visitor); + Supplement<LocalDOMWindow>::Trace(visitor); visitor->Trace(players_); } -Vector<WebString> MediaInspectorContextImpl::GetAllPlayerIds() { +Vector<WebString> MediaInspectorContextImpl::AllPlayerIds() { Vector<WebString> existing_players; existing_players.ReserveCapacity(players_.size()); for (const auto& player_id : players_.Keys()) @@ -59,22 +54,11 @@ Vector<WebString> MediaInspectorContextImpl::GetAllPlayerIds() { return existing_players; } -std::pair<Vector<InspectorPlayerProperty>, Vector<InspectorPlayerEvent>> -MediaInspectorContextImpl::GetPropertiesAndEvents(const WebString& player_id) { - Vector<InspectorPlayerProperty> to_send_properties; - Vector<InspectorPlayerEvent> to_send_events; - - const auto& player_search = players_.find(player_id); - if (player_search != players_.end()) { - to_send_properties.ReserveCapacity(player_search->value->properties.size()); - for (const auto& prop : player_search->value->properties.Values()) - to_send_properties.push_back(prop); - to_send_events.ReserveCapacity(player_search->value->events.size()); - for (const auto& event : player_search->value->events) - to_send_events.insert(to_send_events.size(), event); - } - - return {std::move(to_send_properties), std::move(to_send_events)}; +const MediaPlayer& MediaInspectorContextImpl::MediaPlayerFromId( + const WebString& player_id) { + const auto& player = players_.find(player_id); + DCHECK_NE(player, players_.end()); + return *player->value; } WebString MediaInspectorContextImpl::CreatePlayer() { @@ -86,34 +70,53 @@ WebString MediaInspectorContextImpl::CreatePlayer() { } // Convert public version of event to protocol version, and send it. +void MediaInspectorContextImpl::NotifyPlayerErrors( + WebString playerId, + const InspectorPlayerErrors& errors) { + const auto& player = players_.find(playerId); + DCHECK_NE(player, players_.end()); + player->value->errors.AppendRange(errors.begin(), errors.end()); + + Vector<InspectorPlayerError> vector = + Iter2Vector<InspectorPlayerError>(errors); + probe::PlayerErrorsRaised(GetSupplementable(), playerId, vector); +} + void MediaInspectorContextImpl::NotifyPlayerEvents( WebString playerId, - InspectorPlayerEvents events) { - const auto& player_search = players_.find(playerId); - if (player_search == players_.end()) - DCHECK(false); - Vector<InspectorPlayerEvent> to_send; - to_send.ReserveCapacity(events.size()); - for (const auto& event : events) { - player_search->value->events.emplace_back(event); - to_send.push_back(event); - } - probe::PlayerEventsAdded(GetSupplementable(), playerId, to_send); + const InspectorPlayerEvents& events) { + const auto& player = players_.find(playerId); + DCHECK_NE(player, players_.end()); + player->value->events.AppendRange(events.begin(), events.end()); + + Vector<InspectorPlayerEvent> vector = + Iter2Vector<InspectorPlayerEvent>(events); + probe::PlayerEventsAdded(GetSupplementable(), playerId, vector); } void MediaInspectorContextImpl::SetPlayerProperties( WebString playerId, - InspectorPlayerProperties props) { - const auto& player_search = players_.find(playerId); - if (player_search == players_.end()) - DCHECK(false); - Vector<InspectorPlayerProperty> to_send; - to_send.ReserveCapacity(props.size()); - for (const auto& property : props) { - to_send.push_back(property); - player_search->value->properties.insert(property.name, property); - } - probe::PlayerPropertiesChanged(GetSupplementable(), playerId, to_send); + const InspectorPlayerProperties& props) { + const auto& player = players_.find(playerId); + DCHECK_NE(player, players_.end()); + for (const auto& property : props) + player->value->properties.insert(property.name, property); + + Vector<InspectorPlayerProperty> vector = + Iter2Vector<InspectorPlayerProperty>(props); + probe::PlayerPropertiesChanged(GetSupplementable(), playerId, vector); +} + +void MediaInspectorContextImpl::NotifyPlayerMessages( + WebString playerId, + const InspectorPlayerMessages& messages) { + const auto& player = players_.find(playerId); + DCHECK_NE(player, players_.end()); + player->value->messages.AppendRange(messages.begin(), messages.end()); + + Vector<InspectorPlayerMessage> vector = + Iter2Vector<InspectorPlayerMessage>(messages); + probe::PlayerMessagesLogged(GetSupplementable(), playerId, vector); } } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_media_context_impl.h b/chromium/third_party/blink/renderer/core/inspector/inspector_media_context_impl.h index 4b6c3eee2ac..04cb0d2c7cc 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_media_context_impl.h +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_media_context_impl.h @@ -5,61 +5,55 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECTOR_MEDIA_CONTEXT_IMPL_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECTOR_MEDIA_CONTEXT_IMPL_H_ -#include <map> -#include <memory> -#include <string> -#include <utility> -#include <vector> - #include "third_party/blink/public/web/web_media_inspector.h" #include "third_party/blink/renderer/core/core_export.h" -#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/platform/supplementable.h" +#include "third_party/blink/renderer/platform/wtf/hash_map.h" +#include "third_party/blink/renderer/platform/wtf/text/string_hash.h" namespace blink { -class Document; -class HTMLMediaElement; +class LocalDOMWindow; struct MediaPlayer final : public GarbageCollected<MediaPlayer> { void Trace(Visitor*) {} WebString player_id; - InspectorPlayerEvents events; + Vector<InspectorPlayerError> errors; + Vector<InspectorPlayerEvent> events; + Vector<InspectorPlayerMessage> messages; HashMap<String, InspectorPlayerProperty> properties; }; class CORE_EXPORT MediaInspectorContextImpl final : public GarbageCollected<MediaInspectorContextImpl>, - public Supplement<LocalFrame>, + public Supplement<LocalDOMWindow>, public MediaInspectorContext { USING_GARBAGE_COLLECTED_MIXIN(MediaInspectorContextImpl); public: static const char kSupplementName[]; - static void ProvideToLocalFrame(LocalFrame&); - // Different ways of getting the singleton instance of - // MediaInspectorContextImpl depending on what things are easily in scope - // caller side. - static MediaInspectorContextImpl* FromLocalFrame(LocalFrame*); - static MediaInspectorContextImpl* FromDocument(const Document&); - static MediaInspectorContextImpl* FromHtmlMediaElement( - const HTMLMediaElement&); + static MediaInspectorContextImpl* From(LocalDOMWindow&); - explicit MediaInspectorContextImpl(LocalFrame&); + explicit MediaInspectorContextImpl(LocalDOMWindow&); // MediaInspectorContext methods. WebString CreatePlayer() override; - void NotifyPlayerEvents(WebString, InspectorPlayerEvents) override; - void SetPlayerProperties(WebString, InspectorPlayerProperties) override; + void NotifyPlayerErrors(WebString playerId, + const InspectorPlayerErrors&) override; + void NotifyPlayerEvents(WebString playerId, + const InspectorPlayerEvents&) override; + void NotifyPlayerMessages(WebString playerId, + const InspectorPlayerMessages&) override; + void SetPlayerProperties(WebString playerId, + const InspectorPlayerProperties&) override; // GarbageCollected methods. void Trace(Visitor*) override; - Vector<WebString> GetAllPlayerIds(); - std::pair<Vector<InspectorPlayerProperty>, Vector<InspectorPlayerEvent>> - GetPropertiesAndEvents(const WebString&); + Vector<WebString> AllPlayerIds(); + const MediaPlayer& MediaPlayerFromId(const WebString&); private: HeapHashMap<String, Member<MediaPlayer>> players_; diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_network_agent.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_network_agent.cc index 79887e2fc68..fd21ad09a6e 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_network_agent.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_network_agent.cc @@ -749,7 +749,12 @@ void InspectorNetworkAgent::DidBlockRequest( const FetchInitiatorInfo& initiator_info, ResourceRequestBlockedReason reason, ResourceType resource_type) { - uint64_t identifier = CreateUniqueIdentifier(); + uint64_t identifier = request.InspectorId(); + if (identifier == 0UL) { + NOTREACHED(); + // Defensively create a valid identifier. + identifier = CreateUniqueIdentifier(); + } InspectorPageAgent::ResourceType type = InspectorPageAgent::ToResourceType(resource_type); @@ -783,6 +788,7 @@ void InspectorNetworkAgent::WillSendRequestInternal( const ResourceResponse& redirect_response, const FetchInitiatorInfo& initiator_info, InspectorPageAgent::ResourceType type) { + CHECK_EQ(identifier, request.InspectorId()); String loader_id = IdentifiersFactory::LoaderId(loader); String request_id = IdentifiersFactory::RequestId(loader, identifier); NetworkResourcesData::ResourceData const* data = @@ -880,6 +886,19 @@ void InspectorNetworkAgent::WillSendNavigationRequest( InspectorPageAgent::kDocumentResource); } +// This method was pulled out of PrepareRequest(), because we want to be able +// to create DevTools issues before the PrepareRequest() call. We need these +// IDs to be set, to properly create a DevTools issue. +void InspectorNetworkAgent::SetDevToolsIds(ResourceRequest& request) { + request.SetDevToolsToken(devtools_token_); + + // The loader parameter is for generating a browser generated ID for a browser + // initiated request. We pass it null here because we are reporting a renderer + // generated ID for a renderer initiated request. + request.SetDevToolsId(IdentifiersFactory::RequestId(/* loader */ nullptr, + request.InspectorId())); +} + void InspectorNetworkAgent::PrepareRequest( DocumentLoader* loader, ResourceRequest& request, @@ -893,7 +912,7 @@ void InspectorNetworkAgent::PrepareRequest( for (const WTF::String& key : extra_request_headers_.Keys()) { const WTF::String& value = extra_request_headers_.Get(key); AtomicString header_name = AtomicString(key); - // When overriding referer, also override referrer policy + // When overriding referrer, also override referrer policy // for this request to assure the request will be allowed. // TODO: Should we store the referrer header somewhere other than // |extra_request_headers_|? @@ -908,8 +927,6 @@ void InspectorNetworkAgent::PrepareRequest( request.SetReportRawHeaders(true); - request.SetDevToolsToken(devtools_token_); - if (cache_disabled_.Get()) { if (LoadsFromCacheOnly(request) && request.GetRequestContext() != mojom::RequestContextType::INTERNAL) { @@ -921,12 +938,6 @@ void InspectorNetworkAgent::PrepareRequest( } if (bypass_service_worker_.Get()) request.SetSkipServiceWorker(true); - - // The loader parameter is for generating a browser generated ID for a browser - // initiated request. We pass it null here because we are reporting a renderer - // generated ID for a renderer initiated request. - request.SetDevToolsId(IdentifiersFactory::RequestId(/* loader */ nullptr, - request.InspectorId())); } void InspectorNetworkAgent::WillSendRequest( @@ -1195,31 +1206,48 @@ InspectorNetworkAgent::BuildInitiatorObject( Document* document, const FetchInitiatorInfo& initiator_info, int max_async_depth) { - if (!initiator_info.imported_module_referrer.IsEmpty()) { + if (initiator_info.is_imported_module && !initiator_info.referrer.IsEmpty()) { std::unique_ptr<protocol::Network::Initiator> initiator_object = protocol::Network::Initiator::create() .setType(protocol::Network::Initiator::TypeEnum::Script) .build(); - initiator_object->setUrl(initiator_info.imported_module_referrer); + initiator_object->setUrl(initiator_info.referrer); initiator_object->setLineNumber( initiator_info.position.line_.ZeroBasedInt()); return initiator_object; } - std::unique_ptr<v8_inspector::protocol::Runtime::API::StackTrace> - current_stack_trace = - SourceLocation::Capture(document ? document->GetExecutionContext() - : nullptr) - ->BuildInspectorObject(max_async_depth); - if (current_stack_trace) { + bool was_requested_by_stylesheet = + initiator_info.name == fetch_initiator_type_names::kCSS || + initiator_info.name == fetch_initiator_type_names::kUacss; + if (was_requested_by_stylesheet && !initiator_info.referrer.IsEmpty()) { std::unique_ptr<protocol::Network::Initiator> initiator_object = protocol::Network::Initiator::create() - .setType(protocol::Network::Initiator::TypeEnum::Script) + .setType(protocol::Network::Initiator::TypeEnum::Parser) .build(); - initiator_object->setStack(std::move(current_stack_trace)); + initiator_object->setUrl(initiator_info.referrer); return initiator_object; } + // We skip stack checking for stylesheet-initiated requests as it may + // represent the cause of a style recalculation rather than the actual + // resources themselves. See crbug.com/918196. + if (!was_requested_by_stylesheet) { + std::unique_ptr<v8_inspector::protocol::Runtime::API::StackTrace> + current_stack_trace = + SourceLocation::Capture(document ? document->GetExecutionContext() + : nullptr) + ->BuildInspectorObject(max_async_depth); + if (current_stack_trace) { + std::unique_ptr<protocol::Network::Initiator> initiator_object = + protocol::Network::Initiator::create() + .setType(protocol::Network::Initiator::TypeEnum::Script) + .build(); + initiator_object->setStack(std::move(current_stack_trace)); + return initiator_object; + } + } + while (document && !document->GetScriptableDocumentParser()) document = document->LocalOwner() ? document->LocalOwner()->ownerDocument() : nullptr; diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_network_agent.h b/chromium/third_party/blink/renderer/core/inspector/inspector_network_agent.h index 9217ce02aae..e6c46fe40a8 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_network_agent.h +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_network_agent.h @@ -192,6 +192,7 @@ class CORE_EXPORT InspectorNetworkAgent final const char* payload, size_t payload_length); void DidReceiveWebSocketMessageError(uint64_t identifier, const String&); + void SetDevToolsIds(ResourceRequest& request); // Called from frontend protocol::Response enable(Maybe<int> total_buffer_size, diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.cc index ab44f6ddbd3..ffe39fd95a3 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.cc @@ -126,7 +126,7 @@ int InspectTool::GetDataResourceId() { bool InspectTool::HandleInputEvent(LocalFrameView* frame_view, const WebInputEvent& input_event, bool* swallow_next_mouse_up) { - if (input_event.GetType() == WebInputEvent::kGestureTap) { + if (input_event.GetType() == WebInputEvent::Type::kGestureTap) { // We only have a use for gesture tap. WebGestureEvent transformed_event = TransformWebGestureEvent( frame_view, static_cast<const WebGestureEvent&>(input_event)); @@ -155,13 +155,13 @@ bool InspectTool::HandleInputEvent(LocalFrameView* frame_view, bool InspectTool::HandleMouseEvent(const WebMouseEvent& mouse_event, bool* swallow_next_mouse_up) { - if (mouse_event.GetType() == WebInputEvent::kMouseMove) + if (mouse_event.GetType() == WebInputEvent::Type::kMouseMove) return HandleMouseMove(mouse_event); - if (mouse_event.GetType() == WebInputEvent::kMouseDown) + if (mouse_event.GetType() == WebInputEvent::Type::kMouseDown) return HandleMouseDown(mouse_event, swallow_next_mouse_up); - if (mouse_event.GetType() == WebInputEvent::kMouseUp) + if (mouse_event.GetType() == WebInputEvent::Type::kMouseUp) return HandleMouseUp(mouse_event); return false; @@ -196,6 +196,10 @@ bool InspectTool::ForwardEventsToOverlay() { return true; } +bool InspectTool::HideOnMouseMove() { + return false; +} + bool InspectTool::HideOnHideHighlight() { return false; } @@ -204,6 +208,34 @@ void InspectTool::Trace(Visitor* visitor) { visitor->Trace(overlay_); } +// Hinge ----------------------------------------------------------------------- + +Hinge::Hinge(FloatQuad quad, + Color content_color, + Color outline_color, + InspectorOverlayAgent* overlay) + : quad_(quad), + content_color_(content_color), + outline_color_(outline_color), + overlay_(overlay) {} + +// static +int Hinge::GetDataResourceId() { + // TODO (soxia): In the future, we should make the hinge working properly + // with tools using different resources. + return IDR_INSPECT_TOOL_HIGHLIGHT_HTML; +} + +void Hinge::Trace(Visitor* visitor) { + visitor->Trace(overlay_); +} + +void Hinge::Draw(float scale) { + InspectorHighlight highlight(scale); + highlight.AppendQuad(quad_, content_color_, outline_color_); + overlay_->EvaluateInOverlay("drawHighlight", highlight.AsProtocolValue()); +} + // InspectorOverlayAgent ------------------------------------------------------- class InspectorOverlayAgent::InspectorPageOverlayDelegate final @@ -226,7 +258,7 @@ class InspectorOverlayAgent::InspectorPageOverlayDelegate final void PaintFrameOverlay(const FrameOverlay& frame_overlay, GraphicsContext& graphics_context, const IntSize&) const override { - if (!overlay_->inspect_tool_) + if (!overlay_->IsVisible()) return; overlay_->PaintOverlayPage(); @@ -329,7 +361,6 @@ InspectorOverlayAgent::InspectorOverlayAgent( v8_session_(v8_session), dom_agent_(dom_agent), swallow_next_mouse_up_(false), - swallow_next_escape_up_(false), backend_node_id_to_inspect_(0), enabled_(&agent_state_, false), show_ad_highlights_(&agent_state_, false), @@ -356,6 +387,7 @@ void InspectorOverlayAgent::Trace(Visitor* visitor) { visitor->Trace(overlay_host_); visitor->Trace(dom_agent_); visitor->Trace(inspect_tool_); + visitor->Trace(hinge_); InspectorBaseAgent::Trace(visitor); } @@ -592,6 +624,48 @@ Response InspectorOverlayAgent::highlightQuad( return Response::Success(); } +Response InspectorOverlayAgent::setShowHinge( + protocol::Maybe<protocol::Overlay::HingeConfig> tool_config) { + // Hide the hinge when called without a configuration. + if (!tool_config.isJust()) { + hinge_ = nullptr; + if (!inspect_tool_) + DisableFrameOverlay(); + ScheduleUpdate(); + return Response::Success(); + } + + // Create a hinge + protocol::Overlay::HingeConfig* config = tool_config.fromJust(); + protocol::DOM::Rect* rect = config->getRect(); + int x = rect->getX(); + int y = rect->getY(); + int width = rect->getWidth(); + int height = rect->getHeight(); + if (x < 0 || y < 0 || width < 0 || height < 0) + return Response::InvalidParams("Invalid hinge rectangle."); + + // Use default color if a content color is not provided. + Color content_color = + config->hasContentColor() + ? InspectorDOMAgent::ParseColor(config->getContentColor(nullptr)) + : Color(38, 38, 38); + // outlineColor uses a kTransparent default from ParseColor if not provided. + Color outline_color = + InspectorDOMAgent::ParseColor(config->getOutlineColor(nullptr)); + + DCHECK(frame_impl_->GetFrameView() && GetFrame()); + + LoadFrameForTool(Hinge::GetDataResourceId()); + EnsureEnableFrameOverlay(); + FloatQuad quad(FloatRect(x, y, width, height)); + hinge_ = + MakeGarbageCollected<Hinge>(quad, content_color, outline_color, this); + ScheduleUpdate(); + + return Response::Success(); +} + Response InspectorOverlayAgent::highlightNode( std::unique_ptr<protocol::Overlay::HighlightConfig> highlight_inspector_object, @@ -645,6 +719,7 @@ Response InspectorOverlayAgent::highlightFrame( Response InspectorOverlayAgent::hideHighlight() { if (inspect_tool_ && inspect_tool_->HideOnHideHighlight()) PickTheRightTool(); + return Response::Success(); } @@ -652,6 +727,7 @@ Response InspectorOverlayAgent::getHighlightObjectForTest( int node_id, Maybe<bool> include_distance, Maybe<bool> include_style, + Maybe<String> colorFormat, std::unique_ptr<protocol::DictionaryValue>* result) { Node* node = nullptr; Response response = dom_agent_->AssertNode(node_id, node); @@ -669,6 +745,18 @@ Response InspectorOverlayAgent::getHighlightObjectForTest( InspectorHighlightConfig config = InspectorHighlight::DefaultConfig(); config.show_styles = include_style.fromMaybe(false); + + String format = colorFormat.fromMaybe("hex"); + + namespace ColorFormatEnum = protocol::Overlay::ColorFormatEnum; + if (format == ColorFormatEnum::Hsl) { + config.color_format = ColorFormat::HSL; + } else if (format == ColorFormatEnum::Rgb) { + config.color_format = ColorFormat::RGB; + } else { + config.color_format = ColorFormat::HEX; + } + InspectorHighlight highlight(node, config, InspectorHighlightContrastInfo(), true /* append_element_info */, include_distance.fromMaybe(false), @@ -711,22 +799,12 @@ void InspectorOverlayAgent::DispatchBufferedTouchEvents() { WebInputEventResult InspectorOverlayAgent::HandleInputEvent( const WebInputEvent& input_event) { - if (input_event.GetType() == WebInputEvent::kMouseUp && + if (input_event.GetType() == WebInputEvent::Type::kMouseUp && swallow_next_mouse_up_) { swallow_next_mouse_up_ = false; return WebInputEventResult::kHandledSuppressed; } - if (input_event.GetType() == WebInputEvent::kKeyUp && - swallow_next_escape_up_) { - const auto& keyboard_event = - static_cast<const WebKeyboardEvent&>(input_event); - if (keyboard_event.windows_key_code == VKEY_ESCAPE) { - swallow_next_escape_up_ = false; - return WebInputEventResult::kHandledSuppressed; - } - } - LocalFrame* frame = GetFrame(); if (!frame || !frame->View() || !frame->ContentLayoutObject() || !inspect_tool_) @@ -749,41 +827,41 @@ WebInputEventResult InspectorOverlayAgent::HandleInputEvent( } // Exit tool upon unhandled Esc. - if (input_event.GetType() == WebInputEvent::kRawKeyDown) { + if (input_event.GetType() == WebInputEvent::Type::kRawKeyDown) { const WebKeyboardEvent& keyboard_event = static_cast<const WebKeyboardEvent&>(input_event); if (keyboard_event.windows_key_code == VKEY_ESCAPE) { GetFrontend()->inspectModeCanceled(); - swallow_next_escape_up_ = true; - return WebInputEventResult::kHandledSuppressed; + return WebInputEventResult::kNotHandled; } } + if (input_event.GetType() == WebInputEvent::Type::kMouseMove && + inspect_tool_->HideOnMouseMove()) { + PickTheRightTool(); + } + return WebInputEventResult::kNotHandled; } WebInputEventResult InspectorOverlayAgent::HandleInputEventInOverlay( const WebInputEvent& input_event) { - if (input_event.GetType() == WebInputEvent::kGestureTap) { + if (input_event.GetType() == WebInputEvent::Type::kGestureTap) { return OverlayMainFrame()->GetEventHandler().HandleGestureEvent( static_cast<const WebGestureEvent&>(input_event)); } if (WebInputEvent::IsMouseEventType(input_event.GetType())) { WebMouseEvent mouse_event = static_cast<const WebMouseEvent&>(input_event); - if (mouse_event.GetType() == WebInputEvent::kMouseMove) { + if (mouse_event.GetType() == WebInputEvent::Type::kMouseMove) { return OverlayMainFrame()->GetEventHandler().HandleMouseMoveEvent( - mouse_event, - TransformWebMouseEventVector(frame_impl_->GetFrameView(), - WebVector<const WebInputEvent*>()), - TransformWebMouseEventVector(frame_impl_->GetFrameView(), - WebVector<const WebInputEvent*>())); + mouse_event, {}, {}); } - if (mouse_event.GetType() == WebInputEvent::kMouseDown) { + if (mouse_event.GetType() == WebInputEvent::Type::kMouseDown) { return OverlayMainFrame()->GetEventHandler().HandleMousePressEvent( mouse_event); } - if (mouse_event.GetType() == WebInputEvent::kMouseUp) { + if (mouse_event.GetType() == WebInputEvent::Type::kMouseUp) { return OverlayMainFrame()->GetEventHandler().HandleMouseReleaseEvent( mouse_event); } @@ -801,7 +879,7 @@ WebInputEventResult InspectorOverlayAgent::HandleInputEventInOverlay( static_cast<const WebKeyboardEvent&>(input_event)); } - if (input_event.GetType() == WebInputEvent::kMouseWheel) { + if (input_event.GetType() == WebInputEvent::Type::kMouseWheel) { return OverlayMainFrame()->GetEventHandler().HandleWheelEvent( static_cast<const WebMouseWheelEvent&>(input_event)); } @@ -810,7 +888,7 @@ WebInputEventResult InspectorOverlayAgent::HandleInputEventInOverlay( } void InspectorOverlayAgent::ScheduleUpdate() { - if (inspect_tool_) { + if (IsVisible()) { GetFrame()->GetPage()->GetChromeClient().ScheduleAnimation( GetFrame()->View()); } @@ -841,8 +919,10 @@ void InspectorOverlayAgent::PaintOverlayPage() { Reset(viewport_size); - DCHECK(inspect_tool_); - inspect_tool_->Draw(WindowToViewportScale()); + if (inspect_tool_) + inspect_tool_->Draw(WindowToViewportScale()); + if (hinge_) + hinge_->Draw(WindowToViewportScale()); OverlayMainFrame()->View()->UpdateAllLifecyclePhases( DocumentUpdateReason::kInspector); @@ -865,10 +945,20 @@ float InspectorOverlayAgent::WindowToViewportScale() const { 1.0f); } -void InspectorOverlayAgent::EnsureOverlayPageCreated() { - if (overlay_page_) +void InspectorOverlayAgent::LoadFrameForTool(int data_resource_id) { + if (frame_resource_name_ == data_resource_id) return; + frame_resource_name_ = data_resource_id; + + if (overlay_page_) { + overlay_page_->WillBeDestroyed(); + overlay_page_.Clear(); + overlay_chrome_client_.Clear(); + overlay_host_->ClearDelegate(); + overlay_host_.Clear(); + } + ScriptForbiddenScope::AllowUserAgentScript allow_script; Page::PageClients page_clients; @@ -905,23 +995,8 @@ void InspectorOverlayAgent::EnsureOverlayPageCreated() { DEFINE_STATIC_LOCAL(Persistent<LocalFrameClient>, dummy_local_frame_client, (MakeGarbageCollected<EmptyLocalFrameClient>())); auto* frame = MakeGarbageCollected<LocalFrame>( - dummy_local_frame_client, *overlay_page_, nullptr, nullptr, nullptr); - frame->SetView(MakeGarbageCollected<LocalFrameView>(*frame)); - frame->Init(); - frame->View()->SetCanHaveScrollbars(false); - frame->View()->SetBaseBackgroundColor(Color::kTransparent); -} - -void InspectorOverlayAgent::LoadFrameForTool() { - if (frame_resource_name_ == inspect_tool_->GetDataResourceId()) - return; - - frame_resource_name_ = inspect_tool_->GetDataResourceId(); - - DEFINE_STATIC_LOCAL(Persistent<LocalFrameClient>, dummy_local_frame_client, - (MakeGarbageCollected<EmptyLocalFrameClient>())); - auto* frame = MakeGarbageCollected<LocalFrame>( - dummy_local_frame_client, *overlay_page_, nullptr, nullptr, nullptr); + dummy_local_frame_client, *overlay_page_, nullptr, + base::UnguessableToken::Create(), nullptr, nullptr); frame->SetView(MakeGarbageCollected<LocalFrameView>(*frame)); frame->Init(); frame->View()->SetCanHaveScrollbars(false); @@ -1161,9 +1236,31 @@ void InspectorOverlayAgent::PickTheRightTool() { inspect_tool = MakeGarbageCollected<PausedInDebuggerTool>( v8_session_, paused_in_debugger_message_.Get()); } + SetInspectTool(inspect_tool); } +void InspectorOverlayAgent::DisableFrameOverlay() { + if (IsVisible() || !frame_overlay_) + return; + + frame_overlay_.reset(); + auto& client = GetFrame()->GetPage()->GetChromeClient(); + client.SetCursorOverridden(false); + client.SetCursor(PointerCursor(), GetFrame()); + + if (auto* frame_view = frame_impl_->GetFrameView()) + frame_view->SetPaintArtifactCompositorNeedsUpdate(); +} + +void InspectorOverlayAgent::EnsureEnableFrameOverlay() { + if (frame_overlay_) + return; + + frame_overlay_ = std::make_unique<FrameOverlay>( + GetFrame(), std::make_unique<InspectorPageOverlayDelegate>(*this)); +} + void InspectorOverlayAgent::SetInspectTool(InspectTool* inspect_tool) { LocalFrameView* view = frame_impl_->GetFrameView(); LocalFrame* frame = GetFrame(); @@ -1172,22 +1269,16 @@ void InspectorOverlayAgent::SetInspectTool(InspectTool* inspect_tool) { if (inspect_tool_) inspect_tool_->Dispose(); - inspect_tool_ = inspect_tool; - if (inspect_tool_) { - EnsureOverlayPageCreated(); - LoadFrameForTool(); - if (!frame_overlay_) { - frame_overlay_ = std::make_unique<FrameOverlay>( - GetFrame(), std::make_unique<InspectorPageOverlayDelegate>(*this)); - } - inspect_tool_->Init(this, GetFrontend()); - } else if (frame_overlay_) { - frame_overlay_.reset(); - auto& client = GetFrame()->GetPage()->GetChromeClient(); - client.SetCursorOverridden(false); - client.SetCursor(PointerCursor(), GetFrame()); - if (auto* frame_view = frame_impl_->GetFrameView()) - frame_view->SetPaintArtifactCompositorNeedsUpdate(); + + if (inspect_tool) { + inspect_tool_ = inspect_tool; + LoadFrameForTool(inspect_tool->GetDataResourceId()); + EnsureEnableFrameOverlay(); + inspect_tool->Init(this, GetFrontend()); + } else { + inspect_tool_ = nullptr; + if (!hinge_) + DisableFrameOverlay(); } ScheduleUpdate(); } @@ -1201,11 +1292,49 @@ Response InspectorOverlayAgent::HighlightConfigFromInspectorObject( } protocol::Overlay::HighlightConfig* config = highlight_inspector_object.fromJust(); + + namespace ColorFormatEnum = protocol::Overlay::ColorFormatEnum; + + String format = config->getColorFormat("hex"); + + if (format != ColorFormatEnum::Rgb && format != ColorFormatEnum::Hex && + format != ColorFormatEnum::Hsl) { + return Response::InvalidParams("Unknown color format"); + } + *out_config = InspectorOverlayAgent::ToHighlightConfig(config); return Response::Success(); } // static +std::unique_ptr<InspectorGridHighlightConfig> +InspectorOverlayAgent::ToGridHighlightConfig( + protocol::Overlay::GridHighlightConfig* config) { + if (!config) { + return nullptr; + } + std::unique_ptr<InspectorGridHighlightConfig> highlight_config = + std::make_unique<InspectorGridHighlightConfig>(); + highlight_config->show_grid_extension_lines = + config->getShowGridExtensionLines(false); + highlight_config->grid_border_dash = config->getGridBorderDash(false); + highlight_config->cell_border_dash = config->getCellBorderDash(false); + highlight_config->grid_color = + InspectorDOMAgent::ParseColor(config->getGridBorderColor(nullptr)); + highlight_config->cell_color = + InspectorDOMAgent::ParseColor(config->getCellBorderColor(nullptr)); + highlight_config->row_gap_color = + InspectorDOMAgent::ParseColor(config->getRowGapColor(nullptr)); + highlight_config->column_gap_color = + InspectorDOMAgent::ParseColor(config->getColumnGapColor(nullptr)); + highlight_config->row_hatch_color = + InspectorDOMAgent::ParseColor(config->getRowHatchColor(nullptr)); + highlight_config->column_hatch_color = + InspectorDOMAgent::ParseColor(config->getColumnHatchColor(nullptr)); + return highlight_config; +} + +// static std::unique_ptr<InspectorHighlightConfig> InspectorOverlayAgent::ToHighlightConfig( protocol::Overlay::HighlightConfig* config) { @@ -1231,6 +1360,22 @@ InspectorOverlayAgent::ToHighlightConfig( InspectorDOMAgent::ParseColor(config->getShapeMarginColor(nullptr)); highlight_config->css_grid = InspectorDOMAgent::ParseColor(config->getCssGridColor(nullptr)); + + namespace ColorFormatEnum = protocol::Overlay::ColorFormatEnum; + + String format = config->getColorFormat("hex"); + + if (format == ColorFormatEnum::Hsl) { + highlight_config->color_format = ColorFormat::HSL; + } else if (format == ColorFormatEnum::Rgb) { + highlight_config->color_format = ColorFormat::RGB; + } else { + highlight_config->color_format = ColorFormat::HEX; + } + + highlight_config->grid_highlight_config = + InspectorOverlayAgent::ToGridHighlightConfig( + config->getGridHighlightConfig(nullptr)); return highlight_config; } diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.h b/chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.h index a81f6463f17..4a2b9d455c9 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.h +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.h @@ -75,6 +75,7 @@ using OverlayFrontend = protocol::Overlay::Metainfo::FrontendClass; class CORE_EXPORT InspectTool : public GarbageCollected<InspectTool> { public: virtual ~InspectTool() = default; + void Init(InspectorOverlayAgent* overlay, OverlayFrontend* frontend); virtual int GetDataResourceId(); virtual bool HandleInputEvent(LocalFrameView* frame_view, @@ -95,19 +96,42 @@ class CORE_EXPORT InspectTool : public GarbageCollected<InspectTool> { virtual void Trace(Visitor* visitor); virtual void Dispose() {} virtual bool HideOnHideHighlight(); + virtual bool HideOnMouseMove(); protected: + InspectTool() = default; virtual void DoInit() {} Member<InspectorOverlayAgent> overlay_; OverlayFrontend* frontend_ = nullptr; }; +class CORE_EXPORT Hinge final : public GarbageCollected<Hinge> { + public: + Hinge(FloatQuad quad, + Color color, + Color outline_color, + InspectorOverlayAgent* overlay); + ~Hinge() = default; + static int GetDataResourceId(); + void Draw(float scale); + void Trace(Visitor* visitor); + + private: + FloatQuad quad_; + Color content_color_; + Color outline_color_; + Member<InspectorOverlayAgent> overlay_; + DISALLOW_COPY_AND_ASSIGN(Hinge); +}; + class CORE_EXPORT InspectorOverlayAgent final : public InspectorBaseAgent<protocol::Overlay::Metainfo>, public InspectorOverlayHost::Delegate { USING_GARBAGE_COLLECTED_MIXIN(InspectorOverlayAgent); public: + static std::unique_ptr<InspectorGridHighlightConfig> ToGridHighlightConfig( + protocol::Overlay::GridHighlightConfig*); static std::unique_ptr<InspectorHighlightConfig> ToHighlightConfig( protocol::Overlay::HighlightConfig*); InspectorOverlayAgent(WebLocalFrameImpl*, @@ -159,7 +183,10 @@ class CORE_EXPORT InspectorOverlayAgent final int node_id, protocol::Maybe<bool> include_distance, protocol::Maybe<bool> include_style, + protocol::Maybe<String> color_format, std::unique_ptr<protocol::DictionaryValue>* highlight) override; + protocol::Response setShowHinge( + protocol::Maybe<protocol::Overlay::HingeConfig> hinge_config) override; // InspectorBaseAgent overrides. void Restore() override; @@ -194,7 +221,6 @@ class CORE_EXPORT InspectorOverlayAgent final bool IsEmpty(); - void EnsureOverlayPageCreated(); LocalFrame* OverlayMainFrame(); void Reset(const IntSize& viewport_size); void OnResizeTimer(TimerBase*); @@ -202,17 +228,19 @@ class CORE_EXPORT InspectorOverlayAgent final protocol::Response CompositingEnabled(); + bool IsVisible() const { return inspect_tool_ || hinge_; } bool InSomeInspectMode(); - void SetNeedsUnbufferedInput(bool unbuffered); void PickTheRightTool(); + // Set or clear a mode tool, or add a highlight tool void SetInspectTool(InspectTool* inspect_tool); - void LoadFrameForTool(); + void LoadFrameForTool(int data_resource_id); + void EnsureEnableFrameOverlay(); + void DisableFrameOverlay(); protocol::Response HighlightConfigFromInspectorObject( protocol::Maybe<protocol::Overlay::HighlightConfig> highlight_inspector_object, std::unique_ptr<InspectorHighlightConfig>*); - Member<WebLocalFrameImpl> frame_impl_; Member<InspectedFrames> inspected_frames_; Member<Page> overlay_page_; @@ -226,8 +254,8 @@ class CORE_EXPORT InspectorOverlayAgent final Member<InspectorDOMAgent> dom_agent_; std::unique_ptr<FrameOverlay> frame_overlay_; Member<InspectTool> inspect_tool_; + Member<Hinge> hinge_; bool swallow_next_mouse_up_; - bool swallow_next_escape_up_; DOMNodeId backend_node_id_to_inspect_; InspectorAgentState::Boolean enabled_; InspectorAgentState::Boolean show_ad_highlights_; diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_page_agent.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_page_agent.cc index 1ff765e6e0e..4f79e404321 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_page_agent.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_page_agent.cc @@ -116,6 +116,25 @@ String ClientNavigationReasonToProtocol(ClientNavigationReason reason) { return ReasonEnum::Reload; } +String NavigationPolicyToProtocol(NavigationPolicy policy) { + namespace DispositionEnum = protocol::Page::ClientNavigationDispositionEnum; + switch (policy) { + case kNavigationPolicyDownload: + return DispositionEnum::Download; + case kNavigationPolicyCurrentTab: + return DispositionEnum::CurrentTab; + case kNavigationPolicyNewBackgroundTab: + return DispositionEnum::NewTab; + case kNavigationPolicyNewForegroundTab: + return DispositionEnum::NewTab; + case kNavigationPolicyNewWindow: + return DispositionEnum::NewWindow; + case kNavigationPolicyNewPopup: + return DispositionEnum::NewWindow; + } + return DispositionEnum::CurrentTab; +} + Resource* CachedResource(LocalFrame* frame, const KURL& url, InspectorResourceContentLoader* loader) { @@ -944,13 +963,14 @@ void InspectorPageAgent::FrameStoppedLoading(LocalFrame* frame) { GetFrontend()->flush(); } -void InspectorPageAgent::FrameRequestedNavigation( - Frame* target_frame, - const KURL& url, - ClientNavigationReason reason) { +void InspectorPageAgent::FrameRequestedNavigation(Frame* target_frame, + const KURL& url, + ClientNavigationReason reason, + NavigationPolicy policy) { GetFrontend()->frameRequestedNavigation( IdentifiersFactory::FrameId(target_frame), - ClientNavigationReasonToProtocol(reason), url.GetString()); + ClientNavigationReasonToProtocol(reason), url.GetString(), + NavigationPolicyToProtocol(policy)); GetFrontend()->flush(); } diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_page_agent.h b/chromium/third_party/blink/renderer/core/inspector/inspector_page_agent.h index fa1e022ce6b..33272e49144 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_page_agent.h +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_page_agent.h @@ -181,7 +181,8 @@ class CORE_EXPORT InspectorPageAgent final void FrameStoppedLoading(LocalFrame*); void FrameRequestedNavigation(Frame* target_frame, const KURL&, - ClientNavigationReason); + ClientNavigationReason, + NavigationPolicy); void FrameScheduledNavigation(LocalFrame*, const KURL&, base::TimeDelta delay, diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_resource_content_loader.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_resource_content_loader.cc index 1a72eca769a..10a6e6b3c17 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_resource_content_loader.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_resource_content_loader.cc @@ -98,10 +98,7 @@ void InspectorResourceContentLoader::Start() { // context document for getting origin and ResourceFetcher to use the // main Document's origin, while using the element document for // CompleteURL() to use imported Documents' base URLs. - if (!document->ContextDocument()) { - continue; - } - fetcher = document->ContextDocument()->Fetcher(); + fetcher = document->GetExecutionContext()->Fetcher(); } if (!resource_request.Url().GetString().IsEmpty()) { urls_to_fetch.insert(resource_request.Url().GetString()); diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_style_sheet.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_style_sheet.cc index 7769a1aa17f..ce12579c49d 100644 --- a/chromium/third_party/blink/renderer/core/inspector/inspector_style_sheet.cc +++ b/chromium/third_party/blink/renderer/core/inspector/inspector_style_sheet.cc @@ -997,7 +997,7 @@ String InspectorStyleSheet::FinalURL() { bool InspectorStyleSheet::SetText(const String& text, ExceptionState& exception_state) { InnerSetText(text, true); - page_style_sheet_->SetText(text, true /* allow_import_rules */, nullptr); + page_style_sheet_->SetText(text, CSSImportRules::kAllow); OnStyleSheetTextChanged(); return true; } diff --git a/chromium/third_party/blink/renderer/core/inspector/legacy_dom_snapshot_agent.cc b/chromium/third_party/blink/renderer/core/inspector/legacy_dom_snapshot_agent.cc index 8970aaf5070..e39da971aaf 100644 --- a/chromium/third_party/blink/renderer/core/inspector/legacy_dom_snapshot_agent.cc +++ b/chromium/third_party/blink/renderer/core/inspector/legacy_dom_snapshot_agent.cc @@ -27,6 +27,7 @@ #include "third_party/blink/renderer/core/html/html_link_element.h" #include "third_party/blink/renderer/core/html/html_template_element.h" #include "third_party/blink/renderer/core/input_type_names.h" +#include "third_party/blink/renderer/core/inspector/dom_traversal_utils.h" #include "third_party/blink/renderer/core/inspector/identifiers_factory.h" #include "third_party/blink/renderer/core/inspector/inspector_dom_agent.h" #include "third_party/blink/renderer/core/inspector/inspector_dom_debugger_agent.h" @@ -303,16 +304,16 @@ LegacyDOMSnapshotAgent::VisitContainerChildren( bool include_user_agent_shadow_tree) { auto children = std::make_unique<protocol::Array<int>>(); - if (!InspectorDOMSnapshotAgent::HasChildren(*container, - include_user_agent_shadow_tree)) + if (!blink::dom_traversal_utils::HasChildren(*container, + include_user_agent_shadow_tree)) return nullptr; - Node* child = InspectorDOMSnapshotAgent::FirstChild( + Node* child = blink::dom_traversal_utils::FirstChild( *container, include_user_agent_shadow_tree); while (child) { children->emplace_back(VisitNode(child, include_event_listeners, include_user_agent_shadow_tree)); - child = InspectorDOMSnapshotAgent::NextSibling( + child = blink::dom_traversal_utils::NextSibling( *child, include_user_agent_shadow_tree); } diff --git a/chromium/third_party/blink/renderer/core/inspector/network_resources_data.cc b/chromium/third_party/blink/renderer/core/inspector/network_resources_data.cc index d9753c22e96..fbbb16aa534 100644 --- a/chromium/third_party/blink/renderer/core/inspector/network_resources_data.cc +++ b/chromium/third_party/blink/renderer/core/inspector/network_resources_data.cc @@ -124,7 +124,7 @@ void NetworkResourcesData::ResourceData::SetResource( } void NetworkResourcesData::ResourceData::ProcessCustomWeakness( - const WeakCallbackInfo& info) { + const LivenessBroker& info) { if (!cached_resource_ || info.IsHeapObjectAlive(cached_resource_)) return; diff --git a/chromium/third_party/blink/renderer/core/inspector/network_resources_data.h b/chromium/third_party/blink/renderer/core/inspector/network_resources_data.h index 1368d3ad52e..2346a511a4f 100644 --- a/chromium/third_party/blink/renderer/core/inspector/network_resources_data.h +++ b/chromium/third_party/blink/renderer/core/inspector/network_resources_data.h @@ -167,7 +167,7 @@ class NetworkResourcesData final uint64_t DataLength() const; void AppendData(const char* data, size_t data_length); size_t DecodeDataToContent(); - void ProcessCustomWeakness(const WeakCallbackInfo&); + void ProcessCustomWeakness(const LivenessBroker&); Member<NetworkResourcesData> network_resources_data_; String request_id_; @@ -188,7 +188,10 @@ class NetworkResourcesData final int64_t pending_encoded_data_length_; scoped_refptr<SharedBuffer> buffer_; + + // We use UntracedMember<> here to do custom weak processing. UntracedMember<const Resource> cached_resource_; + scoped_refptr<BlobDataHandle> downloaded_file_blob_; Vector<AtomicString> certificate_; scoped_refptr<EncodedFormData> post_data_; diff --git a/chromium/third_party/blink/renderer/core/inspector/thread_debugger.cc b/chromium/third_party/blink/renderer/core/inspector/thread_debugger.cc index ba97400cb64..bcc4cf90adb 100644 --- a/chromium/third_party/blink/renderer/core/inspector/thread_debugger.cc +++ b/chromium/third_party/blink/renderer/core/inspector/thread_debugger.cc @@ -456,15 +456,15 @@ void ThreadDebugger::GetEventListenersCallback( void ThreadDebugger::consoleTime(const v8_inspector::StringView& title) { // TODO(dgozman): we can save on a copy here if trace macro would take a // pointer with length. - TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", - ToCoreString(title).Utf8().c_str(), this); + TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN0( + "blink.console", ToCoreString(title).Utf8().c_str(), this); } void ThreadDebugger::consoleTimeEnd(const v8_inspector::StringView& title) { // TODO(dgozman): we can save on a copy here if trace macro would take a // pointer with length. - TRACE_EVENT_COPY_ASYNC_END0("blink.console", - ToCoreString(title).Utf8().c_str(), this); + TRACE_EVENT_COPY_NESTABLE_ASYNC_END0( + "blink.console", ToCoreString(title).Utf8().c_str(), this); } void ThreadDebugger::consoleTimeStamp(const v8_inspector::StringView& title) { diff --git a/chromium/third_party/blink/renderer/core/inspector/worker_inspector_controller.cc b/chromium/third_party/blink/renderer/core/inspector/worker_inspector_controller.cc index 27331049b52..e9e2fe1c23e 100644 --- a/chromium/third_party/blink/renderer/core/inspector/worker_inspector_controller.cc +++ b/chromium/third_party/blink/renderer/core/inspector/worker_inspector_controller.cc @@ -33,6 +33,7 @@ #include "base/single_thread_task_runner.h" #include "third_party/blink/renderer/core/core_probe_sink.h" #include "third_party/blink/renderer/core/inspector/devtools_session.h" +#include "third_party/blink/renderer/core/inspector/inspector_audits_agent.h" #include "third_party/blink/renderer/core/inspector/inspector_emulation_agent.h" #include "third_party/blink/renderer/core/inspector/inspector_log_agent.h" #include "third_party/blink/renderer/core/inspector/inspector_network_agent.h" @@ -110,9 +111,12 @@ void WorkerInspectorController::AttachSession(DevToolsSession* session, session->Append(MakeGarbageCollected<InspectorLogAgent>( thread_->GetConsoleMessageStorage(), nullptr, session->V8Session())); if (auto* scope = DynamicTo<WorkerGlobalScope>(thread_->GlobalScope())) { - session->Append(MakeGarbageCollected<InspectorNetworkAgent>( - inspected_frames_.Get(), scope, session->V8Session())); + auto* network_agent = MakeGarbageCollected<InspectorNetworkAgent>( + inspected_frames_.Get(), scope, session->V8Session()); + session->Append(network_agent); session->Append(MakeGarbageCollected<InspectorEmulationAgent>(nullptr)); + session->Append(MakeGarbageCollected<InspectorAuditsAgent>( + network_agent, thread_->GetInspectorIssueStorage())); } ++session_count_; } |