Title: [140927] trunk
Revision
140927
Author
joc...@chromium.org
Date
2013-01-27 02:58:30 -0800 (Sun, 27 Jan 2013)

Log Message

Check notification permissions in the show() method
https://bugs.webkit.org/show_bug.cgi?id=108009

Reviewed by Adam Barth.

Source/WebCore:

Tests: fast/notifications/notifications-constructor-with-permission.html
       fast/notifications/notifications-constructor-without-permission.html

* Modules/notifications/Notification.cpp:
(WebCore::Notification::show):
(WebCore::Notification::taskTimerFired):

LayoutTests:

* fast/notifications/notifications-constructor-with-permission-expected.txt: Added.
* fast/notifications/notifications-constructor-with-permission.html: Added.
* fast/notifications/notifications-constructor-without-permission-expected.txt: Added.
* fast/notifications/notifications-constructor-without-permission.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (140926 => 140927)


--- trunk/LayoutTests/ChangeLog	2013-01-27 07:02:45 UTC (rev 140926)
+++ trunk/LayoutTests/ChangeLog	2013-01-27 10:58:30 UTC (rev 140927)
@@ -1,3 +1,15 @@
+2013-01-27  Jochen Eisinger  <joc...@chromium.org>
+
+        Check notification permissions in the show() method
+        https://bugs.webkit.org/show_bug.cgi?id=108009
+
+        Reviewed by Adam Barth.
+
+        * fast/notifications/notifications-constructor-with-permission-expected.txt: Added.
+        * fast/notifications/notifications-constructor-with-permission.html: Added.
+        * fast/notifications/notifications-constructor-without-permission-expected.txt: Added.
+        * fast/notifications/notifications-constructor-without-permission.html: Added.
+
 2013-01-26  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r140880.

Added: trunk/LayoutTests/fast/notifications/notifications-constructor-with-permission-expected.txt (0 => 140927)


--- trunk/LayoutTests/fast/notifications/notifications-constructor-with-permission-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/notifications/notifications-constructor-with-permission-expected.txt	2013-01-27 10:58:30 UTC (rev 140927)
@@ -0,0 +1,5 @@
+DESKTOP NOTIFICATION: icon , title Hello world, text 
+Sending notifications with permission...
+
+PASS: show event fired.
+

Added: trunk/LayoutTests/fast/notifications/notifications-constructor-with-permission.html (0 => 140927)


--- trunk/LayoutTests/fast/notifications/notifications-constructor-with-permission.html	                        (rev 0)
+++ trunk/LayoutTests/fast/notifications/notifications-constructor-with-permission.html	2013-01-27 10:58:30 UTC (rev 140927)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script type="text/_javascript_">
+        function log(message)
+        {
+            document.getElementById("result").innerHTML += message + "<br>";
+        }
+        
+        function runTests()
+        {
+            if (window.testRunner) {
+                testRunner.grantWebNotificationPermission("file://");
+                testRunner.dumpAsText();
+                testRunner.waitUntilDone();
+            }
+
+            if (!window.Notification) {
+                log("FAIL: No Notification constructor!");
+            }
+            
+            var N = new Notification("Hello world");
+            N._onshow_ = function() { log("PASS: show event fired."); }
+            N._onerror_ = function() { log("FAIL: error event fired."); }
+            setTimeout(function() { testRunner.notifyDone(); }, 100);
+        }
+    </script>
+</head>
+<body>
+<p>Sending notifications with permission...</p>
+<div id="result"></div>
+
+<script type="text/_javascript_">
+runTests();
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/fast/notifications/notifications-constructor-without-permission-expected.txt (0 => 140927)


--- trunk/LayoutTests/fast/notifications/notifications-constructor-without-permission-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/notifications/notifications-constructor-without-permission-expected.txt	2013-01-27 10:58:30 UTC (rev 140927)
@@ -0,0 +1,4 @@
+Sending notifications without permission...
+
+PASS: error event fired.
+

Added: trunk/LayoutTests/fast/notifications/notifications-constructor-without-permission.html (0 => 140927)


--- trunk/LayoutTests/fast/notifications/notifications-constructor-without-permission.html	                        (rev 0)
+++ trunk/LayoutTests/fast/notifications/notifications-constructor-without-permission.html	2013-01-27 10:58:30 UTC (rev 140927)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script type="text/_javascript_">
+        function log(message)
+        {
+            document.getElementById("result").innerHTML += message + "<br>";
+        }
+        
+        function runTests()
+        {
+            if (window.testRunner) {
+                // NO PERMISSION testRunner.grantWebNotificationPermission("file://");
+                testRunner.dumpAsText();
+                testRunner.waitUntilDone();
+            }
+
+            if (!window.Notification) {
+                log("FAIL: No Notification constructor!");
+            }
+            
+            var N = new Notification("Hello world");
+            N._onshow_ = function() { log("FAIL: show event fired."); }
+            N._onerror_ = function() { log("PASS: error event fired."); }
+            setTimeout(function() { testRunner.notifyDone(); }, 100);
+        }
+    </script>
+</head>
+<body>
+<p>Sending notifications without permission...</p>
+<div id="result"></div>
+
+<script type="text/_javascript_">
+runTests();
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (140926 => 140927)


--- trunk/Source/WebCore/ChangeLog	2013-01-27 07:02:45 UTC (rev 140926)
+++ trunk/Source/WebCore/ChangeLog	2013-01-27 10:58:30 UTC (rev 140927)
@@ -1,3 +1,17 @@
+2013-01-27  Jochen Eisinger  <joc...@chromium.org>
+
+        Check notification permissions in the show() method
+        https://bugs.webkit.org/show_bug.cgi?id=108009
+
+        Reviewed by Adam Barth.
+
+        Tests: fast/notifications/notifications-constructor-with-permission.html
+               fast/notifications/notifications-constructor-without-permission.html
+
+        * Modules/notifications/Notification.cpp:
+        (WebCore::Notification::show):
+        (WebCore::Notification::taskTimerFired):
+
 2013-01-26  Tony Chang  <t...@chromium.org>
 
         [chromium] Don't use goma to preprocess bindings idl files

Modified: trunk/Source/WebCore/Modules/notifications/Notification.cpp (140926 => 140927)


--- trunk/Source/WebCore/Modules/notifications/Notification.cpp	2013-01-27 07:02:45 UTC (rev 140926)
+++ trunk/Source/WebCore/Modules/notifications/Notification.cpp	2013-01-27 10:58:30 UTC (rev 140927)
@@ -169,9 +169,19 @@
 void Notification::show() 
 {
     // prevent double-showing
-    if (m_state == Idle && m_notificationCenter->client() && m_notificationCenter->client()->show(this)) {
-        m_state = Showing;
-        setPendingActivity(this);
+    if (m_state == Idle && m_notificationCenter->client()) {
+#if ENABLE(NOTIFICATIONS)
+        if (!static_cast<Document*>(scriptExecutionContext())->page())
+            return;
+        if (NotificationController::from(static_cast<Document*>(scriptExecutionContext())->page())->client()->checkPermission(scriptExecutionContext()) != NotificationClient::PermissionAllowed) {
+            dispatchErrorEvent();
+            return;
+        }
+#endif
+        if (m_notificationCenter->client()->show(this)) {
+            m_state = Showing;
+            setPendingActivity(this);
+        }
     }
 }
 
@@ -240,12 +250,7 @@
 void Notification::taskTimerFired(Timer<Notification>* timer)
 {
     ASSERT(scriptExecutionContext()->isDocument());
-    ASSERT(static_cast<Document*>(scriptExecutionContext())->page());
     ASSERT_UNUSED(timer, timer == m_taskTimer.get());
-    if (NotificationController::from(static_cast<Document*>(scriptExecutionContext())->page())->client()->checkPermission(scriptExecutionContext()) != NotificationClient::PermissionAllowed) {
-        dispatchErrorEvent();
-        return;
-    }
     show();
 }
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to