Changeset 248890 in webkit


Ignore:
Timestamp:
Aug 19, 2019 9:22:03 PM (5 years ago)
Author:
Devin Rousso
Message:

Web Inspector: have more aggressive checks for dataURLs provided to console.screenshot
https://bugs.webkit.org/show_bug.cgi?id=200747

Reviewed by Joseph Pecoraro.

Source/WebCore:

Always send any /data:*+/ strings to the frontend and have it render there. If that doesn't
work, have the frontend "spoof" an error message look and feel.

Test: inspector/console/console-screenshot.html

  • page/PageConsoleClient.cpp:

(WebCore::PageConsoleClient::screenshot):

Source/WebInspectorUI:

Always send any /data:*+/ strings to the frontend and have it render there. If that doesn't
work, have the frontend "spoof" an error message look and feel.

  • UserInterface/Views/ConsoleMessageView.js:

(WI.ConsoleMessageView.prototype._appendMessageTextAndArguments):

  • Localizations/en.lproj/localizedStrings.js:

LayoutTests:

  • inspector/console/console-screenshot.html:
  • inspector/console/console-screenshot-expected.txt:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r248876 r248890  
     12019-08-19  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: have more aggressive checks for dataURLs provided to `console.screenshot`
     4        https://bugs.webkit.org/show_bug.cgi?id=200747
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        * inspector/console/console-screenshot.html:
     9        * inspector/console/console-screenshot-expected.txt:
     10
    1112019-08-19  Alexey Shvayka  <shvaikalesh@gmail.com>
    212
  • trunk/LayoutTests/inspector/console/console-screenshot-expected.txt

    r248736 r248890  
    88CONSOLE MESSAGE: [object ImageBitmap]
    99CONSOLE MESSAGE: [object CanvasRenderingContext2D]
     10CONSOLE MESSAGE: Viewport
    1011CONSOLE MESSAGE: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAABNJREFUCB1j/M/AAEQMDEwgAgQAHxcCAmtAm/sAAAAASUVORK5CYII=
    11 CONSOLE MESSAGE: Viewport
     12CONSOLE MESSAGE: data:fake/mime
     13CONSOLE MESSAGE: data:image/png;base64,<INVALID>
     14CONSOLE MESSAGE: data:image/png;a1=b2;base64,
    1215CONSOLE MESSAGE: Viewport
    1316CONSOLE MESSAGE: Viewport
     
    4851
    4952-- Running test case: console.screenshot.Node.DetachedNonScreenshotable
    50 PASS: Could not capture screenshot
     53PASS: Error: Could not capture screenshot
    5154
    5255-- Running test case: console.screenshot.ImageData
     
    6871PASS: The image height should be 2px.
    6972
    70 -- Running test case: console.screenshot.String.Base64.Valid
     73-- Running test case: console.screenshot.String.Valid
     74PASS: The added message should be an image.
     75PASS: The image should not be empty.
     76PASS: The image width should be greater than 2px.
     77PASS: The image height should be greater than 2px.
     78
     79-- Running test case: console.screenshot.String.dataURL.Valid
    7180PASS: The added message should be an image.
    7281PASS: The image should not be empty.
     
    7483PASS: The image height should be 2px.
    7584
    76 -- Running test case: console.screenshot.String.Base64.NoContent
     85-- Running test case: console.screenshot.String.dataURL.InvalidMIME
    7786PASS: The added message should be an image.
    7887PASS: The image should not be empty.
    79 PASS: The image width should be greater than 2px.
    80 PASS: The image height should be greater than 2px.
     88PASS: The image should not load.
    8189
    82 -- Running test case: console.screenshot.String.Base64.Invalid
     90-- Running test case: console.screenshot.String.dataURL.InvalidContent
     91PASS: The added message should be an image.
     92PASS: The image should not be empty.
     93PASS: The image should not load.
     94
     95-- Running test case: console.screenshot.String.dataURL.InvalidNoContent
     96PASS: The added message should be an image.
     97PASS: The image should not be empty.
     98PASS: The image should not load.
     99
     100-- Running test case: console.screenshot.String.dataURL.ValidNoContent
    83101PASS: The added message should be an image.
    84102PASS: The image should not be empty.
  • trunk/LayoutTests/inspector/console/console-screenshot.html

    r248736 r248890  
    7777
    7878                if (message.level === WI.ConsoleMessage.MessageLevel.Error) {
    79                     InspectorTest.expectThat(shouldError, message.messageText);
     79                    InspectorTest.expectThat(shouldError, "Error: " + message.messageText);
    8080                    return;
    8181                }
     
    8484                InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty.");
    8585
    86                 let img = await WI.ImageUtilities.promisifyLoad(message.messageText);
    87                 if (shouldCaptureViewport) {
    88                     InspectorTest.expectGreaterThan(img.width, 2, "The image width should be greater than 2px.");
    89                     InspectorTest.expectGreaterThan(img.height, 2, "The image height should be greater than 2px.");
    90                 } else {
    91                     InspectorTest.expectEqual(img.width, 2, "The image width should be 2px.");
    92                     InspectorTest.expectEqual(img.height, 2, "The image height should be 2px.");
     86                try {
     87                    let image = new Image;
     88                    await new Promise((resolve, reject) => {
     89                        image.addEventListener("load", resolve);
     90                        image.addEventListener("error", reject);
     91                        image.src = message.messageText;
     92                    });
     93
     94                    if (shouldCaptureViewport) {
     95                        InspectorTest.expectGreaterThan(image.width, 2, "The image width should be greater than 2px.");
     96                        InspectorTest.expectGreaterThan(image.height, 2, "The image height should be greater than 2px.");
     97                    } else {
     98                        InspectorTest.expectEqual(image.width, 2, "The image width should be 2px.");
     99                        InspectorTest.expectEqual(image.height, 2, "The image height should be 2px.");
     100                    }
     101                } catch {
     102                    InspectorTest.expectThat(shouldError, "The image should not load.");
    93103                }
    94104            },
     
    150160
    151161    addTest({
    152         name: "console.screenshot.String.Base64.Valid",
     162        name: "console.screenshot.String.Valid",
     163        expression: `console.screenshot("test")`,
     164        shouldCaptureViewport: true,
     165    });
     166
     167    addTest({
     168        name: "console.screenshot.String.dataURL.Valid",
    153169        expression: `console.screenshot("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAABNJREFUCB1j/M/AAEQMDEwgAgQAHxcCAmtAm/sAAAAASUVORK5CYII=")`, // 2x2 red square
    154170    });
    155171
    156172    addTest({
    157         name: "console.screenshot.String.Base64.NoContent",
     173        name: "console.screenshot.String.dataURL.InvalidMIME",
     174        expression: `console.screenshot("data:fake/mime")`,
     175        shouldError: true,
     176    });
     177
     178    addTest({
     179        name: "console.screenshot.String.dataURL.InvalidContent",
     180        expression: `console.screenshot("data:image/png;base64,<INVALID>")`,
     181        shouldError: true,
     182    });
     183
     184    addTest({
     185        name: "console.screenshot.String.dataURL.InvalidNoContent",
    158186        expression: `console.screenshot("data:image/png;a1=b2;base64,")`,
    159         shouldCaptureViewport: true,
    160     });
    161 
    162     addTest({
    163         name: "console.screenshot.String.Base64.Invalid",
    164         expression: `console.screenshot("invalid")`,
     187        shouldError: true,
     188    });
     189
     190    addTest({
     191        name: "console.screenshot.String.dataURL.ValidNoContent",
     192        expression: `console.screenshot("data:")`,
    165193        shouldCaptureViewport: true,
    166194    });
  • trunk/Source/WebCore/ChangeLog

    r248886 r248890  
     12019-08-19  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: have more aggressive checks for dataURLs provided to `console.screenshot`
     4        https://bugs.webkit.org/show_bug.cgi?id=200747
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        Always send any /data:*+/ strings to the frontend and have it render there. If that doesn't
     9        work, have the frontend "spoof" an error message look and feel.
     10
     11        Test: inspector/console/console-screenshot.html
     12
     13        * page/PageConsoleClient.cpp:
     14        (WebCore::PageConsoleClient::screenshot):
     15
    1162019-08-19  Jer Noble  <jer.noble@apple.com>
    217
  • trunk/Source/WebCore/page/PageConsoleClient.cpp

    r248846 r248890  
    6565#include <JavaScriptCore/ConsoleMessage.h>
    6666#include <JavaScriptCore/JSCInlines.h>
    67 #include <JavaScriptCore/RegularExpression.h>
    6867#include <JavaScriptCore/ScriptArguments.h>
    6968#include <JavaScriptCore/ScriptCallStack.h>
     
    388387        } else {
    389388            String base64;
    390             if (possibleTarget.getString(state, base64)) {
    391                 JSC::Yarr::RegularExpression regex("^data:image/(?:[^;]+;)+base64,.+$"_s, JSC::Yarr::TextCaseSensitivity::TextCaseInsensitive);
    392                 if (regex.match(base64) != -1) {
    393                     target = possibleTarget;
    394                     dataURL = base64;
    395                 }
     389            if (possibleTarget.getString(state, base64) && base64.startsWithIgnoringASCIICase("data:"_s) && base64.length() > 5) {
     390                target = possibleTarget;
     391                dataURL = base64;
    396392            }
    397393        }
  • trunk/Source/WebInspectorUI/ChangeLog

    r248889 r248890  
     12019-08-19  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: have more aggressive checks for dataURLs provided to `console.screenshot`
     4        https://bugs.webkit.org/show_bug.cgi?id=200747
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        Always send any /data:*+/ strings to the frontend and have it render there. If that doesn't
     9        work, have the frontend "spoof" an error message look and feel.
     10
     11        * UserInterface/Views/ConsoleMessageView.js:
     12        (WI.ConsoleMessageView.prototype._appendMessageTextAndArguments):
     13
     14        * Localizations/en.lproj/localizedStrings.js:
     15
    1162019-08-19  Nikita Vasilyev  <nvasilyev@apple.com>
    217
  • trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js

    r248773 r248890  
    297297localizedStrings["Copy Table"] = "Copy Table";
    298298localizedStrings["Copy as cURL"] = "Copy as cURL";
     299localizedStrings["Could not capture screenshot"] = "Could not capture screenshot";
    299300localizedStrings["Could not fetch properties. Object may no longer exist."] = "Could not fetch properties. Object may no longer exist.";
    300301localizedStrings["Count"] = "Count";
  • trunk/Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js

    r248766 r248890  
    306306            case WI.ConsoleMessage.MessageType.Image: {
    307307                if (this._message.level === WI.ConsoleMessage.MessageLevel.Log) {
     308                    let divider = null;
     309
    308310                    if (this._message.parameters.length > 1) {
    309311                        this._appendFormattedArguments(element, this._message.parameters.slice(1));
    310312
    311                         element.appendChild(document.createElement("hr"));
     313                        divider = element.appendChild(document.createElement("hr"));
    312314                    }
    313315
     
    318320
    319321                    if (this._message.messageText) {
    320                         let img = element.appendChild(document.createElement("img"));
     322                        let img = document.createElement("img");
    321323                        img.classList.add("show-grid");
    322324                        img.src = this._message.messageText;
     
    327329                            else
    328330                                img.height = img.height / window.devicePixelRatio;
     331                            element.appendChild(img);
     332                        });
     333                        img.addEventListener("error", (event) => {
     334                            this._element.setAttribute("data-labelprefix", WI.UIString("Error: "));
     335                            this._element.classList.add("console-error-level");
     336                            this._element.classList.remove("console-log-level");
     337
     338                            if (divider) {
     339                                while (divider.nextSibling)
     340                                    divider.nextSibling.remove();
     341                            } else
     342                                element.removeChildren();
     343
     344                            let args = [WI.UIString("Could not capture screenshot"), this._message.messageText];
     345                            if (this._extraParameters)
     346                                args = args.concat(this._extraParameters);
     347                            this._appendFormattedArguments(element, args);
    329348                        });
    330349                    }
     
    333352
    334353                if (this._message.level === WI.ConsoleMessage.MessageLevel.Error) {
    335                     let args = [this._message.messageText];
     354                    let args = [];
     355                    if (this._message.messageText === "Could not capture screenshot")
     356                        args.push(WI.UIString("Could not capture screenshot"));
     357                    else
     358                        args.push(this._message.messageText);
    336359                    if (this._extraParameters)
    337360                        args = args.concat(this._extraParameters);
Note: See TracChangeset for help on using the changeset viewer.