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 @@ ...@@ -11,6 +11,7 @@
#include "content/child/service_worker/service_worker_handle_reference.h" #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/service_worker_provider_context.h"
#include "content/child/service_worker/web_service_worker_impl.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/thread_safe_sender.h"
#include "content/child/webmessageportchannel_impl.h" #include "content/child/webmessageportchannel_impl.h"
#include "content/common/service_worker/service_worker_messages.h" #include "content/common/service_worker/service_worker_messages.h"
...@@ -81,12 +82,12 @@ void ServiceWorkerDispatcher::RegisterServiceWorker( ...@@ -81,12 +82,12 @@ void ServiceWorkerDispatcher::RegisterServiceWorker(
int provider_id, int provider_id,
const GURL& pattern, const GURL& pattern,
const GURL& script_url, const GURL& script_url,
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) { WebServiceWorkerRegistrationCallbacks* callbacks) {
DCHECK(callbacks); DCHECK(callbacks);
if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() || if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() ||
script_url.possibly_invalid_spec().size() > GetMaxURLChars()) { script_url.possibly_invalid_spec().size() > GetMaxURLChars()) {
scoped_ptr<WebServiceWorkerProvider::WebServiceWorkerCallbacks> scoped_ptr<WebServiceWorkerRegistrationCallbacks>
owned_callbacks(callbacks); owned_callbacks(callbacks);
scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError(
WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); WebServiceWorkerError::ErrorTypeSecurity, "URL too long"));
...@@ -102,11 +103,11 @@ void ServiceWorkerDispatcher::RegisterServiceWorker( ...@@ -102,11 +103,11 @@ void ServiceWorkerDispatcher::RegisterServiceWorker(
void ServiceWorkerDispatcher::UnregisterServiceWorker( void ServiceWorkerDispatcher::UnregisterServiceWorker(
int provider_id, int provider_id,
const GURL& pattern, const GURL& pattern,
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) { WebServiceWorkerRegistrationCallbacks* callbacks) {
DCHECK(callbacks); DCHECK(callbacks);
if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) {
scoped_ptr<WebServiceWorkerProvider::WebServiceWorkerCallbacks> scoped_ptr<WebServiceWorkerRegistrationCallbacks>
owned_callbacks(callbacks); owned_callbacks(callbacks);
scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError(
WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); WebServiceWorkerError::ErrorTypeSecurity, "URL too long"));
...@@ -209,20 +210,24 @@ void ServiceWorkerDispatcher::OnRegistered( ...@@ -209,20 +210,24 @@ void ServiceWorkerDispatcher::OnRegistered(
int thread_id, int thread_id,
int request_id, int request_id,
const ServiceWorkerObjectInfo& info) { const ServiceWorkerObjectInfo& info) {
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = WebServiceWorkerRegistrationCallbacks* callbacks =
pending_callbacks_.Lookup(request_id); pending_callbacks_.Lookup(request_id);
DCHECK(callbacks); DCHECK(callbacks);
if (!callbacks) if (!callbacks)
return; return;
#ifdef DISABLE_SERVICE_WORKER_REGISTRATION
callbacks->onSuccess(GetServiceWorker(info, true)); callbacks->onSuccess(GetServiceWorker(info, true));
#else
callbacks->onSuccess(new WebServiceWorkerRegistrationImpl(info));
#endif
pending_callbacks_.Remove(request_id); pending_callbacks_.Remove(request_id);
} }
void ServiceWorkerDispatcher::OnUnregistered( void ServiceWorkerDispatcher::OnUnregistered(
int thread_id, int thread_id,
int request_id) { int request_id) {
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = WebServiceWorkerRegistrationCallbacks* callbacks =
pending_callbacks_.Lookup(request_id); pending_callbacks_.Lookup(request_id);
DCHECK(callbacks); DCHECK(callbacks);
if (!callbacks) if (!callbacks)
...@@ -237,7 +242,7 @@ void ServiceWorkerDispatcher::OnRegistrationError( ...@@ -237,7 +242,7 @@ void ServiceWorkerDispatcher::OnRegistrationError(
int request_id, int request_id,
WebServiceWorkerError::ErrorType error_type, WebServiceWorkerError::ErrorType error_type,
const base::string16& message) { const base::string16& message) {
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = WebServiceWorkerRegistrationCallbacks* callbacks =
pending_callbacks_.Lookup(request_id); pending_callbacks_.Lookup(request_id);
DCHECK(callbacks); DCHECK(callbacks);
if (!callbacks) if (!callbacks)
......
...@@ -39,6 +39,9 @@ class WebServiceWorkerImpl; ...@@ -39,6 +39,9 @@ class WebServiceWorkerImpl;
// scripts through methods like navigator.registerServiceWorker(). // scripts through methods like navigator.registerServiceWorker().
class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
public: public:
typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks
WebServiceWorkerRegistrationCallbacks;
explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender);
virtual ~ServiceWorkerDispatcher(); virtual ~ServiceWorkerDispatcher();
...@@ -50,12 +53,12 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { ...@@ -50,12 +53,12 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
int provider_id, int provider_id,
const GURL& pattern, const GURL& pattern,
const GURL& script_url, const GURL& script_url,
blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks); WebServiceWorkerRegistrationCallbacks* callbacks);
// Corresponds to navigator.serviceWorker.unregister() // Corresponds to navigator.serviceWorker.unregister()
void UnregisterServiceWorker( void UnregisterServiceWorker(
int provider_id, int provider_id,
const GURL& pattern, const GURL& pattern,
blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks); WebServiceWorkerRegistrationCallbacks* callbacks);
// Called when a new provider context for a document is created. Usually // 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 // this happens when a new document is being loaded, and is called much
...@@ -96,7 +99,7 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { ...@@ -96,7 +99,7 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
static ServiceWorkerDispatcher* GetThreadSpecificInstance(); static ServiceWorkerDispatcher* GetThreadSpecificInstance();
private: private:
typedef IDMap<blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks, typedef IDMap<WebServiceWorkerRegistrationCallbacks,
IDMapOwnPointer> CallbackMap; IDMapOwnPointer> CallbackMap;
typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap; typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap;
typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap;
......
...@@ -71,14 +71,14 @@ void WebServiceWorkerProviderImpl::setClient( ...@@ -71,14 +71,14 @@ void WebServiceWorkerProviderImpl::setClient(
void WebServiceWorkerProviderImpl::registerServiceWorker( void WebServiceWorkerProviderImpl::registerServiceWorker(
const WebURL& pattern, const WebURL& pattern,
const WebURL& script_url, const WebURL& script_url,
WebServiceWorkerCallbacks* callbacks) { WebServiceWorkerRegistrationCallbacks* callbacks) {
GetDispatcher()->RegisterServiceWorker( GetDispatcher()->RegisterServiceWorker(
provider_id_, pattern, script_url, callbacks); provider_id_, pattern, script_url, callbacks);
} }
void WebServiceWorkerProviderImpl::unregisterServiceWorker( void WebServiceWorkerProviderImpl::unregisterServiceWorker(
const WebURL& pattern, const WebURL& pattern,
WebServiceWorkerCallbacks* callbacks) { WebServiceWorkerRegistrationCallbacks* callbacks) {
GetDispatcher()->UnregisterServiceWorker( GetDispatcher()->UnregisterServiceWorker(
provider_id_, pattern, callbacks); provider_id_, pattern, callbacks);
} }
......
...@@ -34,10 +34,10 @@ class WebServiceWorkerProviderImpl ...@@ -34,10 +34,10 @@ class WebServiceWorkerProviderImpl
virtual void registerServiceWorker(const blink::WebURL& pattern, virtual void registerServiceWorker(const blink::WebURL& pattern,
const blink::WebURL& script_url, const blink::WebURL& script_url,
WebServiceWorkerCallbacks*); WebServiceWorkerRegistrationCallbacks*);
virtual void unregisterServiceWorker(const blink::WebURL& pattern, virtual void unregisterServiceWorker(const blink::WebURL& pattern,
WebServiceWorkerCallbacks*); WebServiceWorkerRegistrationCallbacks*);
ServiceWorkerProviderContext* context() { return context_.get(); } 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 @@ ...@@ -169,6 +169,8 @@
'child/service_worker/web_service_worker_impl.h', '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.cc',
'child/service_worker/web_service_worker_provider_impl.h', '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.cc',
'child/shared_worker_devtools_agent.h', 'child/shared_worker_devtools_agent.h',
'child/simple_webmimeregistry_impl.cc', '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