Changeset 160202 in webkit


Ignore:
Timestamp:
Dec 5, 2013 4:57:43 PM (10 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: expose node and frame snapshot capabilities.
https://bugs.webkit.org/show_bug.cgi?id=124326

Patch by Brian J. Burg <Brian Burg> on 2013-12-05
Reviewed by Joseph Pecoraro.

Source/WebCore:

This adds snapshotRect() and snapshotNode() to the Page domain.
Both methods create snapshots using FrameSnapshotting APIs
and send images to the inspector frontend as a data URL.

Remove the unimplemented Page.captureScreenshot API.

  • inspector/InspectorPageAgent.cpp:

(WebCore::InspectorPageAgent::snapshotNode): Added.
(WebCore::InspectorPageAgent::snapshotRect): Added.

  • inspector/InspectorPageAgent.h:
  • inspector/protocol/Page.json: Added new protocol APIs.

Source/WebInspectorUI:

Add method signatures for snapshotNode() and snapshotRect().
Remove method signature for unimplemented Page.captureScreenshot.

  • UserInterface/InspectorBackendCommands.js:
Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r160200 r160202  
     12013-12-05  Brian J. Burg  <burg@cs.washington.edu>
     2
     3        Web Inspector: expose node and frame snapshot capabilities.
     4        https://bugs.webkit.org/show_bug.cgi?id=124326
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        This adds snapshotRect() and snapshotNode() to the Page domain.
     9        Both methods create snapshots using FrameSnapshotting APIs
     10        and send images to the inspector frontend as a data URL.
     11
     12        Remove the unimplemented Page.captureScreenshot API.
     13
     14        * inspector/InspectorPageAgent.cpp:
     15        (WebCore::InspectorPageAgent::snapshotNode): Added.
     16        (WebCore::InspectorPageAgent::snapshotRect): Added.
     17        * inspector/InspectorPageAgent.h:
     18        * inspector/protocol/Page.json: Added new protocol APIs.
     19
    1202013-12-04 Bear Travis <betravis@adobe.com>
    221
  • trunk/Source/WebCore/inspector/InspectorPageAgent.cpp

    r160012 r160202  
    5252#include "Frame.h"
    5353#include "FrameLoader.h"
     54#include "FrameSnapshotting.h"
    5455#include "FrameView.h"
    5556#include "GeolocationController.h"
     
    5859#include "HTMLNames.h"
    5960#include "IdentifiersFactory.h"
     61#include "ImageBuffer.h"
    6062#include "InjectedScriptManager.h"
    6163#include "InspectorAgent.h"
    6264#include "InspectorClient.h"
     65#include "InspectorDOMAgent.h"
    6366#include "InspectorFrontend.h"
    6467#include "InspectorInstrumentation.h"
     
    12521255}
    12531256
    1254 void InspectorPageAgent::captureScreenshot(ErrorString* errorString, String* data)
    1255 {
    1256     if (!m_client->captureScreenshot(data))
    1257         *errorString = "Could not capture screenshot";
     1257void InspectorPageAgent::snapshotNode(ErrorString* errorString, int nodeId, String* outDataURL)
     1258{
     1259    Frame* frame = mainFrame();
     1260    ASSERT(frame);
     1261
     1262    InspectorDOMAgent* domAgent = m_instrumentingAgents->inspectorDOMAgent();
     1263    ASSERT(domAgent);
     1264    Node* node = domAgent->assertNode(errorString, nodeId);
     1265    if (!node)
     1266        return;
     1267
     1268    std::unique_ptr<ImageBuffer> snapshot = WebCore::snapshotNode(*frame, *node);
     1269    if (!snapshot) {
     1270        *errorString = ASCIILiteral("Could not capture snapshot");
     1271        return;
     1272    }
     1273
     1274    *outDataURL = snapshot->toDataURL(ASCIILiteral("image/png"));
     1275}
     1276
     1277void InspectorPageAgent::snapshotRect(ErrorString* errorString, int x, int y, int width, int height, const String& coordinateSystem, String* outDataURL)
     1278{
     1279    Frame* frame = mainFrame();
     1280    ASSERT(frame);
     1281
     1282    SnapshotOptions options = SnapshotOptionsNone;
     1283    if (coordinateSystem == "Viewport")
     1284        options |= SnapshotOptionsInViewCoordinates;
     1285
     1286    IntRect rectangle(x, y, width, height);
     1287    std::unique_ptr<ImageBuffer> snapshot = snapshotFrameRect(*frame, rectangle, options);
     1288
     1289    if (!snapshot) {
     1290        *errorString = ASCIILiteral("Could not capture snapshot");
     1291        return;
     1292    }
     1293
     1294    *outDataURL = snapshot->toDataURL(ASCIILiteral("image/png"));
    12581295}
    12591296
  • trunk/Source/WebCore/inspector/InspectorPageAgent.h

    r160012 r160202  
    130130    virtual void getCompositingBordersVisible(ErrorString*, bool* out_param);
    131131    virtual void setCompositingBordersVisible(ErrorString*, bool);
    132     virtual void captureScreenshot(ErrorString*, String* data);
     132    virtual void snapshotNode(ErrorString*, int nodeId, String* outDataURL);
     133    virtual void snapshotRect(ErrorString*, int x, int y, int width, int height, const String& coordinateSystem, String* outDataURL);
    133134    virtual void handleJavaScriptDialog(ErrorString*, bool accept, const String* promptText);
    134135    virtual void archive(ErrorString*, String* data);
  • trunk/Source/WebCore/inspector/protocol/Page.json

    r159233 r160202  
    88            "enum": ["Document", "Stylesheet", "Image", "Font", "Script", "XHR", "WebSocket", "Other"],
    99            "description": "Resource type as it was perceived by the rendering engine."
     10        },
     11        {
     12            "id": "CoordinateSystem",
     13            "type": "string",
     14            "enum": ["Viewport", "Page"],
     15            "description": "Coordinate system used by supplied coordinates."
    1016        },
    1117        {
     
    345351        },
    346352        {
    347             "name": "captureScreenshot",
    348             "description": "Capture page screenshot.",
    349             "returns": [
    350                 { "name": "data", "type": "string", "description": "Base64-encoded image data (PNG)." }
     353            "name": "snapshotNode",
     354            "description": "Capture a snapshot of the specified node that does not include unrelated layers.",
     355            "parameters": [
     356                { "name": "nodeId", "$ref": "DOM.NodeId", "description": "Id of the node to snapshot." }
     357            ],
     358            "returns": [
     359                { "name": "dataURL", "type": "string", "description": "Base64-encoded image data (PNG)." }
     360            ]
     361        },
     362        {
     363            "name": "snapshotRect",
     364            "description": "Capture a snapshot of the page within the specified rectangle and coordinate system.",
     365            "parameters": [
     366                { "name": "x", "type": "integer", "description": "X coordinate" },
     367                { "name": "y", "type": "integer", "description": "Y coordinate" },
     368                { "name": "width", "type": "integer", "description": "Rectangle width" },
     369                { "name": "height", "type": "integer", "description": "Rectangle height" },
     370                { "name": "coordinateSystem", "$ref": "CoordinateSystem", "description": "Indicates the coordinate system of the supplied rectangle." }
     371            ],
     372            "returns": [
     373                { "name": "dataURL", "type": "string", "description": "Base64-encoded image data (PNG)." }
    351374            ]
    352375        },
  • trunk/Source/WebInspectorUI/ChangeLog

    r160198 r160202  
     12013-12-05  Brian J. Burg  <burg@cs.washington.edu>
     2
     3        Web Inspector: expose node and frame snapshot capabilities.
     4        https://bugs.webkit.org/show_bug.cgi?id=124326
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        Add method signatures for snapshotNode() and snapshotRect().
     9        Remove method signature for unimplemented Page.captureScreenshot.
     10
     11        * UserInterface/InspectorBackendCommands.js:
     12
    1132013-12-05  Alexandru Chiculita  <achicu@adobe.com>
    214
  • trunk/Source/WebInspectorUI/UserInterface/InspectorBackendCommands.js

    r159475 r160202  
    11// File is generated by Source/WebCore/inspector/CodeGeneratorInspector.py
    22
     3// Copyright (c) 2013 Apple Inc. All Rights Reserved.
    34// Copyright (c) 2011 The Chromium Authors. All rights reserved.
    45// Use of this source code is governed by a BSD-style license that can be
     
    290291InspectorBackend.registerPageDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Page");
    291292InspectorBackend.registerEnum("Page.ResourceType", {Document: "Document", Stylesheet: "Stylesheet", Image: "Image", Font: "Font", Script: "Script", XHR: "XHR", WebSocket: "WebSocket", Other: "Other"});
     293InspectorBackend.registerEnum("Page.CoordinateSystem", {Viewport: "Viewport", Page: "Page"});
    292294InspectorBackend.registerEvent("Page.domContentEventFired", ["timestamp"]);
    293295InspectorBackend.registerEvent("Page.loadEventFired", ["timestamp"]);
     
    335337InspectorBackend.registerCommand("Page.getCompositingBordersVisible", [], ["result"]);
    336338InspectorBackend.registerCommand("Page.setCompositingBordersVisible", [{"name": "visible", "type": "boolean", "optional": false}], []);
    337 InspectorBackend.registerCommand("Page.captureScreenshot", [], ["data"]);
     339InspectorBackend.registerCommand("Page.snapshotNode", [{"name": "nodeId", "type": "number", "optional": false}], ["dataURL"]);
     340InspectorBackend.registerCommand("Page.snapshotRect", [{"name": "x", "type": "number", "optional": false}, {"name": "y", "type": "number", "optional": false}, {"name": "width", "type": "number", "optional": false}, {"name": "height", "type": "number", "optional": false}, {"name": "coordinateSystem", "type": "string", "optional": false}], ["dataURL"]);
    338341InspectorBackend.registerCommand("Page.handleJavaScriptDialog", [{"name": "accept", "type": "boolean", "optional": false}, {"name": "promptText", "type": "string", "optional": true}], []);
    339342InspectorBackend.registerCommand("Page.archive", [], ["data"]);
  • trunk/Source/WebInspectorUI/UserInterface/Legacy/7.0/InspectorBackendCommands.js

    r156357 r160202  
    11// File is generated by Source/WebCore/inspector/CodeGeneratorInspector.py
    22
     3// Copyright (c) 2013 Apple Inc. All Rights Reserved.
    34// Copyright (c) 2011 The Chromium Authors. All rights reserved.
    45// Use of this source code is governed by a BSD-style license that can be
     
    6768InspectorBackend.registerCommand("Page.getCompositingBordersVisible", [], ["result"]);
    6869InspectorBackend.registerCommand("Page.setCompositingBordersVisible", [{"name": "visible", "type": "boolean", "optional": false}], []);
    69 InspectorBackend.registerCommand("Page.captureScreenshot", [], ["data"]);
    7070InspectorBackend.registerCommand("Page.handleJavaScriptDialog", [{"name": "accept", "type": "boolean", "optional": false}, {"name": "promptText", "type": "string", "optional": true}], []);
    7171
  • trunk/Source/WebInspectorUI/Versions/Inspector-iOS-7.0.json

    r156357 r160202  
    409409                "parameters": [
    410410                    { "name": "visible", "type": "boolean", "description": "True for showing compositing borders." }
    411                 ]
    412             },
    413             {
    414                 "name": "captureScreenshot",
    415                 "description": "Capture page screenshot.",
    416                 "returns": [
    417                     { "name": "data", "type": "string", "description": "Base64-encoded image data (PNG)." }
    418411                ]
    419412            },
Note: See TracChangeset for help on using the changeset viewer.