• Kenichi Ishibashi's avatar
    service worker: Merge DidInitializeWorkerContext() into WillEvaluateScript() · 5a0d62f3
    Kenichi Ishibashi authored
    This CL:
    * removes one not-well-documented method from WebServiceWorkerContextClient
    * is a preparation for a potential fix of race condition in service worker
      extension
    
    The context of the second bullet is a bit complicated. Service worker
    background extension has following ordering assumption at initialization:
    1. ExtensionMsg_Loaded is received on renderer
       extensions::Dispatcher::OnLoaded()
    2. Installing extension API bindings
       extensions::Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread()
    
    However there is no such guarantees. The current implementation
    happens to be working just because creating EmbeddedWorkerInstanceClient
    is bound to RenderThreadImpl and StartWorker() mojo message is handled
    after ExtensionMsg_Loaded.
    
    To make sure the above ordering we need to wait for the loaded message
    before installing extension API bindings. DidInitializeWorkerContext()
    isn't a right place to install extension API bindings because it is called
    via blink::WorkerThread::InitializeOnWorkerThread(), which doesn't wait
    for anything after StartWorker() mojo message is received.
    
    Fortunately we have blink::WorkerGlobalScope::ReadyToRunScript(). This
    was introduced for service worker update to suspend service worker
    execution after script fetch. We could probably use this to wait for
    the extension loaded IPC message. ReadyToRunScript() calls
    WillEvaluateScript() before executing the script so this would be a
    better place to install extension API bindings.
    
    Bug: 995134
    Change-Id: I54d44391149225c5c52294bcca32a86705a9c0a8
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1775856
    Commit-Queue: Matt Falkenhagen <falken@chromium.org>
    Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
    Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
    Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#692997}
    5a0d62f3
content_renderer_client.h 18.6 KB