Home | History | Annotate | Download | only in web_modal
      1 // Copyright 2014 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 #ifndef COMPONENTS_WEB_MODAL_SINGLE_POPUP_MANAGER_H_
      6 #define COMPONENTS_WEB_MODAL_SINGLE_POPUP_MANAGER_H_
      7 
      8 #include "components/web_modal/native_web_contents_modal_dialog.h"
      9 
     10 namespace content {
     11 class WebContents;
     12 }
     13 
     14 namespace web_modal {
     15 
     16 // Interface from SinglePopupManager to PopupManager.
     17 class SinglePopupManagerDelegate {
     18  public:
     19   SinglePopupManagerDelegate() {}
     20   virtual ~SinglePopupManagerDelegate() {}
     21 
     22   // Notify the delegate that the dialog is closing. The
     23   // calling SinglePopupManager will be deleted before the end of this call.
     24   virtual void WillClose(NativePopup popup) = 0;
     25 
     26  private:
     27   DISALLOW_COPY_AND_ASSIGN(SinglePopupManagerDelegate);
     28 };
     29 
     30 // Provides an interface for platform-specific UI implementation for popups.
     31 // Each object will manage a single NativePopup window during its lifecycle.
     32 // The rule of thumb is that only one popup will be shown at a time per tab.
     33 // (Exceptions exist.)
     34 //
     35 // Implementation classes should accept a NativePopup at construction time
     36 // and register to be notified when the dialog is closing, so that it can
     37 // notify its delegate (WillClose method).
     38 class SinglePopupManager {
     39  public:
     40   virtual ~SinglePopupManager() {}
     41 
     42   // If the manager returns non-null to this call, it is bound to a particular
     43   // tab and will be hidden and shown if that tab visibility changes.
     44   virtual content::WebContents* GetBoundWebContents() = 0;
     45 
     46   // Makes the popup visible.
     47   virtual void Show() = 0;
     48 
     49   // Hides the popup without closing it.
     50   virtual void Hide() = 0;
     51 
     52   // Closes the popup.
     53   // This method must call WillClose() on the delegate.
     54   // Important note: this object will be deleted at the close of that
     55   // invocation.
     56   virtual void Close() = 0;
     57 
     58   // Sets focus on the popup.
     59   virtual void Focus() = 0;
     60 
     61   // Pulsates the popup to draw the user's attention to it.
     62   virtual void Pulse() = 0;
     63 
     64   // Returns the popup under management by this object.
     65   virtual NativePopup popup() = 0;
     66 
     67   // Returns true if the popup under management was initiated by a user
     68   // gesture. When this is true, the popup manager will hide any existing
     69   // popups and move the newly-created NativePopup to the top of the display
     70   // queue.
     71   virtual bool HasUserGesture() = 0;
     72 
     73   // Returns true if the popup under management is tolerant of being overlapped
     74   // by other popups. This may be true for large web-modals which cover most of
     75   // the window real estate (e.g. print preview).
     76   virtual bool MayBeOverlapped() = 0;
     77 
     78   // Returns true if the popup under management should close if there is a
     79   // navigation underneath it, including the showing of any interstitial
     80   // content. Popups which relate to the web content being displayed will
     81   // ordinarily set this to true.
     82   // TODO(gbillock): should be generalized in code location or by splitting
     83   // the API to support the same-origin logic in WCMDM::DidNavigateMainFrame.
     84   // TBD right now because we're not sure which knobs need to be set here.
     85   virtual bool ShouldCloseOnNavigation() = 0;
     86 
     87  protected:
     88   SinglePopupManager() {}
     89 
     90  private:
     91   DISALLOW_COPY_AND_ASSIGN(SinglePopupManager);
     92 };
     93 
     94 }  // namespace web_modal
     95 
     96 #endif  // COMPONENTS_WEB_MODAL_SINGLE_POPUP_MANAGER_H_
     97