Index: ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.h |
diff --git a/ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.h b/ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..58c463a7d79142be8dfe3a35d4a6c35a9f7c5ba3 |
--- /dev/null |
+++ b/ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.h |
@@ -0,0 +1,63 @@ |
+// 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. |
+ |
+#ifndef IOS_CLEAN_CHROME_BROWSER_UI_WEB_CONTENTS_OVERLAYS_WEB_OVERLAY_QUEUE_H_ |
+#define IOS_CLEAN_CHROME_BROWSER_UI_WEB_CONTENTS_OVERLAYS_WEB_OVERLAY_QUEUE_H_ |
+ |
+#import <Foundation/Foundation.h> |
+ |
+#include "base/ios/weak_nsobject.h" |
+#import "base/mac/scoped_nsobject.h" |
+#import "ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_coordinator.h" |
+#import "ios/web/public/web_state/web_state_user_data.h" |
+ |
+@protocol WebOverlaySchedulerCommands; |
+ |
+// Class used to enqueue overlay coordinators that are requested by a WebState. |
+// It uses WebOverlaySchedulerCommands to communicate with WebOverlayScheduler |
+// to decide when to display the overlay UI. |
+class WebOverlayQueue : public web::WebStateUserData<WebOverlayQueue> { |
+ public: |
+ ~WebOverlayQueue() override; |
+ |
+ // Factory method that instantaites a WebOverlayQueue for |web_state| that |
+ // uses |dispatcher| to send overlay scheduling commands. |
+ static void CreateForWebState(web::WebState* web_state, |
+ id<WebOverlaySchedulerCommands> dispatcher); |
+ |
+ // Adds |web_overlay| to the queue and schedules its presentation. |
+ void AddWebOverlay(WebOverlayCoordinator* overlay_coordinator); |
+ // Returns whether there are any queued overlays. |
+ bool HasQueuedOverlays() const; |
+ // Displays the next overlay over |web_coordinator|'s UI. |web_coordinator| |
+ // is expected to be displaying the web view that requested the overlay. |
+ void StartNextOverlay(BrowserCoordinator* web_coordinator); |
+ // Returns whether an overlay is curently started. |
+ bool IsShowingOverlay() const; |
+ // Notifies the WebOverlayQueue that |overlay_coordinator| was stopped. |
+ void WebOverlayWasStopped(WebOverlayCoordinator* overlay_coordinator); |
+ // Cancels all queued overlays for this WebState. If one is being displayed, |
+ // it will be stopped and cancelled. |
+ void CancelOverlays(); |
+ |
+ private: |
+ friend class web::WebStateUserData<WebOverlayQueue>; |
+ // The WebState with which this presenter is associated. |
+ web::WebState* web_state_; |
+ // The WebOverlayScheduler dispatcher passed on construction. |
+ base::WeakNSProtocol<id<WebOverlaySchedulerCommands>> dispatcher_; |
+ // The queue of overlays that were added for this WebState. Overlays will be |
+ // removed when they are stopped or when they |
+ base::scoped_nsobject<NSMutableArray<WebOverlayCoordinator*>> overlays_; |
+ // Whether the first overlay in |overlays_| is started. |
+ bool showing_overlay_; |
+ |
+ // Private constructor. New instances should be created via |
+ // CreateForWebState() and accessed via FromWebState(). |
+ explicit WebOverlayQueue(web::WebState* web_state, |
+ id<WebOverlaySchedulerCommands> dispatcher); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WebOverlayQueue); |
+}; |
+#endif // IOS_CLEAN_CHROME_BROWSER_UI_WEB_CONTENTS_OVERLAYS_WEB_OVERLAY_QUEUE_H_ |