Bug 135120

Summary: Web Inspector: the inspector should live in its own process
Product: WebKit Reporter: Brian Burg <burg>
Component: Web InspectorAssignee: Timothy Hatcher <timothy>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, bfulgham, buildbot, cdumez, commit-queue, graouts, gyuyoung.kim, joepeck, mkwst, ossy, rakuco, rniwa, ryuan.choi, sam, sergio, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Bug Depends on: 137522    
Bug Blocks: 135830, 136350    
Attachments:
Description Flags
WIP
none
WIP (correct)
none
WIP (latest)
none
WIP (almost final)
none
WIP (almost final x2)
none
WIP (almost final x3)
none
WIP (almost final x4)
buildbot: commit-queue-
Archive of layout-test-results from webkit-ews-08 for mac-mountainlion
none
WIP (latest final)
none
WIP (For Bots)
none
WIP (Rebased For Bots)
none
WIP (Binary Patch)
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch andersca: review+, andersca: commit-queue-

Description Brian Burg 2014-07-21 10:10:02 PDT
It would be approximately way easier to profile if it were isolated from the inspected page's Web Content process.
Comment 1 Radar WebKit Bug Importer 2014-07-21 10:10:45 PDT
<rdar://problem/17748414>
Comment 2 Timothy Hatcher 2014-07-22 11:51:56 PDT
Internal dupe of <rdar://problem/11749409>.
Comment 3 Timothy Hatcher 2014-08-28 14:49:19 PDT
I am working on this.
Comment 4 Timothy Hatcher 2014-09-04 22:56:47 PDT
Created attachment 237676 [details]
WIP
Comment 5 Timothy Hatcher 2014-09-04 22:58:18 PDT
Created attachment 237677 [details]
WIP (correct)
Comment 6 Timothy Hatcher 2014-09-05 17:34:42 PDT
Created attachment 237727 [details]
WIP (latest)
Comment 7 Brian Burg 2014-09-05 18:05:04 PDT
Comment on attachment 237727 [details]
WIP (latest)

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

Looks pretty slick overall. Seeking some clarification on the code path for GTK/EFL: does it change at all? Some of the messages looked deleted but I didn't see any updates to the other platform-specific files.

> Source/WebCore/inspector/InspectorController.cpp:198
> +void InspectorController::setInspectorFrontendClient(InspectorFrontendClient* inspectorFrontendClient)

Before, the Controller owned the client. Who owns it now? Can this pass a reference?

> Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm:-137
> -    , m_frontendClient(0)

This should still be initialized to nullptr, right?

> Source/WebKit2/UIProcess/WebInspectorProxy.cpp:110
>          pageGroup->preferences().setLogsPageMessagesToSystemConsoleEnabled(true);

Can you update the comment above this to mean "developers can inspector the inspector in debug mode _without changing any settings_" ? AFAICT, that's what it does.

> Source/WebKit2/WebProcess/WebPage/WebInspector.cpp:1
>  /*

Per the naming conventions, files that implement the InspectorProcess probably should be in Source/WebKit2/InspectorProcess/* not in WebProcess.

> Source/WebKit2/WebProcess/WebPage/WebInspectorUI.cpp:30
> +#include "WebPage.h"

newline after ENABLE(...)
Comment 8 Timothy Hatcher 2014-09-05 18:44:50 PDT
Comment on attachment 237727 [details]
WIP (latest)

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

>> Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm:-137
>> -    , m_frontendClient(0)
> 
> This should still be initialized to nullptr, right?

It was removed. They aren't in the same process anymore.

>> Source/WebKit2/UIProcess/WebInspectorProxy.cpp:110
>>          pageGroup->preferences().setLogsPageMessagesToSystemConsoleEnabled(true);
> 
> Can you update the comment above this to mean "developers can inspector the inspector in debug mode _without changing any settings_" ? AFAICT, that's what it does.

Sure.

>> Source/WebKit2/WebProcess/WebPage/WebInspector.cpp:1
>>  /*
> 
> Per the naming conventions, files that implement the InspectorProcess probably should be in Source/WebKit2/InspectorProcess/* not in WebProcess.

They are in WebProcess, just two different web processes now.
Comment 9 Timothy Hatcher 2014-09-05 18:53:37 PDT
Comment on attachment 237727 [details]
WIP (latest)

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

>>> Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm:-137
>>> -    , m_frontendClient(0)
>> 
>> This should still be initialized to nullptr, right?
> 
> It was removed. They aren't in the same process anymore.

Oh, this is WK1. m_frontendClient is a unique_ptr now which defaults to nullptr.
Comment 10 Timothy Hatcher 2014-09-05 18:55:25 PDT
Comment on attachment 237727 [details]
WIP (latest)

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

>> Source/WebCore/inspector/InspectorController.cpp:198
>> +void InspectorController::setInspectorFrontendClient(InspectorFrontendClient* inspectorFrontendClient)
> 
> Before, the Controller owned the client. Who owns it now? Can this pass a reference?

The higher level objects in WK2 and WK1 own it now with a lifetime of the Page. It might be possible to pass as a reference, but it needs to be nullable.
Comment 11 Timothy Hatcher 2014-09-08 11:32:47 PDT
Created attachment 237798 [details]
WIP (almost final)

Posting to let EWS try things while I look into a layout test hang.
Comment 12 WebKit Commit Bot 2014-09-08 11:35:05 PDT
Attachment 237798 [details] did not pass style-queue:


ERROR: Source/WebKit2/WebProcess/WebPage/WebInspectorUI.cpp:32:  Alphabetical sorting problem.  [build/include_order] [4]
ERROR: Source/WebKit2/WebProcess/WebPage/WebInspectorUI.cpp:39:  Alphabetical sorting problem.  [build/include_order] [4]
ERROR: Source/WebKit2/WebProcess/WebPage/WebInspectorUI.cpp:42:  Alphabetical sorting problem.  [build/include_order] [4]
ERROR: Source/WebKit2/WebProcess/WebPage/WebInspectorUI.cpp:145:  Declaration has space between type name and * in const char *sideString  [whitespace/declaration] [3]
ERROR: Source/WebKit2/WebProcess/WebPage/WebInspectorUI.h:39:  Should have a space between // and comment  [whitespace/comments] [4]
ERROR: Source/WebCore/WebCore.exp.in:0:  Source/WebCore/WebCore.exp.in should be sorted, use Tools/Scripts/sort-export-file script  [list/order] [5]
Total errors found: 6 in 38 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 13 Timothy Hatcher 2014-09-08 12:31:38 PDT
Created attachment 237803 [details]
WIP (almost final x2)
Comment 14 Timothy Hatcher 2014-09-08 13:08:49 PDT
Created attachment 237806 [details]
WIP (almost final x3)
Comment 15 Timothy Hatcher 2014-09-08 16:37:33 PDT
Created attachment 237818 [details]
WIP (almost final x4)
Comment 16 Build Bot 2014-09-08 19:29:06 PDT
Comment on attachment 237818 [details]
WIP (almost final x4)

Attachment 237818 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/5085997704413184

New failing tests:
http/tests/xmlhttprequest/access-control-repeated-failed-preflight-crash.html
Comment 17 Build Bot 2014-09-08 19:29:12 PDT
Created attachment 237830 [details]
Archive of layout-test-results from webkit-ews-08 for mac-mountainlion

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: webkit-ews-08  Port: mac-mountainlion  Platform: Mac OS X 10.8.5
Comment 18 Timothy Hatcher 2014-09-12 10:29:31 PDT
Created attachment 238037 [details]
WIP (latest final)
Comment 19 Brian Burg 2014-09-12 23:21:37 PDT
Comment on attachment 238037 [details]
WIP (latest final)

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

Will look at this more later, but some quick comments:

* Missing ChangeLogs.
* Many tests in LayoutTests/inspector/ will crash under WK1 if you force them to run. This is a regression.
* Saving resources seems to work, but it names the downloaded files as "Unknown". Is this a regression?

> Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp:185
> +    // Set a default sizes based on InspectorFrontendClientLocal.

grammar.
Comment 20 Brian Burg 2014-09-13 11:26:27 PDT
It would also be nice to name the inspector process something different from com.apple.WebKit.WebContent[.Development] so that different web processes can be easily distinguished from Xcode.
Comment 21 Brian Burg 2014-09-13 15:58:57 PDT
Looks like Safari expects some symbols that were removed in this patch. Maybe these should be stubbed out and deprecated until Safari no longer uses them.

dyld: lazy symbol binding failed: Symbol not found: _WKInspectorIsProfilingJavaScript
  Referenced from: /System/Library/StagedFrameworks/Safari/Safari.framework/Versions/A/Safari
  Expected in: /Users/burg/repos/replay-staging/OpenSource/WebKitBuild/Debug/WebKit2.framework/Versions/A/WebKit2
Comment 22 Brian Burg 2014-09-13 16:42:30 PDT
(In reply to comment #21)
> Looks like Safari expects some symbols that were removed in this patch. Maybe these should be stubbed out and deprecated until Safari no longer uses them.
> 
> dyld: lazy symbol binding failed: Symbol not found: _WKInspectorIsProfilingJavaScript
>   Referenced from: /System/Library/StagedFrameworks/Safari/Safari.framework/Versions/A/Safari
>   Expected in: /Users/burg/repos/replay-staging/OpenSource/WebKitBuild/Debug/WebKit2.framework/Versions/A/WebKit2

To clarify, this happens when you open the Develop menu in Safari launched from `run-safari`.

Another bug (which I'll have to unapply the patch to get around, for now): the `pagehide` event is not getting fired when the inspector closes, so breakpoints and the current view state are not being persisted across reopening the inspector.
Comment 23 Timothy Hatcher 2014-09-13 18:27:59 PDT
(In reply to comment #20)
> It would also be nice to name the inspector process something different from com.apple.WebKit.WebContent[.Development] so that different web processes can be easily distinguished from Xcode.

Joe and I talked about this too. One issue is we are not guaranteed to be in our own process. Safari sets the process limit to 20. We should force our own process that all inspectors share, then we can name it properly.
Comment 24 Timothy Hatcher 2014-09-13 18:28:46 PDT
(In reply to comment #21)
> Looks like Safari expects some symbols that were removed in this patch. Maybe these should be stubbed out and deprecated until Safari no longer uses them.
> 
> dyld: lazy symbol binding failed: Symbol not found: _WKInspectorIsProfilingJavaScript
>   Referenced from: /System/Library/StagedFrameworks/Safari/Safari.framework/Versions/A/Safari
>   Expected in: /Users/burg/repos/replay-staging/OpenSource/WebKitBuild/Debug/WebKit2.framework/Versions/A/WebKit2

Oops. Yeah, we need to stub those out.
Comment 25 Timothy Hatcher 2014-09-13 18:33:15 PDT
(In reply to comment #22)
> Another bug (which I'll have to unapply the patch to get around, for now): the `pagehide` event is not getting fired when the inspector closes, so breakpoints and the current view state are not being persisted across reopening the inspector.

I thought Joe was having issues with page hide not firing already?
Comment 26 Brian Burg 2014-09-13 20:14:24 PDT
(In reply to comment #25)
> (In reply to comment #22)
> > Another bug (which I'll have to unapply the patch to get around, for now): the `pagehide` event is not getting fired when the inspector closes, so breakpoints and the current view state are not being persisted across reopening the inspector.
> 
> I thought Joe was having issues with page hide not firing already?

I recall some discussion about this, but can't find a bug. And, it is definitely a regression with this patch applied vs not.
Comment 27 Joseph Pecoraro 2014-09-15 11:12:35 PDT
(In reply to comment #26)
> (In reply to comment #25)
> > (In reply to comment #22)
> > > Another bug (which I'll have to unapply the patch to get around, for now): the `pagehide` event is not getting fired when the inspector closes, so breakpoints and the current view state are not being persisted across reopening the inspector.
> > 
> > I thought Joe was having issues with page hide not firing already?
> 
> I recall some discussion about this, but can't find a bug. And, it is definitely a regression with this patch applied vs not.

In my last tip of tree build page hide events were working as expected. Were you still seeing issues? That will certainly affect state restoration as well.
Comment 28 Timothy Hatcher 2014-09-21 11:15:54 PDT
Created attachment 238427 [details]
WIP (For Bots)

This version passes inspector and inspector-protocol tests. Still need ChangeLogs, then I will post it for review. Checking EWS first.
Comment 29 Brian Burg 2014-09-21 12:03:37 PDT
Comment on attachment 238427 [details]
WIP (For Bots)

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

> Source/WebInspectorUI/UserInterface/Protocol/InspectorFrontendAPI.js:127
> +        console.assert(InspectorFrontendAPI[methodName], "Unexpected InspectorFrontendAPI method name: " + InspectorFrontendAPI[methodName]);

I wish we could do:

if (!console.assert(pred, ...))
    return;

But this would require some more intelligent rewriting to strip console assertions.
Comment 30 Timothy Hatcher 2014-09-21 13:18:47 PDT
Created attachment 238430 [details]
WIP (Rebased For Bots)
Comment 31 Brian Burg 2014-09-21 16:05:30 PDT
Comment on attachment 238430 [details]
WIP (Rebased For Bots)

"Binary files a/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js and b/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js differ"

^-- this is causing the patch to not apply. What diff command are you using? I've never had this problem using `Tools/Scripts/webkit-patch upload`
Comment 32 Timothy Hatcher 2014-09-21 16:09:32 PDT
Created attachment 238437 [details]
WIP (Binary Patch)
Comment 33 WebKit Commit Bot 2014-09-21 16:10:46 PDT
Attachment 238437 [details] did not pass style-queue:


ERROR: Source/WebKit2/UIProcess/WebInspectorProxy.cpp:351:  Missing space before {  [whitespace/braces] [5]
Total errors found: 1 in 52 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 34 Timothy Hatcher 2014-09-21 20:06:47 PDT
Created attachment 238446 [details]
Patch
Comment 35 Timothy Hatcher 2014-09-21 20:18:27 PDT
This will need a WebKIt2 owner review.
Comment 36 Brian Burg 2014-09-21 20:35:52 PDT
Comment on attachment 238446 [details]
Patch

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

> Source/WebKit2/ChangeLog:108
> +        Stop taking an optional InspectorFrontendChannel and be it directly. Create a connection that can

'be it'
Comment 37 Timothy Hatcher 2014-09-21 23:56:24 PDT
Created attachment 238454 [details]
Patch
Comment 38 Timothy Hatcher 2014-09-22 08:01:54 PDT
Created attachment 238483 [details]
Patch
Comment 39 Timothy Hatcher 2014-09-22 15:14:21 PDT
Created attachment 238499 [details]
Patch
Comment 40 Timothy Hatcher 2014-09-22 16:27:32 PDT
Created attachment 238503 [details]
Patch
Comment 41 Anders Carlsson 2014-09-24 09:59:27 PDT
Comment on attachment 238503 [details]
Patch

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

> Source/WebCore/testing/Internals.cpp:1495
> +    m_frontendWindow.clear();

This should use = nullptr.

> Source/WebKit2/UIProcess/API/C/WKInspector.cpp:177
> -bool WKInspectorIsDebuggingJavaScript(WKInspectorRef inspectorRef)
> +bool WKInspectorIsDebuggingJavaScript(WKInspectorRef)

As discussed, these should move to WKDeprecatedFunctions.

> Source/WebKit2/UIProcess/WebInspectorProxy.cpp:359
> +    static std::once_flag onceFlag;
> +    static LazyNeverDestroyed<RefPtr<WebContext>> context;
> +
> +    std::call_once(onceFlag, [] {
> +        WebContextConfiguration configuration;
> +        WebContext::applyPlatformSpecificConfigurationDefaults(configuration);
> +        context.construct(WebContext::create(configuration));
> +        context.get()->setProcessModel(ProcessModelMultipleSecondaryProcesses);
> +    });

There's no need to put a smart pointer inside a LazyNeverDestroyed. This can just be something like:

static WebContext* context;
if (!context) {
 /// initialize context
}

return *context;

> Source/WebKit2/WebProcess/WebPage/WebInspector.messages.in:25
> -messages -> WebInspector LegacyReceiver {
> +messages -> WebInspector {

Very nice!
Comment 42 Timothy Hatcher 2014-09-24 13:07:13 PDT
http://trac.webkit.org/changeset/173929
Comment 43 Joseph Pecoraro 2014-09-24 15:06:43 PDT
32-bit mac build fix: <http://trac.webkit.org/changeset/173933>
Comment 44 Timothy Hatcher 2014-09-24 21:15:15 PDT
WK1 test crash fix: http://trac.webkit.org/changeset/173936
Comment 45 Brent Fulgham 2014-09-25 17:36:42 PDT
64-bit Windows build fix: http://trac.webkit.org/changeset/173986.