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_); | |
|
Peter Beverloo
2016/09/28 12:23:13
Oops, sorry that I missed this - this code can't b
bmalcolm
2016/09/28 18:30:09
Done.
| |
| 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) | |
| 46 continue; | |
| 47 | |
| 48 const content::WebContents* active_contents = | |
| 49 browser->tab_strip_model()->GetActiveWebContents(); | |
| 50 if (!active_contents) | |
| 51 continue; | |
| 52 | |
| 53 // Check to see if | |
| 54 // (a) the active tab in the browser shares its origin with the | |
| 55 // notification. | |
| 56 // (b) the browser is fullscreen | |
| 57 // (c) the browser has focus. | |
| 58 if (active_contents->GetURL().GetOrigin() == origin_ && | |
| 59 browser->exclusive_access_manager()->context()->IsFullscreen() && | |
| 60 browser->window()->IsActive()) { | |
| 61 return true; | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 return false; | |
| 66 } | |
| OLD | NEW |