Commit 8ec879c2 authored by nhiroki@chromium.org's avatar nhiroki@chromium.org

ServiceWorker: Implement ServiceWorkerRegistration [2/3]

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
parent bdceb3ba
......@@ -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"
......@@ -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"));
......@@ -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"));
......@@ -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)
......@@ -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)
......
......@@ -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();
......@@ -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
......@@ -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;
......
......@@ -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);
}
......
......@@ -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(); }
......
// 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
// 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_
......@@ -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',
......
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