Source/WebCore: Bring notifications support to WK1 mac
authorjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Feb 2012 00:00:59 +0000 (00:00 +0000)
committerjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Feb 2012 00:00:59 +0000 (00:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78783
<rdar://problem/10610578>

Reviewed by Anders Carlsson.

* WebCore.exp.in: Expose dispatchErrorEvent on Notification.

Source/WebKit: Bring notifications support to WK1 mac: showing, canceling, removing notifications
https://bugs.webkit.org/show_bug.cgi?id=78783
<rdar://problem/10610578>

Reviewed by Anders Carlsson.

* WebKit.xcodeproj/project.pbxproj: Added new files.

Source/WebKit/mac: Bring notifications support to WK1 mac: permission requests
https://bugs.webkit.org/show_bug.cgi?id=78783
<rdar://problem/10610578>

Reviewed by Anders Carlsson.

* WebCoreSupport/WebNotificationClient.h:
* WebCoreSupport/WebNotificationClient.mm: Create policy listener, which conforms to the
WebAllowDenyPolicyListener protocol, similar to geolocation.
(WebNotificationClient::requestPermission):
(WebNotificationClient::checkPermission):
(-[WebNotificationPolicyListener initWithCallback:]):
(-[WebNotificationPolicyListener allow]): Call the callback.
(-[WebNotificationPolicyListener deny]): Call the callback.
* WebView/WebUIDelegatePrivate.h: Define new UI delegate method to ask the user to decide a
policy for navigations.

====
Bring notifications support to WK1 mac: showing, canceling, removing notifications

Create a WebKit wrapper object for WebCore::Notification, which also keeps track of an assigned
ID.
* WebView/WebNotification.h: Added.
(WebSecurityOrigin):
* WebView/WebNotification.mm: Added.
(core):
(-[WebNotification initWithCoreNotification:notificationID:]):
(-[WebNotification init]):
(-[WebNotification dealloc]):
(-[WebNotification title]):
(-[WebNotification body]):
(-[WebNotification origin]):
(-[WebNotification notificationID]):
(-[WebNotification dispatchShowEvent]):
(-[WebNotification dispatchCloseEvent]):
(-[WebNotification dispatchClickEvent]):
(-[WebNotification dispatchErrorEvent]):
* WebView/WebNotificationInternal.h: Added.
(WebCore): Internal category to allow creating instances with WebCore objects.

Extend WebView to include a WebNotificationProvider, which clients implement.
* WebView/WebViewData.h: Add a private member for the provider.
* WebView/WebViewPrivate.h:
    * Define an enum WebNotificationPermission that mirrors WebCore::NotificationPresenter::Permission
    that client which implement the provider can use to return policy decisions.
    * Define WebNotificationProvider.
    * Category WebViewNotification extends WebView with methods that set and manager the
    notification provider, and handle events from the platform notifications.
* WebView/WebView.mm:
(-[WebView _setNotificationProvider:]): Sets the provider when initializing the WebView.
(-[WebView _notificationControllerDestroyed]):
(-[WebView _notificationProvider]):
(-[WebView _notificationDidShow:]):
(-[WebView _notificationDidClick:]):
(-[WebView _notificationsDidClose:]):

* WebCoreSupport/WebNotificationClient.h: Add variables that map between WebCore::Notification
instances, their assigned IDs, their contexts, and corresponding WebKit wrapper objects.
* WebCoreSupport/WebNotificationClient.mm:
(generateNotificationID): Created unique IDs for each shown notification.
(WebNotificationClient::show): Create wrapper object for notification, assign ID, cache the
mappings between the objects, and forward it to the provider.
(WebNotificationClient::cancel):
(WebNotificationClient::clearNotifications): Clear all notifications associated with the
provided context.
(WebNotificationClient::notificationObjectDestroyed): Remove the notification from the maps.
(WebNotificationClient::notificationControllerDestroyed): If the controller is destroyed, tell
the provider to clear of the notifications related to this web view.

====
(Prep work for) Bring notifications support to WK1 mac

Rename WebGeolocationPolicyListener. The interface is generic enough to be reused for
notification requests. To avoid having to create a new listener type, instead rename it
to WebAllowDenyPolicyListener.
* WebView/WebUIDelegatePrivate.h: Rename the protocol.
* WebCoreSupport/WebGeolocationClient.mm: Refactor geolocation request listener to use
new name.

Add preference to keep track of whether notifications are enabled in general.
* WebView/WebPreferenceKeysPrivate.h: Add WebNotificationsEnabledKey for storing the
preference.
* WebView/WebPreferences.mm:
(+[WebPreferences initialize]): By default have them enabled.
(-[WebPreferences setNotificationsEnabled:]):
(-[WebPreferences notificationsEnabled]):
* WebView/WebPreferencesPrivate.h:

Add a stringValue method that exposes WebCore::SecurityOrigin::toString() for storing the
notification policy for a given origin.
* WebCoreSupport/WebSecurityOrigin.mm:
(-[WebSecurityOrigin stringValue]):
* WebCoreSupport/WebSecurityOriginPrivate.h:

Tools: Bring notifications support to WK1 mac
https://bugs.webkit.org/show_bug.cgi?id=78783
<rdar://problem/10610578>

Reviewed by Anders Carlsson.

* DumpRenderTree/mac/UIDelegate.mm: Refactor WebGeolocationPolicyListener to WebAllowDenyPolicyListener.
(-[UIDelegate webView:decidePolicyForGeolocationRequestFromOrigin:frame:listener:]):
(-[UIDelegate timerFired]):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@108409 268f45cc-cd09-0410-ab3c-d52691b4dbfc

23 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebKit/ChangeLog
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebGeolocationClient.mm
Source/WebKit/mac/WebCoreSupport/WebNotificationClient.h
Source/WebKit/mac/WebCoreSupport/WebNotificationClient.mm
Source/WebKit/mac/WebCoreSupport/WebSecurityOrigin.mm
Source/WebKit/mac/WebCoreSupport/WebSecurityOriginPrivate.h
Source/WebKit/mac/WebView/WebNotification.h [new file with mode: 0644]
Source/WebKit/mac/WebView/WebNotification.mm [new file with mode: 0644]
Source/WebKit/mac/WebView/WebNotificationInternal.h [new file with mode: 0644]
Source/WebKit/mac/WebView/WebPreferenceKeysPrivate.h
Source/WebKit/mac/WebView/WebPreferences.h
Source/WebKit/mac/WebView/WebPreferences.mm
Source/WebKit/mac/WebView/WebPreferencesPrivate.h
Source/WebKit/mac/WebView/WebUIDelegatePrivate.h
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit/mac/WebView/WebViewData.h
Source/WebKit/mac/WebView/WebViewPrivate.h
Tools/ChangeLog
Tools/DumpRenderTree/mac/UIDelegate.mm

index 4d30611..c3db3e3 100644 (file)
@@ -1,3 +1,13 @@
+2012-02-21  Jon Lee  <jonlee@apple.com>
+
+        Bring notifications support to WK1 mac
+        https://bugs.webkit.org/show_bug.cgi?id=78783
+        <rdar://problem/10610578>
+
+        Reviewed by Anders Carlsson.
+
+        * WebCore.exp.in: Expose dispatchErrorEvent on Notification.
+
 2012-02-21  No'am Rosenthal  <noam.rosenthal@nokia.com>
 
         [Qt] Previous web page appears outside content rect
index 73e8638..9d55461 100644 (file)
@@ -2078,6 +2078,7 @@ __ZN7WebCore12NotificationD1Ev
 __ZN7WebCore12Notification17dispatchShowEventEv
 __ZN7WebCore12Notification18dispatchClickEventEv
 __ZN7WebCore12Notification18dispatchCloseEventEv
+__ZN7WebCore12Notification18dispatchErrorEventEv
 #endif
 
 #if ENABLE(THREADED_SCROLLING)
index 9845e8d..2889ffc 100644 (file)
@@ -1,3 +1,13 @@
+2012-02-21  Jon Lee  <jonlee@apple.com>
+
+        Bring notifications support to WK1 mac: showing, canceling, removing notifications
+        https://bugs.webkit.org/show_bug.cgi?id=78783
+        <rdar://problem/10610578>
+
+        Reviewed by Anders Carlsson.
+
+        * WebKit.xcodeproj/project.pbxproj: Added new files.
+
 2012-02-21  Adam Roben  <aroben@apple.com>
 
         Roll out r108309, r108323, and r108326
index 16cdf4c..c8de755 100644 (file)
@@ -74,6 +74,9 @@
                226E9E6B09D0AA8200F3A2BC /* WebNetscapeDeprecatedFunctions.c in Sources */ = {isa = PBXBuildFile; fileRef = 226E9E6909D0AA8200F3A2BC /* WebNetscapeDeprecatedFunctions.c */; settings = {COMPILER_FLAGS = "-Wno-deprecated-declarations"; }; };
                22F219CC08D236730030E078 /* WebBackForwardListPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 22F219CB08D236730030E078 /* WebBackForwardListPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                29AEF960134C76FB00FE5096 /* OutlookQuirksUserScript.js in Resources */ = {isa = PBXBuildFile; fileRef = 29AEF95D134C755400FE5096 /* OutlookQuirksUserScript.js */; };
+               312E2FE514E48182007CCA18 /* WebNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = 312E2FE314E48182007CCA18 /* WebNotification.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               312E2FE614E48182007CCA18 /* WebNotification.mm in Sources */ = {isa = PBXBuildFile; fileRef = 312E2FE414E48182007CCA18 /* WebNotification.mm */; };
+               312E2FE914E48215007CCA18 /* WebNotificationInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 312E2FE814E48215007CCA18 /* WebNotificationInternal.h */; };
                31C11A6E1476552E0049A4CC /* WebNotificationClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 31C11A6C1476552E0049A4CC /* WebNotificationClient.h */; };
                31C11A6F1476552E0049A4CC /* WebNotificationClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 31C11A6D1476552E0049A4CC /* WebNotificationClient.mm */; };
                37B6FB4E1063530C000FDB3B /* WebPDFDocumentExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 37B6FB4C1063530C000FDB3B /* WebPDFDocumentExtras.h */; };
                2D36FD5E03F78F9E00A80166 /* WebFormDelegatePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebFormDelegatePrivate.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                2D81DAB203EB0B2D00A80166 /* WebFormDelegate.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebFormDelegate.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                2D81DAB303EB0B2D00A80166 /* WebFormDelegate.m */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = WebFormDelegate.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
+               312E2FE314E48182007CCA18 /* WebNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNotification.h; sourceTree = "<group>"; };
+               312E2FE414E48182007CCA18 /* WebNotification.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNotification.mm; sourceTree = "<group>"; };
+               312E2FE814E48215007CCA18 /* WebNotificationInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNotificationInternal.h; sourceTree = "<group>"; };
                31C11A6C1476552E0049A4CC /* WebNotificationClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNotificationClient.h; sourceTree = "<group>"; };
                31C11A6D1476552E0049A4CC /* WebNotificationClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNotificationClient.mm; sourceTree = "<group>"; };
                35081D9202B6D4D80ACA2ACA /* WebHTMLRepresentation.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; indentWidth = 4; path = WebHTMLRepresentation.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                                F834AAD60E64B1C700E2737C /* WebTextIterator.mm */,
                                515E27CC0458C86500CA2D3A /* WebUIDelegate.h */,
                                65A7D44A0568AB2600E70EF6 /* WebUIDelegatePrivate.h */,
+                               312E2FE314E48182007CCA18 /* WebNotification.h */,
+                               312E2FE414E48182007CCA18 /* WebNotification.mm */,
+                               312E2FE814E48215007CCA18 /* WebNotificationInternal.h */,
                                51A8B579042834F700CA2D3A /* WebView.h */,
                                51A8B57A042834F700CA2D3A /* WebView.mm */,
                                BC2E464B0FD8A96800A9D9DE /* WebViewData.h */,
                                9398109B0824BF01008DF038 /* WebViewInternal.h in Headers */,
                                939810710824BF01008DF038 /* WebViewPrivate.h in Headers */,
                                41F4484F10338E8C0030E55E /* WebWorkersPrivate.h in Headers */,
+                               312E2FE514E48182007CCA18 /* WebNotification.h in Headers */,
+                               312E2FE914E48215007CCA18 /* WebNotificationInternal.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                939811070824BF01008DF038 /* WebView.mm in Sources */,
                                BC2E464E0FD8A96800A9D9DE /* WebViewData.mm in Sources */,
                                41F4485010338E8C0030E55E /* WebWorkersPrivate.mm in Sources */,
+                               312E2FE614E48182007CCA18 /* WebNotification.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 1d7618d..ad43842 100644 (file)
@@ -1,3 +1,99 @@
+2012-02-21  Jon Lee  <jonlee@apple.com>
+
+        Bring notifications support to WK1 mac: permission requests
+        https://bugs.webkit.org/show_bug.cgi?id=78783
+        <rdar://problem/10610578>
+
+        Reviewed by Anders Carlsson.
+
+        * WebCoreSupport/WebNotificationClient.h:
+        * WebCoreSupport/WebNotificationClient.mm: Create policy listener, which conforms to the
+        WebAllowDenyPolicyListener protocol, similar to geolocation.
+        (WebNotificationClient::requestPermission):
+        (WebNotificationClient::checkPermission):
+        (-[WebNotificationPolicyListener initWithCallback:]):
+        (-[WebNotificationPolicyListener allow]): Call the callback.
+        (-[WebNotificationPolicyListener deny]): Call the callback.
+        * WebView/WebUIDelegatePrivate.h: Define new UI delegate method to ask the user to decide a
+        policy for navigations.
+
+        ====
+        Bring notifications support to WK1 mac: showing, canceling, removing notifications
+
+        Create a WebKit wrapper object for WebCore::Notification, which also keeps track of an assigned
+        ID.
+        * WebView/WebNotification.h: Added.
+        (WebSecurityOrigin):
+        * WebView/WebNotification.mm: Added.
+        (core):
+        (-[WebNotification initWithCoreNotification:notificationID:]):
+        (-[WebNotification init]):
+        (-[WebNotification dealloc]):
+        (-[WebNotification title]):
+        (-[WebNotification body]):
+        (-[WebNotification origin]):
+        (-[WebNotification notificationID]):
+        (-[WebNotification dispatchShowEvent]):
+        (-[WebNotification dispatchCloseEvent]):
+        (-[WebNotification dispatchClickEvent]):
+        (-[WebNotification dispatchErrorEvent]):
+        * WebView/WebNotificationInternal.h: Added.
+        (WebCore): Internal category to allow creating instances with WebCore objects.
+
+        Extend WebView to include a WebNotificationProvider, which clients implement.
+        * WebView/WebViewData.h: Add a private member for the provider.
+        * WebView/WebViewPrivate.h:
+            * Define an enum WebNotificationPermission that mirrors WebCore::NotificationPresenter::Permission
+            that client which implement the provider can use to return policy decisions.
+            * Define WebNotificationProvider.
+            * Category WebViewNotification extends WebView with methods that set and manager the
+            notification provider, and handle events from the platform notifications.
+        * WebView/WebView.mm:
+        (-[WebView _setNotificationProvider:]): Sets the provider when initializing the WebView.
+        (-[WebView _notificationControllerDestroyed]):
+        (-[WebView _notificationProvider]):
+        (-[WebView _notificationDidShow:]):
+        (-[WebView _notificationDidClick:]):
+        (-[WebView _notificationsDidClose:]):
+
+        * WebCoreSupport/WebNotificationClient.h: Add variables that map between WebCore::Notification
+        instances, their assigned IDs, their contexts, and corresponding WebKit wrapper objects.
+        * WebCoreSupport/WebNotificationClient.mm:
+        (generateNotificationID): Created unique IDs for each shown notification.
+        (WebNotificationClient::show): Create wrapper object for notification, assign ID, cache the
+        mappings between the objects, and forward it to the provider.
+        (WebNotificationClient::cancel):
+        (WebNotificationClient::clearNotifications): Clear all notifications associated with the
+        provided context.
+        (WebNotificationClient::notificationObjectDestroyed): Remove the notification from the maps.
+        (WebNotificationClient::notificationControllerDestroyed): If the controller is destroyed, tell
+        the provider to clear of the notifications related to this web view.
+
+        ====
+        (Prep work for) Bring notifications support to WK1 mac
+
+        Rename WebGeolocationPolicyListener. The interface is generic enough to be reused for
+        notification requests. To avoid having to create a new listener type, instead rename it
+        to WebAllowDenyPolicyListener.
+        * WebView/WebUIDelegatePrivate.h: Rename the protocol.
+        * WebCoreSupport/WebGeolocationClient.mm: Refactor geolocation request listener to use
+        new name.
+
+        Add preference to keep track of whether notifications are enabled in general.
+        * WebView/WebPreferenceKeysPrivate.h: Add WebNotificationsEnabledKey for storing the
+        preference.
+        * WebView/WebPreferences.mm:
+        (+[WebPreferences initialize]): By default have them enabled.
+        (-[WebPreferences setNotificationsEnabled:]):
+        (-[WebPreferences notificationsEnabled]):
+        * WebView/WebPreferencesPrivate.h:
+
+        Add a stringValue method that exposes WebCore::SecurityOrigin::toString() for storing the
+        notification policy for a given origin.
+        * WebCoreSupport/WebSecurityOrigin.mm:
+        (-[WebSecurityOrigin stringValue]):
+        * WebCoreSupport/WebSecurityOriginPrivate.h:
+
 2012-02-21  Sam Weinig  <sam@webkit.org>
 
         Attempt to fix the Snow Leopard build.
index b52b7bc..541f40c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2012 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -37,7 +37,7 @@
 
 using namespace WebCore;
 
-@interface WebGeolocationPolicyListener : NSObject <WebGeolocationPolicyListener>
+@interface WebGeolocationPolicyListener : NSObject <WebAllowDenyPolicyListener>
 {
     RefPtr<Geolocation> _geolocation;
 }
index 82903ca..960c72e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #import <WebCore/NotificationPresenter.h>
 
+#import <WebCore/Notification.h>
+#import <wtf/HashMap.h>
+#import <wtf/RefPtr.h>
+#import <wtf/RetainPtr.h>
+
 namespace WebCore {
 class ScriptExecutionContext;
 class VoidCallback;
 }
 
+@class WebNotification;
 @class WebView;
 
 class WebNotificationClient : public WebCore::NotificationPresenter {
@@ -40,11 +46,18 @@ public:
 private:
     virtual bool show(WebCore::Notification*) OVERRIDE;
     virtual void cancel(WebCore::Notification*) OVERRIDE;
+    virtual void clearNotifications(WebCore::ScriptExecutionContext*) OVERRIDE;
     virtual void notificationObjectDestroyed(WebCore::Notification*) OVERRIDE;
     virtual void notificationControllerDestroyed() OVERRIDE;
     virtual void requestPermission(WebCore::ScriptExecutionContext*, PassRefPtr<WebCore::VoidCallback>) OVERRIDE;
-    virtual void cancelRequestsForPermission(WebCore::ScriptExecutionContext*) OVERRIDE;
+    virtual void cancelRequestsForPermission(WebCore::ScriptExecutionContext*) OVERRIDE { }
     virtual WebCore::NotificationPresenter::Permission checkPermission(WebCore::ScriptExecutionContext*) OVERRIDE;
 
     WebView *m_webView;
+    HashMap<uint64_t, RetainPtr<WebNotification> > m_notificationIDMap;
+    HashMap<RefPtr<WebCore::Notification>, uint64_t> m_notificationMap;
+    
+    typedef HashMap<RefPtr<WebCore::ScriptExecutionContext>, Vector<uint64_t> > NotificationContextMap;
+    NotificationContextMap m_notificationContextMap;
+
 };
index 80138e3..5c117a0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #import "WebNotificationClient.h"
 
+#import "WebNotificationInternal.h"
+#import "WebViewInternal.h"
 #import <WebCore/NotImplemented.h>
 #import <WebCore/Notification.h>
 
+#if ENABLE(NOTIFICATIONS)
+#import "WebDelegateImplementationCaching.h"
+#import "WebPreferencesPrivate.h"
+#import "WebSecurityOriginInternal.h"
+#import "WebUIDelegatePrivate.h"
+#import <WebCore/BlockExceptions.h>
+#import <WebCore/Page.h>
+#import <WebCore/ScriptExecutionContext.h>
+#endif
+
 using namespace WebCore;
 
+#if ENABLE(NOTIFICATIONS)
+@interface WebNotificationPolicyListener : NSObject <WebAllowDenyPolicyListener>
+{
+    RefPtr<VoidCallback> _callback;
+}
+- (id)initWithCallback:(PassRefPtr<VoidCallback>)callback;
+@end
+#endif
+
+#if ENABLE(NOTIFICATIONS)
+static uint64_t generateNotificationID()
+{
+    static uint64_t uniqueNotificationID = 1;
+    return uniqueNotificationID++;
+}
+#endif
+
 WebNotificationClient::WebNotificationClient(WebView *webView)
     : m_webView(webView)
 {
 }
 
-bool WebNotificationClient::show(Notification*)
+bool WebNotificationClient::show(Notification* notification)
 {
-    notImplemented();
+#if ENABLE(NOTIFICATIONS)
+    if (![m_webView _notificationProvider])
+        return false;
+
+    uint64_t notificationID = generateNotificationID();
+    RetainPtr<WebNotification> webNotification = adoptNS([[WebNotification alloc] initWithCoreNotification:notification notificationID:notificationID]);
+    m_notificationMap.set(notification, notificationID);
+    m_notificationIDMap.set(notificationID, webNotification);
+
+    NotificationContextMap::iterator it = m_notificationContextMap.find(notification->scriptExecutionContext());
+    if (it == m_notificationContextMap.end()) {
+        pair<NotificationContextMap::iterator, bool> addedPair = m_notificationContextMap.add(notification->scriptExecutionContext(), Vector<uint64_t>());
+        it = addedPair.first;
+    }
+    it->second.append(notificationID);
+
+    [[m_webView _notificationProvider] showNotification:webNotification.get() fromWebView:m_webView];
+    return true;
+#else
+    UNUSED_PARAM(notification);
     return false;
+#endif
 }
 
-void WebNotificationClient::cancel(Notification*)
+void WebNotificationClient::cancel(Notification* notification)
 {
-    notImplemented();
+#if ENABLE(NOTIFICATIONS)
+    uint64_t notificationID = m_notificationMap.get(notification);
+    if (!notificationID)
+        return;
+    
+    WebNotification *webNotification = m_notificationIDMap.get(notificationID).get();
+    ASSERT(webNotification);
+    [[m_webView _notificationProvider] cancelNotification:webNotification];
+#else
+    UNUSED_PARAM(notification);
+#endif
 }
 
-void WebNotificationClient::notificationObjectDestroyed(WebCore::Notification*)
+void WebNotificationClient::clearNotifications(ScriptExecutionContext* context)
 {
-    notImplemented();
+#if ENABLE(NOTIFICATIONS)
+    NotificationContextMap::iterator it = m_notificationContextMap.find(context);
+    if (it == m_notificationContextMap.end())
+        return;
+    
+    Vector<uint64_t>& notificationIDs = it->second;
+    NSMutableArray *nsIDs = [NSMutableArray array];
+    size_t count = notificationIDs.size();
+    for (size_t i = 0; i < count; ++i)
+        [nsIDs addObject:[NSNumber numberWithUnsignedLongLong:notificationIDs[i]]];
+    [[m_webView _notificationProvider] clearNotifications:nsIDs];
+
+    for (size_t i = 0; i < count; ++i) {
+        RetainPtr<WebNotification> webNotification = m_notificationIDMap.take(notificationIDs[i]);
+        if (!webNotification)
+            continue;
+        m_notificationMap.remove(core(webNotification.get()));
+    }
+    
+    m_notificationContextMap.remove(it);
+#else
+    UNUSED_PARAM(context);
+#endif
+}
+
+void WebNotificationClient::notificationObjectDestroyed(Notification* notification)
+{
+#if ENABLE(NOTIFICATIONS)
+    uint64_t notificationID = m_notificationMap.take(notification);
+    if (!notificationID)
+        return;
+
+    RetainPtr<WebNotification> webNotification = m_notificationIDMap.take(notificationID);
+    ASSERT(webNotification.get());
+
+    NotificationContextMap::iterator it = m_notificationContextMap.find(notification->scriptExecutionContext());
+    ASSERT(it != m_notificationContextMap.end());
+    size_t index = it->second.find(notificationID);
+    ASSERT(index != notFound);
+    it->second.remove(index);
+    if (it->second.isEmpty())
+        m_notificationContextMap.remove(it);
+
+    [[m_webView _notificationProvider] notificationDestroyed:webNotification.get()];
+#else
+    UNUSED_PARAM(notification);
+#endif
 }
 
 void WebNotificationClient::notificationControllerDestroyed()
 {
+#if ENABLE(NOTIFICATIONS)
+    NSMutableArray *notificationIDs = [NSMutableArray array];
+    HashMap<uint64_t, RetainPtr<WebNotification> >::iterator itEnd = m_notificationIDMap.end();
+    for (HashMap<uint64_t, RetainPtr<WebNotification> >::iterator it = m_notificationIDMap.begin(); it != itEnd; ++it)
+        [notificationIDs addObject:[NSNumber numberWithUnsignedLongLong:it->first]];
+    [[m_webView _notificationProvider] clearNotifications:notificationIDs];
+    [m_webView _notificationControllerDestroyed];
+#endif
     delete this;
 }
 
-void WebNotificationClient::requestPermission(WebCore::ScriptExecutionContext*, PassRefPtr<WebCore::VoidCallback>)
+void WebNotificationClient::requestPermission(ScriptExecutionContext* context, PassRefPtr<VoidCallback> callback)
 {
-    notImplemented();
+#if ENABLE(NOTIFICATIONS)
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    
+    SEL selector = @selector(webView:decidePolicyForNotificationRequestFromOrigin:listener:);
+    if (![[m_webView UIDelegate] respondsToSelector:selector])
+        return;
+    
+    WebSecurityOrigin *webOrigin = [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:context->securityOrigin()];
+    WebNotificationPolicyListener* listener = [[WebNotificationPolicyListener alloc] initWithCallback:callback];
+    
+    CallUIDelegate(m_webView, selector, webOrigin, listener);
+    
+    [webOrigin release];
+    [listener release];
+    
+    END_BLOCK_OBJC_EXCEPTIONS;
+#else
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(callback);
+#endif
 }
 
-void WebNotificationClient::cancelRequestsForPermission(WebCore::ScriptExecutionContext*)
+NotificationPresenter::Permission WebNotificationClient::checkPermission(ScriptExecutionContext* context)
 {
-    notImplemented();
+#if ENABLE(NOTIFICATIONS)
+    if (!context || !context->isDocument())
+        return NotificationPresenter::PermissionDenied;
+    if (![[m_webView preferences] notificationsEnabled])
+        return NotificationPresenter::PermissionDenied;
+    WebSecurityOrigin *webOrigin = [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:context->securityOrigin()];
+    WebNotificationPermission permission = [[m_webView _notificationProvider] policyForOrigin:webOrigin];
+    [webOrigin release];
+    switch (permission) {
+        case WebNotificationPermissionAllowed:
+            return NotificationPresenter::PermissionAllowed;
+        case WebNotificationPermissionDenied:
+            return NotificationPresenter::PermissionDenied;
+        case WebNotificationPermissionNotAllowed:
+            return NotificationPresenter::PermissionNotAllowed;
+        default:
+            return NotificationPresenter::PermissionNotAllowed;
+    }
+#else
+    UNUSED_PARAM(context);
+    return NotificationPresenter::PermissionDenied;
+#endif
 }
 
-NotificationPresenter::Permission WebNotificationClient::checkPermission(WebCore::ScriptExecutionContext*)
+#if ENABLE(NOTIFICATIONS)
+@implementation WebNotificationPolicyListener
+- (id)initWithCallback:(PassRefPtr<VoidCallback>)callback
 {
-    notImplemented();
-    return NotificationPresenter::PermissionDenied;
+    if (!(self = [super init]))
+        return nil;
+
+    ASSERT(callback);
+    _callback = callback;
+    return self;
 }
+
+- (void)allow
+{
+    _callback->handleEvent();
+}
+
+- (void)deny
+{
+    _callback->handleEvent();
+}
+
+@end
+#endif
index 2373f84..8f38fed 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2007, 2010, 2012 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -66,6 +66,11 @@ using namespace WebCore;
     return reinterpret_cast<SecurityOrigin*>(_private)->databaseIdentifier();
 }
 
+- (NSString *)stringValue
+{
+    return reinterpret_cast<SecurityOrigin*>(_private)->toString();
+}
+
 // Deprecated. Use host instead. This needs to stay here until we ship a new Safari.
 - (NSString *)domain
 {
index a784aba..fae4c33 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2010 Apple Inc.  All rights reserved.
+ * Copyright (C) 2007, 2010, 2012 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -41,6 +41,7 @@
 - (NSString *)host;
 
 - (NSString *)databaseIdentifier;
+- (NSString *)stringValue;
 
 // Returns zero if the port is the default port for the protocol, non-zero otherwise.
 - (unsigned short)port;
diff --git a/Source/WebKit/mac/WebView/WebNotification.h b/Source/WebKit/mac/WebView/WebNotification.h
new file mode 100644 (file)
index 0000000..c04b2ad
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2012 Apple Computer, 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:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  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.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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.
+ */
+
+@class WebNotificationPrivate;
+@class WebSecurityOrigin;
+
+@interface WebNotification : NSObject
+{
+    WebNotificationPrivate *_private;
+}
+
+- (NSString *)title;
+- (NSString *)body;
+- (WebSecurityOrigin *)origin;
+- (uint64_t)notificationID;
+
+- (void)dispatchShowEvent;
+- (void)dispatchCloseEvent;
+- (void)dispatchClickEvent;
+- (void)dispatchErrorEvent;
+
+@end
diff --git a/Source/WebKit/mac/WebView/WebNotification.mm b/Source/WebKit/mac/WebView/WebNotification.mm
new file mode 100644 (file)
index 0000000..b247008
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2012 Apple Computer, 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:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  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.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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.
+ */
+
+#import "WebNotification.h"
+
+#import "WebNotificationInternal.h"
+#import "WebSecurityOriginInternal.h"
+#import <WebCore/Notification.h>
+#import <WebCore/ScriptExecutionContext.h>
+#import <wtf/PassRefPtr.h>
+#import <wtf/RefPtr.h>
+
+using namespace WebCore;
+
+OBJC_CLASS WebNotificationInternal;
+
+@interface WebNotificationPrivate : NSObject
+{
+@public
+    WebNotificationInternal *_internal;
+    uint64_t _notificationID;
+}
+@end
+
+@implementation WebNotificationPrivate
+@end
+
+#if ENABLE(NOTIFICATIONS)
+@implementation WebNotification (WebNotificationInternal)
+Notification* core(WebNotification *notification)
+{
+    if (!notification->_private)
+        return 0;
+    return reinterpret_cast<Notification*>(notification->_private->_internal);
+}
+
+- (id)initWithCoreNotification:(Notification*)coreNotification notificationID:(uint64_t)notificationID
+{
+    if (!(self = [super init]))
+        return nil;
+    coreNotification->ref();
+    _private = [[WebNotificationPrivate alloc] init];
+    _private->_internal = reinterpret_cast<WebNotificationInternal*>(coreNotification);
+    _private->_notificationID = notificationID;
+    return self;
+}
+@end
+#endif
+
+@implementation WebNotification
+- (id)init
+{
+    return nil;
+}
+
+- (void)dealloc
+{
+    Notification* notification = core(self);
+    if (notification)
+        notification->deref();
+
+    [super dealloc];
+}
+
+- (NSString *)title
+{
+    ASSERT(core(self));
+    return core(self)->contents().title;
+}
+
+- (NSString *)body
+{
+    ASSERT(core(self));
+    return core(self)->contents().body;
+}
+
+- (WebSecurityOrigin *)origin
+{
+    ASSERT(core(self));
+    return [[[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:core(self)->scriptExecutionContext()->securityOrigin()] autorelease];
+}
+
+- (uint64_t)notificationID
+{
+    ASSERT(core(self));
+    return _private->_notificationID;
+}
+
+- (void)dispatchShowEvent
+{
+    ASSERT(core(self));
+    core(self)->dispatchShowEvent();
+}
+
+- (void)dispatchCloseEvent
+{
+    ASSERT(core(self));
+    core(self)->dispatchCloseEvent();
+}
+
+- (void)dispatchClickEvent
+{
+    ASSERT(core(self));
+    core(self)->dispatchClickEvent();
+}
+
+- (void)dispatchErrorEvent
+{
+    ASSERT(core(self));
+    core(self)->dispatchErrorEvent();
+}
+
+@end
diff --git a/Source/WebKit/mac/WebView/WebNotificationInternal.h b/Source/WebKit/mac/WebView/WebNotificationInternal.h
new file mode 100644 (file)
index 0000000..b624069
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2012 Apple Computer, 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:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  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.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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.
+ */
+
+#import "WebNotification.h"
+
+#if ENABLE(NOTIFICATIONS)
+
+namespace WebCore {
+class Notification;
+}
+
+WebCore::Notification* core(WebNotification *);
+
+@interface WebNotification (WebNotificationInternal)
+- (id)initWithCoreNotification:(WebCore::Notification*)coreNotification notificationID:(uint64_t)notificationID;
+@end
+
+#endif
index b123a6c..22ca342 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2005, 2012 Apple Computer, Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #define WebKitShouldDisplaySubtitlesPreferenceKey @"WebKitShouldDisplaySubtitles"
 #define WebKitShouldDisplayCaptionsPreferenceKey @"WebKitShouldDisplayCaptions"
 #define WebKitShouldDisplayTextDescriptionsPreferenceKey @"WebKitShouldDisplayTextDescriptions"
+#define WebKitNotificationsEnabledKey @"WebKitNotificationsEnabled"
 
 // These are private both because callers should be using the cover methods and because the
 // cover methods themselves are private.
index 80cc935..03ae412 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003, 2004, 2005 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2003, 2004, 2005, 2012 Apple Computer, Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
index bec8519..8a801a7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006, 2007, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2005, 2006, 2007, 2011, 2012 Apple Inc. All rights reserved.
  *           (C) 2006 Graham Dennis (graham.dennis@gmail.com)
  *
  * Redistribution and use in source and binary forms, with or without
@@ -394,6 +394,7 @@ static WebCacheModel cacheModelForMainBundle(void)
         [NSNumber numberWithBool:NO],   WebKitShouldDisplaySubtitlesPreferenceKey,
         [NSNumber numberWithBool:NO],   WebKitShouldDisplayCaptionsPreferenceKey,
         [NSNumber numberWithBool:NO],   WebKitShouldDisplayTextDescriptionsPreferenceKey,
+        [NSNumber numberWithBool:YES],  WebKitNotificationsEnabledKey,
 
         [NSNumber numberWithLongLong:ApplicationCacheStorage::noQuota()], WebKitApplicationCacheTotalQuota,
         [NSNumber numberWithLongLong:ApplicationCacheStorage::noQuota()], WebKitApplicationCacheDefaultOriginQuota,
@@ -1642,6 +1643,16 @@ static NSString *classIBCreatorID = nil;
     return [self _boolValueForKey:WebKitShouldDisplayTextDescriptionsPreferenceKey];
 }
 
+- (void)setNotificationsEnabled:(BOOL)flag
+{
+    [self _setBoolValue:flag forKey:WebKitNotificationsEnabledKey];
+}
+
+- (BOOL)notificationsEnabled
+{
+    return [self _boolValueForKey:WebKitNotificationsEnabledKey];
+}
+
 @end
 
 @implementation WebPreferences (WebInternal)
index dc1e6b8..890d206 100644 (file)
@@ -289,4 +289,7 @@ extern NSString *WebPreferencesChangedInternalNotification;
 - (void)setShouldDisplayTextDescriptions:(BOOL)flag;
 - (BOOL)shouldDisplayTextDescriptions;
 
+- (void)setNotificationsEnabled:(BOOL)flag;
+- (BOOL)notificationsEnabled;
+
 @end
index 9c98fdf..df57026 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -119,7 +119,7 @@ extern NSString *WebConsoleMessageDebugMessageLevel;
 
 @class WebSecurityOrigin;
 
-@protocol WebGeolocationPolicyListener <NSObject>
+@protocol WebAllowDenyPolicyListener <NSObject>
 - (void)allow;
 - (void)deny;
 @end
@@ -223,7 +223,8 @@ extern NSString *WebConsoleMessageDebugMessageLevel;
 */
 - (void)webView:(WebView *)webView decidePolicyForGeolocationRequestFromOrigin:(WebSecurityOrigin *)origin
                                                                          frame:(WebFrame *)frame
-                                                                      listener:(id<WebGeolocationPolicyListener>)listener;
+                                                                      listener:(id<WebAllowDenyPolicyListener>)listener;
+- (void)webView:(WebView *)webView decidePolicyForNotificationRequestFromOrigin:(WebSecurityOrigin *)origin listener:(id<WebAllowDenyPolicyListener>)listener;
 
 - (void)webView:(WebView *)sender elementDidFocusNode:(DOMNode *)node;
 - (void)webView:(WebView *)sender elementDidBlurNode:(DOMNode *)node;
index 84f183d..d9c4fdc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2005-2012 Apple Inc. All rights reserved.
  * Copyright (C) 2006 David Smith (catfish.man@gmail.com)
  * Copyright (C) 2010 Igalia S.L
  *
@@ -6411,6 +6411,43 @@ static void glibContextIterationCallback(CFRunLoopObserverRef, CFRunLoopActivity
 
 @end
 
+@implementation WebView (WebViewNotification)
+- (void)_setNotificationProvider:(id<WebNotificationProvider>)notificationProvider
+{
+    if (_private) {
+        _private->_notificationProvider = notificationProvider;
+        [_private->_notificationProvider registerWebView:self];
+    }
+}
+
+- (void)_notificationControllerDestroyed
+{
+    [[self _notificationProvider] unregisterWebView:self];
+}
+
+- (id<WebNotificationProvider>)_notificationProvider
+{
+    if (_private)
+        return _private->_notificationProvider;
+    return nil;
+}
+
+- (void)_notificationDidShow:(uint64_t)notificationID
+{
+    [[self _notificationProvider] webView:self didShowNotification:notificationID];
+}
+
+- (void)_notificationDidClick:(uint64_t)notificationID
+{
+    [[self _notificationProvider] webView:self didClickNotification:notificationID];
+}
+
+- (void)_notificationsDidClose:(NSArray *)notificationIDs
+{
+    [[self _notificationProvider] webView:self didCloseNotifications:notificationIDs];
+}
+@end
+
 @implementation WebView (WebViewPrivateStyleInfo)
 
 - (JSValueRef)_computedStyleIncludingVisitedInfo:(JSContextRef)context forElement:(JSValueRef)value
index 665cb91..ea2bfcf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All rights reserved.
  * Copyright (C) 2010 Igalia S.L
  *
  * Redistribution and use in source and binary forms, with or without
@@ -50,6 +50,7 @@ namespace WebCore {
 @protocol WebFormDelegate;
 @protocol WebDeviceOrientationProvider;
 @protocol WebGeolocationProvider;
+@protocol WebNotificationProvider;
 #if ENABLE(VIDEO)
 @class WebVideoFullscreenController;
 #endif
@@ -191,6 +192,7 @@ private:
 #endif
     id<WebGeolocationProvider> _geolocationProvider;
     id<WebDeviceOrientationProvider> m_deviceOrientationProvider;
+    id<WebNotificationProvider> _notificationProvider;
 
     RefPtr<WebCore::HistoryItem> _globalHistoryItem;
 
index cd92f31..e0fee81 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2005-2012 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 @class WebDeviceOrientation;
 @class WebGeolocationPosition;
 @class WebInspector;
+@class WebNotification;
 @class WebPreferences;
 @class WebScriptWorld;
+@class WebSecurityOrigin;
 @class WebTextIterator;
 
 @protocol WebDeviceOrientationProvider;
@@ -104,6 +106,13 @@ typedef enum {
     WebPaginationModeVertical,
 } WebPaginationMode;
 
+// This needs to be in sync with WebCore::NotificationPresenter::Permission
+typedef enum {
+    WebNotificationPermissionAllowed,
+    WebNotificationPermissionNotAllowed,
+    WebNotificationPermissionDenied
+} WebNotificationPermission;
+
 @interface WebController : NSTreeController {
     IBOutlet WebView *webView;
 }
@@ -701,6 +710,21 @@ Could be worth adding to the API.
 - (WebGeolocationPosition *)lastPosition;
 @end
 
+@protocol WebNotificationProvider
+- (void)registerWebView:(WebView *)webView;
+- (void)unregisterWebView:(WebView *)webView;
+
+- (void)showNotification:(WebNotification *)notification fromWebView:(WebView *)webView;
+- (void)cancelNotification:(WebNotification *)notification;
+- (void)notificationDestroyed:(WebNotification *)notification;
+- (void)clearNotifications:(NSArray *)notificationIDs;
+- (WebNotificationPermission)policyForOrigin:(WebSecurityOrigin *)origin;
+
+- (void)webView:(WebView *)webView didShowNotification:(uint64_t)notificationID;
+- (void)webView:(WebView *)webView didClickNotification:(uint64_t)notificationID;
+- (void)webView:(WebView *)webView didCloseNotifications:(NSArray *)notificationIDs;
+@end
+
 @interface WebView (WebViewGeolocation)
 - (void)_setGeolocationProvider:(id<WebGeolocationProvider>)locationProvider;
 - (id<WebGeolocationProvider>)_geolocationProvider;
@@ -709,6 +733,16 @@ Could be worth adding to the API.
 - (void)_geolocationDidFailWithError:(NSError *)error;
 @end
 
+@interface WebView (WebViewNotification)
+- (void)_setNotificationProvider:(id<WebNotificationProvider>)notificationProvider;
+- (id<WebNotificationProvider>)_notificationProvider;
+- (void)_notificationControllerDestroyed;
+
+- (void)_notificationDidShow:(uint64_t)notificationID;
+- (void)_notificationDidClick:(uint64_t)notificationID;
+- (void)_notificationsDidClose:(NSArray *)notificationIDs;
+@end
+
 @interface WebView (WebViewPrivateStyleInfo)
 - (JSValueRef)_computedStyleIncludingVisitedInfo:(JSContextRef)context forElement:(JSValueRef)value;
 @end
index 4732aa5..dbf7cde 100644 (file)
@@ -1,3 +1,15 @@
+2012-02-21  Jon Lee  <jonlee@apple.com>
+
+        Bring notifications support to WK1 mac
+        https://bugs.webkit.org/show_bug.cgi?id=78783
+        <rdar://problem/10610578>
+
+        Reviewed by Anders Carlsson.
+
+        * DumpRenderTree/mac/UIDelegate.mm: Refactor WebGeolocationPolicyListener to WebAllowDenyPolicyListener.
+        (-[UIDelegate webView:decidePolicyForGeolocationRequestFromOrigin:frame:listener:]):
+        (-[UIDelegate timerFired]):
+
 2012-02-21  Kentaro Hara  <haraken@chromium.org>
 
         Enable the IDL attribute checker in run-bindings-tests
index 493c02d..87eece4 100644 (file)
@@ -195,7 +195,7 @@ DumpRenderTreeDraggingInfo *draggingInfo = nil;
         printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", [text UTF8String]);
 }
 
-- (void)webView:(WebView *)webView decidePolicyForGeolocationRequestFromOrigin:(WebSecurityOrigin *)origin frame:(WebFrame *)frame listener:(id<WebGeolocationPolicyListener>)listener
+- (void)webView:(WebView *)webView decidePolicyForGeolocationRequestFromOrigin:(WebSecurityOrigin *)origin frame:(WebFrame *)frame listener:(id<WebAllowDenyPolicyListener>)listener
 {
     if (!gLayoutTestController->isGeolocationPermissionSet()) {
         if (!m_pendingGeolocationPermissionListeners)
@@ -230,7 +230,7 @@ DumpRenderTreeDraggingInfo *draggingInfo = nil;
     ASSERT(gLayoutTestController->isGeolocationPermissionSet());
     m_timer = 0;
     NSEnumerator* enumerator = [m_pendingGeolocationPermissionListeners objectEnumerator];
-    id<WebGeolocationPolicyListener> listener;
+    id<WebAllowDenyPolicyListener> listener;
     while ((listener = [enumerator nextObject])) {
         if (gLayoutTestController->geolocationPermission())
             [listener allow];