1635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project/*
25f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian * Copyright (C) 2009 Google Inc. All rights reserved.
38f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian *
4635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * Redistribution and use in source and binary forms, with or without
5635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * modification, are permitted provided that the following conditions are
6635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * met:
78f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian *
8635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     * Redistributions of source code must retain the above copyright
9635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * notice, this list of conditions and the following disclaimer.
10635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     * Redistributions in binary form must reproduce the above
11635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * copyright notice, this list of conditions and the following disclaimer
12635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * in the documentation and/or other materials provided with the
13635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * distribution.
14635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     * Neither the name of Google Inc. nor the names of its
15635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * contributors may be used to endorse or promote products derived from
16635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * this software without specific prior written permission.
178f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian *
18635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project */
30635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
31231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#ifndef NotificationCenter_h
32231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#define NotificationCenter_h
33635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
34231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "Notification.h"
35231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "NotificationContents.h"
3606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen#include "ScriptExecutionContext.h"
37231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "WorkerThread.h"
38231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include <wtf/OwnPtr.h>
395f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#include <wtf/PassRefPtr.h>
40231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include <wtf/RefCounted.h>
41231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include <wtf/RefPtr.h>
42231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
43231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#if ENABLE(NOTIFICATIONS)
44635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
45635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectnamespace WebCore {
46635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
47231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    class NotificationCenter : public RefCounted<NotificationCenter>, public ActiveDOMObject {
485f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    public:
49231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        static PassRefPtr<NotificationCenter> create(ScriptExecutionContext* context, NotificationPresenter* presenter) { return adoptRef(new NotificationCenter(context, presenter)); }
50cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block
51545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch        PassRefPtr<Notification> createHTMLNotification(const String& URI, ExceptionCode& ec)
52231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        {
53643ca7872b450ea4efacab6188849e5aac2ba161Steve Block            if (!presenter()) {
54643ca7872b450ea4efacab6188849e5aac2ba161Steve Block                ec = INVALID_STATE_ERR;
55643ca7872b450ea4efacab6188849e5aac2ba161Steve Block                return 0;
56643ca7872b450ea4efacab6188849e5aac2ba161Steve Block            }
57dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            if (URI.isEmpty()) {
58dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block                ec = SYNTAX_ERR;
59dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block                return 0;
60dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            }
612fc2651226baac27029e38c9d6ef883fa32084dbSteve Block            return Notification::create(scriptExecutionContext()->completeURL(URI), scriptExecutionContext(), ec, this);
62231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        }
63231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
64545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch        PassRefPtr<Notification> createNotification(const String& iconURI, const String& title, const String& body, ExceptionCode& ec)
655f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        {
66643ca7872b450ea4efacab6188849e5aac2ba161Steve Block            if (!presenter()) {
67643ca7872b450ea4efacab6188849e5aac2ba161Steve Block                ec = INVALID_STATE_ERR;
68643ca7872b450ea4efacab6188849e5aac2ba161Steve Block                return 0;
69643ca7872b450ea4efacab6188849e5aac2ba161Steve Block            }
702fc2651226baac27029e38c9d6ef883fa32084dbSteve Block            NotificationContents contents(iconURI.isEmpty() ? KURL() : scriptExecutionContext()->completeURL(iconURI), title, body);
712fc2651226baac27029e38c9d6ef883fa32084dbSteve Block            return Notification::create(contents, scriptExecutionContext(), ec, this);
725f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        }
735f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
74231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        NotificationPresenter* presenter() const { return m_notificationPresenter; }
75231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
76231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        int checkPermission();
77231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void requestPermission(PassRefPtr<VoidCallback> callback);
78231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
79e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        void disconnectFrame();
80643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
815f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    private:
82231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        NotificationCenter(ScriptExecutionContext*, NotificationPresenter*);
83231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
84231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        NotificationPresenter* m_notificationPresenter;
855f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    };
86635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
87635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project} // namespace WebCore
88635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
89231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#endif // ENABLE(NOTIFICATIONS)
905f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
91231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#endif // NotificationCenter_h
92