Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/notifications/web_notification_delegate.h" | |
| 6 | |
| 7 #include "chrome/browser/notifications/notification_common.h" | |
| 8 #include "chrome/browser/profiles/profile.h" | |
| 9 #include "chrome/browser/ui/browser.h" | |
| 10 #include "chrome/browser/ui/browser_list.h" | |
| 11 #include "chrome/browser/ui/browser_window.h" | |
| 12 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" | |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 | |
| 16 WebNotificationDelegate::WebNotificationDelegate( | |
| 17 content::BrowserContext* browser_context, | |
| 18 const std::string& notification_id, | |
| 19 const GURL& origin) | |
| 20 : browser_context_(browser_context), | |
| 21 notification_id_(notification_id), | |
| 22 origin_(origin) {} | |
| 23 | |
| 24 WebNotificationDelegate::~WebNotificationDelegate() {} | |
| 25 | |
| 26 std::string WebNotificationDelegate::id() const { | |
| 27 return notification_id_; | |
| 28 } | |
| 29 | |
| 30 void WebNotificationDelegate::SettingsClick() { | |
| 31 NotificationCommon::OpenNotificationSettings(browser_context_); | |
| 32 } | |
| 33 | |
| 34 bool WebNotificationDelegate::ShouldDisplaySettingsButton() { | |
| 35 return true; | |
| 36 } | |
| 37 | |
| 38 bool WebNotificationDelegate::ShouldDisplayOverFullscreen() const { | |
| 39 Profile* profile = Profile::FromBrowserContext(browser_context_); | |
| 40 DCHECK(profile); | |
| 41 // Check to see if this notification comes from a webpage that is displaying | |
| 42 // fullscreen content. | |
| 43 for (auto* browser : *BrowserList::GetInstance()) { | |
| 44 // Only consider the browsers for the profile that created the notification | |
| 45 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
| |
| 46 const content::WebContents* active_contents = | |
| 47 browser->tab_strip_model()->GetActiveWebContents(); | |
| 48 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.
| |
| 49 // Check to see if | |
| 50 // (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.
| |
| 51 // (b) the browser is fullscreen | |
| 52 // (c) the browser has focus. | |
| 53 if (active_contents->GetURL().GetOrigin() == origin_ && | |
| 54 browser->exclusive_access_manager()->context()->IsFullscreen() && | |
| 55 browser->window()->IsActive()) | |
| 56 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.
| |
| 57 } | |
| 58 } | |
| 59 | |
| 60 return false; | |
| 61 } | |
| OLD | NEW |