Bug 99941

Summary: Web Inspector: Pipe requests through to Inspector in order to add "initiator" links to messages.
Product: WebKit Reporter: Mike West <mkwst>
Component: Web Inspector (Deprecated)Assignee: Mike West <mkwst>
Status: RESOLVED FIXED    
Severity: Normal CC: apavlov, keishi, loislo, pfeldman, pmuellr, vsevik, web-inspector-bugs, webkit.review.bot, yurys
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 100735    
Attachments:
Description Flags
Adding a new 'addMessageToConsole' method.
none
How usage might look.
none
Patch
none
Patch
none
Patch
none
Patch for landing none

Description Mike West 2012-10-21 11:17:16 PDT
Messages associated with requests can generally be improved by linking to the point at which the message was generated. I had a quick conversation with Pavel about this, he suggested to file a bug to continue the discussion.

As an example, the mixed content warning "The page at XXX displayed insecure content from YYY." should link off to the element or code snippet that caused the insecure resource to load (see https://mkw.st/p/mixed/ for an example of the current state).  This will be partially resolved with 97979, which adds a call stack when relevant, but won't help when the resource is loaded by the parser. If no call stack is present, it would make sense to use that space to link to the request's initiator.

I've dug around a bit to see how this might work. The only place I've found that creates a console message with a requestID set is the mixed MIME type error from inside the inspector (NetworkManager.js:191). Is there a mechanism to bind requests and console messages together when creating the message from WebCore?

If not, I think the best I can do is to do a 'resourceForURL' lookup for every URL I see in the message, which seems error-prone.

WDYT?
Comment 1 Pavel Feldman 2012-10-23 09:26:16 PDT
See ConsoleMessage.cpp:148, it does:

jsonObj->setNetworkRequestId(m_requestId)
Comment 2 Mike West 2012-10-26 05:44:20 PDT
(In reply to comment #1)
> See ConsoleMessage.cpp:148, it does:
> 
> jsonObj->setNetworkRequestId(m_requestId)

Got it, thanks! At the moment, the only mechanisms to pass a request identifier into the inspector seems to be ' InspectorConsoleAgent::didFinishXHRLoading', 'InspectorConsoleAgent::didReceiveResponse', and 'InspectorConsoleAgent::didFailLoading'.

I'd like to expose a new variant of 'addMessageToConsole' to allow passing a request identifier in from various other points in WebCore. I'll spin up a strawman patch for discussion soonish.
Comment 3 Mike West 2012-10-26 07:19:05 PDT
Created attachment 170919 [details]
Adding a new 'addMessageToConsole' method.
Comment 4 Mike West 2012-10-26 07:19:28 PDT
Comment on attachment 170919 [details]
Adding a new 'addMessageToConsole' method.

Not for landing, but a strawman of how this might look.
Comment 5 Mike West 2012-10-26 07:20:08 PDT
Created attachment 170920 [details]
How usage might look.

Again, not for landing, but an example of how the new addToConsole method might be useful.
Comment 6 Pavel Feldman 2012-10-29 01:31:00 PDT
Comment on attachment 170919 [details]
Adding a new 'addMessageToConsole' method.

View in context: https://bugs.webkit.org/attachment.cgi?id=170919&action=review

> Source/WebCore/page/Console.h:58
> +    void addMessage(MessageSource, MessageType, MessageLevel, const String& message, const String& sourceURL = String(), unsigned lineNumber = 0, PassRefPtr<ScriptCallStack> = 0, unsigned long identifier = 0);

requestIdentifier?

> Source/WebCore/page/Console.h:60
> +    void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned long identifier, const String& url);

Why do we need this one? Is this convenience method? It sounds like its arguments fall into a subset of the one you are adjusting above.
Comment 7 Mike West 2012-10-29 01:33:15 PDT
(In reply to comment #6)
> (From update of attachment 170919 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=170919&action=review
> 
> > Source/WebCore/page/Console.h:58
> > +    void addMessage(MessageSource, MessageType, MessageLevel, const String& message, const String& sourceURL = String(), unsigned lineNumber = 0, PassRefPtr<ScriptCallStack> = 0, unsigned long identifier = 0);
> 
> requestIdentifier?

Yup. That's a better name.

> 
> > Source/WebCore/page/Console.h:60
> > +    void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned long identifier, const String& url);
> 
> Why do we need this one? Is this convenience method? It sounds like its arguments fall into a subset of the one you are adjusting above.

Just convenience. It seemed reasonable to have a separate method for resource-related console messages for the same reasons it's nice to have a separate method for url/line-number and stacktrace messages.
Comment 8 Pavel Feldman 2012-10-29 01:35:21 PDT
Comment on attachment 170919 [details]
Adding a new 'addMessageToConsole' method.

View in context: https://bugs.webkit.org/attachment.cgi?id=170919&action=review

>>> Source/WebCore/page/Console.h:60
>>> +    void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned long identifier, const String& url);
>> 
>> Why do we need this one? Is this convenience method? It sounds like its arguments fall into a subset of the one you are adjusting above.
> 
> Just convenience. It seemed reasonable to have a separate method for resource-related console messages for the same reasons it's nice to have a separate method for url/line-number and stacktrace messages.

You don't need another Instrumentation method then - we only want such convenience for the call sites, not inside the inspector guts.
Comment 9 Mike West 2012-10-29 01:39:05 PDT
(In reply to comment #8)
> (From update of attachment 170919 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=170919&action=review
> 
> >>> Source/WebCore/page/Console.h:60
> >>> +    void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned long identifier, const String& url);
> >> 
> >> Why do we need this one? Is this convenience method? It sounds like its arguments fall into a subset of the one you are adjusting above.
> > 
> > Just convenience. It seemed reasonable to have a separate method for resource-related console messages for the same reasons it's nice to have a separate method for url/line-number and stacktrace messages.
> 
> You don't need another Instrumentation method then - we only want such convenience for the call sites, not inside the inspector guts.

You're right; this would be covered by the new method on Document. I'll spin a new patch.
Comment 10 Mike West 2012-10-29 02:36:50 PDT
(In reply to comment #9)
> (In reply to comment #8)
> > (From update of attachment 170919 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=170919&action=review
> > 
> > >>> Source/WebCore/page/Console.h:60
> > >>> +    void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned long identifier, const String& url);
> > >> 
> > >> Why do we need this one? Is this convenience method? It sounds like its arguments fall into a subset of the one you are adjusting above.
> > > 
> > > Just convenience. It seemed reasonable to have a separate method for resource-related console messages for the same reasons it's nice to have a separate method for url/line-number and stacktrace messages.
> > 
> > You don't need another Instrumentation method then - we only want such convenience for the call sites, not inside the inspector guts.
> 
> You're right; this would be covered by the new method on Document. I'll spin a new patch.

Actually, now that I look at the Instrumentation code again, I'm not sure I understand your suggestion.

Currently, we have two InspectorInstrumentation::addMessageToConsole methods: one for line numbered messages, and one for stack traces (well, four, since those two are replicated for workers). This patch adds another for request identifiers.

Are you suggesting that those should be combined into one method that accepts all relevant arguments, and decides which ConsoleMessage to construct based upon the given parameters?
Comment 11 Mike West 2012-10-29 04:40:37 PDT
Created attachment 171204 [details]
Patch
Comment 12 Mike West 2012-10-29 04:42:53 PDT
After a bit of discussion with Pavel (thanks!), I've cleaned up this patch, and updated 'InspectorConsoleAgent::didFinishXHRLoading', 'InspectorConsoleAgent::didReceiveResponse', and 'InspectorConsoleAgent::didFailLoading' to use the new parameter on 'addMessageToConsole' rather than replicating the work themselves. That should test that the existing functionality works as expected.

I'll repurpose 97979 to use this functionality once it lands, which will still more or less look like https://bugs.webkit.org/attachment.cgi?id=170920.

WDYT?
Comment 13 Pavel Feldman 2012-10-29 04:48:37 PDT
Comment on attachment 171204 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=171204&action=review

> Source/WebCore/dom/ScriptExecutionContext.h:86
> +    void addConsoleMessage(MessageSource, MessageType, MessageLevel, const String& message, const String& sourceURL = String(), unsigned lineNumber = 0, PassRefPtr<ScriptCallStack> = 0, unsigned long requestIdentifier = 0);

Are there any immediate clients for this one?

> Source/WebCore/inspector/InspectorConsoleAgent.cpp:159
> +    String requestId = requestIdentifier ? IdentifiersFactory::requestId(requestIdentifier) : String();

You could push this further and make ConsoleMessage constructor accept unsigned long. You would be able to leave more code below as is then.
Comment 14 Mike West 2012-10-29 05:04:35 PDT
(In reply to comment #13)
> (From update of attachment 171204 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=171204&action=review
> 
> > Source/WebCore/dom/ScriptExecutionContext.h:86
> > +    void addConsoleMessage(MessageSource, MessageType, MessageLevel, const String& message, const String& sourceURL = String(), unsigned lineNumber = 0, PassRefPtr<ScriptCallStack> = 0, unsigned long requestIdentifier = 0);
> 
> Are there any immediate clients for this one?

No. I'll need to do some work in the callers to pipe a request identifier in. I'm happy to drop it from the patch and add it in with a client if that's something you'd like to see.

> 
> > Source/WebCore/inspector/InspectorConsoleAgent.cpp:159
> > +    String requestId = requestIdentifier ? IdentifiersFactory::requestId(requestIdentifier) : String();
> 
> You could push this further and make ConsoleMessage constructor accept unsigned long. You would be able to leave more code below as is then.

That makes sense. I'll make this change.
Comment 15 Mike West 2012-10-29 05:40:38 PDT
Created attachment 171210 [details]
Patch
Comment 16 Mike West 2012-10-29 05:42:54 PDT
(In reply to comment #14)

> > > Source/WebCore/inspector/InspectorConsoleAgent.cpp:159
> > > +    String requestId = requestIdentifier ? IdentifiersFactory::requestId(requestIdentifier) : String();
> > 
> > You could push this further and make ConsoleMessage constructor accept unsigned long. You would be able to leave more code below as is then.
> 
> That makes sense. I'll make this change.

I've made half of this change. :)  I pushed the IdentifiersFactory::requestId call down into ConsoleMessage (and adjusted it to return an empty string if provided with 0 as an ID to obviate the 'if' here). I haven't, however, reverted the changes to call addMessageToConsole. It makes more sense to me to centralize the logic about which ConsoleMessage to create in that method, rather than spreading it out over these three. These methods generate a message, but I think they should hand off to the existing method to push it to the console.

WDYT?
Comment 17 Mike West 2012-10-30 03:07:16 PDT
(In reply to comment #14)
> (In reply to comment #13)
> > (From update of attachment 171204 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=171204&action=review
> > 
> > > Source/WebCore/dom/ScriptExecutionContext.h:86
> > > +    void addConsoleMessage(MessageSource, MessageType, MessageLevel, const String& message, const String& sourceURL = String(), unsigned lineNumber = 0, PassRefPtr<ScriptCallStack> = 0, unsigned long requestIdentifier = 0);
> > 
> > Are there any immediate clients for this one?
> 
> No. I'll need to do some work in the callers to pipe a request identifier in. I'm happy to drop it from the patch and add it in with a client if that's something you'd like to see.

There's now a client of this change in 100735. Would you like me to move the ScriptExecutionContext/Document changes into that patch, or are you ok with landing this patch as-is?
Comment 18 Pavel Feldman 2012-10-30 04:41:09 PDT
Comment on attachment 171210 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=171210&action=review

> Source/WebCore/inspector/InspectorConsoleAgent.cpp:159
> +    String requestId = requestIdentifier ? IdentifiersFactory::requestId(requestIdentifier) : String();

You don't need it anymore?

> Source/WebCore/inspector/InspectorConsoleAgent.cpp:167
> +    String requestId = requestIdentifier ? IdentifiersFactory::requestId(requestIdentifier) : String();

ditto
Comment 19 Mike West 2012-10-30 05:20:58 PDT
Created attachment 171423 [details]
Patch
Comment 20 Mike West 2012-10-30 05:22:16 PDT
Created attachment 171424 [details]
Patch for landing
Comment 21 WebKit Review Bot 2012-10-30 09:56:29 PDT
Comment on attachment 171424 [details]
Patch for landing

Clearing flags on attachment: 171424

Committed r132918: <http://trac.webkit.org/changeset/132918>
Comment 22 WebKit Review Bot 2012-10-30 09:56:34 PDT
All reviewed patches have been landed.  Closing bug.