Changeset 225709 in webkit


Ignore:
Timestamp:
Dec 8, 2017, 3:03:58 PM (8 years ago)
Author:
Joseph Pecoraro
Message:

ServiceWorker Inspector: Various issues inspecting service worker on mobile.twitter.com
https://bugs.webkit.org/show_bug.cgi?id=180520
<rdar://problem/35900764>

Reviewed by Brian Burg.

Source/JavaScriptCore:

  • inspector/protocol/ServiceWorker.json:

Include content script content in the initialization info.

Source/WebCore:

  • inspector/agents/worker/ServiceWorkerAgent.cpp:

(WebCore::ServiceWorkerAgent::getInitializationInfo):

  • inspector/agents/worker/ServiceWorkerAgent.h:

Add initial script content to initialization so we always at least have main resource content.

Source/WebInspectorUI:

  • UserInterface/Main.html:
  • UserInterface/Test.html:

New files.

  • UserInterface/Controllers/SourceMapManager.js:

(WI.SourceMapManager.prototype._loadAndParseSourceMap):

  • UserInterface/Models/SourceMapResource.js:

(WI.SourceMapResource.prototype.requestContentFromBackend):
A ServiceWorker inspector doesn't have a main frame, fall back to an
empty frameIdentifier, it is ignored by the Service Worker network agent.

  • UserInterface/Base/Main.js:

Handle a Service Worker inspector where there is no frame. This can
search the main resource's resource collection.

  • UserInterface/Controllers/DebuggerManager.js:

(WI.DebuggerManager.prototype.scriptDidParse):

  • UserInterface/Controllers/FrameResourceManager.js:

(WI.FrameResourceManager.prototype.resourceRequestDidFailLoading):
In Service Workers the resources won't have a parent frame.

(WI.FrameResourceManager.prototype._addNewResourceToFrameOrTarget):
(WI.FrameResourceManager.prototype._processServiceWorkerInitializationInfo):
In service worker initialization fallback to using the script content
as the main resource if we didn't get a Script that actually includes it.

  • UserInterface/Models/LocalScript.js:

(WI.LocalScript):
(WI.LocalScript.prototype.requestContentFromBackend):
A way to create a local Script with content.

  • UserInterface/Views/SourceCodeTextEditor.js:

(WI.SourceCodeTextEditor.prototype.get _supportsDebugging):
Disallow breakpoints in a LocalScript since we have no way to tell the
backend where to set breakpoints.

  • UserInterface/Models/TextRange.js:

(WI.TextRange.fromText):
Add a way to get a TextRange from static text.

Location:
trunk/Source
Files:
15 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r225698 r225709  
     12017-12-08  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        ServiceWorker Inspector: Various issues inspecting service worker on mobile.twitter.com
     4        https://bugs.webkit.org/show_bug.cgi?id=180520
     5        <rdar://problem/35900764>
     6
     7        Reviewed by Brian Burg.
     8
     9        * inspector/protocol/ServiceWorker.json:
     10        Include content script content in the initialization info.
     11
    1122017-12-08  Konstantin Tokarev  <annulen@yandex.ru>
    213
  • trunk/Source/JavaScriptCore/inspector/protocol/ServiceWorker.json

    r224826 r225709  
    55    "types": [
    66        {
    7             "id": "InitializationInfo",
     7            "id": "Configuration",
    88            "type": "object",
    99            "description": "ServiceWorker metadata and initial state.",
     
    1111                { "name": "targetId", "type": "string" },
    1212                { "name": "securityOrigin", "type": "string" },
    13                 { "name": "url", "type": "string", "description": "ServiceWorker main script URL." }
     13                { "name": "url", "type": "string", "description": "ServiceWorker main script URL." },
     14                { "name": "content", "type": "string", "description": "ServiceWorker main script content." }
    1415            ]
    1516        }
     
    2021            "description": "Returns the initialization information for this target.",
    2122            "returns": [
    22                 { "name": "info", "$ref": "InitializationInfo" }
     23                { "name": "info", "$ref": "Configuration" }
    2324            ]
    2425        }
  • trunk/Source/WebCore/ChangeLog

    r225708 r225709  
     12017-12-08  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        ServiceWorker Inspector: Various issues inspecting service worker on mobile.twitter.com
     4        https://bugs.webkit.org/show_bug.cgi?id=180520
     5        <rdar://problem/35900764>
     6
     7        Reviewed by Brian Burg.
     8
     9        * inspector/agents/worker/ServiceWorkerAgent.cpp:
     10        (WebCore::ServiceWorkerAgent::getInitializationInfo):
     11        * inspector/agents/worker/ServiceWorkerAgent.h:
     12        Add initial script content to initialization so we always at least have main resource content.
     13
    1142017-12-08  Joseph Pecoraro  <pecoraro@apple.com>
    215
  • trunk/Source/WebCore/inspector/agents/worker/ServiceWorkerAgent.cpp

    r224826 r225709  
    5353}
    5454
    55 void ServiceWorkerAgent::getInitializationInfo(ErrorString&, RefPtr<Inspector::Protocol::ServiceWorker::InitializationInfo>& info)
     55void ServiceWorkerAgent::getInitializationInfo(ErrorString&, RefPtr<Inspector::Protocol::ServiceWorker::Configuration>& info)
    5656{
    57     info = Inspector::Protocol::ServiceWorker::InitializationInfo::create()
     57    info = Inspector::Protocol::ServiceWorker::Configuration::create()
    5858        .setTargetId(m_serviceWorkerGlobalScope.identifier())
    5959        .setSecurityOrigin(m_serviceWorkerGlobalScope.securityOrigin()->toRawString())
    6060        .setUrl(m_serviceWorkerGlobalScope.thread().contextData().scriptURL)
     61        .setContent(m_serviceWorkerGlobalScope.thread().contextData().script)
    6162        .release();
    6263}
  • trunk/Source/WebCore/inspector/agents/worker/ServiceWorkerAgent.h

    r224826 r225709  
    4848
    4949    // ServiceWorkerBackendDispatcherHandler
    50     void getInitializationInfo(ErrorString&, RefPtr<Inspector::Protocol::ServiceWorker::InitializationInfo>&) final;
     50    void getInitializationInfo(ErrorString&, RefPtr<Inspector::Protocol::ServiceWorker::Configuration>&) final;
    5151
    5252private:
  • trunk/Source/WebInspectorUI/ChangeLog

    r225704 r225709  
     12017-12-08  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        ServiceWorker Inspector: Various issues inspecting service worker on mobile.twitter.com
     4        https://bugs.webkit.org/show_bug.cgi?id=180520
     5        <rdar://problem/35900764>
     6
     7        Reviewed by Brian Burg.
     8
     9        * UserInterface/Main.html:
     10        * UserInterface/Test.html:
     11        New files.
     12
     13        * UserInterface/Controllers/SourceMapManager.js:
     14        (WI.SourceMapManager.prototype._loadAndParseSourceMap):
     15        * UserInterface/Models/SourceMapResource.js:
     16        (WI.SourceMapResource.prototype.requestContentFromBackend):
     17        A ServiceWorker inspector doesn't have a main frame, fall back to an
     18        empty frameIdentifier, it is ignored by the Service Worker network agent.
     19
     20        * UserInterface/Base/Main.js:
     21        Handle a Service Worker inspector where there is no frame. This can
     22        search the main resource's resource collection.
     23
     24        * UserInterface/Controllers/DebuggerManager.js:
     25        (WI.DebuggerManager.prototype.scriptDidParse):
     26
     27        * UserInterface/Controllers/FrameResourceManager.js:
     28        (WI.FrameResourceManager.prototype.resourceRequestDidFailLoading):
     29        In Service Workers the resources won't have a parent frame.
     30
     31        (WI.FrameResourceManager.prototype._addNewResourceToFrameOrTarget):
     32        (WI.FrameResourceManager.prototype._processServiceWorkerInitializationInfo):
     33        In service worker initialization fallback to using the script content
     34        as the main resource if we didn't get a Script that actually includes it.
     35
     36        * UserInterface/Models/LocalScript.js:
     37        (WI.LocalScript):
     38        (WI.LocalScript.prototype.requestContentFromBackend):
     39        A way to create a local Script with content.
     40
     41        * UserInterface/Views/SourceCodeTextEditor.js:
     42        (WI.SourceCodeTextEditor.prototype.get _supportsDebugging):
     43        Disallow breakpoints in a LocalScript since we have no way to tell the
     44        backend where to set breakpoints.
     45
     46        * UserInterface/Models/TextRange.js:
     47        (WI.TextRange.fromText):
     48        Add a way to get a TextRange from static text.
     49
    1502017-12-08  Michael Catanzaro  <mcatanzaro@igalia.com>
    251
  • trunk/Source/WebInspectorUI/UserInterface/Base/Main.js

    r225587 r225709  
    811811    }
    812812
    813     var searchChildFrames = false;
     813    let searchChildFrames = false;
    814814    if (!frame) {
    815815        frame = this.frameResourceManager.mainFrame;
     
    817817    }
    818818
    819     console.assert(frame);
    820 
    821     // WI.Frame.resourceForURL does not check the main resource, only sub-resources. So check both.
     819    let resource;
    822820    let simplifiedURL = removeURLFragment(url);
    823     var resource = frame.url === simplifiedURL ? frame.mainResource : frame.resourceForURL(simplifiedURL, searchChildFrames);
     821    if (frame) {
     822        // WI.Frame.resourceForURL does not check the main resource, only sub-resources. So check both.
     823        resource = frame.url === simplifiedURL ? frame.mainResource : frame.resourceForURL(simplifiedURL, searchChildFrames);
     824    } else if (WI.sharedApp.debuggableType === WI.DebuggableType.ServiceWorker)
     825        resource = WI.mainTarget.resourceCollection.resourceForURL(removeURLFragment(url));
     826
    824827    if (resource) {
    825828        let positionToReveal = new WI.SourceCodePosition(options.lineNumber, 0);
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js

    r225244 r225709  
    711711        targetData.addScript(script);
    712712
    713         if (!target.mainResource && (target !== WI.mainResource || WI.sharedApp.debuggableType === WI.DebuggableType.ServiceWorker)) {
    714             // FIXME: <https://webkit.org/b/164427> Web Inspector: WorkerTarget's mainResource should be a Resource not a Script
    715             // We make the main resource of a WorkerTarget the Script instead of the Resource
    716             // because the frontend may not be informed of the Resource. We should guarantee
    717             // the frontend is informed of the Resource.
     713        // FIXME: <https://webkit.org/b/164427> Web Inspector: WorkerTarget's mainResource should be a Resource not a Script
     714        // We make the main resource of a WorkerTarget the Script instead of the Resource
     715        // because the frontend may not be informed of the Resource. We should guarantee
     716        // the frontend is informed of the Resource.
     717        if (WI.sharedApp.debuggableType === WI.DebuggableType.ServiceWorker) {
     718            // A ServiceWorker starts with a LocalScript for the main resource but we can replace it during initialization.
     719            if (target.mainResource instanceof WI.LocalScript) {
     720                if (script.url === target.name)
     721                    target.mainResource = script;
     722            }
     723        } else if (!target.mainResource && target !== WI.mainTarget) {
     724            // A Worker starts without a main resource and we insert one.
    718725            if (script.url === target.name) {
    719726                target.mainResource = script;
     
    735742        this.dispatchEventToListeners(WI.DebuggerManager.Event.ScriptAdded, {script});
    736743
    737         if (target !== WI.mainTarget && !script.isMainResource() && !script.resource)
     744        if ((target !== WI.mainTarget || WI.sharedApp.debuggableType === WI.DebuggableType.ServiceWorker) && !script.isMainResource() && !script.resource)
    738745            target.addScript(script);
    739746    }
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/FrameResourceManager.js

    r225244 r225709  
    4444
    4545        if (window.ServiceWorkerAgent)
    46             ServiceWorkerAgent.getInitializationInfo(this._processServiceWorkerInitializationInfo.bind(this));
     46            ServiceWorkerAgent.getInitializationInfo(this._processServiceWorkerConfiguration.bind(this));
    4747
    4848        if (window.NetworkAgent)
     
    459459        resource.markAsFailed(canceled, elapsedTime, errorText);
    460460
    461         if (resource === resource.parentFrame.provisionalMainResource)
     461        if (resource.parentFrame && resource === resource.parentFrame.provisionalMainResource)
    462462            resource.parentFrame.clearProvisionalLoad();
    463463
     
    535535        } else {
    536536            // This is a new request for a new frame, which is always the main resource.
     537            console.assert(WI.sharedApp.debuggableType !== WI.DebuggableType.ServiceWorker);
    537538            console.assert(!targetId);
    538539            resource = new WI.Resource(url, null, type, loaderIdentifier, targetId, requestIdentifier, requestMethod, requestHeaders, requestData, elapsedTime, walltime, initiatorSourceCodeLocation, originalRequestWillBeSentTimestamp);
     
    629630    }
    630631
    631     _processServiceWorkerInitializationInfo(error, initializationPayload)
     632    _processServiceWorkerConfiguration(error, initializationPayload)
    632633    {
    633634        console.assert(this._waitingForMainFrameResourceTreePayload);
     
    643644        WI.mainTarget.identifier = initializationPayload.targetId;
    644645        WI.mainTarget.name = initializationPayload.url;
     646
     647        // Create a main resource with this content in case the content never shows up as a WI.Script.
     648        const type = WI.Script.SourceType.Program;
     649        let script = new WI.LocalScript(WI.mainTarget, initializationPayload.url, type, initializationPayload.content);
     650        WI.mainTarget.mainResource = script;
     651
     652        InspectorBackend.runAfterPendingDispatches(() => {
     653            if (WI.mainTarget.mainResource === script) {
     654                // We've now received all the scripts, if we don't have a better main resource use this LocalScript.
     655                WI.debuggerManager.dataForTarget(WI.mainTarget).addScript(script);
     656                WI.debuggerManager.dispatchEventToListeners(WI.DebuggerManager.Event.ScriptAdded, {script});
     657            }
     658        });
    645659    }
    646660
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/SourceMapManager.js

    r223308 r225709  
    137137            frameIdentifier = originalSourceCode.parentFrame.id;
    138138
    139         if (!frameIdentifier)
     139        if (!frameIdentifier && WI.frameResourceManager.mainFrame)
    140140            frameIdentifier = WI.frameResourceManager.mainFrame.id;
     141        else
     142            frameIdentifier = "";
    141143
    142144        NetworkAgent.loadResource(frameIdentifier, sourceMapURL, sourceMapLoaded.bind(this));
  • trunk/Source/WebInspectorUI/UserInterface/Main.html

    r225547 r225709  
    329329    <script src="Models/TimelineRecord.js"></script>
    330330
     331    <script src="Models/Resource.js"></script>
     332    <script src="Models/Script.js"></script>
     333    <script src="Models/LocalScript.js"></script>
     334
    331335    <script src="Models/AnalyzerMessage.js"></script>
    332336    <script src="Models/ApplicationCacheFrame.js"></script>
     
    412416    <script src="Models/RecordingInitialStateAction.js"></script>
    413417    <script src="Models/RenderingFrameTimelineRecord.js"></script>
    414     <script src="Models/Resource.js"></script>
    415418    <script src="Models/ResourceCollection.js"></script>
    416419    <script src="Models/ResourceQueryMatch.js"></script>
     
    420423    <script src="Models/Revision.js"></script>
    421424    <script src="Models/ScopeChainNode.js"></script>
    422     <script src="Models/Script.js"></script>
    423425    <script src="Models/ScriptInstrument.js"></script>
    424426    <script src="Models/ScriptSyntaxTree.js"></script>
  • trunk/Source/WebInspectorUI/UserInterface/Models/LocalScript.js

    r225708 r225709  
    2424 */
    2525
    26 #pragma once
     26WI.LocalScript = class LocalScript extends WI.Script
     27{
     28    constructor(target, url, sourceType, text)
     29    {
     30        super(target, null, WI.TextRange.fromText(text), url, sourceType);
    2731
    28 #if ENABLE(SERVICE_WORKER)
     32        this._text = text;
     33    }
    2934
    30 #include "InspectorWebAgentBase.h"
    31 #include <inspector/InspectorBackendDispatchers.h>
     35    // Public
    3236
    33 namespace WebCore {
    34 
    35 class ServiceWorkerGlobalScope;
    36 
    37 typedef String ErrorString;
    38 
    39 class ServiceWorkerAgent final : public InspectorAgentBase, public Inspector::ServiceWorkerBackendDispatcherHandler {
    40     WTF_MAKE_NONCOPYABLE(ServiceWorkerAgent);
    41     WTF_MAKE_FAST_ALLOCATED;
    42 public:
    43     explicit ServiceWorkerAgent(WorkerAgentContext&);
    44     virtual ~ServiceWorkerAgent() = default;
    45 
    46     void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) final;
    47     void willDestroyFrontendAndBackend(Inspector::DisconnectReason) final;
    48 
    49     // ServiceWorkerBackendDispatcherHandler
    50     void getInitializationInfo(ErrorString&, RefPtr<Inspector::Protocol::ServiceWorker::InitializationInfo>&) final;
    51 
    52 private:
    53     ServiceWorkerGlobalScope& m_serviceWorkerGlobalScope;
    54     RefPtr<Inspector::ServiceWorkerBackendDispatcher> m_backendDispatcher;
     37    requestContentFromBackend()
     38    {
     39        return Promise.resolve({scriptSource: this._text});
     40    }
    5541};
    56 
    57 } // namespace WebCore
    58 
    59 #endif // ENABLE(SERVICE_WORKER)
  • trunk/Source/WebInspectorUI/UserInterface/Models/SourceMapResource.js

    r221891 r225709  
    141141            frameIdentifier = this._sourceMap.originalSourceCode.parentFrame.id;
    142142
    143         if (!frameIdentifier)
     143        if (!frameIdentifier && WI.frameResourceManager.mainFrame)
    144144            frameIdentifier = WI.frameResourceManager.mainFrame.id;
     145        else
     146            frameIdentifier = "";
    145147
    146148        return NetworkAgent.loadResource(frameIdentifier, this.url).then(sourceMapResourceLoaded.bind(this)).catch(sourceMapResourceLoadError.bind(this));
  • trunk/Source/WebInspectorUI/UserInterface/Models/TextRange.js

    r225568 r225709  
    5050            this._endColumn = NaN;
    5151        }
     52    }
     53
     54    // Static
     55
     56    static fromText(text)
     57    {
     58        let lines = text.split("\n");
     59        return new WI.TextRange(0, 0, lines.length - 1, lines.lastValue.length);
    5260    }
    5361
     
    153161        return this.cloneAndModify(-line, deltaStartColumn, -line, deltaEndColumn);
    154162    }
    155 
    156163};
  • trunk/Source/WebInspectorUI/UserInterface/Test.html

    r224606 r225709  
    101101    <script src="Models/TimelineRange.js"></script>
    102102    <script src="Models/TimelineRecord.js"></script>
     103
     104    <script src="Models/Resource.js"></script>
     105    <script src="Models/Script.js"></script>
     106    <script src="Models/LocalScript.js"></script>
    103107
    104108    <script src="Models/Breakpoint.js"></script>
     
    169173    <script src="Models/RecordingInitialStateAction.js"></script>
    170174    <script src="Models/RenderingFrameTimelineRecord.js"></script>
    171     <script src="Models/Resource.js"></script>
    172175    <script src="Models/ResourceCollection.js"></script>
    173176    <script src="Models/ResourceQueryMatch.js"></script>
     
    177180    <script src="Models/Revision.js"></script>
    178181    <script src="Models/ScopeChainNode.js"></script>
    179     <script src="Models/Script.js"></script>
    180182    <script src="Models/ScriptInstrument.js"></script>
    181183    <script src="Models/ScriptSyntaxTree.js"></script>
  • trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js

    r220119 r225709  
    11751175            return this._sourceCode.type === WI.Resource.Type.Document || this._sourceCode.type === WI.Resource.Type.Script;
    11761176        if (this._sourceCode instanceof WI.Script)
    1177             return true;
     1177            return !(this._sourceCode instanceof WI.LocalScript);
    11781178        return false;
    11791179    }
Note: See TracChangeset for help on using the changeset viewer.