COMMIT_MESSAGE

 1[BlackBerry] Add notification support for the BlackBerry port.
 2https://bugs.webkit.org/show_bug.cgi?id=73194
 3
 4Reviewed by NOBODY (OOPS!).
 5
 6* blackberry/WebCoreSupport/NotificationPresenterImpl.cpp: Added.
 7(WebKit::NotificationPresenterImpl::getInstance):
 8(WebKit::NotificationPresenterImpl::NotificationPresenterImpl):
 9(WebKit::NotificationPresenterImpl::~NotificationPresenterImpl):
 10(WebKit::NotificationPresenterImpl::show):
 11(WebKit::NotificationPresenterImpl::cancel):
 12(WebKit::NotificationPresenterImpl::notificationObjectDestroyed):
 13(WebKit::NotificationPresenterImpl::requestPermission):
 14(WebKit::NotificationPresenterImpl::onPermission):
 15(WebKit::NotificationPresenterImpl::cancelRequestsForPermission):
 16(WebKit::NotificationPresenterImpl::checkPermission):
 17(WebKit::NotificationPresenterImpl::notificationClicked):
 18* blackberry/WebCoreSupport/NotificationPresenterImpl.h: Added.

Source/WebKit/ChangeLog

 12011-11-29 Robin Qiu <robin.qiu@torchmobile.com.cn>
 2
 3 [BlackBerry] Add notification support for the BlackBerry port.
 4 https://bugs.webkit.org/show_bug.cgi?id=73194
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * blackberry/WebCoreSupport/NotificationPresenterImpl.cpp: Added.
 9 (WebKit::NotificationPresenterImpl::getInstance):
 10 (WebKit::NotificationPresenterImpl::NotificationPresenterImpl):
 11 (WebKit::NotificationPresenterImpl::~NotificationPresenterImpl):
 12 (WebKit::NotificationPresenterImpl::show):
 13 (WebKit::NotificationPresenterImpl::cancel):
 14 (WebKit::NotificationPresenterImpl::notificationObjectDestroyed):
 15 (WebKit::NotificationPresenterImpl::requestPermission):
 16 (WebKit::NotificationPresenterImpl::onPermission):
 17 (WebKit::NotificationPresenterImpl::cancelRequestsForPermission):
 18 (WebKit::NotificationPresenterImpl::checkPermission):
 19 (WebKit::NotificationPresenterImpl::notificationClicked):
 20 * blackberry/WebCoreSupport/NotificationPresenterImpl.h: Added.
 21
1222011-11-26 Jonathan Dong <jonathan.dong@torchmobile.com.cn>
223
324 [CMake] Clean up Web Inspector target in Source/WebKit/blackberry/CMakeListsBlackBerry.txt

Source/WebKit/blackberry/WebCoreSupport/NotificationPresenterImpl.cpp

 1/*
 2 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
 3 *
 4 * This library is free software; you can redistribute it and/or
 5 * modify it under the terms of the GNU Lesser General Public
 6 * License as published by the Free Software Foundation; either
 7 * version 2 of the License, or (at your option) any later version.
 8 *
 9 * This library is distributed in the hope that it will be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 12 * Lesser General Public License for more details.
 13 *
 14 * You should have received a copy of the GNU Lesser General Public
 15 * License along with this library; if not, write to the Free Software
 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 17 */
 18
 19#include "config.h"
 20
 21#if ENABLE(NOTIFICATIONS)
 22
 23#include "NotificationPresenterImpl.h"
 24
 25#include "Event.h"
 26#include "Notification.h"
 27#include "NotificationPresenterBlackBerry.h"
 28#include "ScriptExecutionContext.h"
 29#include "StringHash.h"
 30#include "UUID.h"
 31#include <wtf/text/CString.h>
 32
 33using namespace WebCore;
 34
 35namespace WebKit {
 36
 37NotificationPresenterImpl* NotificationPresenterImpl::m_instance = 0;
 38
 39NotificationPresenter* NotificationPresenterImpl::instance()
 40{
 41 if (!m_instance)
 42 m_instance = new NotificationPresenterImpl();
 43 return m_instance;
 44}
 45
 46NotificationPresenterImpl::NotificationPresenterImpl()
 47{
 48 m_platformPresenter = adoptPtr(BlackBerry::Platform::NotificationPresenterBlackBerry::create(this));
 49}
 50
 51NotificationPresenterImpl::~NotificationPresenterImpl()
 52{
 53}
 54
 55
 56bool NotificationPresenterImpl::show(Notification* n)
 57{
 58 if (NotificationPresenter::PermissionAllowed != checkPermission(n->scriptExecutionContext()))
 59 return false;
 60
 61 RefPtr<Notification> notification = n;
 62 if (m_notifications.contains(notification))
 63 return false;
 64
 65 String uuid = createCanonicalUUIDString();
 66 m_notifications.add(notification, uuid);
 67 String message;
 68 if (notification->isHTML()) {
 69 // FIXME: load and display HTML content
 70 message = notification->url().string();
 71 } else {
 72 // FIXME: strip to one line
 73 message = notification->contents().title() + ": " + notification->contents().body();
 74 }
 75
 76 m_platformPresenter->show(std::string(uuid.utf8().data()), std::string(message.utf8().data()));
 77 return true;
 78}
 79
 80void NotificationPresenterImpl::cancel(Notification* n)
 81{
 82 RefPtr<Notification> notification = n;
 83 if (m_notifications.contains(notification)) {
 84 m_platformPresenter->cancel(std::string(m_notifications.get(notification).utf8().data()));
 85 m_notifications.remove(notification);
 86 }
 87}
 88
 89void NotificationPresenterImpl::notificationObjectDestroyed(Notification* notification)
 90{
 91 cancel(notification);
 92}
 93
 94void NotificationPresenterImpl::requestPermission(ScriptExecutionContext* context, PassRefPtr<VoidCallback> callback)
 95{
 96 m_permissionRequests.add(context, callback);
 97 m_platformPresenter->requestPermission(std::string(context->url().host().utf8().data()));
 98}
 99
 100void NotificationPresenterImpl::onPermission(const std::string& domainStr, bool isAllowed)
 101{
 102 String domain = String::fromUTF8(domainStr.c_str());
 103 PermissionRequestMap::iterator iter = m_permissionRequests.begin();
 104 for (; iter != m_permissionRequests.end(); ++iter) {
 105 if (iter->first->url().host() == domain) {
 106 if (isAllowed) {
 107 m_allowedDomains.add(domain);
 108 iter->second->handleEvent();
 109 } else
 110 m_allowedDomains.remove(domain);
 111
 112 m_permissionRequests.remove(iter);
 113 break;
 114 }
 115 }
 116}
 117
 118void NotificationPresenterImpl::cancelRequestsForPermission(ScriptExecutionContext*)
 119{
 120 // Because we are using a modal dialog to request permission, it's probably impossible to cancel it.
 121}
 122
 123NotificationPresenter::Permission NotificationPresenterImpl::checkPermission(ScriptExecutionContext* context)
 124{
 125 // FIXME: Should store the permission information into file permenently instead of in m_allowedDomains.
 126 // The suggested place to do this is in m_platformPresenter->checkPermission().
 127
 128 if (m_allowedDomains.contains(context->url().host()))
 129 return NotificationPresenter::PermissionAllowed;
 130 return NotificationPresenter::PermissionNotAllowed;
 131
 132}
 133
 134// This function will be called by platform side.
 135void NotificationPresenterImpl::notificationClicked(const std::string& idStr)
 136{
 137 String id = String::fromUTF8(idStr.c_str());
 138 NotificationMap::iterator iter = m_notifications.begin();
 139 for (; iter != m_notifications.end(); ++iter)
 140 if (iter->second == id && iter->first->scriptExecutionContext()) {
 141 iter->first->dispatchEvent(Event::create(eventNames().clickEvent, false, true));
 142 m_notifications.remove(iter);
 143 }
 144}
 145
 146} // namespace WebKit
 147
 148#endif // ENABLE(NOTIFICATIONS)

Source/WebKit/blackberry/WebCoreSupport/NotificationPresenterImpl.h

 1/*
 2 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
 3 *
 4 * This library is free software; you can redistribute it and/or
 5 * modify it under the terms of the GNU Lesser General Public
 6 * License as published by the Free Software Foundation; either
 7 * version 2 of the License, or (at your option) any later version.
 8 *
 9 * This library is distributed in the hope that it will be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 12 * Lesser General Public License for more details.
 13 *
 14 * You should have received a copy of the GNU Lesser General Public
 15 * License along with this library; if not, write to the Free Software
 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 17 */
 18
 19#ifndef NotificationPresenterImpl_h
 20#define NotificationPresenterImpl_h
 21
 22#if ENABLE(NOTIFICATIONS)
 23
 24#include "HashMap.h"
 25#include "HashSet.h"
 26#include "NotificationAckListener.h"
 27#include "NotificationPresenter.h"
 28#include "NotificationPresenterBlackBerry.h"
 29#include "PlatformString.h"
 30#include "StringHash.h"
 31#include <string>
 32#include <wtf/OwnPtr.h>
 33
 34namespace WebKit {
 35
 36class NotificationPresenterImpl : public WebCore::NotificationPresenter, public BlackBerry::Platform::NotificationAckListener {
 37
 38public:
 39 static NotificationPresenter* instance();
 40 virtual ~NotificationPresenterImpl();
 41
 42 // Requests that a notification be shown.
 43 virtual bool show(WebCore::Notification*);
 44
 45 // Requests that a notification that has already been shown be canceled.
 46 virtual void cancel(WebCore::Notification*);
 47
 48 // Informs the presenter that a WebCore::Notification object has been destroyed
 49 // (such as by a page transition). The presenter may continue showing
 50 // the notification, but must not attempt to call the event handlers.
 51 virtual void notificationObjectDestroyed(WebCore::Notification*);
 52
 53 // Requests user permission to show desktop notifications from a particular
 54 // script context. The callback parameter should be run when the user has
 55 // made a decision.
 56 virtual void requestPermission(WebCore::ScriptExecutionContext*, PassRefPtr<WebCore::VoidCallback>);
 57
 58 // Cancel all outstanding requests for the ScriptExecutionContext
 59 virtual void cancelRequestsForPermission(WebCore::ScriptExecutionContext*);
 60
 61 // Checks the current level of permission.
 62 virtual Permission checkPermission(WebCore::ScriptExecutionContext*);
 63
 64
 65 // Interfaces inherits from NotificationAckListener:
 66 virtual void notificationClicked(const std::string& id);
 67 virtual void onPermission(const std::string& domain, bool isAllowed);
 68
 69private:
 70 NotificationPresenterImpl();
 71
 72private:
 73 static NotificationPresenterImpl* m_instance;
 74 OwnPtr<BlackBerry::Platform::NotificationPresenterBlackBerry> m_platformPresenter;
 75 typedef HashMap<RefPtr<WebCore::Notification>, WTF::String> NotificationMap;
 76 NotificationMap m_notifications;
 77 typedef HashMap<RefPtr<WebCore::ScriptExecutionContext>, RefPtr<WebCore::VoidCallback> > PermissionRequestMap;
 78 PermissionRequestMap m_permissionRequests;
 79 HashSet<WTF::String> m_allowedDomains;
 80};
 81
 82} // namespace WebKit
 83
 84#endif // ENABLE(NOTIFICATIONS)
 85
 86#endif // NotificationPresenterImpl_h