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

Unified Diff: ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.mm

Issue 2921833002: [iOS Clean] Created OverlayService.
Patch Set: self review Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.mm
diff --git a/ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.mm b/ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.mm
new file mode 100644
index 0000000000000000000000000000000000000000..ba2faa73cc182c79f41ec9db0a46029754701dcb
--- /dev/null
+++ b/ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.mm
@@ -0,0 +1,85 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.h"
+
+#include "base/logging.h"
+#import "ios/clean/chrome/browser/ui/commands/web_overlay_commands.h"
+#import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+DEFINE_WEB_STATE_USER_DATA_KEY(WebOverlayQueue);
+
+// static
+void WebOverlayQueue::CreateForWebState(
+ web::WebState* web_state,
+ id<WebOverlaySchedulerCommands> dispatcher) {
+ DCHECK(web_state);
+ DCHECK(dispatcher);
+ if (!FromWebState(web_state)) {
+ std::unique_ptr<WebOverlayQueue> queue =
+ base::WrapUnique(new WebOverlayQueue(web_state, dispatcher));
+ web_state->SetUserData(UserDataKey(), std::move(queue));
+ }
+}
+
+WebOverlayQueue::WebOverlayQueue(web::WebState* web_state,
+ id<WebOverlaySchedulerCommands> dispatcher)
+ : web_state_(web_state),
+ dispatcher_(dispatcher),
+ overlays_([[NSMutableArray alloc] init]),
+ showing_overlay_(false) {
+ DCHECK(web_state);
+ DCHECK(dispatcher);
+}
+
+WebOverlayQueue::~WebOverlayQueue() {}
+
+void WebOverlayQueue::AddWebOverlay(
+ WebOverlayCoordinator* overlay_coordinator) {
+ // Add the overlay coordinator to the queue, then notify the scheduler.
+ DCHECK(overlay_coordinator);
+ [overlays_ addObject:overlay_coordinator];
+ [dispatcher_ scheduleWebOverlayForWebState:web_state_];
+}
+
+bool WebOverlayQueue::HasQueuedOverlays() const {
+ return [overlays_ count] > 0U;
+}
+
+void WebOverlayQueue::StartNextOverlay(BrowserCoordinator* web_coordinator) {
+ DCHECK(web_coordinator);
+ DCHECK(HasQueuedOverlays());
+ DCHECK(!IsShowingOverlay());
+ [[overlays_ firstObject] startOverlayingWebCoordinator:web_coordinator];
+ showing_overlay_ = true;
+}
+
+bool WebOverlayQueue::IsShowingOverlay() const {
+ return showing_overlay_;
+}
+
+void WebOverlayQueue::WebOverlayWasStopped(
+ WebOverlayCoordinator* overlay_coordinator) {
+ DCHECK(overlay_coordinator);
+ DCHECK_EQ([overlays_ firstObject], overlay_coordinator);
+ DCHECK(showing_overlay_);
+ [overlays_ removeObjectAtIndex:0];
+ showing_overlay_ = false;
+}
+
+void WebOverlayQueue::CancelOverlays() {
+ // Call the WebKit completion blocks for all queued overlays.
+ for (WebOverlayCoordinator* overlay_coordinator in overlays_.get()) {
+ [overlay_coordinator cancelWebKitCompletion];
+ }
+ // Stop the currently visible one, if necessary.
+ if (showing_overlay_)
+ [[overlays_ firstObject] stop];
+ // Empty the queue.
+ [overlays_ removeAllObjects];
+}

Powered by Google App Engine
This is Rietveld 408576698