Index: chrome/browser/notifications/web_notification_delegate.cc |
diff --git a/chrome/browser/notifications/web_notification_delegate.cc b/chrome/browser/notifications/web_notification_delegate.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..da20df4b1be12a3d33f903ccd83afddbfc7f9426 |
--- /dev/null |
+++ b/chrome/browser/notifications/web_notification_delegate.cc |
@@ -0,0 +1,61 @@ |
+// Copyright 2016 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 "chrome/browser/notifications/web_notification_delegate.h" |
+ |
+#include "chrome/browser/notifications/notification_common.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/browser_list.h" |
+#include "chrome/browser/ui/browser_window.h" |
+#include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
+#include "content/public/browser/web_contents.h" |
+ |
+WebNotificationDelegate::WebNotificationDelegate( |
+ content::BrowserContext* browser_context, |
+ const std::string& notification_id, |
+ const GURL& origin) |
+ : browser_context_(browser_context), |
+ notification_id_(notification_id), |
+ origin_(origin) {} |
+ |
+WebNotificationDelegate::~WebNotificationDelegate() {} |
+ |
+std::string WebNotificationDelegate::id() const { |
+ return notification_id_; |
+} |
+ |
+void WebNotificationDelegate::SettingsClick() { |
+ NotificationCommon::OpenNotificationSettings(browser_context_); |
+} |
+ |
+bool WebNotificationDelegate::ShouldDisplaySettingsButton() { |
+ return true; |
+} |
+ |
+bool WebNotificationDelegate::ShouldDisplayOverFullscreen() const { |
+ Profile* profile = Profile::FromBrowserContext(browser_context_); |
+ DCHECK(profile); |
+ // Check to see if this notification comes from a webpage that is displaying |
+ // fullscreen content. |
+ for (auto* browser : *BrowserList::GetInstance()) { |
+ // Only consider the browsers for the profile that created the notification |
+ if (browser->profile() == profile) { |
Peter Beverloo
2016/09/27 17:17:36
micro nit: you could check whether the |browser|'s
bmalcolm
2016/09/27 20:34:36
I normally choose that pattern when there are seve
|
+ const content::WebContents* active_contents = |
+ browser->tab_strip_model()->GetActiveWebContents(); |
+ DCHECK(active_contents); |
Peter Beverloo
2016/09/27 17:17:37
The documentation says that this may be NULL, and
bmalcolm
2016/09/27 20:34:36
Done.
|
+ // Check to see if |
+ // (a) the active tab in the browser is the source of the notification. |
Peter Beverloo
2016/09/27 17:17:37
I'd rephrase this, since it may not be. We don't h
bmalcolm
2016/09/27 20:34:36
Done.
|
+ // (b) the browser is fullscreen |
+ // (c) the browser has focus. |
+ if (active_contents->GetURL().GetOrigin() == origin_ && |
+ browser->exclusive_access_manager()->context()->IsFullscreen() && |
+ browser->window()->IsActive()) |
+ return true; |
Peter Beverloo
2016/09/27 17:17:37
micro nit: brackets for multi-line if statements.
bmalcolm
2016/09/27 20:34:36
Done.
|
+ } |
+ } |
+ |
+ return false; |
+} |