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