Home | History | Annotate | Download | only in views
      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 CHROME_BROWSER_UI_VIEWS_SESSION_CRASHED_BUBBLE_VIEW_H_
      6 #define CHROME_BROWSER_UI_VIEWS_SESSION_CRASHED_BUBBLE_VIEW_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
     10 #include "content/public/browser/notification_observer.h"
     11 #include "content/public/browser/notification_registrar.h"
     12 #include "content/public/browser/web_contents_observer.h"
     13 #include "ui/views/bubble/bubble_delegate.h"
     14 #include "ui/views/controls/button/button.h"
     15 #include "ui/views/controls/styled_label_listener.h"
     16 
     17 namespace views {
     18 class Checkbox;
     19 class GridLayout;
     20 class LabelButton;
     21 class Widget;
     22 }
     23 
     24 namespace content {
     25 class WebContents;
     26 class RenderViewHost;
     27 }
     28 
     29 class Browser;
     30 
     31 // It creates a session restore request bubble when the previous session has
     32 // crashed. It also presents an option to enable metrics reporting, if it not
     33 // enabled already.
     34 class SessionCrashedBubbleView
     35     : public views::BubbleDelegateView,
     36       public views::ButtonListener,
     37       public views::StyledLabelListener,
     38       public content::WebContentsObserver,
     39       public content::NotificationObserver,
     40       public TabStripModelObserver {
     41  public:
     42   static void Show(Browser* browser);
     43 
     44  private:
     45   // A helper class that listens to browser removal event.
     46   class BrowserRemovalObserver;
     47 
     48   SessionCrashedBubbleView(views::View* anchor_view,
     49                            Browser* browser,
     50                            content::WebContents* web_contents,
     51                            bool offer_uma_optin);
     52   virtual ~SessionCrashedBubbleView();
     53 
     54   // Creates and shows the session crashed bubble, with |offer_uma_optin|
     55   // indicating whether the UMA opt-in checkbox should be shown. Called
     56   // by Show after checking whether the UMA option should be presented and it
     57   // takes ownership of |browser_observer|.
     58   static void ShowForReal(scoped_ptr<BrowserRemovalObserver> browser_observer,
     59                           bool offer_uma_optin);
     60 
     61   // WidgetDelegateView methods.
     62   virtual views::View* GetInitiallyFocusedView() OVERRIDE;
     63   virtual base::string16 GetWindowTitle() const OVERRIDE;
     64   virtual bool ShouldShowWindowTitle() const OVERRIDE;
     65   virtual bool ShouldShowCloseButton() const OVERRIDE;
     66 
     67   // views::BubbleDelegateView methods.
     68   virtual void Init() OVERRIDE;
     69 
     70   // views::ButtonListener methods.
     71   virtual void ButtonPressed(views::Button* sender,
     72                              const ui::Event& event) OVERRIDE;
     73 
     74   // views::StyledLabelListener methods.
     75   virtual void StyledLabelLinkClicked(const gfx::Range& range,
     76                                       int event_flags) OVERRIDE;
     77 
     78   // content::WebContentsObserver methods.
     79   virtual void DidStartNavigationToPendingEntry(
     80       const GURL& url,
     81       content::NavigationController::ReloadType reload_type) OVERRIDE;
     82   virtual void DidFinishLoad(
     83       int64 frame_id,
     84       const GURL& validated_url,
     85       bool is_main_frame,
     86       content::RenderViewHost* render_view_host) OVERRIDE;
     87   virtual void WasShown() OVERRIDE;
     88   virtual void WasHidden() OVERRIDE;
     89 
     90   // content::NotificationObserver methods.
     91   virtual void Observe(
     92       int type,
     93       const content::NotificationSource& source,
     94       const content::NotificationDetails& details) OVERRIDE;
     95 
     96   // TabStripModelObserver methods.
     97   // When the tab with current bubble is being dragged and dropped to a new
     98   // window or to another window, the bubble will be dismissed as if the user
     99   // chose not to restore the previous session.
    100   virtual void TabDetachedAt(
    101       content::WebContents* contents,
    102       int index) OVERRIDE;
    103 
    104   // Create the view for user to opt in to Uma.
    105   void CreateUmaOptinView(views::GridLayout* layout);
    106 
    107   // Restore previous session after user selects so.
    108   void RestorePreviousSession(views::Button* sender);
    109 
    110   // Close and destroy the bubble.
    111   void CloseBubble();
    112 
    113   content::NotificationRegistrar registrar_;
    114 
    115   // Used for opening the question mark link as well as access the tab strip.
    116   Browser* browser_;
    117 
    118   // The web content associated with current bubble.
    119   content::WebContents* web_contents_;
    120 
    121   // Button for the user to confirm a session restore.
    122   views::LabelButton* restore_button_;
    123 
    124   // Checkbox for the user to opt-in to UMA reporting.
    125   views::Checkbox* uma_option_;
    126 
    127   // Whether or not the UMA opt-in option should be shown.
    128   bool offer_uma_optin_;
    129 
    130   // Whether or not a navigation has started on current tab.
    131   bool started_navigation_;
    132 
    133   DISALLOW_COPY_AND_ASSIGN(SessionCrashedBubbleView);
    134 };
    135 
    136 #endif  // CHROME_BROWSER_UI_VIEWS_SESSION_CRASHED_BUBBLE_VIEW_H_
    137