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

Side by Side Diff: chrome/browser/extensions/api/notifications/notifications_api.cc

Issue 2335293002: ShouldDisplayOverFullscreen implementation (Closed)
Patch Set: ShouldDisplayOverFullscreen refinements 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 unified diff | Download patch
OLDNEW
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/extensions/api/notifications/notifications_api.h" 5 #include "chrome/browser/extensions/api/notifications/notifications_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/notifications/notification_ui_manager.h" 24 #include "chrome/browser/notifications/notification_ui_manager.h"
25 #include "chrome/browser/notifications/notifier_state_tracker.h" 25 #include "chrome/browser/notifications/notifier_state_tracker.h"
26 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" 26 #include "chrome/browser/notifications/notifier_state_tracker_factory.h"
27 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/common/extensions/api/notifications/notification_style.h" 28 #include "chrome/common/extensions/api/notifications/notification_style.h"
29 #include "components/keyed_service/content/browser_context_keyed_service_shutdow n_notifier_factory.h" 29 #include "components/keyed_service/content/browser_context_keyed_service_shutdow n_notifier_factory.h"
30 #include "components/keyed_service/core/keyed_service_shutdown_notifier.h" 30 #include "components/keyed_service/core/keyed_service_shutdown_notifier.h"
31 #include "content/public/browser/render_process_host.h" 31 #include "content/public/browser/render_process_host.h"
32 #include "content/public/browser/render_view_host.h" 32 #include "content/public/browser/render_view_host.h"
33 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
34 #include "extensions/browser/app_window/app_window.h"
35 #include "extensions/browser/app_window/app_window_registry.h"
36 #include "extensions/browser/app_window/native_app_window.h"
34 #include "extensions/browser/event_router.h" 37 #include "extensions/browser/event_router.h"
35 #include "extensions/browser/extension_system_provider.h" 38 #include "extensions/browser/extension_system_provider.h"
36 #include "extensions/browser/extensions_browser_client.h" 39 #include "extensions/browser/extensions_browser_client.h"
37 #include "extensions/common/extension.h" 40 #include "extensions/common/extension.h"
38 #include "extensions/common/features/feature.h" 41 #include "extensions/common/features/feature.h"
39 #include "third_party/skia/include/core/SkBitmap.h" 42 #include "third_party/skia/include/core/SkBitmap.h"
40 #include "ui/base/layout.h" 43 #include "ui/base/layout.h"
41 #include "ui/gfx/image/image.h" 44 #include "ui/gfx/image/image.h"
42 #include "ui/gfx/image/image_skia.h" 45 #include "ui/gfx/image/image_skia.h"
43 #include "ui/gfx/image/image_skia_operations.h" 46 #include "ui/gfx/image/image_skia_operations.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 }; 139 };
137 140
138 class NotificationsApiDelegate : public NotificationDelegate { 141 class NotificationsApiDelegate : public NotificationDelegate {
139 public: 142 public:
140 NotificationsApiDelegate(ChromeAsyncExtensionFunction* api_function, 143 NotificationsApiDelegate(ChromeAsyncExtensionFunction* api_function,
141 Profile* profile, 144 Profile* profile,
142 const std::string& extension_id, 145 const std::string& extension_id,
143 const std::string& id) 146 const std::string& id)
144 : api_function_(api_function), 147 : api_function_(api_function),
145 event_router_(EventRouter::Get(profile)), 148 event_router_(EventRouter::Get(profile)),
149 profile_(profile),
dewittj 2016/09/14 21:06:51 Don't store profile, call GetProfile()
bmalcolm 2016/09/14 21:56:24 GetProfile isn't available in NotificationsApiDele
dewittj 2016/09/14 23:09:46 You're right. One way to do it is to call api_fun
146 extension_id_(extension_id), 150 extension_id_(extension_id),
147 id_(id), 151 id_(id),
148 scoped_id_(CreateScopedIdentifier(extension_id, id)) { 152 scoped_id_(CreateScopedIdentifier(extension_id, id)) {
149 DCHECK(api_function_); 153 DCHECK(api_function_);
150 shutdown_notifier_subscription_ = 154 shutdown_notifier_subscription_ =
151 ShutdownNotifierFactory::GetInstance()->Get(profile)->Subscribe( 155 ShutdownNotifierFactory::GetInstance()->Get(profile)->Subscribe(
152 base::Bind(&NotificationsApiDelegate::Shutdown, 156 base::Bind(&NotificationsApiDelegate::Shutdown,
153 base::Unretained(this))); 157 base::Unretained(this)));
154 } 158 }
155 159
(...skipping 25 matching lines...) Expand all
181 void ButtonClick(int index) override { 185 void ButtonClick(int index) override {
182 std::unique_ptr<base::ListValue> args(CreateBaseEventArgs()); 186 std::unique_ptr<base::ListValue> args(CreateBaseEventArgs());
183 args->AppendInteger(index); 187 args->AppendInteger(index);
184 SendEvent(events::NOTIFICATIONS_ON_BUTTON_CLICKED, 188 SendEvent(events::NOTIFICATIONS_ON_BUTTON_CLICKED,
185 notifications::OnButtonClicked::kEventName, 189 notifications::OnButtonClicked::kEventName,
186 EventRouter::USER_GESTURE_ENABLED, std::move(args)); 190 EventRouter::USER_GESTURE_ENABLED, std::move(args));
187 } 191 }
188 192
189 std::string id() const override { return scoped_id_; } 193 std::string id() const override { return scoped_id_; }
190 194
195 // Should only display when fullscreen if this app is the source of the
196 // fullscreen window.
197 bool ShouldDisplayOverFullscreen() const override {
198 AppWindowRegistry::AppWindowList windows =
199 AppWindowRegistry::Get(profile_)->GetAppWindowsForApp(extension_id_);
200 for (const auto& window : windows) {
201 // Window must be fullscreen and visible
202 if (window->IsFullscreen() && window->GetBaseWindow()->IsActive()) {
dewittj 2016/09/14 21:06:51 nit: single line if blocks should not have braces
bmalcolm 2016/09/14 21:56:24 Done.
203 return true;
204 }
205 }
206 return false;
207 }
208
191 private: 209 private:
192 ~NotificationsApiDelegate() override {} 210 ~NotificationsApiDelegate() override {}
193 211
194 void SendEvent(events::HistogramValue histogram_value, 212 void SendEvent(events::HistogramValue histogram_value,
195 const std::string& name, 213 const std::string& name,
196 EventRouter::UserGestureState user_gesture, 214 EventRouter::UserGestureState user_gesture,
197 std::unique_ptr<base::ListValue> args) { 215 std::unique_ptr<base::ListValue> args) {
198 if (!event_router_) 216 if (!event_router_)
199 return; 217 return;
200 218
(...skipping 14 matching lines...) Expand all
215 return args; 233 return args;
216 } 234 }
217 235
218 scoped_refptr<ChromeAsyncExtensionFunction> api_function_; 236 scoped_refptr<ChromeAsyncExtensionFunction> api_function_;
219 237
220 // Since this class is refcounted it may outlive the profile. We listen for 238 // Since this class is refcounted it may outlive the profile. We listen for
221 // profile-keyed service shutdown events and reset to nullptr at that time, 239 // profile-keyed service shutdown events and reset to nullptr at that time,
222 // so make sure to check for a valid pointer before use. 240 // so make sure to check for a valid pointer before use.
223 EventRouter* event_router_; 241 EventRouter* event_router_;
224 242
243 Profile* profile_;
225 const std::string extension_id_; 244 const std::string extension_id_;
226 const std::string id_; 245 const std::string id_;
227 const std::string scoped_id_; 246 const std::string scoped_id_;
228 247
229 std::unique_ptr<KeyedServiceShutdownNotifier::Subscription> 248 std::unique_ptr<KeyedServiceShutdownNotifier::Subscription>
230 shutdown_notifier_subscription_; 249 shutdown_notifier_subscription_;
231 250
232 DISALLOW_COPY_AND_ASSIGN(NotificationsApiDelegate); 251 DISALLOW_COPY_AND_ASSIGN(NotificationsApiDelegate);
233 }; 252 };
234 253
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 : api::notifications::PERMISSION_LEVEL_DENIED; 741 : api::notifications::PERMISSION_LEVEL_DENIED;
723 742
724 SetResult(base::MakeUnique<base::StringValue>( 743 SetResult(base::MakeUnique<base::StringValue>(
725 api::notifications::ToString(result))); 744 api::notifications::ToString(result)));
726 SendResponse(true); 745 SendResponse(true);
727 746
728 return true; 747 return true;
729 } 748 }
730 749
731 } // namespace extensions 750 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698