Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(795)

Unified Diff: chrome/browser/notifications/web_notification_delegate.cc

Issue 2377553003: Add ShouldDisplayOverFullscreen support to web notifications. (Closed)
Patch Set: Final formatting fixes Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/notifications/web_notification_delegate.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ae8e77c64d2cba022e478b921a1ad15fa1637a1a
--- /dev/null
+++ b/chrome/browser/notifications/web_notification_delegate.cc
@@ -0,0 +1,68 @@
+// 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 {
+#if !defined(OS_ANDROID)
+ 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)
+ continue;
+
+ const content::WebContents* active_contents =
+ browser->tab_strip_model()->GetActiveWebContents();
+ if (!active_contents)
+ continue;
+
+ // Check to see if
+ // (a) the active tab in the browser shares its origin with the
+ // notification.
+ // (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;
+ }
+ }
+#endif
+
+ return false;
+}
« no previous file with comments | « chrome/browser/notifications/web_notification_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698