Bug 175237 - Implement most of ServiceWorkerContainer::addRegistration
Summary: Implement most of ServiceWorkerContainer::addRegistration
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Brady Eidson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-08-04 23:24 PDT by Brady Eidson
Modified: 2017-08-09 12:58 PDT (History)
8 users (show)

See Also:


Attachments
WIP for EWS (33.45 KB, patch)
2017-08-04 23:28 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff
WIP for EWS (33.45 KB, patch)
2017-08-04 23:32 PDT, Brady Eidson
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews104 for mac-elcapitan-wk2 (1013.58 KB, application/zip)
2017-08-05 09:44 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews103 for mac-elcapitan (1.01 MB, application/zip)
2017-08-05 09:49 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews113 for mac-elcapitan (612.91 KB, application/zip)
2017-08-05 09:52 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews126 for ios-simulator-wk2 (870.32 KB, application/zip)
2017-08-05 10:15 PDT, Build Bot
no flags Details
WIP for EWS (33.45 KB, patch)
2017-08-05 13:09 PDT, Brady Eidson
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews104 for mac-elcapitan-wk2 (980.53 KB, application/zip)
2017-08-05 14:07 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews114 for mac-elcapitan (634.58 KB, application/zip)
2017-08-05 14:09 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews125 for ios-simulator-wk2 (869.41 KB, application/zip)
2017-08-05 14:34 PDT, Build Bot
no flags Details
WIP for EWS (33.47 KB, patch)
2017-08-05 14:37 PDT, Brady Eidson
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews106 for mac-elcapitan-wk2 (989.40 KB, application/zip)
2017-08-05 15:36 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews123 for ios-simulator-wk2 (872.36 KB, application/zip)
2017-08-05 16:03 PDT, Build Bot
no flags Details
WIP for EWS (74.68 KB, patch)
2017-08-05 20:10 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff
Patch (83.27 KB, patch)
2017-08-05 21:19 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff
Patch (83.46 KB, patch)
2017-08-06 23:16 PDT, Brady Eidson
aestes: review+
aestes: commit-queue-
Details | Formatted Diff | Diff
PFL (83.45 KB, patch)
2017-08-07 09:08 PDT, Brady Eidson
beidson: commit-queue-
Details | Formatted Diff | Diff
PFL (83.45 KB, patch)
2017-08-07 09:10 PDT, Brady Eidson
commit-queue: commit-queue-
Details | Formatted Diff | Diff
PFL again... (83.43 KB, patch)
2017-08-07 10:51 PDT, Brady Eidson
commit-queue: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brady Eidson 2017-08-04 23:24:26 PDT
Implement most of ServiceWorkerContainer::addRegistration

Up to - but not including - actually posting the job to the job queue.

Seems silly, except it lays a lot of infrastructure to make future work go quicker.
Comment 1 Brady Eidson 2017-08-04 23:28:14 PDT
Created attachment 317331 [details]
WIP for EWS
Comment 2 Build Bot 2017-08-04 23:29:09 PDT Comment hidden (obsolete)
Comment 3 Brady Eidson 2017-08-04 23:32:26 PDT
Created attachment 317332 [details]
WIP for EWS
Comment 4 Build Bot 2017-08-05 09:44:15 PDT
Comment on attachment 317332 [details]
WIP for EWS

Attachment 317332 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/4259696

Number of test failures exceeded the failure limit.
Comment 5 Build Bot 2017-08-05 09:44:16 PDT
Created attachment 317337 [details]
Archive of layout-test-results from ews104 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 6 Build Bot 2017-08-05 09:49:41 PDT
Comment on attachment 317332 [details]
WIP for EWS

Attachment 317332 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/4259719

New failing tests:
fast/history/page-cache-geolocation.html
fast/history/page-cache-geolocation-active-watcher.html
fast/loader/window-properties-restored-from-page-cache.html
fast/history/page-cache-geolocation-active-oneshot.html
Comment 7 Build Bot 2017-08-05 09:49:43 PDT
Created attachment 317338 [details]
Archive of layout-test-results from ews103 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews103  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 8 Build Bot 2017-08-05 09:52:22 PDT
Comment on attachment 317332 [details]
WIP for EWS

Attachment 317332 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/4259686

Number of test failures exceeded the failure limit.
Comment 9 Build Bot 2017-08-05 09:52:23 PDT
Created attachment 317339 [details]
Archive of layout-test-results from ews113 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews113  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 10 Build Bot 2017-08-05 10:15:10 PDT
Comment on attachment 317332 [details]
WIP for EWS

Attachment 317332 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/4259729

Number of test failures exceeded the failure limit.
Comment 11 Build Bot 2017-08-05 10:15:12 PDT
Created attachment 317340 [details]
Archive of layout-test-results from ews126 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews126  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.5
Comment 12 Brady Eidson 2017-08-05 13:08:26 PDT
It definitely has to be an ActiveDOMObject, gotta be much smarted about the canSuspendForDocumentSuspension return value in the future. For now it can be "true" universally.
Comment 13 Brady Eidson 2017-08-05 13:09:29 PDT
Created attachment 317345 [details]
WIP for EWS
Comment 14 Build Bot 2017-08-05 14:07:04 PDT
Comment on attachment 317345 [details]
WIP for EWS

Attachment 317345 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/4260643

Number of test failures exceeded the failure limit.
Comment 15 Build Bot 2017-08-05 14:07:05 PDT
Created attachment 317347 [details]
Archive of layout-test-results from ews104 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 16 Build Bot 2017-08-05 14:09:37 PDT
Comment on attachment 317345 [details]
WIP for EWS

Attachment 317345 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/4260636

Number of test failures exceeded the failure limit.
Comment 17 Build Bot 2017-08-05 14:09:38 PDT
Created attachment 317348 [details]
Archive of layout-test-results from ews114 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews114  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 18 Build Bot 2017-08-05 14:34:42 PDT
Comment on attachment 317345 [details]
WIP for EWS

Attachment 317345 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/4260677

Number of test failures exceeded the failure limit.
Comment 19 Build Bot 2017-08-05 14:34:44 PDT
Created attachment 317349 [details]
Archive of layout-test-results from ews125 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews125  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.5
Comment 20 Brady Eidson 2017-08-05 14:37:30 PDT
Created attachment 317350 [details]
WIP for EWS
Comment 21 Build Bot 2017-08-05 15:36:20 PDT
Comment on attachment 317350 [details]
WIP for EWS

Attachment 317350 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/4260974

Number of test failures exceeded the failure limit.
Comment 22 Build Bot 2017-08-05 15:36:21 PDT
Created attachment 317351 [details]
Archive of layout-test-results from ews106 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 23 Build Bot 2017-08-05 16:03:08 PDT
Comment on attachment 317350 [details]
WIP for EWS

Attachment 317350 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/4261004

Number of test failures exceeded the failure limit.
Comment 24 Build Bot 2017-08-05 16:03:09 PDT
Created attachment 317352 [details]
Archive of layout-test-results from ews123 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews123  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.5
Comment 25 Brady Eidson 2017-08-05 20:10:18 PDT
Created attachment 317356 [details]
WIP for EWS
Comment 26 Brady Eidson 2017-08-05 21:19:46 PDT
Created attachment 317357 [details]
Patch
Comment 27 youenn fablet 2017-08-06 22:54:10 PDT
Comment on attachment 317357 [details]
Patch

LGTM overall.
Main question is why ServiceWorkerContainer needs to be ActiveDOMObject.
It is not clear from this patch but I guess there is a reason.

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

> Source/WebCore/page/NavigatorBase.cpp:81
> +    m_serviceWorkerContainer = ServiceWorkerContainer::create(context, *this);

It seems to be better to create m_serviceWorkerContainer when needed.
Cannot we use CallWith in the getter?

If we need to create it here, we should move to a unique ref instead of a unique ptr.

> Source/WebCore/page/NavigatorBase.h:58
> +    NavigatorBase(ScriptExecutionContext&);

explicit.

> Source/WebCore/page/WorkerNavigator.cpp:34
> +    , m_userAgent(userAgent)

userAgent should be a String&&

> Source/WebCore/page/WorkerNavigator.h:41
> +    explicit WorkerNavigator(ScriptExecutionContext&, const String&);

No longer need for explicit if there is really a need for ScriptExecutionContext& as a parameter.

> Source/WebCore/workers/ServiceWorkerContainer.cpp:68
> +    auto* context = scriptExecutionContext();

Can we use CallWith=ScriptExecutionContext that will provide a ScriptExecutionContext& directly?

> Source/WebCore/workers/ServiceWorkerContainer.cpp:75
> +        promise->reject(Exception(TypeError, ASCIILiteral("serviceWorker.register() cannot be called with a null script URL")));

I like error messages with messages like done here!
Other code usually use "Exception { }" instead of Exception().

> Source/WebCore/workers/ServiceWorkerContainer.cpp:97
> +    String scope = options.scope.isEmpty() ? "./" : options.scope;

ASCIILiteral?

> Source/WebCore/workers/ServiceWorkerContainer.h:42
> +class ServiceWorkerContainer final : public EventTargetWithInlineData, public ActiveDOMObject {

It is not very clear to me why ServiceWorkerContainer should be an ActiveDOMObject but I guess it is fine.

> Source/WebCore/workers/ServiceWorkerContainer.h:48
> +    explicit ServiceWorkerContainer(ScriptExecutionContext&, NavigatorBase&);

No longer need for explicit.

> Source/WebCore/workers/ServiceWorkerRegistration.cpp:55
> +    return UpdateViaCache::None;

Probably not a big deal but initial value is imports according spec.
Comment 28 Brady Eidson 2017-08-06 23:06:10 PDT
Points I don't reply to I address as a given with no further explanation.

(In reply to youenn fablet from comment #27)
> Comment on attachment 317357 [details]
> Patch
> 
> LGTM overall.
> Main question is why ServiceWorkerContainer needs to be ActiveDOMObject.
> It is not clear from this patch but I guess there is a reason.

It is the object that will be the decider of "is there SW activity going on in this Document's context that would prevent Document suspension"

(That will be coming up next in https://bugs.webkit.org/show_bug.cgi?id=175241

> View in context:
> https://bugs.webkit.org/attachment.cgi?id=317357&action=review
> 
> > Source/WebCore/page/NavigatorBase.cpp:81
> > +    m_serviceWorkerContainer = ServiceWorkerContainer::create(context, *this);
> 
> It seems to be better to create m_serviceWorkerContainer when needed.
> Cannot we use CallWith in the getter?

I believe "CallWith=Context" gives you the active context of the script making the call, not the context of the DOMWindow whose Navigator owns this ServiceWorkerContainer.

Assuming I'm right about that (which I think I am?) we need to capture the context of the actual DOMWindow/WorkerGlobalScope the container belongs to at creation.

> If we need to create it here, we should move to a unique ref instead of a
> unique ptr.

Good call.

> > Source/WebCore/page/WorkerNavigator.h:41
> > +    explicit WorkerNavigator(ScriptExecutionContext&, const String&);
> 
> No longer need for explicit if there is really a need for
> ScriptExecutionContext& as a parameter.
> 
> > Source/WebCore/workers/ServiceWorkerContainer.cpp:68
> > +    auto* context = scriptExecutionContext();
> 
> Can we use CallWith=ScriptExecutionContext that will provide a
> ScriptExecutionContext& directly?

See my reply above.

I believe this is the normal trap we fall into with other DOMWindow et.al. calls in confusing "the context this object belongs to" with "the context from which the JS call is being made", which are not necessarily the same.
 
> > Source/WebCore/workers/ServiceWorkerContainer.cpp:75
> > +        promise->reject(Exception(TypeError, ASCIILiteral("serviceWorker.register() cannot be called with a null script URL")));
> 
> I like error messages with messages like done here!
> Other code usually use "Exception { }" instead of Exception().

New other code sure does. I missed the memo. Is that actually preferred style now? I though we preferred brace construction only when the type can definitely be inferred.

> > Source/WebCore/workers/ServiceWorkerContainer.h:42
> > +class ServiceWorkerContainer final : public EventTargetWithInlineData, public ActiveDOMObject {
> 
> It is not very clear to me why ServiceWorkerContainer should be an
> ActiveDOMObject but I guess it is fine.

See above.

In this patch it definitely could simply be a ContextDestructionObserver, but coming very soon (e.g. next patch) it will be managing a live queue of tasks that directly relate to Document suspension.

> > Source/WebCore/workers/ServiceWorkerRegistration.cpp:55
> > +    return UpdateViaCache::None;
> 
> Probably not a big deal but initial value is imports according spec.

This particular line is truly about stubbing, but you're right.
Comment 29 Brady Eidson 2017-08-06 23:14:56 PDT
(In reply to youenn fablet from comment #27)
> Comment on attachment 317357 [details]
> Patch
> ...
> 
> > Source/WebCore/page/WorkerNavigator.cpp:34
> > +    , m_userAgent(userAgent)
> 
> userAgent should be a String&&

This one turned out to be *not* true.
Comment 30 Brady Eidson 2017-08-06 23:16:45 PDT
Created attachment 317401 [details]
Patch
Comment 31 Andy Estes 2017-08-07 09:01:17 PDT
Comment on attachment 317401 [details]
Patch

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

> Source/WebCore/WebCore.xcodeproj/project.pbxproj:27513
> +				51F174FE1F35899200C74950 /* WorkerType.h in Headers */,

This list looked sorted before you added WorkerType.h.

> Source/WebCore/WebCore.xcodeproj/project.pbxproj:27602
> +				51F174FF1F35899700C74950 /* ServiceWorkerUpdateViaCache.h in Headers */,

Ditto.

> Source/WebCore/WebCore.xcodeproj/project.pbxproj:28551
> +				51F175061F358BF700C74950 /* JSWorkerType.h in Headers */,

Ditto.

> Source/WebCore/WebCore.xcodeproj/project.pbxproj:28834
> +				51F175031F358B3B00C74950 /* JSServiceWorkerUpdateViaCache.h in Headers */,

Ditto.

> Source/WebCore/WebCore.xcodeproj/project.pbxproj:32210
> +				51F175071F358BF900C74950 /* JSWorkerType.cpp in Sources */,

Ditto.

> Source/WebCore/WebCore.xcodeproj/project.pbxproj:33848
> +				51F175021F358B3B00C74950 /* JSServiceWorkerUpdateViaCache.cpp in Sources */,

Ditto.

> Source/WebCore/page/NavigatorBase.h:66
> -    std::unique_ptr<ServiceWorkerContainer> m_serviceWorkerContainer;
> +    UniqueRef<ServiceWorkerContainer> m_serviceWorkerContainer;

Should this be guarded with an #if ENABLE(SERVICE_WORKER)?

> Source/WebCore/workers/ServiceWorkerContainer.cpp:63
> +    promise->reject(Exception(UnknownError, ASCIILiteral("serviceWorker.ready() is not yet implemented")));

I like how you use brace initialization for the Exception in addRegistration().

> Source/WebCore/workers/ServiceWorkerContainer.cpp:75
> +        promise->reject(Exception { TypeError, ASCIILiteral("serviceWorker.register() cannot be called with a null script URL") });

You say "null script URL" in the error message, but you check for an empty or null URL.
Comment 32 Brady Eidson 2017-08-07 09:05:05 PDT
(In reply to Andy Estes from comment #31)
> Comment on attachment 317401 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=317401&action=review
> 
> > Source/WebCore/WebCore.xcodeproj/project.pbxproj:27513
> > +				51F174FE1F35899200C74950 /* WorkerType.h in Headers */,
> 
> This list looked sorted before you added WorkerType.h.

Regarding all of these: In the parts of the project that show up in the UI they are alphabetized.
In the rest of the project file, Xcode doesn't try to alphabetize.

> 
> > Source/WebCore/page/NavigatorBase.h:66
> > -    std::unique_ptr<ServiceWorkerContainer> m_serviceWorkerContainer;
> > +    UniqueRef<ServiceWorkerContainer> m_serviceWorkerContainer;
> 
> Should this be guarded with an #if ENABLE(SERVICE_WORKER)?

It is!

> > Source/WebCore/workers/ServiceWorkerContainer.cpp:63
> > +    promise->reject(Exception(UnknownError, ASCIILiteral("serviceWorker.ready() is not yet implemented")));
> 
> I like how you use brace initialization for the Exception in
> addRegistration().
> 
> > Source/WebCore/workers/ServiceWorkerContainer.cpp:75
> > +        promise->reject(Exception { TypeError, ASCIILiteral("serviceWorker.register() cannot be called with a null script URL") });
> 
> You say "null script URL" in the error message, but you check for an empty
> or null URL.

👍
Comment 33 Brady Eidson 2017-08-07 09:08:09 PDT
Created attachment 317420 [details]
PFL
Comment 34 Brady Eidson 2017-08-07 09:10:23 PDT
Created attachment 317421 [details]
PFL
Comment 35 WebKit Commit Bot 2017-08-07 09:53:21 PDT
Comment on attachment 317421 [details]
PFL

Rejecting attachment 317421 [details] from commit-queue.

Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch', '--status-host=webkit-queues.webkit.org', '--bot-id=webkit-cq-03', 'land-attachment', '--force-clean', '--non-interactive', '--parent-command=commit-queue', 317421, '--port=mac']" exit_code: 2 cwd: /Volumes/Data/EWS/WebKit

Last 500 characters of output:
0-ab3c-d52691b4dbfc ...
Currently at 220334 = f709d2127e0549b7123f04882043bb4b5825e026
r220335 = 69d38d63e6c2256d07edefc13a2a8d7e86fe6bba
r220336 = 603851053c1797ceae110d4ecd8ec23585e12f23
r220337 = c158e17d784e3056240cef3cc20a7039c826ac5e
r220342 = 4530f04e017f6f530e1dae4d9b6c70213acb9e65
Done rebuilding .git/svn/refs/remotes/origin/master/.rev_map.268f45cc-cd09-0410-ab3c-d52691b4dbfc
First, rewinding head to replay your work on top of it...
Fast-forwarded master to refs/remotes/origin/master.

Full output: http://webkit-queues.webkit.org/results/4270641
Comment 36 Brady Eidson 2017-08-07 10:51:50 PDT
Created attachment 317437 [details]
PFL again...
Comment 37 WebKit Commit Bot 2017-08-07 11:23:27 PDT
Comment on attachment 317437 [details]
PFL again...

Rejecting attachment 317437 [details] from commit-queue.

Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch', '--status-host=webkit-queues.webkit.org', '--bot-id=webkit-cq-02', 'land-attachment', '--force-clean', '--non-interactive', '--parent-command=commit-queue', 317437, '--port=mac']" exit_code: 1 cwd: /Volumes/Data/EWS/WebKit

Last 500 characters of output:
rdparty/autoinstalled/mechanize/_urllib2_fork.py", line 332, in _call_chain
    result = func(*args)
  File "/Volumes/Data/EWS/WebKit/Tools/Scripts/webkitpy/thirdparty/autoinstalled/mechanize/_urllib2_fork.py", line 1170, in https_open
    return self.do_open(conn_factory, req)
  File "/Volumes/Data/EWS/WebKit/Tools/Scripts/webkitpy/thirdparty/autoinstalled/mechanize/_urllib2_fork.py", line 1118, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 60] Operation timed out>

Full output: http://webkit-queues.webkit.org/results/4271045
Comment 38 Ryan Haddad 2017-08-07 11:37:48 PDT
Despite the commit bot error, it appears that this landed in https://trac.webkit.org/changeset/220344/webkit
Comment 39 Radar WebKit Bug Importer 2017-08-09 12:58:28 PDT
<rdar://problem/33808422>