diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 23:48:32 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 23:48:32 +0000 |
commit | 4ff02f753fefef3430438c3c5f0f3ba6a5271ddb (patch) | |
tree | 1364a64d5d29b2511349bfadeca30b7d40b1337a /chrome | |
parent | e40c87f893cbe182dcd83ee2e01c341ba2a7e680 (diff) | |
download | chromium_src-4ff02f753fefef3430438c3c5f0f3ba6a5271ddb.zip chromium_src-4ff02f753fefef3430438c3c5f0f3ba6a5271ddb.tar.gz chromium_src-4ff02f753fefef3430438c3c5f0f3ba6a5271ddb.tar.bz2 |
Revert 31839 - Notifications permission infobar should only be shown in response to a user gesture, not arbitrary script.
Includes UI test which verify the infobar is shown from a gesture, and not shown from raw script.
BUG=27215
TEST=included
Review URL: http://codereview.chromium.org/387011
TBR=johnnyg@chromium.org
Review URL: http://codereview.chromium.org/385080
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31857 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
6 files changed, 7 insertions, 102 deletions
diff --git a/chrome/browser/notifications/notifications_uitest.cc b/chrome/browser/notifications/notifications_uitest.cc deleted file mode 100755 index 22284bc..0000000 --- a/chrome/browser/notifications/notifications_uitest.cc +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/file_path.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/test/automation/browser_proxy.h" -#include "chrome/test/automation/tab_proxy.h" -#include "chrome/test/ui/ui_test.h" -#include "net/base/net_util.h" -#include "net/url_request/url_request_unittest.h" - -class NotificationsPermissionTest : public UITest { - public: - NotificationsPermissionTest() { - launch_arguments_.AppendSwitch(switches::kEnableDesktopNotifications); - dom_automation_enabled_ = true; - show_window_ = true; - } -}; - -#if defined(OS_WIN) -TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) { - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot, NULL); - ASSERT_TRUE(server.get() != NULL); - - scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); - scoped_refptr<TabProxy> tab(browser->GetActiveTab()); - tab->NavigateToURL(server->TestServerPageW( - L"files/notifications/notifications_request_function.html")); - WaitUntilTabCount(1); - - // Request permission by calling request() while eval'ing an inline script; - // That's considered a user gesture to webkit, and should produce an infobar. - bool result; - tab->ExecuteAndExtractBool(L"", - L"window.domAutomationController.send(request());", - &result); - EXPECT_TRUE(result); - - int info_bar_count; - tab->GetInfoBarCount(&info_bar_count); - EXPECT_EQ(1, info_bar_count); -} - -TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) { - const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot, NULL); - ASSERT_TRUE(server.get() != NULL); - - scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); - scoped_refptr<TabProxy> tab(browser->GetActiveTab()); - - // Load a page which just does a request; no user gesture should result - // in no infobar. - tab->NavigateToURL(server->TestServerPageW( - L"files/notifications/notifications_request_inline.html")); - WaitUntilTabCount(1); - - int info_bar_count; - tab->GetInfoBarCount(&info_bar_count); - EXPECT_EQ(0, info_bar_count); -} -#endif // OS_WIN diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 2182c47..cc5c492 100755 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -4287,7 +4287,6 @@ 'browser/login_prompt_uitest.cc', 'browser/media_uitest.cc', 'browser/metrics/metrics_service_uitest.cc', - 'browser/notifications/notifications_uitest.cc', 'browser/printing/printing_layout_uitest.cc', 'browser/process_singleton_linux_uitest.cc', 'browser/renderer_host/resource_dispatcher_host_uitest.cc', diff --git a/chrome/common/desktop_notifications/active_notification_tracker.cc b/chrome/common/desktop_notifications/active_notification_tracker.cc index d3d50cd..3357ab3 100644 --- a/chrome/common/desktop_notifications/active_notification_tracker.cc +++ b/chrome/common/desktop_notifications/active_notification_tracker.cc @@ -13,7 +13,7 @@ using WebKit::WebNotificationPermissionCallback; bool ActiveNotificationTracker::GetId( const WebNotification& notification, int& id) { - DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); + DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); ReverseTable::iterator iter = reverse_notification_table_.find(notification); if (iter == reverse_notification_table_.end()) return false; @@ -23,7 +23,7 @@ bool ActiveNotificationTracker::GetId( bool ActiveNotificationTracker::GetNotification( int id, WebNotification* notification) { - DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); + DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); WebNotification* lookup = notification_table_.Lookup(id); if (!lookup) return false; @@ -34,7 +34,7 @@ bool ActiveNotificationTracker::GetNotification( int ActiveNotificationTracker::RegisterNotification( const WebKit::WebNotification& proxy) { - DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); + DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); WebNotification* notification = new WebNotification(proxy); int id = notification_table_.Add(notification); reverse_notification_table_[proxy] = id; @@ -42,7 +42,7 @@ int ActiveNotificationTracker::RegisterNotification( } void ActiveNotificationTracker::UnregisterNotification(int id) { - DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); + DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); // We want to free the notification after removing it from the table. scoped_ptr<WebNotification> notification(notification_table_.Lookup(id)); notification_table_.Remove(id); @@ -53,17 +53,17 @@ void ActiveNotificationTracker::UnregisterNotification(int id) { WebNotificationPermissionCallback* ActiveNotificationTracker::GetCallback( int id) { - DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); + DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); return callback_table_.Lookup(id); } int ActiveNotificationTracker::RegisterPermissionRequest( WebNotificationPermissionCallback* callback) { - DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); + DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); return callback_table_.Add(callback); } void ActiveNotificationTracker::OnPermissionRequestComplete(int id) { - DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); + DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); callback_table_.Remove(id); } diff --git a/chrome/renderer/notification_provider.cc b/chrome/renderer/notification_provider.cc index 6746350..9510cab 100644 --- a/chrome/renderer/notification_provider.cc +++ b/chrome/renderer/notification_provider.cc @@ -55,10 +55,6 @@ WebNotificationPresenter::Permission NotificationProvider::checkPermission( void NotificationProvider::requestPermission( const WebString& origin, WebNotificationPermissionCallback* callback) { - // We only request permission in response to a user gesture. - if (!view_->webview()->mainFrame()->isProcessingUserGesture()) - return; - int id = manager_.RegisterPermissionRequest(callback); Send(new ViewHostMsg_RequestNotificationPermission(view_->routing_id(), diff --git a/chrome/test/data/notifications/notifications_request_function.html b/chrome/test/data/notifications/notifications_request_function.html deleted file mode 100755 index 55b6a86..0000000 --- a/chrome/test/data/notifications/notifications_request_function.html +++ /dev/null @@ -1,13 +0,0 @@ -<html> -<head> -<script> -function request() { - window.webkitNotifications.requestPermission(); - return true; -} -</script> -</head> -<body> -Standing by to request permission... -</body> -</html>
\ No newline at end of file diff --git a/chrome/test/data/notifications/notifications_request_inline.html b/chrome/test/data/notifications/notifications_request_inline.html deleted file mode 100755 index 97db796..0000000 --- a/chrome/test/data/notifications/notifications_request_inline.html +++ /dev/null @@ -1,10 +0,0 @@ -<html> -<head> -</head> -<body> -Requesting permission... -</body> -<script> -window.webkitNotifications.requestPermission(); -</script> -</html>
\ No newline at end of file |