Commit 772859c8 authored by dominicc@chromium.org's avatar dominicc@chromium.org

Simplify ServiceWorkerContainer's access to its window.

Actually two refactorings for navigator.serviceWorker.ready which is
sensitive to lifetimes. No change in behavior.

First, ServiceWorkerContainer is a DOMWindowLifecycleObserver to
access a window for postMessage. But it already has an execution
context that can provide the DOMWindow. Use that instead.

Second, adds an unrelated assertion that the container's
ServiceWorkerContainerClient has been cleaned up by the time that the
container is deleted. To do otherwise is to leave the
ServiceWorkerContainerClient with a dangling pointer to the container.

BUG=363967

Review URL: https://codereview.chromium.org/328663010

git-svn-id: svn://svn.chromium.org/blink/trunk@175973 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 5ae5559f
......@@ -64,6 +64,7 @@ PassRefPtr<ServiceWorkerContainer> ServiceWorkerContainer::create(ExecutionConte
ServiceWorkerContainer::~ServiceWorkerContainer()
{
ASSERT(!m_provider);
}
void ServiceWorkerContainer::detachClient()
......@@ -189,17 +190,16 @@ void ServiceWorkerContainer::setController(blink::WebServiceWorker* serviceWorke
void ServiceWorkerContainer::dispatchMessageEvent(const blink::WebString& message, const blink::WebMessagePortChannelArray& webChannels)
{
if (!executionContext() || !window())
if (!executionContext() || !executionContext()->executingWindow())
return;
OwnPtr<MessagePortArray> ports = MessagePort::toMessagePortArray(executionContext(), webChannels);
RefPtr<SerializedScriptValue> value = SerializedScriptValue::createFromWire(message);
window()->dispatchEvent(MessageEvent::create(ports.release(), value));
executionContext()->executingWindow()->dispatchEvent(MessageEvent::create(ports.release(), value));
}
ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContext)
: ContextLifecycleObserver(executionContext)
, DOMWindowLifecycleObserver(executionContext->isDocument() ? toDocument(executionContext)->domWindow() : 0)
, m_provider(0)
{
ScriptWrappable::init(this);
......
......@@ -34,7 +34,6 @@
#include "bindings/v8/ScriptPromise.h"
#include "bindings/v8/ScriptWrappable.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/DOMWindowLifecycleObserver.h"
#include "modules/serviceworkers/ServiceWorker.h"
#include "public/platform/WebServiceWorkerProviderClient.h"
#include "wtf/Forward.h"
......@@ -56,7 +55,6 @@ class ServiceWorkerContainer FINAL :
public RefCounted<ServiceWorkerContainer>,
public ScriptWrappable,
public ContextLifecycleObserver,
public DOMWindowLifecycleObserver,
public blink::WebServiceWorkerProviderClient {
public:
static PassRefPtr<ServiceWorkerContainer> create(ExecutionContext*);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment