Changeset 148768 in webkit


Ignore:
Timestamp:
Apr 19, 2013 2:06:03 PM (11 years ago)
Author:
Joseph Pecoraro
Message:

Web Inspector: Backend should detect sourceMappingURLs in CSS Resources
https://bugs.webkit.org/show_bug.cgi?id=114854

Source/WebCore:

Reviewed by Timothy Hatcher.

Test: http/tests/inspector/network/css-source-mapping-url.html

  • inspector/Inspector.json:
  • Page.getResourceTree - add sourceMapURL to resource payloads
  • Network.loadingFinished and Network.requestServedFromMemoryCache, include extra resource info object with possible sourceMapURL.
  • inspector/ContentSearchUtils.h:
  • inspector/ContentSearchUtils.cpp:

(WebCore::ContentSearchUtils::scriptCommentPattern):
(WebCore::ContentSearchUtils::stylesheetCommentPattern):
(WebCore::ContentSearchUtils::findMagicComment):
(WebCore::ContentSearchUtils::findScriptSourceURL):
(WebCore::ContentSearchUtils::findScriptSourceMapURL):
(WebCore::ContentSearchUtils::findStylesheetSourceMapURL):
Separate Script and Stylesheet regex pattern creation, but
share the search function using the pattern.

  • inspector/InspectorDebuggerAgent.cpp:

(WebCore::InspectorDebuggerAgent::sourceMapURLForScript):
(WebCore::InspectorDebuggerAgent::didParseSource):
Update function names. Check for the SourceMap header before
checking for a sourceMappingURL comment.

  • inspector/InspectorPageAgent.h:
  • inspector/InspectorPageAgent.cpp:

(WebCore::InspectorPageAgent::sourceMapURLForResource):
(WebCore::InspectorPageAgent::buildObjectForFrameTree):
Provide the sourceMapURL for Page.getResourceTree.

  • inspector/InspectorResourceAgent.cpp:

(WebCore::buildObjectForExtraResourceInfo):
(WebCore::buildObjectForCachedResource):
(WebCore::InspectorResourceAgent::didFinishLoading):
(WebCore::InspectorResourceAgent::didLoadResourceFromMemoryCache):
Include ExtraResourceInfo objects in finish loading and
request served from cache.

LayoutTests:

Test a different ways we would expect to see a sourceMapURL for
stylesheet resources.

Reviewed by NOBODY (OOPS!).

  • http/tests/inspector/network/css-source-mapping-url-expected.txt: Added.
  • http/tests/inspector/network/css-source-mapping-url.html: Added.
  • http/tests/inspector/network/resources/source-map-test-style.css: Added.
  • http/tests/inspector/network/resources/source-map-test-style.css.map: Added.
  • http/tests/inspector/network/resources/source-map-test-style.scss: Added.
Location:
trunk
Files:
5 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r148751 r148768  
     12013-04-19  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Backend should detect sourceMappingURLs in CSS Resources
     4        https://bugs.webkit.org/show_bug.cgi?id=114854
     5
     6        Test a different ways we would expect to see a sourceMapURL for
     7        stylesheet resources.
     8
     9        Reviewed by Timothy Hatcher.
     10
     11        * http/tests/inspector/network/css-source-mapping-url-expected.txt: Added.
     12        * http/tests/inspector/network/css-source-mapping-url.html: Added.
     13        * http/tests/inspector/network/resources/source-map-test-style.css: Added.
     14        * http/tests/inspector/network/resources/source-map-test-style.css.map: Added.
     15        * http/tests/inspector/network/resources/source-map-test-style.scss: Added.
     16
    1172013-04-19  Sudarsana Nagineni  <sudarsana.nagineni@intel.com>
    218
  • trunk/Source/WebCore/ChangeLog

    r148765 r148768  
     12013-04-19  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Backend should detect sourceMappingURLs in CSS Resources
     4        https://bugs.webkit.org/show_bug.cgi?id=114854
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        Test: http/tests/inspector/network/css-source-mapping-url.html
     9
     10        * inspector/Inspector.json:
     11        - Page.getResourceTree - add sourceMapURL to resource payloads
     12        - Network.loadingFinished and Network.requestServedFromMemoryCache,
     13          include the sourceMapURL in the results.
     14
     15        * inspector/ContentSearchUtils.h:
     16        * inspector/ContentSearchUtils.cpp:
     17        (WebCore::ContentSearchUtils::scriptCommentPattern):
     18        (WebCore::ContentSearchUtils::stylesheetCommentPattern):
     19        (WebCore::ContentSearchUtils::findMagicComment):
     20        (WebCore::ContentSearchUtils::findScriptSourceURL):
     21        (WebCore::ContentSearchUtils::findScriptSourceMapURL):
     22        (WebCore::ContentSearchUtils::findStylesheetSourceMapURL):
     23        Separate Script and Stylesheet regex pattern creation, but
     24        share the search function using the pattern.
     25
     26        * inspector/InspectorDebuggerAgent.cpp:
     27        (WebCore::InspectorDebuggerAgent::sourceMapURLForScript):
     28        (WebCore::InspectorDebuggerAgent::didParseSource):
     29        Update function names. Check for the SourceMap header before
     30        checking for a sourceMappingURL comment.
     31
     32        * inspector/InspectorPageAgent.h:
     33        * inspector/InspectorPageAgent.cpp:
     34        (WebCore::InspectorPageAgent::sourceMapURLForResource):
     35        (WebCore::InspectorPageAgent::buildObjectForFrameTree):
     36        Provide the sourceMapURL for Page.getResourceTree.
     37
     38        * inspector/InspectorResourceAgent.cpp:
     39        (WebCore::buildObjectForCachedResource):
     40        (WebCore::InspectorResourceAgent::didFinishLoading):
     41        (WebCore::InspectorResourceAgent::didLoadResourceFromMemoryCache):
     42        Include sourceMapURLs in finish loading and request served from cache.
     43
    1442013-04-19  Shawn Singh  <shawnsingh@chromium.org>
    245
  • trunk/Source/WebCore/inspector/ContentSearchUtils.cpp

    r144434 r148768  
    169169}
    170170
    171 static String findMagicComment(const String& content, const String& name)
    172 {
    173     String patternString = "//@[\040\t]" + name + "=[\040\t]*([^\\s\'\"]*)[\040\t]*$";
     171static String scriptCommentPattern(const String& name)
     172{
     173    // "//@ <name>=<value>"
     174    return "//@[\040\t]" + name + "=[\040\t]*([^\\s\'\"]*)[\040\t]*$";
     175}
     176
     177static String stylesheetCommentPattern(const String& name)
     178{
     179    // "/*@ <name>=<value> */"
     180    return "/\\*@[\040\t]" + name + "=[\040\t]*([^\\s\'\"]*)[\040\t]*\\*/";
     181}
     182
     183static String findMagicComment(const String& content, const String& patternString)
     184{
    174185    const char* error = 0;
    175186    JSC::Yarr::YarrPattern pattern(patternString, false, true, &error);
     
    189200}
    190201
    191 String findSourceURL(const String& content)
    192 {
    193     return findMagicComment(content, "sourceURL");
    194 }
    195 
    196 String findSourceMapURL(const String& content)
    197 {
    198     return findMagicComment(content, "sourceMappingURL");
     202String findScriptSourceURL(const String& content)
     203{
     204    return findMagicComment(content, scriptCommentPattern("sourceURL"));
     205}
     206
     207String findScriptSourceMapURL(const String& content)
     208{
     209    return findMagicComment(content, scriptCommentPattern("sourceMappingURL"));
     210}
     211
     212String findStylesheetSourceMapURL(const String& content)
     213{
     214    return findMagicComment(content, stylesheetCommentPattern("sourceMappingURL"));
    199215}
    200216
  • trunk/Source/WebCore/inspector/ContentSearchUtils.h

    r144434 r148768  
    5050PassOwnPtr<Vector<size_t> > lineEndings(const String&);
    5151
    52 String findSourceURL(const String& content);
    53 String findSourceMapURL(const String& content);
     52String findScriptSourceURL(const String& content);
     53String findScriptSourceMapURL(const String& content);
     54String findStylesheetSourceMapURL(const String& content);
    5455
    5556} // namespace ContentSearchUtils
  • trunk/Source/WebCore/inspector/Inspector.json

    r148723 r148768  
    136136                                { "name": "mimeType", "type": "string", "description": "Resource mimeType as determined by the browser." },
    137137                                { "name": "failed", "type": "boolean", "optional": true, "description": "True if the resource failed to load." },
    138                                 { "name": "canceled", "type": "boolean", "optional": true, "description": "True if the resource was canceled during loading." }
     138                                { "name": "canceled", "type": "boolean", "optional": true, "description": "True if the resource was canceled during loading." },
     139                                { "name": "sourceMapURL", "type": "string", "optional": true, "description": "URL of source map associated with this resource (if any)." }
    139140                            ]
    140141                        },
     
    976977                    { "name": "type", "$ref": "Page.ResourceType", "description": "Type of this resource." },
    977978                    { "name": "response", "$ref": "Response", "optional": true, "description": "Cached response data." },
    978                     { "name": "bodySize", "type": "number", "description": "Cached response body size." }
     979                    { "name": "bodySize", "type": "number", "description": "Cached response body size." },
     980                    { "name": "sourceMapURL", "type": "string", "optional": true, "description": "URL of source map associated with this resource (if any)." }
    979981                ]
    980982            },
     
    11121114                "parameters": [
    11131115                    { "name": "requestId", "$ref": "RequestId", "description": "Request identifier." },
    1114                     { "name": "timestamp", "$ref": "Timestamp", "description": "Timestamp." }
     1116                    { "name": "timestamp", "$ref": "Timestamp", "description": "Timestamp." },
     1117                    { "name": "sourceMapURL", "type": "string", "optional": true, "description": "URL of source map associated with this resource (if any)." }
    11151118                ]
    11161119            },
  • trunk/Source/WebCore/inspector/InspectorDebuggerAgent.cpp

    r147962 r148768  
    633633String InspectorDebuggerAgent::sourceMapURLForScript(const Script& script)
    634634{
    635     DEFINE_STATIC_LOCAL(String, sourceMapHttpHeader, (ASCIILiteral("X-SourceMap")));
    636 
    637     String sourceMapURL = ContentSearchUtils::findSourceMapURL(script.source);
    638     if (!sourceMapURL.isEmpty())
    639         return sourceMapURL;
    640 
    641     if (script.url.isEmpty())
    642         return String();
    643 
    644     InspectorPageAgent* pageAgent = m_instrumentingAgents->inspectorPageAgent();
    645     if (!pageAgent)
    646         return String();
    647 
    648     CachedResource* resource = pageAgent->cachedResource(pageAgent->mainFrame(), KURL(ParsedURLString, script.url));
    649     if (resource)
    650         return resource->response().httpHeaderField(sourceMapHttpHeader);
    651     return String();
     635    DEFINE_STATIC_LOCAL(String, sourceMapHTTPHeader, (ASCIILiteral("X-SourceMap")));
     636
     637    if (!script.url.isEmpty()) {
     638        if (InspectorPageAgent* pageAgent = m_instrumentingAgents->inspectorPageAgent()) {
     639            CachedResource* resource = pageAgent->cachedResource(pageAgent->mainFrame(), KURL(ParsedURLString, script.url));
     640            if (resource) {
     641                String sourceMapHeader = resource->response().httpHeaderField(sourceMapHTTPHeader);
     642                if (!sourceMapHeader.isEmpty())
     643                    return sourceMapHeader;
     644            }
     645        }
     646    }
     647
     648    return ContentSearchUtils::findScriptSourceMapURL(script.source);
    652649}
    653650
     
    662659    String sourceURL;
    663660    if (!script.startLine && !script.startColumn)
    664         sourceURL = ContentSearchUtils::findSourceURL(script.source);
     661        sourceURL = ContentSearchUtils::findScriptSourceURL(script.source);
    665662    bool hasSourceURL = !sourceURL.isEmpty();
    666663    String scriptURL = hasSourceURL ? sourceURL : script.url;
  • trunk/Source/WebCore/inspector/InspectorPageAgent.cpp

    r148373 r148768  
    268268}
    269269
     270//static
     271String InspectorPageAgent::sourceMapURLForResource(CachedResource* cachedResource)
     272{
     273    DEFINE_STATIC_LOCAL(String, sourceMapHTTPHeader, (ASCIILiteral("X-SourceMap")));
     274
     275    if (!cachedResource)
     276        return String();
     277
     278    // Scripts are handled in a separate path.
     279    if (cachedResource->type() != CachedResource::CSSStyleSheet)
     280        return String();
     281
     282    String sourceMapHeader = cachedResource->response().httpHeaderField(sourceMapHTTPHeader);
     283    if (!sourceMapHeader.isEmpty())
     284        return sourceMapHeader;
     285
     286    String content;
     287    bool base64Encoded;
     288    if (InspectorPageAgent::cachedResourceContent(cachedResource, &content, &base64Encoded) && !base64Encoded)
     289        return ContentSearchUtils::findStylesheetSourceMapURL(content);
     290
     291    return String();
     292}
     293
    270294CachedResource* InspectorPageAgent::cachedResource(Frame* frame, const KURL& url)
    271295{
     
    11151139        else if (cachedResource->status() == CachedResource::LoadError)
    11161140            resourceObject->setFailed(true);
     1141        String sourceMappingURL = InspectorPageAgent::sourceMapURLForResource(cachedResource);
     1142        if (!sourceMappingURL.isEmpty())
     1143            resourceObject->setSourceMapURL(sourceMappingURL);
    11171144        subresources->addItem(resourceObject);
    11181145    }
  • trunk/Source/WebCore/inspector/InspectorPageAgent.h

    r148545 r148768  
    8787    static bool sharedBufferContent(PassRefPtr<SharedBuffer>, const String& textEncodingName, bool withBase64Encode, String* result);
    8888    static void resourceContent(ErrorString*, Frame*, const KURL&, String* result, bool* base64Encoded);
     89    static String sourceMapURLForResource(CachedResource*);
    8990
    9091    static PassRefPtr<SharedBuffer> resourceData(Frame*, const KURL&, String* textEncodingName);
  • trunk/Source/WebCore/inspector/InspectorResourceAgent.cpp

    r148256 r148768  
    168168}
    169169
    170 static PassRefPtr<TypeBuilder::Network::CachedResource> buildObjectForCachedResource(const CachedResource& cachedResource, DocumentLoader* loader)
     170static PassRefPtr<TypeBuilder::Network::CachedResource> buildObjectForCachedResource(CachedResource* cachedResource, DocumentLoader* loader)
    171171{
    172172    RefPtr<TypeBuilder::Network::CachedResource> resourceObject = TypeBuilder::Network::CachedResource::create()
    173         .setUrl(cachedResource.url())
    174         .setType(InspectorPageAgent::cachedResourceTypeJson(cachedResource))
    175         .setBodySize(cachedResource.encodedSize());
    176     RefPtr<TypeBuilder::Network::Response> resourceResponse = buildObjectForResourceResponse(cachedResource.response(), loader);
     173        .setUrl(cachedResource->url())
     174        .setType(InspectorPageAgent::cachedResourceTypeJson(*cachedResource))
     175        .setBodySize(cachedResource->encodedSize());
     176
     177    RefPtr<TypeBuilder::Network::Response> resourceResponse = buildObjectForResourceResponse(cachedResource->response(), loader);
    177178    if (resourceResponse)
    178179        resourceObject->setResponse(resourceResponse);
     180
     181    String sourceMappingURL = InspectorPageAgent::sourceMapURLForResource(cachedResource);
     182    if (!sourceMappingURL.isEmpty())
     183        resourceObject->setSourceMapURL(sourceMappingURL);
     184
    179185    return resourceObject;
    180186}
     
    293299        finishTime = currentTime();
    294300
    295     m_frontend->loadingFinished(requestId, finishTime);
     301    String sourceMappingURL;
     302    NetworkResourcesData::ResourceData const* resourceData = m_resourcesData->data(requestId);
     303    if (resourceData && resourceData->cachedResource())
     304        sourceMappingURL = InspectorPageAgent::sourceMapURLForResource(resourceData->cachedResource());
     305
     306    m_frontend->loadingFinished(requestId, finishTime, !sourceMappingURL.isEmpty() ? &sourceMappingURL : 0);
    296307}
    297308
     
    328339    RefPtr<TypeBuilder::Network::Initiator> initiatorObject = buildInitiatorObject(loader->frame() ? loader->frame()->document() : 0);
    329340
    330     m_frontend->requestServedFromMemoryCache(requestId, frameId, loaderId, loader->url().string(), currentTime(), initiatorObject, buildObjectForCachedResource(*resource, loader));
     341    m_frontend->requestServedFromMemoryCache(requestId, frameId, loaderId, loader->url().string(), currentTime(), initiatorObject, buildObjectForCachedResource(resource, loader));
    331342}
    332343
Note: See TracChangeset for help on using the changeset viewer.