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 #if !defined(OS_ANDROID) | |
dewittj
2016/09/28 20:01:54
This is probably fine for now, but eventually we'l
bmalcolm
2016/09/29 20:53:14
Acknowledged.
| |
40 Profile* profile = Profile::FromBrowserContext(browser_context_); | |
41 DCHECK(profile); | |
42 // Check to see if this notification comes from a webpage that is displaying | |
43 // fullscreen content. | |
44 for (auto* browser : *BrowserList::GetInstance()) { | |
45 // Only consider the browsers for the profile that created the notification | |
46 if (browser->profile() != profile) | |
47 continue; | |
48 | |
49 const content::WebContents* active_contents = | |
50 browser->tab_strip_model()->GetActiveWebContents(); | |
51 if (!active_contents) | |
52 continue; | |
53 | |
54 // Check to see if | |
55 // (a) the active tab in the browser shares its origin with the | |
56 // notification. | |
57 // (b) the browser is fullscreen | |
58 // (c) the browser has focus. | |
59 if (active_contents->GetURL().GetOrigin() == origin_ && | |
60 browser->exclusive_access_manager()->context()->IsFullscreen() && | |
61 browser->window()->IsActive()) { | |
62 return true; | |
63 } | |
64 } | |
65 #endif | |
66 | |
67 return false; | |
68 } | |
OLD | NEW |