diff options
author | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-25 17:38:23 +0000 |
---|---|---|
committer | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-25 17:38:23 +0000 |
commit | 42219753c0e79431d59af4aeeb769730a9fabfbd (patch) | |
tree | 1ba1097254e156e6951252231c238eda7d8403d8 | |
parent | 3fe87738f5042d30977ab6263c6e3565f45b4c3a (diff) | |
download | chromium_src-42219753c0e79431d59af4aeeb769730a9fabfbd.zip chromium_src-42219753c0e79431d59af4aeeb769730a9fabfbd.tar.gz chromium_src-42219753c0e79431d59af4aeeb769730a9fabfbd.tar.bz2 |
If a page is navigated within the same render process, the active notifications need to go out of scope so we don't try to fire events on them back to the original page.
BUG=32862
TEST=reload page then close notification
Review URL: http://codereview.chromium.org/549140
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37019 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 24 insertions, 3 deletions
diff --git a/chrome/common/desktop_notifications/active_notification_tracker.cc b/chrome/common/desktop_notifications/active_notification_tracker.cc index d3d50cd..bcb6e2b 100644 --- a/chrome/common/desktop_notifications/active_notification_tracker.cc +++ b/chrome/common/desktop_notifications/active_notification_tracker.cc @@ -51,6 +51,14 @@ void ActiveNotificationTracker::UnregisterNotification(int id) { reverse_notification_table_.erase(*notification); } +void ActiveNotificationTracker::Clear() { + ReverseTable::iterator iter = reverse_notification_table_.begin(); + while (iter != reverse_notification_table_.end()) { + UnregisterNotification((*iter).second); + ++iter; + } +} + WebNotificationPermissionCallback* ActiveNotificationTracker::GetCallback( int id) { DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); diff --git a/chrome/common/desktop_notifications/active_notification_tracker.h b/chrome/common/desktop_notifications/active_notification_tracker.h index b25c42e..1676f32 100644 --- a/chrome/common/desktop_notifications/active_notification_tracker.h +++ b/chrome/common/desktop_notifications/active_notification_tracker.h @@ -35,6 +35,9 @@ class ActiveNotificationTracker { void OnPermissionRequestComplete(int id); WebKit::WebNotificationPermissionCallback* GetCallback(int id); + // Clears out all active notifications. Useful on page navigation. + void Clear(); + private: typedef std::map<WebKit::WebNotification, int> ReverseTable; @@ -47,4 +50,3 @@ class ActiveNotificationTracker { }; #endif // CHROME_COMMON_DESKTOP_NOTIFICATIONS_ACTIVE_NOTIFICATION_TRACKER_H_ - diff --git a/chrome/renderer/notification_provider.cc b/chrome/renderer/notification_provider.cc index 30ca716..4489951 100644 --- a/chrome/renderer/notification_provider.cc +++ b/chrome/renderer/notification_provider.cc @@ -79,6 +79,10 @@ bool NotificationProvider::OnMessageReceived(const IPC::Message& message) { return handled; } +void NotificationProvider::OnNavigate() { + // manager_.Clear(); +} + bool NotificationProvider::ShowHTML(const WebNotification& notification, int id) { // Disallow HTML notifications from non-HTTP schemes. @@ -126,9 +130,10 @@ void NotificationProvider::OnClose(int id, bool by_user) { bool found = manager_.GetNotification(id, ¬ification); // |found| may be false if the WebNotification went out of scope in // the page before the associated toast was closed by the user. - if (found) + if (found) { notification.dispatchCloseEvent(by_user); - manager_.UnregisterNotification(id); + manager_.UnregisterNotification(id); + } } void NotificationProvider::OnPermissionRequestComplete(int id) { diff --git a/chrome/renderer/notification_provider.h b/chrome/renderer/notification_provider.h index d02ee15..7c5ca71 100644 --- a/chrome/renderer/notification_provider.h +++ b/chrome/renderer/notification_provider.h @@ -36,6 +36,9 @@ class NotificationProvider : public WebKit::WebNotificationPresenter { // IPC message handler called from RenderView. bool OnMessageReceived(const IPC::Message& message); + // Called when the RenderView navigates. + void OnNavigate(); + private: // Internal methods used to show notifications. bool ShowHTML(const WebKit::WebNotification& notification, int id); diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 9b6c758..e56673ed 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -807,6 +807,9 @@ void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { if (devtools_agent_.get()) devtools_agent_->OnNavigate(); + if (notification_provider_.get()) + notification_provider_->OnNavigate(); + child_process_logging::SetActiveURL(params.url); AboutHandler::MaybeHandle(params.url); |