diff options
| author | Steve Block <steveblock@google.com> | 2011-05-13 06:44:40 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-05-13 06:44:40 -0700 |
| commit | 08014c20784f3db5df3a89b73cce46037b77eb59 (patch) | |
| tree | 47749210d31e19e6e2f64036fa8fae2ad693476f /Source/WebCore/notifications | |
| parent | 860220379e56aeb66424861ad602b07ee22b4055 (diff) | |
| parent | 4c3661f7918f8b3f139f824efb7855bedccb4c94 (diff) | |
| download | external_webkit-08014c20784f3db5df3a89b73cce46037b77eb59.zip external_webkit-08014c20784f3db5df3a89b73cce46037b77eb59.tar.gz external_webkit-08014c20784f3db5df3a89b73cce46037b77eb59.tar.bz2 | |
Merge changes Ide388898,Ic49f367c,I1158a808,Iacb6ca5d,I2100dd3a,I5c1abe54,Ib0ef9902,I31dbc523,I570314b3
* changes:
Merge WebKit at r75315: Update WebKit version
Merge WebKit at r75315: Add FrameLoaderClient PageCache stubs
Merge WebKit at r75315: Stub out AXObjectCache::remove()
Merge WebKit at r75315: Fix ImageBuffer
Merge WebKit at r75315: Fix PluginData::initPlugins()
Merge WebKit at r75315: Fix conflicts
Merge WebKit at r75315: Fix Makefiles
Merge WebKit at r75315: Move Android-specific WebCore files to Source
Merge WebKit at r75315: Initial merge by git.
Diffstat (limited to 'Source/WebCore/notifications')
| -rw-r--r-- | Source/WebCore/notifications/Notification.cpp | 229 | ||||
| -rw-r--r-- | Source/WebCore/notifications/Notification.h | 154 | ||||
| -rw-r--r-- | Source/WebCore/notifications/Notification.idl | 60 | ||||
| -rw-r--r-- | Source/WebCore/notifications/NotificationCenter.cpp | 76 | ||||
| -rw-r--r-- | Source/WebCore/notifications/NotificationCenter.h | 93 | ||||
| -rw-r--r-- | Source/WebCore/notifications/NotificationCenter.idl | 44 | ||||
| -rw-r--r-- | Source/WebCore/notifications/NotificationContents.h | 60 | ||||
| -rw-r--r-- | Source/WebCore/notifications/NotificationPresenter.h | 84 |
8 files changed, 800 insertions, 0 deletions
diff --git a/Source/WebCore/notifications/Notification.cpp b/Source/WebCore/notifications/Notification.cpp new file mode 100644 index 0000000..4cb2f85 --- /dev/null +++ b/Source/WebCore/notifications/Notification.cpp @@ -0,0 +1,229 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(NOTIFICATIONS) + +#include "Notification.h" +#include "NotificationCenter.h" +#include "NotificationContents.h" + +#include "Document.h" +#include "EventNames.h" +#include "ResourceRequest.h" +#include "ResourceResponse.h" +#include "ThreadableLoader.h" +#include "WorkerContext.h" + +namespace WebCore { + +Notification::Notification(const KURL& url, ScriptExecutionContext* context, ExceptionCode& ec, PassRefPtr<NotificationCenter> provider) + : ActiveDOMObject(context, this) + , m_isHTML(true) + , m_state(Idle) + , m_notificationCenter(provider) +{ + ASSERT(m_notificationCenter->presenter()); + if (m_notificationCenter->presenter()->checkPermission(context) != NotificationPresenter::PermissionAllowed) { + ec = SECURITY_ERR; + return; + } + + if (url.isEmpty() || !url.isValid()) { + ec = SYNTAX_ERR; + return; + } + + m_notificationURL = url; +} + +Notification::Notification(const NotificationContents& contents, ScriptExecutionContext* context, ExceptionCode& ec, PassRefPtr<NotificationCenter> provider) + : ActiveDOMObject(context, this) + , m_isHTML(false) + , m_contents(contents) + , m_state(Idle) + , m_notificationCenter(provider) +{ + ASSERT(m_notificationCenter->presenter()); + if (m_notificationCenter->presenter()->checkPermission(context) != NotificationPresenter::PermissionAllowed) { + ec = SECURITY_ERR; + return; + } + + if (!contents.icon().isEmpty() && !contents.icon().isValid()) { + ec = SYNTAX_ERR; + return; + } +} + +Notification::~Notification() +{ + if (m_state == Loading) { + ASSERT_NOT_REACHED(); + cancel(); + } +} + +PassRefPtr<Notification> Notification::create(const KURL& url, ScriptExecutionContext* context, ExceptionCode& ec, PassRefPtr<NotificationCenter> provider) +{ + return adoptRef(new Notification(url, context, ec, provider)); +} + +PassRefPtr<Notification> Notification::create(const NotificationContents& contents, ScriptExecutionContext* context, ExceptionCode& ec, PassRefPtr<NotificationCenter> provider) +{ + return adoptRef(new Notification(contents, context, ec, provider)); +} + +void Notification::show() +{ +#if PLATFORM(QT) + if (iconURL().isEmpty()) { + // Set the state before actually showing, because + // handling of ondisplay may rely on that. + if (m_state == Idle) { + m_state = Showing; + if (m_notificationCenter->presenter()) + m_notificationCenter->presenter()->show(this); + } + } else + startLoading(); +#else + // prevent double-showing + if (m_state == Idle && m_notificationCenter->presenter() && m_notificationCenter->presenter()->show(this)) + m_state = Showing; +#endif +} + +void Notification::cancel() +{ + switch (m_state) { + case Idle: + break; + case Loading: + m_state = Cancelled; + stopLoading(); + break; + case Showing: + if (m_notificationCenter->presenter()) + m_notificationCenter->presenter()->cancel(this); + break; + case Cancelled: + break; + } +} + +EventTargetData* Notification::eventTargetData() +{ + return &m_eventTargetData; +} + +EventTargetData* Notification::ensureEventTargetData() +{ + return &m_eventTargetData; +} + +void Notification::contextDestroyed() +{ + ActiveDOMObject::contextDestroyed(); + if (m_notificationCenter->presenter()) + m_notificationCenter->presenter()->notificationObjectDestroyed(this); +} + +void Notification::startLoading() +{ + if (m_state != Idle) + return; + setPendingActivity(this); + m_state = Loading; + ThreadableLoaderOptions options; + options.sendLoadCallbacks = false; + options.sniffContent = false; + options.forcePreflight = false; + options.allowCredentials = AllowStoredCredentials; + options.crossOriginRequestPolicy = AllowCrossOriginRequests; + m_loader = ThreadableLoader::create(scriptExecutionContext(), this, ResourceRequest(iconURL()), options); +} + +void Notification::stopLoading() +{ + m_iconData = 0; + RefPtr<ThreadableLoader> protect(m_loader); + m_loader->cancel(); +} + +void Notification::didReceiveResponse(const ResourceResponse& response) +{ + int status = response.httpStatusCode(); + if (status && (status < 200 || status > 299)) { + stopLoading(); + return; + } + m_iconData = SharedBuffer::create(); +} + +void Notification::didReceiveData(const char* data, int lengthReceived) +{ + m_iconData->append(data, lengthReceived); +} + +void Notification::didFinishLoading(unsigned long) +{ + finishLoading(); +} + +void Notification::didFail(const ResourceError&) +{ + finishLoading(); +} + +void Notification::didFailRedirectCheck() +{ + finishLoading(); +} + +void Notification::didReceiveAuthenticationCancellation(const ResourceResponse&) +{ + finishLoading(); +} + +void Notification::finishLoading() +{ + if (m_state == Loading) { + if (m_notificationCenter->presenter() && m_notificationCenter->presenter()->show(this)) + m_state = Showing; + } + unsetPendingActivity(this); +} + +} // namespace WebCore + +#endif // ENABLE(NOTIFICATIONS) diff --git a/Source/WebCore/notifications/Notification.h b/Source/WebCore/notifications/Notification.h new file mode 100644 index 0000000..f14a302 --- /dev/null +++ b/Source/WebCore/notifications/Notification.h @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef Notification_h +#define Notification_h + +#include "ActiveDOMObject.h" +#include "Event.h" +#include "EventListener.h" +#include "EventNames.h" +#include "EventTarget.h" +#include "ExceptionCode.h" +#include "KURL.h" +#include "NotificationPresenter.h" +#include "NotificationContents.h" +#include "RegisteredEventListener.h" +#include "SharedBuffer.h" +#include "TextDirection.h" +#include "ThreadableLoader.h" +#include "ThreadableLoaderClient.h" +#include <wtf/OwnPtr.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> +#include <wtf/RefPtr.h> +#include <wtf/text/AtomicStringHash.h> + +#if ENABLE(NOTIFICATIONS) +namespace WebCore { + + class NotificationCenter; + class WorkerContext; + + class Notification : public RefCounted<Notification>, public ActiveDOMObject, public ThreadableLoaderClient, public EventTarget { + public: + static PassRefPtr<Notification> create(const KURL& url, ScriptExecutionContext* context, ExceptionCode& ec, PassRefPtr<NotificationCenter> provider); + static PassRefPtr<Notification> create(const NotificationContents& contents, ScriptExecutionContext* context, ExceptionCode& ec, PassRefPtr<NotificationCenter> provider); + + virtual ~Notification(); + + void show(); + void cancel(); + + bool isHTML() { return m_isHTML; } + KURL url() { return m_notificationURL; } + KURL iconURL() { return m_contents.icon(); } + NotificationContents& contents() { return m_contents; } + + String dir() const { return m_direction; } + void setDir(const String& dir) { m_direction = dir; } + String replaceId() const { return m_replaceId; } + void setReplaceId(const String& replaceId) { m_replaceId = replaceId; } + + TextDirection direction() const { return dir() == "rtl" ? RTL : LTR; } + + DEFINE_ATTRIBUTE_EVENT_LISTENER(display); + DEFINE_ATTRIBUTE_EVENT_LISTENER(error); + DEFINE_ATTRIBUTE_EVENT_LISTENER(close); + DEFINE_ATTRIBUTE_EVENT_LISTENER(click); + + using RefCounted<Notification>::ref; + using RefCounted<Notification>::deref; + + // EventTarget interface + virtual ScriptExecutionContext* scriptExecutionContext() const { return ActiveDOMObject::scriptExecutionContext(); } + virtual Notification* toNotification() { return this; } + + // ActiveDOMObject interface + virtual void contextDestroyed(); + + void stopLoading(); + + SharedBuffer* iconData() { return m_iconData.get(); } + void releaseIconData() { m_iconData = 0; } + + // Deprecated. Use functions from NotificationCenter. + void detachPresenter() { } + + virtual void didReceiveResponse(const ResourceResponse&); + virtual void didReceiveData(const char* data, int lengthReceived); + virtual void didFinishLoading(unsigned long identifier); + virtual void didFail(const ResourceError&); + virtual void didFailRedirectCheck(); + virtual void didReceiveAuthenticationCancellation(const ResourceResponse&); + + private: + Notification(const KURL&, ScriptExecutionContext*, ExceptionCode&, PassRefPtr<NotificationCenter>); + Notification(const NotificationContents&, ScriptExecutionContext*, ExceptionCode&, PassRefPtr<NotificationCenter>); + + // EventTarget interface + virtual void refEventTarget() { ref(); } + virtual void derefEventTarget() { deref(); } + virtual EventTargetData* eventTargetData(); + virtual EventTargetData* ensureEventTargetData(); + + void startLoading(); + void finishLoading(); + + bool m_isHTML; + KURL m_notificationURL; + NotificationContents m_contents; + + String m_direction; + String m_replaceId; + + enum NotificationState { + Idle = 0, + Loading = 1, + Showing = 2, + Cancelled = 3 + }; + + NotificationState m_state; + + RefPtr<NotificationCenter> m_notificationCenter; + + EventTargetData m_eventTargetData; + + RefPtr<ThreadableLoader> m_loader; + RefPtr<SharedBuffer> m_iconData; + }; + +} // namespace WebCore + +#endif // ENABLE(NOTIFICATIONS) + +#endif // Notifications_h diff --git a/Source/WebCore/notifications/Notification.idl b/Source/WebCore/notifications/Notification.idl new file mode 100644 index 0000000..66a1229 --- /dev/null +++ b/Source/WebCore/notifications/Notification.idl @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +module threads { + + interface [ + Conditional=NOTIFICATIONS, + EventTarget, + OmitConstructor + ] Notification { + void show(); + void cancel(); + + attribute EventListener ondisplay; + attribute EventListener onerror; + attribute EventListener onclose; + attribute EventListener onclick; + + attribute DOMString dir; + attribute DOMString replaceId; + + // EventTarget interface + void addEventListener(in DOMString type, + in EventListener listener, + in boolean useCapture); + void removeEventListener(in DOMString type, + in EventListener listener, + in boolean useCapture); + boolean dispatchEvent(in Event evt) + raises(EventException); + }; + +} diff --git a/Source/WebCore/notifications/NotificationCenter.cpp b/Source/WebCore/notifications/NotificationCenter.cpp new file mode 100644 index 0000000..a2289ec --- /dev/null +++ b/Source/WebCore/notifications/NotificationCenter.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(NOTIFICATIONS) + +#include "NotificationCenter.h" + +#include "Document.h" +#include "VoidCallback.h" +#include "WorkerContext.h" + +namespace WebCore { + +NotificationCenter::NotificationCenter(ScriptExecutionContext* context, NotificationPresenter* presenter) + : ActiveDOMObject(context, this) + , m_scriptExecutionContext(context) + , m_notificationPresenter(presenter) {} + +int NotificationCenter::checkPermission() +{ + if (!presenter()) + return NotificationPresenter::PermissionDenied; + return m_notificationPresenter->checkPermission(m_scriptExecutionContext); +} + +void NotificationCenter::requestPermission(PassRefPtr<VoidCallback> callback) +{ + if (!presenter()) + return; + m_notificationPresenter->requestPermission(m_scriptExecutionContext, callback); +} + +void NotificationCenter::disconnectFrame() +{ + // m_notificationPresenter should never be 0. But just to be safe, we check it here. + // Due to the mysterious bug http://code.google.com/p/chromium/issues/detail?id=49323. + ASSERT(m_notificationPresenter); + if (!m_notificationPresenter) + return; + m_notificationPresenter->cancelRequestsForPermission(m_scriptExecutionContext); + m_notificationPresenter = 0; + m_scriptExecutionContext = 0; +} + +} // namespace WebCore + +#endif // ENABLE(NOTIFICATIONS) diff --git a/Source/WebCore/notifications/NotificationCenter.h b/Source/WebCore/notifications/NotificationCenter.h new file mode 100644 index 0000000..adad59d --- /dev/null +++ b/Source/WebCore/notifications/NotificationCenter.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef NotificationCenter_h +#define NotificationCenter_h + +#include "Notification.h" +#include "NotificationContents.h" +#include "ScriptExecutionContext.h" +#include "WorkerThread.h" +#include <wtf/OwnPtr.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> +#include <wtf/RefPtr.h> + +#if ENABLE(NOTIFICATIONS) + +namespace WebCore { + + class NotificationCenter : public RefCounted<NotificationCenter>, public ActiveDOMObject { + public: + static PassRefPtr<NotificationCenter> create(ScriptExecutionContext* context, NotificationPresenter* presenter) { return adoptRef(new NotificationCenter(context, presenter)); } + + PassRefPtr<Notification> createHTMLNotification(const String& URI, ExceptionCode& ec) + { + if (!presenter()) { + ec = INVALID_STATE_ERR; + return 0; + } + if (URI.isEmpty()) { + ec = SYNTAX_ERR; + return 0; + } + return Notification::create(m_scriptExecutionContext->completeURL(URI), context(), ec, this); + } + + PassRefPtr<Notification> createNotification(const String& iconURI, const String& title, const String& body, ExceptionCode& ec) + { + if (!presenter()) { + ec = INVALID_STATE_ERR; + return 0; + } + NotificationContents contents(iconURI.isEmpty() ? KURL() : m_scriptExecutionContext->completeURL(iconURI), title, body); + return Notification::create(contents, context(), ec, this); + } + + ScriptExecutionContext* context() const { return m_scriptExecutionContext; } + NotificationPresenter* presenter() const { return m_notificationPresenter; } + + int checkPermission(); + void requestPermission(PassRefPtr<VoidCallback> callback); + + void disconnectFrame(); + + private: + NotificationCenter(ScriptExecutionContext*, NotificationPresenter*); + + ScriptExecutionContext* m_scriptExecutionContext; + NotificationPresenter* m_notificationPresenter; + }; + +} // namespace WebCore + +#endif // ENABLE(NOTIFICATIONS) + +#endif // NotificationCenter_h diff --git a/Source/WebCore/notifications/NotificationCenter.idl b/Source/WebCore/notifications/NotificationCenter.idl new file mode 100644 index 0000000..86420b8 --- /dev/null +++ b/Source/WebCore/notifications/NotificationCenter.idl @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +module threads { + + interface [ + Conditional=NOTIFICATIONS, + OmitConstructor + ] NotificationCenter { + [V8Custom] Notification createHTMLNotification(in DOMString url) raises(Exception); + [V8Custom] Notification createNotification(in DOMString iconUrl, in DOMString title, in DOMString body) raises(Exception); + + int checkPermission(); + [Custom] void requestPermission(in VoidCallback callback); + }; + +} diff --git a/Source/WebCore/notifications/NotificationContents.h b/Source/WebCore/notifications/NotificationContents.h new file mode 100644 index 0000000..5807f30 --- /dev/null +++ b/Source/WebCore/notifications/NotificationContents.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef NotificationContents_h +#define NotificationContents_h + +#if ENABLE(NOTIFICATIONS) + +namespace WebCore { + + class NotificationContents { + public: + NotificationContents() {} + NotificationContents(const KURL& iconUrl, const String& title, const String& body) + : m_icon(iconUrl) + , m_title(title) + , m_body(body) {} + + KURL icon() const { return m_icon; } + String title() const { return m_title; } + String body() const { return m_body; } + + private: + KURL m_icon; + String m_title; + String m_body; + }; + +} // namespace WebCore + +#endif // ENABLE(NOTIFICATIONS) + +#endif // NotificationContents_h diff --git a/Source/WebCore/notifications/NotificationPresenter.h b/Source/WebCore/notifications/NotificationPresenter.h new file mode 100644 index 0000000..9602199 --- /dev/null +++ b/Source/WebCore/notifications/NotificationPresenter.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef NotificationPresenter_h +#define NotificationPresenter_h + +#include <wtf/PassRefPtr.h> +#include "VoidCallback.h" + +#if ENABLE(NOTIFICATIONS) + +namespace WebCore { + + class Document; + class Notification; + class KURL; + class ScriptExecutionContext; + + class NotificationPresenter { + + public: + enum Permission { + PermissionAllowed, // User has allowed notifications + PermissionNotAllowed, // User has not yet allowed + PermissionDenied // User has explicitly denied permission + }; + + virtual ~NotificationPresenter() {} + + // Requests that a notification be shown. + virtual bool show(Notification*) = 0; + + // Requests that a notification that has already been shown be canceled. + virtual void cancel(Notification*) = 0; + + // Informs the presenter that a Notification object has been destroyed + // (such as by a page transition). The presenter may continue showing + // the notification, but must not attempt to call the event handlers. + virtual void notificationObjectDestroyed(Notification*) = 0; + + // Requests user permission to show desktop notifications from a particular + // script context. The callback parameter should be run when the user has + // made a decision. + virtual void requestPermission(ScriptExecutionContext*, PassRefPtr<VoidCallback>) = 0; + + // Cancel all outstanding requests for the ScriptExecutionContext + virtual void cancelRequestsForPermission(ScriptExecutionContext*) = 0; + + // Checks the current level of permission. + virtual Permission checkPermission(ScriptExecutionContext*) = 0; + }; + +} // namespace WebCore + +#endif // ENABLE(NOTIFICATIONS) + +#endif // NotificationPresenter_h |
