Skip to content

Commit

Permalink
ServiceWorker: Implement ServiceWorkerRegistration [2/3]
Browse files Browse the repository at this point in the history
This implements WebServiceWorkerRegistration based on the latest spec
and resolves a register promise with it instead of a ServiceWorker object.

Spec: https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-registration-obj 

[1] Blink: https://codereview.chromium.org/413123002/
[2] Chromium: This patch.
[3] Blink: Remove the macro and fix a bunch of layout tests.


BUG=396400
TEST=compile (tests will be added by subsequent patches)

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285599 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
nhiroki@chromium.org committed Jul 25, 2014
1 parent bdceb3b commit 8ec879c
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 14 deletions.
19 changes: 12 additions & 7 deletions content/child/service_worker/service_worker_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "content/child/service_worker/service_worker_handle_reference.h"
#include "content/child/service_worker/service_worker_provider_context.h"
#include "content/child/service_worker/web_service_worker_impl.h"
#include "content/child/service_worker/web_service_worker_registration_impl.h"
#include "content/child/thread_safe_sender.h"
#include "content/child/webmessageportchannel_impl.h"
#include "content/common/service_worker/service_worker_messages.h"
Expand Down Expand Up @@ -81,12 +82,12 @@ void ServiceWorkerDispatcher::RegisterServiceWorker(
int provider_id,
const GURL& pattern,
const GURL& script_url,
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) {
WebServiceWorkerRegistrationCallbacks* callbacks) {
DCHECK(callbacks);

if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() ||
script_url.possibly_invalid_spec().size() > GetMaxURLChars()) {
scoped_ptr<WebServiceWorkerProvider::WebServiceWorkerCallbacks>
scoped_ptr<WebServiceWorkerRegistrationCallbacks>
owned_callbacks(callbacks);
scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError(
WebServiceWorkerError::ErrorTypeSecurity, "URL too long"));
Expand All @@ -102,11 +103,11 @@ void ServiceWorkerDispatcher::RegisterServiceWorker(
void ServiceWorkerDispatcher::UnregisterServiceWorker(
int provider_id,
const GURL& pattern,
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) {
WebServiceWorkerRegistrationCallbacks* callbacks) {
DCHECK(callbacks);

if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) {
scoped_ptr<WebServiceWorkerProvider::WebServiceWorkerCallbacks>
scoped_ptr<WebServiceWorkerRegistrationCallbacks>
owned_callbacks(callbacks);
scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError(
WebServiceWorkerError::ErrorTypeSecurity, "URL too long"));
Expand Down Expand Up @@ -209,20 +210,24 @@ void ServiceWorkerDispatcher::OnRegistered(
int thread_id,
int request_id,
const ServiceWorkerObjectInfo& info) {
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks =
WebServiceWorkerRegistrationCallbacks* callbacks =
pending_callbacks_.Lookup(request_id);
DCHECK(callbacks);
if (!callbacks)
return;

#ifdef DISABLE_SERVICE_WORKER_REGISTRATION
callbacks->onSuccess(GetServiceWorker(info, true));
#else
callbacks->onSuccess(new WebServiceWorkerRegistrationImpl(info));
#endif
pending_callbacks_.Remove(request_id);
}

void ServiceWorkerDispatcher::OnUnregistered(
int thread_id,
int request_id) {
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks =
WebServiceWorkerRegistrationCallbacks* callbacks =
pending_callbacks_.Lookup(request_id);
DCHECK(callbacks);
if (!callbacks)
Expand All @@ -237,7 +242,7 @@ void ServiceWorkerDispatcher::OnRegistrationError(
int request_id,
WebServiceWorkerError::ErrorType error_type,
const base::string16& message) {
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks =
WebServiceWorkerRegistrationCallbacks* callbacks =
pending_callbacks_.Lookup(request_id);
DCHECK(callbacks);
if (!callbacks)
Expand Down
9 changes: 6 additions & 3 deletions content/child/service_worker/service_worker_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class WebServiceWorkerImpl;
// scripts through methods like navigator.registerServiceWorker().
class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
public:
typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks
WebServiceWorkerRegistrationCallbacks;

explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender);
virtual ~ServiceWorkerDispatcher();

Expand All @@ -50,12 +53,12 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
int provider_id,
const GURL& pattern,
const GURL& script_url,
blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks);
WebServiceWorkerRegistrationCallbacks* callbacks);
// Corresponds to navigator.serviceWorker.unregister()
void UnregisterServiceWorker(
int provider_id,
const GURL& pattern,
blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks);
WebServiceWorkerRegistrationCallbacks* callbacks);

// Called when a new provider context for a document is created. Usually
// this happens when a new document is being loaded, and is called much
Expand Down Expand Up @@ -96,7 +99,7 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
static ServiceWorkerDispatcher* GetThreadSpecificInstance();

private:
typedef IDMap<blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks,
typedef IDMap<WebServiceWorkerRegistrationCallbacks,
IDMapOwnPointer> CallbackMap;
typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap;
typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ void WebServiceWorkerProviderImpl::setClient(
void WebServiceWorkerProviderImpl::registerServiceWorker(
const WebURL& pattern,
const WebURL& script_url,
WebServiceWorkerCallbacks* callbacks) {
WebServiceWorkerRegistrationCallbacks* callbacks) {
GetDispatcher()->RegisterServiceWorker(
provider_id_, pattern, script_url, callbacks);
}

void WebServiceWorkerProviderImpl::unregisterServiceWorker(
const WebURL& pattern,
WebServiceWorkerCallbacks* callbacks) {
WebServiceWorkerRegistrationCallbacks* callbacks) {
GetDispatcher()->UnregisterServiceWorker(
provider_id_, pattern, callbacks);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class WebServiceWorkerProviderImpl

virtual void registerServiceWorker(const blink::WebURL& pattern,
const blink::WebURL& script_url,
WebServiceWorkerCallbacks*);
WebServiceWorkerRegistrationCallbacks*);

virtual void unregisterServiceWorker(const blink::WebURL& pattern,
WebServiceWorkerCallbacks*);
WebServiceWorkerRegistrationCallbacks*);

ServiceWorkerProviderContext* context() { return context_.get(); }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/child/service_worker/web_service_worker_registration_impl.h"

#include "content/common/service_worker/service_worker_types.h"

namespace content {

WebServiceWorkerRegistrationImpl::WebServiceWorkerRegistrationImpl(
const ServiceWorkerObjectInfo& info)
: scope_(info.scope) {
}

WebServiceWorkerRegistrationImpl::~WebServiceWorkerRegistrationImpl() {
}

blink::WebURL WebServiceWorkerRegistrationImpl::scope() const {
return scope_;
}

} // namespace content
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_CHILD_SERVICE_WORKER_WEB_SERVICE_WORKER_REGISTRATION_IMPL_H_
#define CONTENT_CHILD_SERVICE_WORKER_WEB_SERVICE_WORKER_REGISTRATION_IMPL_H_

#include "base/compiler_specific.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerRegistration.h"

namespace content {

struct ServiceWorkerObjectInfo;

class WebServiceWorkerRegistrationImpl
: NON_EXPORTED_BASE(public blink::WebServiceWorkerRegistration) {
public:
explicit WebServiceWorkerRegistrationImpl(
const ServiceWorkerObjectInfo& info);
virtual ~WebServiceWorkerRegistrationImpl();

virtual blink::WebURL scope() const;

private:
const GURL scope_;

DISALLOW_COPY_AND_ASSIGN(WebServiceWorkerRegistrationImpl);
};

} // namespace content

#endif // CONTENT_CHILD_SERVICE_WORKER_WEB_SERVICE_WORKER_REGISTRATION_IMPL_H_
2 changes: 2 additions & 0 deletions content/content_child.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
'child/service_worker/web_service_worker_impl.h',
'child/service_worker/web_service_worker_provider_impl.cc',
'child/service_worker/web_service_worker_provider_impl.h',
'child/service_worker/web_service_worker_registration_impl.cc',
'child/service_worker/web_service_worker_registration_impl.h',
'child/shared_worker_devtools_agent.cc',
'child/shared_worker_devtools_agent.h',
'child/simple_webmimeregistry_impl.cc',
Expand Down

0 comments on commit 8ec879c

Please sign in to comment.