OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/ash/balloon_collection_impl_ash.h" | 5 #include "chrome/browser/ui/views/ash/balloon_collection_impl_ash.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/system/status_area_widget.h" | 9 #include "ash/system/status_area_widget.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 return; // HTML notifications are not supported in Ash. | 52 return; // HTML notifications are not supported in Ash. |
53 if (notification.title().empty() && notification.body().empty()) | 53 if (notification.title().empty() && notification.body().empty()) |
54 return; // Empty notification, don't show. | 54 return; // Empty notification, don't show. |
55 } | 55 } |
56 return BalloonCollectionImpl::Add(notification, profile); | 56 return BalloonCollectionImpl::Add(notification, profile); |
57 } | 57 } |
58 | 58 |
59 void BalloonCollectionImplAsh::DisableExtension( | 59 void BalloonCollectionImplAsh::DisableExtension( |
60 const std::string& notifcation_id) { | 60 const std::string& notifcation_id) { |
61 Balloon* balloon = base().FindBalloonById(notifcation_id); | 61 Balloon* balloon = base().FindBalloonById(notifcation_id); |
62 if (!balloon) | 62 const extensions::Extension* extension = GetBalloonExtension(balloon); |
63 return; | |
64 ExtensionService* extension_service = | |
65 balloon->profile()->GetExtensionService(); | |
66 const GURL& origin = balloon->notification().origin_url(); | |
67 const extensions::Extension* extension = | |
68 extension_service->extensions()->GetExtensionOrAppByURL( | |
69 ExtensionURLInfo(origin)); | |
70 if (!extension) | 63 if (!extension) |
71 return; | 64 return; |
72 extension_service->DisableExtension( | 65 balloon->profile()->GetExtensionService()->DisableExtension( |
73 extension->id(), extensions::Extension::DISABLE_USER_ACTION); | 66 extension->id(), extensions::Extension::DISABLE_USER_ACTION); |
74 } | 67 } |
75 | 68 |
76 void BalloonCollectionImplAsh::DisableNotificationsFromSource( | 69 void BalloonCollectionImplAsh::DisableNotificationsFromSource( |
77 const std::string& notifcation_id) { | 70 const std::string& notifcation_id) { |
78 Balloon* balloon = base().FindBalloonById(notifcation_id); | 71 Balloon* balloon = base().FindBalloonById(notifcation_id); |
79 if (!balloon) | 72 if (!balloon) |
80 return; | 73 return; |
81 DesktopNotificationService* service = | 74 DesktopNotificationService* service = |
82 DesktopNotificationServiceFactory::GetForProfile(balloon->profile()); | 75 DesktopNotificationServiceFactory::GetForProfile(balloon->profile()); |
83 service->DenyPermission(balloon->notification().origin_url()); | 76 service->DenyPermission(balloon->notification().origin_url()); |
84 } | 77 } |
85 | 78 |
86 void BalloonCollectionImplAsh::NotificationRemoved( | 79 void BalloonCollectionImplAsh::NotificationRemoved( |
87 const std::string& notifcation_id) { | 80 const std::string& notifcation_id) { |
88 RemoveById(notifcation_id); | 81 RemoveById(notifcation_id); |
89 } | 82 } |
90 | 83 |
91 void BalloonCollectionImplAsh::ShowSettings(const std::string& notifcation_id) { | 84 void BalloonCollectionImplAsh::ShowSettings(const std::string& notifcation_id) { |
92 Balloon* balloon = base().FindBalloonById(notifcation_id); | 85 Balloon* balloon = base().FindBalloonById(notifcation_id); |
93 Profile* profile = | 86 Profile* profile = |
94 balloon ? balloon->profile() : ProfileManager::GetDefaultProfile(); | 87 balloon ? balloon->profile() : ProfileManager::GetDefaultProfile(); |
95 Browser* browser = browser::FindOrCreateTabbedBrowser(profile); | 88 Browser* browser = browser::FindOrCreateTabbedBrowser(profile); |
96 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 89 if (GetBalloonExtension(balloon)) |
| 90 chrome::ShowExtensions(browser); |
| 91 else |
| 92 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
97 } | 93 } |
98 | 94 |
99 void BalloonCollectionImplAsh::OnClicked(const std::string& notifcation_id) { | 95 void BalloonCollectionImplAsh::OnClicked(const std::string& notifcation_id) { |
100 Balloon* balloon = base().FindBalloonById(notifcation_id); | 96 Balloon* balloon = base().FindBalloonById(notifcation_id); |
101 if (!balloon) | 97 if (!balloon) |
102 return; | 98 return; |
103 balloon->OnClick(); | 99 balloon->OnClick(); |
104 } | 100 } |
105 | 101 |
106 bool BalloonCollectionImplAsh::AddWebUIMessageCallback( | 102 bool BalloonCollectionImplAsh::AddWebUIMessageCallback( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 balloon->set_view(balloon_view); | 157 balloon->set_view(balloon_view); |
162 gfx::Size size(layout().min_balloon_width(), layout().min_balloon_height()); | 158 gfx::Size size(layout().min_balloon_width(), layout().min_balloon_height()); |
163 balloon->set_content_size(size); | 159 balloon->set_content_size(size); |
164 } else { | 160 } else { |
165 BalloonViewAsh* balloon_view = new BalloonViewAsh(this); | 161 BalloonViewAsh* balloon_view = new BalloonViewAsh(this); |
166 balloon->set_view(balloon_view); | 162 balloon->set_view(balloon_view); |
167 } | 163 } |
168 return balloon; | 164 return balloon; |
169 } | 165 } |
170 | 166 |
| 167 const extensions::Extension* BalloonCollectionImplAsh::GetBalloonExtension( |
| 168 Balloon* balloon) { |
| 169 if (!balloon) |
| 170 return NULL; |
| 171 ExtensionService* extension_service = |
| 172 balloon->profile()->GetExtensionService(); |
| 173 const GURL& origin = balloon->notification().origin_url(); |
| 174 return extension_service->extensions()->GetExtensionOrAppByURL( |
| 175 ExtensionURLInfo(origin)); |
| 176 } |
| 177 |
171 // For now, only use BalloonCollectionImplAsh on ChromeOS, until | 178 // For now, only use BalloonCollectionImplAsh on ChromeOS, until |
172 // system_notifications_ is replaced with status area notifications. | 179 // system_notifications_ is replaced with status area notifications. |
173 #if defined(OS_CHROMEOS) | 180 #if defined(OS_CHROMEOS) |
174 // static | 181 // static |
175 BalloonCollection* BalloonCollection::Create() { | 182 BalloonCollection* BalloonCollection::Create() { |
176 return new BalloonCollectionImplAsh(); | 183 return new BalloonCollectionImplAsh(); |
177 } | 184 } |
178 #endif | 185 #endif |
OLD | NEW |