Commit 8a06ab3d authored by aa@chromium.org's avatar aa@chromium.org

Reapply 54008: Expand the NotificationPresenter::checkPermission() interface

to send the full URL of the requesting context, as well as a pointer to the
document if that context was a document.

git-svn-id: svn://svn.chromium.org/blink/trunk@54015 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ca72ade5
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include "Document.h" #include "Document.h"
#include "EventNames.h" #include "EventNames.h"
#include "WorkerContext.h" #include "WorkerContext.h"
namespace WebCore { namespace WebCore {
...@@ -49,7 +49,8 @@ Notification::Notification(const String& url, ScriptExecutionContext* context, E ...@@ -49,7 +49,8 @@ Notification::Notification(const String& url, ScriptExecutionContext* context, E
, m_presenter(provider) , m_presenter(provider)
{ {
ASSERT(m_presenter); ASSERT(m_presenter);
if (m_presenter->checkPermission(context->securityOrigin()) != NotificationPresenter::PermissionAllowed) { Document* document = context->isDocument() ? static_cast<Document*>(context) : 0;
if (m_presenter->checkPermission(context->url(), document) != NotificationPresenter::PermissionAllowed) {
ec = SECURITY_ERR; ec = SECURITY_ERR;
return; return;
} }
...@@ -69,11 +70,12 @@ Notification::Notification(const NotificationContents& contents, ScriptExecution ...@@ -69,11 +70,12 @@ Notification::Notification(const NotificationContents& contents, ScriptExecution
, m_presenter(provider) , m_presenter(provider)
{ {
ASSERT(m_presenter); ASSERT(m_presenter);
if (m_presenter->checkPermission(context->securityOrigin()) != NotificationPresenter::PermissionAllowed) { Document* document = context->isDocument() ? static_cast<Document*>(context) : 0;
if (m_presenter->checkPermission(context->url(), document) != NotificationPresenter::PermissionAllowed) {
ec = SECURITY_ERR; ec = SECURITY_ERR;
return; return;
} }
KURL icon = context->completeURL(contents.icon()); KURL icon = context->completeURL(contents.icon());
if (!icon.isEmpty() && !icon.isValid()) { if (!icon.isEmpty() && !icon.isValid()) {
ec = SYNTAX_ERR; ec = SYNTAX_ERR;
......
...@@ -40,16 +40,18 @@ ...@@ -40,16 +40,18 @@
namespace WebCore { namespace WebCore {
NotificationCenter::NotificationCenter(ScriptExecutionContext* context, NotificationPresenter* presenter) NotificationCenter::NotificationCenter(ScriptExecutionContext* context, NotificationPresenter* presenter)
: ActiveDOMObject(context, this) : ActiveDOMObject(context, this)
, m_scriptExecutionContext(context) , m_scriptExecutionContext(context)
, m_notificationPresenter(presenter) {} , m_notificationPresenter(presenter) {}
int NotificationCenter::checkPermission() int NotificationCenter::checkPermission()
{ {
if (!presenter()) if (!presenter())
return NotificationPresenter::PermissionDenied; return NotificationPresenter::PermissionDenied;
return m_notificationPresenter->checkPermission(m_scriptExecutionContext->securityOrigin()); return m_notificationPresenter->checkPermission(
m_scriptExecutionContext->url(),
m_scriptExecutionContext->isDocument() ? static_cast<Document*>(m_scriptExecutionContext) : 0);
} }
void NotificationCenter::requestPermission(PassRefPtr<VoidCallback> callback) void NotificationCenter::requestPermission(PassRefPtr<VoidCallback> callback)
......
...@@ -38,14 +38,16 @@ ...@@ -38,14 +38,16 @@
namespace WebCore { namespace WebCore {
class Document;
class Notification; class Notification;
class KURL;
class SecurityOrigin; class SecurityOrigin;
class String; class String;
class NotificationPresenter { class NotificationPresenter {
public: public:
enum Permission { enum Permission {
PermissionAllowed, // User has allowed notifications PermissionAllowed, // User has allowed notifications
PermissionNotAllowed, // User has not yet allowed PermissionNotAllowed, // User has not yet allowed
PermissionDenied // User has explicitly denied permission PermissionDenied // User has explicitly denied permission
...@@ -54,23 +56,25 @@ namespace WebCore { ...@@ -54,23 +56,25 @@ namespace WebCore {
virtual ~NotificationPresenter() {} virtual ~NotificationPresenter() {}
// Requests that a notification be shown. // Requests that a notification be shown.
virtual bool show(Notification* object) = 0; virtual bool show(Notification*) = 0;
// Requests that a notification that has already been shown be canceled. // Requests that a notification that has already been shown be canceled.
virtual void cancel(Notification* object) = 0; virtual void cancel(Notification*) = 0;
// Informs the presenter that a Notification object has been destroyed // Informs the presenter that a Notification object has been destroyed
// (such as by a page transition). The presenter may continue showing // (such as by a page transition). The presenter may continue showing
// the notification, but must not attempt to call the event handlers. // the notification, but must not attempt to call the event handlers.
virtual void notificationObjectDestroyed(Notification* object) = 0; virtual void notificationObjectDestroyed(Notification*) = 0;
// Requests user permission to show desktop notifications from a particular // Requests user permission to show desktop notifications from a particular
// origin. The callback parameter should be run when the user has // origin. The callback parameter should be run when the user has
// made a decision. // made a decision.
virtual void requestPermission(SecurityOrigin* origin, PassRefPtr<VoidCallback> callback) = 0; virtual void requestPermission(SecurityOrigin*, PassRefPtr<VoidCallback>) = 0;
// Checks the current level of permission. // Checks the current level of permission for the specified URL. If the
virtual Permission checkPermission(SecurityOrigin* origin) = 0; // URL is a document (as opposed to a worker or other ScriptExecutionContext),
// |document| will also be provided.
virtual Permission checkPermission(const KURL&, Document*) = 0;
}; };
} // namespace WebCore } // namespace WebCore
......
2010-01-27 Aaron Boodman <aa@chromium.org>
Reviewed by Darin Adler.
Send full URL and application id of requesting context to Chromium
when checking notification permissions.
https://bugs.webkit.org/show_bug.cgi?id=34238
* public/WebDocument.h:
* src/WebDocument.cpp:
(WebKit::WebDocument::applicationID):
Implement applicationID() method.
* public/WebNotificationPresenter.h:
* src/NotificationPresenterImpl.cpp:
(WebKit::NotificationPresenterImpl::checkPermission):
* src/NotificationPresenterImpl.h:
Send applicationID and full URL through to Chromium.
2010-01-27 Darin Fisher <darin@chromium.org> 2010-01-27 Darin Fisher <darin@chromium.org>
Reviewed by Pavel Feldman. Reviewed by Pavel Feldman.
......
...@@ -68,6 +68,7 @@ public: ...@@ -68,6 +68,7 @@ public:
WEBKIT_API WebNodeCollection all(); WEBKIT_API WebNodeCollection all();
WEBKIT_API WebURL completeURL(const WebString&) const; WEBKIT_API WebURL completeURL(const WebString&) const;
WEBKIT_API WebElement getElementById(const WebString& id) const; WEBKIT_API WebElement getElementById(const WebString& id) const;
WEBKIT_API WebString applicationID() const;
#if WEBKIT_IMPLEMENTATION #if WEBKIT_IMPLEMENTATION
WebDocument(const WTF::PassRefPtr<WebCore::Document>&); WebDocument(const WTF::PassRefPtr<WebCore::Document>&);
......
...@@ -35,8 +35,10 @@ ...@@ -35,8 +35,10 @@
namespace WebKit { namespace WebKit {
class WebDocument;
class WebNotification; class WebNotification;
class WebNotificationPermissionCallback; class WebNotificationPermissionCallback;
class WebURL;
// Provides the services to show desktop notifications to the user. // Provides the services to show desktop notifications to the user.
class WebNotificationPresenter { class WebNotificationPresenter {
...@@ -57,8 +59,9 @@ public: ...@@ -57,8 +59,9 @@ public:
// being destroyed. Does _not_ remove the notification if being shown, but detaches it from receiving events. // being destroyed. Does _not_ remove the notification if being shown, but detaches it from receiving events.
virtual void objectDestroyed(const WebNotification&) = 0; virtual void objectDestroyed(const WebNotification&) = 0;
// Checks the permission level of a given origin. // Checks the permission level for the given URL. If the URL is being displayed in a document
virtual Permission checkPermission(const WebString& origin) = 0; // (as opposed to a worker or other ScriptExecutionContext), |document| will also be provided.
virtual Permission checkPermission(const WebURL& url, WebDocument* document) = 0;
// Requests permission for a given origin. This operation is asynchronous and the callback provided // Requests permission for a given origin. This operation is asynchronous and the callback provided
// will be invoked when the permission decision is made. Callback pointer must remain // will be invoked when the permission decision is made. Callback pointer must remain
......
...@@ -33,12 +33,15 @@ ...@@ -33,12 +33,15 @@
#if ENABLE(NOTIFICATIONS) #if ENABLE(NOTIFICATIONS)
#include "Document.h"
#include "Notification.h" #include "Notification.h"
#include "SecurityOrigin.h" #include "SecurityOrigin.h"
#include "WebDocument.h"
#include "WebNotification.h" #include "WebNotification.h"
#include "WebNotificationPermissionCallback.h" #include "WebNotificationPermissionCallback.h"
#include "WebNotificationPresenter.h" #include "WebNotificationPresenter.h"
#include "WebURL.h"
#include <wtf/PassRefPtr.h> #include <wtf/PassRefPtr.h>
...@@ -89,9 +92,13 @@ void NotificationPresenterImpl::notificationObjectDestroyed(Notification* notifi ...@@ -89,9 +92,13 @@ void NotificationPresenterImpl::notificationObjectDestroyed(Notification* notifi
m_presenter->objectDestroyed(PassRefPtr<Notification>(notification)); m_presenter->objectDestroyed(PassRefPtr<Notification>(notification));
} }
NotificationPresenter::Permission NotificationPresenterImpl::checkPermission(SecurityOrigin* origin) NotificationPresenter::Permission NotificationPresenterImpl::checkPermission(const KURL& url, Document* document)
{ {
int result = m_presenter->checkPermission(origin->toString()); WebDocument webDocument;
if (document)
webDocument = document;
int result = m_presenter->checkPermission(url, document ? &webDocument : 0);
return static_cast<NotificationPresenter::Permission>(result); return static_cast<NotificationPresenter::Permission>(result);
} }
......
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
virtual bool show(WebCore::Notification* object); virtual bool show(WebCore::Notification* object);
virtual void cancel(WebCore::Notification* object); virtual void cancel(WebCore::Notification* object);
virtual void notificationObjectDestroyed(WebCore::Notification* object); virtual void notificationObjectDestroyed(WebCore::Notification* object);
virtual WebCore::NotificationPresenter::Permission checkPermission(WebCore::SecurityOrigin* origin); virtual WebCore::NotificationPresenter::Permission checkPermission(const WebCore::KURL& url, WebCore::Document* document);
virtual void requestPermission(WebCore::SecurityOrigin* origin, WTF::PassRefPtr<WebCore::VoidCallback> callback); virtual void requestPermission(WebCore::SecurityOrigin* origin, WTF::PassRefPtr<WebCore::VoidCallback> callback);
private: private:
......
...@@ -32,12 +32,14 @@ ...@@ -32,12 +32,14 @@
#include "WebDocument.h" #include "WebDocument.h"
#include "Document.h" #include "Document.h"
#include "DocumentLoader.h"
#include "Element.h" #include "Element.h"
#include "HTMLAllCollection.h" #include "HTMLAllCollection.h"
#include "HTMLBodyElement.h" #include "HTMLBodyElement.h"
#include "HTMLCollection.h" #include "HTMLCollection.h"
#include "HTMLElement.h" #include "HTMLElement.h"
#include "HTMLHeadElement.h" #include "HTMLHeadElement.h"
#include "NodeList.h"
#include "WebElement.h" #include "WebElement.h"
#include "WebFrameImpl.h" #include "WebFrameImpl.h"
...@@ -111,4 +113,38 @@ WebElement WebDocument::getElementById(const WebString& id) const ...@@ -111,4 +113,38 @@ WebElement WebDocument::getElementById(const WebString& id) const
return WebElement(constUnwrap<Document>()->getElementById(id)); return WebElement(constUnwrap<Document>()->getElementById(id));
} }
WebString WebDocument::applicationID() const
{
const char* kChromeApplicationHeader = "x-chrome-application";
// First check if the document's response included a header indicating the
// application it should go with.
const Document* document = constUnwrap<Document>();
Frame* frame = document->frame();
if (!frame)
return WebString();
DocumentLoader* loader = frame->loader()->documentLoader();
if (!loader)
return WebString();
WebString headerValue =
loader->response().httpHeaderField(kChromeApplicationHeader);
if (!headerValue.isEmpty())
return headerValue;
// Otherwise, fall back to looking for the meta tag.
RefPtr<NodeList> metaTags =
const_cast<Document*>(document)->getElementsByTagName("meta");
for (unsigned i = 0; i < metaTags->length(); ++i) {
Element* element = static_cast<Element*>(metaTags->item(i));
if (element->getAttribute("http-equiv").lower() ==
kChromeApplicationHeader) {
return element->getAttribute("value");
}
}
return WebString();
}
} // namespace WebKit } // namespace WebKit
2010-01-27 Aaron Boodman <aa@chromium.org>
Expand NotificationCenter::checkPermission() interface.
It now passes the full URL instead of just the origin.
https://bugs.webkit.org/show_bug.cgi?id=34238
* WebCoreSupport/WebDesktopNotificationsDelegate.cpp:
(WebDesktopNotificationsDelegate::checkPermission):
* WebCoreSupport/WebDesktopNotificationsDelegate.h:
2010-01-27 Adam Roben <aroben@apple.com> 2010-01-27 Adam Roben <aroben@apple.com>
Make it possible to instantiate WebSerializedJSValue using Make it possible to instantiate WebSerializedJSValue using
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include "WebSecurityOrigin.h" #include "WebSecurityOrigin.h"
#include "WebView.h" #include "WebView.h"
#include <WebCore/BString.h> #include <WebCore/BString.h>
#include <WebCore/Document.h>
#include <WebCore/KURL.h>
#if ENABLE(NOTIFICATIONS) #if ENABLE(NOTIFICATIONS)
...@@ -170,10 +172,10 @@ void WebDesktopNotificationsDelegate::requestPermission(SecurityOrigin* origin, ...@@ -170,10 +172,10 @@ void WebDesktopNotificationsDelegate::requestPermission(SecurityOrigin* origin,
notificationDelegate()->requestNotificationPermission(org); notificationDelegate()->requestNotificationPermission(org);
} }
NotificationPresenter::Permission WebDesktopNotificationsDelegate::checkPermission(SecurityOrigin* origin) NotificationPresenter::Permission WebDesktopNotificationsDelegate::checkPermission(const KURL& url, Document*)
{ {
int out = 0; int out = 0;
BString org(origin->toString()); BString org(SecurityOrigin::create(url)->toString());
if (hasNotificationDelegate()) if (hasNotificationDelegate())
notificationDelegate()->checkNotificationPermission(org, &out); notificationDelegate()->checkNotificationPermission(org, &out);
return (NotificationPresenter::Permission) out; return (NotificationPresenter::Permission) out;
......
...@@ -36,6 +36,11 @@ ...@@ -36,6 +36,11 @@
interface IWebDesktopNotificationPresenter; interface IWebDesktopNotificationPresenter;
namespace WebCore {
class Document;
class KURL;
}
class WebDesktopNotificationsDelegate : public WebCore::NotificationPresenter { class WebDesktopNotificationsDelegate : public WebCore::NotificationPresenter {
public: public:
WebDesktopNotificationsDelegate(WebView* view); WebDesktopNotificationsDelegate(WebView* view);
...@@ -45,7 +50,7 @@ public: ...@@ -45,7 +50,7 @@ public:
virtual void cancel(WebCore::Notification* object); virtual void cancel(WebCore::Notification* object);
virtual void notificationObjectDestroyed(WebCore::Notification* object); virtual void notificationObjectDestroyed(WebCore::Notification* object);
virtual void requestPermission(WebCore::SecurityOrigin* origin, PassRefPtr<WebCore::VoidCallback> callback); virtual void requestPermission(WebCore::SecurityOrigin* origin, PassRefPtr<WebCore::VoidCallback> callback);
virtual WebCore::NotificationPresenter::Permission checkPermission(WebCore::SecurityOrigin* origin); virtual WebCore::NotificationPresenter::Permission checkPermission(const KURL& url, Document* document);
private: private:
bool hasNotificationDelegate(); bool hasNotificationDelegate();
......
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