Bug 196725

Summary: Web Inspector: REGRESSION: lazy agents used outside of frontend/instrumentation can be accessed before being created
Product: WebKit Reporter: Devin Rousso <hi>
Component: Web InspectorAssignee: Devin Rousso <hi>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, ews-watchlist, hi, inspector-bugzilla-changes, joepeck, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 195971    
Attachments:
Description Flags
Patch
none
Patch none

Description Devin Rousso 2019-04-08 21:08:19 PDT
`WebCore::InspectorFrontendClientLocal::showMainResourceForFrame` and `WebKit::WebInspector::showMainResourceForFrame` both access `WebCore::InspectorController::pageAgent`, even though the underlying `m_pageAgent` isn't instantiated until the first frontend connects.
Comment 1 Devin Rousso 2019-04-08 21:08:40 PDT
<rdar://problem/49669810>
Comment 2 Devin Rousso 2019-04-08 21:13:59 PDT
Created attachment 367025 [details]
Patch
Comment 3 Devin Rousso 2019-04-09 12:51:04 PDT
Created attachment 367064 [details]
Patch
Comment 4 Timothy Hatcher 2019-04-10 15:19:49 PDT
Comment on attachment 367064 [details]
Patch

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

> Source/WebCore/inspector/InspectorController.h:110
> -    InspectorPageAgent* pageAgent() const { return m_pageAgent; }
> +
> +    InspectorDOMAgent& ensureDOMAgent();
> +    WEBCORE_EXPORT InspectorPageAgent& ensurePageAgent();

Why not just have pageAgent() and a domAgent() getter create the agents if needed and drop the need for the ensure functions?
Comment 5 Devin Rousso 2019-04-10 15:34:53 PDT
Comment on attachment 367064 [details]
Patch

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

>> Source/WebCore/inspector/InspectorController.h:110
>> +    WEBCORE_EXPORT InspectorPageAgent& ensurePageAgent();
> 
> Why not just have pageAgent() and a domAgent() getter create the agents if needed and drop the need for the ensure functions?

I vaguely remember there being a discussion about this style on one of the webkit-* mailing lists.  I prefer the "ensure" as it makes it clearer to callers that this function might create an object, rather than just return whatever currently exists.
Comment 6 WebKit Commit Bot 2019-04-10 16:15:14 PDT
Comment on attachment 367064 [details]
Patch

Clearing flags on attachment: 367064

Committed r244167: <https://trac.webkit.org/changeset/244167>
Comment 7 WebKit Commit Bot 2019-04-10 16:15:15 PDT
All reviewed patches have been landed.  Closing bug.