Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / views / session_crashed_bubble_view.h
blob09086d09a838786b260f32809cc607d2628d0649
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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_SESSION_CRASHED_BUBBLE_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_SESSION_CRASHED_BUBBLE_VIEW_H_
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"
17 namespace views {
18 class Checkbox;
19 class GridLayout;
20 class LabelButton;
21 class Widget;
24 namespace content {
25 class WebContents;
26 class RenderViewHost;
29 class Browser;
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 bool Show(Browser* browser);
44 private:
45 // A helper class that listens to browser removal event.
46 class BrowserRemovalObserver;
48 SessionCrashedBubbleView(views::View* anchor_view,
49 Browser* browser,
50 content::WebContents* web_contents,
51 bool offer_uma_optin);
52 ~SessionCrashedBubbleView() override;
54 // Creates and shows the session crashed bubble, with |uma_opted_in_already|
55 // indicating whether the user has already opted-in to UMA. It will be called
56 // by Show. It takes ownership of |browser_observer|.
57 static void ShowForReal(scoped_ptr<BrowserRemovalObserver> browser_observer,
58 bool uma_opted_in_already);
60 // WidgetDelegateView methods.
61 views::View* GetInitiallyFocusedView() override;
62 base::string16 GetWindowTitle() const override;
63 bool ShouldShowWindowTitle() const override;
64 bool ShouldShowCloseButton() const override;
65 void OnWidgetDestroying(views::Widget* widget) override;
67 // views::BubbleDelegateView methods.
68 void Init() override;
70 // views::ButtonListener methods.
71 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
73 // views::StyledLabelListener methods.
74 void StyledLabelLinkClicked(const gfx::Range& range,
75 int event_flags) override;
77 // content::WebContentsObserver methods.
78 void DidStartNavigationToPendingEntry(
79 const GURL& url,
80 content::NavigationController::ReloadType reload_type) override;
81 void DidFinishLoad(content::RenderFrameHost* render_frame_host,
82 const GURL& validated_url) override;
83 void WasShown() override;
84 void WasHidden() override;
86 // content::NotificationObserver methods.
87 void Observe(int type,
88 const content::NotificationSource& source,
89 const content::NotificationDetails& details) override;
91 // TabStripModelObserver methods.
92 // When the tab with current bubble is being dragged and dropped to a new
93 // window or to another window, the bubble will be dismissed as if the user
94 // chose not to restore the previous session.
95 void TabDetachedAt(content::WebContents* contents, int index) override;
97 // Create the view for the user to opt in to UMA.
98 views::View* CreateUMAOptinView();
100 // Restore previous session after user selects so.
101 void RestorePreviousSession(views::Button* sender);
103 // Close and destroy the bubble.
104 void CloseBubble();
106 content::NotificationRegistrar registrar_;
108 // Used for opening the question mark link as well as access the tab strip.
109 Browser* browser_;
111 // The web content associated with current bubble.
112 content::WebContents* web_contents_;
114 // Button for the user to confirm a session restore.
115 views::LabelButton* restore_button_;
117 // Checkbox for the user to opt-in to UMA reporting.
118 views::Checkbox* uma_option_;
120 // Whether or not the UMA opt-in option should be shown.
121 bool offer_uma_optin_;
123 // Whether or not a navigation has started on current tab.
124 bool started_navigation_;
126 // Whether or not the user chose to restore previous session. It is used to
127 // collect bubble usage stats.
128 bool restored_;
130 DISALLOW_COPY_AND_ASSIGN(SessionCrashedBubbleView);
133 #endif // CHROME_BROWSER_UI_VIEWS_SESSION_CRASHED_BUBBLE_VIEW_H_