// The output from all these methods matches what DumpRenderTree produces.
bool NotificationPresenter::show(const WebNotification& notification)
{
    WebString identifier = identifierForNotification(notification);
    if (!notification.replaceId().isEmpty()) {
        string replaceId(notification.replaceId().utf8());
        if (m_replacements.find(replaceId) != m_replacements.end())
            m_delegate->printMessage(string("REPLACING NOTIFICATION ") + m_replacements.find(replaceId)->second + "\n");

        m_replacements[replaceId] = identifier.utf8();
    }

    if (notification.isHTML())
        m_delegate->printMessage(string("DESKTOP NOTIFICATION: contents at ") + string(notification.url().spec()) + "\n");
    else {
        m_delegate->printMessage("DESKTOP NOTIFICATION:");
        m_delegate->printMessage(notification.direction() == WebTextDirectionRightToLeft ? "(RTL)" : "");
        m_delegate->printMessage(" icon ");
        m_delegate->printMessage(notification.iconURL().isEmpty() ? "" : notification.iconURL().spec().data());
        m_delegate->printMessage(", title ");
        m_delegate->printMessage(notification.title().isEmpty() ? "" : notification.title().utf8().data());
        m_delegate->printMessage(", text ");
        m_delegate->printMessage(notification.body().isEmpty() ? "" : notification.body().utf8().data());
        m_delegate->printMessage("\n");
    }

    string id(identifier.utf8());
    m_activeNotifications[id] = notification;

    Platform::current()->callOnMainThread(deferredDisplayDispatch, new WebNotification(notification));
    return true;
}
void WebKitNotificationProvider::show(WebPageProxy* page, const WebNotification& webNotification)
{
    GRefPtr<WebKitNotification> notification = m_notifications.get(webNotification.notificationID());

    if (!notification) {
        notification = adoptGRef(webkitNotificationCreate(WEBKIT_WEB_VIEW(page->viewWidget()), webNotification));
        g_signal_connect(notification.get(), "closed", G_CALLBACK(notificationCloseCallback), this);
        g_signal_connect(notification.get(), "clicked", G_CALLBACK(notificationClickedCallback), this);
        m_notifications.set(webNotification.notificationID(), notification);
    }

    if (webkitWebViewEmitShowNotification(WEBKIT_WEB_VIEW(page->viewWidget()), notification.get()))
        m_notificationManager->providerDidShowNotification(webNotification.notificationID());
}
示例#3
0
WebNotification* WebNotification::createInstance(BSTR name /*=0*/, IUnknown* anObject /*=0*/, IPropertyBag* userInfo /*=0*/)
{
    WebNotification* instance = new WebNotification(name, anObject, userInfo);
    instance->AddRef();
    return instance;
}
void WebKitNotificationProvider::cancel(const WebNotification& webNotification)
{
    cancelNotificationByID(webNotification.notificationID());
}
// The output from all these methods matches what DumpRenderTree produces.
bool NotificationPresenter::show(const WebNotification& notification)
{
    WebString identifier = identifierForNotification(notification);
    if (!notification.replaceId().isEmpty()) {
        WTF::String replaceId(notification.replaceId().data(), notification.replaceId().length());
        if (m_replacements.find(replaceId) != m_replacements.end())
            printf("REPLACING NOTIFICATION %s\n",
                   m_replacements.find(replaceId)->second.utf8().data());

        m_replacements.set(replaceId, WTF::String(identifier.data(), identifier.length()));
    }

    if (notification.isHTML()) {
        printf("DESKTOP NOTIFICATION: contents at %s\n",
               notification.url().spec().data());
    } else {
        printf("DESKTOP NOTIFICATION:%s icon %s, title %s, text %s\n",
               notification.direction() == WebTextDirectionRightToLeft ? "(RTL)" : "",
               notification.iconURL().isEmpty() ? "" :
               notification.iconURL().spec().data(),
               notification.title().isEmpty() ? "" :
               notification.title().utf8().data(),
               notification.body().isEmpty() ? "" :
               notification.body().utf8().data());
    }

    WTF::String id(identifier.data(), identifier.length());
    m_activeNotifications.set(id, notification);

    webKitClient()->callOnMainThread(deferredDisplayDispatch, new WebNotification(notification));
    return true;
}
static void deferredDisplayDispatch(void* context)
{
    WebNotification* notification = static_cast<WebNotification*>(context);
    notification->dispatchDisplayEvent();
    delete notification;
}
static WebString identifierForNotification(const WebNotification& notification)
{
    if (notification.isHTML())
        return notification.url().spec().utf16();
    return notification.title();
}