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