Commit 4e673ec4 authored by peter@chromium.org's avatar peter@chromium.org

Implement the ServiceWorkerRegistration.showNotification() method.

This patch implements the showNotification() method by extending the
ServiceWorkerRegistration object, and calling through to the Platform
for requesting display of a persistent notification.

BUG=432527

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

git-svn-id: svn://svn.chromium.org/blink/trunk@185326 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 2bec5595
<!doctype html>
<html>
<head>
<title>Notifications: ServiceWorkerRegistration.showNotification().</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../serviceworker/resources/test-helpers.js"></script>
</head>
<body>
<script>
// Tests that the showNotification() function is exposed on the ServiceWorkerRegistration
// object. As of right now, this is only exposed in documents.
async_test(function (test) {
var scope = 'resources/scope/serviceworkerregistration-show-notification',
worker_url = 'resources/empty-worker.js';
service_worker_unregister_and_register(test, worker_url, scope).then(function (registration) {
assert_inherits(registration, 'showNotification', 'showNotification() must be exposed.');
registration.showNotification('Title', {
body: 'Hello, world!',
icon: '/icon.png'
}).then(function() {
assert_unreached('showNotification() is expected to reject.');
}).catch(test.step_func_done());
}).catch(unreached_rejection(test));
}, 'showNotification() must be exposed on the Document-based ServiceWorkerRegistration.');
</script>
</body>
</html>
\ No newline at end of file
...@@ -243,6 +243,7 @@ ...@@ -243,6 +243,7 @@
'netinfo/NavigatorNetworkInformation.idl', 'netinfo/NavigatorNetworkInformation.idl',
'netinfo/WorkerNavigatorNetworkInformation.idl', 'netinfo/WorkerNavigatorNetworkInformation.idl',
'notifications/ServiceWorkerGlobalScopeNotifications.idl', 'notifications/ServiceWorkerGlobalScopeNotifications.idl',
'notifications/ServiceWorkerRegistrationNotifications.idl',
'performance/SharedWorkerPerformance.idl', 'performance/SharedWorkerPerformance.idl',
'performance/WorkerGlobalScopePerformance.idl', 'performance/WorkerGlobalScopePerformance.idl',
'presentation/NavigatorPresentation.idl', 'presentation/NavigatorPresentation.idl',
...@@ -745,6 +746,8 @@ ...@@ -745,6 +746,8 @@
'notifications/NotificationPermissionClient.cpp', 'notifications/NotificationPermissionClient.cpp',
'notifications/NotificationPermissionClient.h', 'notifications/NotificationPermissionClient.h',
'notifications/ServiceWorkerGlobalScopeNotifications.h', 'notifications/ServiceWorkerGlobalScopeNotifications.h',
'notifications/ServiceWorkerRegistrationNotifications.cpp',
'notifications/ServiceWorkerRegistrationNotifications.h',
'performance/SharedWorkerPerformance.cpp', 'performance/SharedWorkerPerformance.cpp',
'performance/WorkerGlobalScopePerformance.cpp', 'performance/WorkerGlobalScopePerformance.cpp',
'performance/WorkerGlobalScopePerformance.h', 'performance/WorkerGlobalScopePerformance.h',
......
// 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 "config.h"
#include "modules/notifications/ServiceWorkerRegistrationNotifications.h"
#include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h"
#include "modules/notifications/NotificationOptions.h"
#include "platform/weborigin/KURL.h"
#include "public/platform/WebNotificationData.h"
namespace blink {
ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptState* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const String& title, const NotificationOptions& options)
{
KURL iconUrl;
if (options.hasIcon() && !options.icon().isEmpty()) {
iconUrl = scriptState->executionContext()->completeURL(options.icon());
if (!iconUrl.isValid())
iconUrl = KURL();
}
WebNotificationData notification(title, WebNotificationData::DirectionLeftToRight, options.lang(), options.body(), options.tag(), iconUrl);
// FIXME: Hook this up with the Blink API once it's been implemented.
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError, "showNotification is not implemented yet."));
}
} // namespace blink
// 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 ServiceWorkerRegistrationNotifications_h
#define ServiceWorkerRegistrationNotifications_h
#include "bindings/core/v8/ScriptPromise.h"
#include "modules/serviceworkers/ServiceWorkerRegistration.h"
namespace blink {
class NotificationOptions;
class ScriptState;
class ServiceWorkerRegistrationNotifications {
public:
static ScriptPromise showNotification(ScriptState*, ServiceWorkerRegistration&, const String& title, const NotificationOptions&);
};
} // namespace blink
#endif // ServiceWorkerRegistrationNotifications_h
// 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.
// https://notifications.spec.whatwg.org/#service-worker-api
[
RuntimeEnabled=ServiceWorkerNotifications
] partial interface ServiceWorkerRegistration {
[CallWith=ScriptState] Promise showNotification(DOMString title, optional NotificationOptions options);
};
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