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 "chrome/browser/ui/tabs/tab_strip_model_observer.h"
9 #include "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_registrar.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "ui/views/bubble/bubble_delegate.h"
13 #include "ui/views/controls/button/button.h"
14 #include "ui/views/controls/styled_label_listener.h"
30 // It creates a session restore request bubble when the previous session has
31 // crashed. It also presents an option to enable metrics reporting, if it not
33 class SessionCrashedBubbleView
34 : public views::BubbleDelegateView
,
35 public views::ButtonListener
,
36 public views::StyledLabelListener
,
37 public content::WebContentsObserver
,
38 public content::NotificationObserver
,
39 public TabStripModelObserver
{
41 static void Show(Browser
* browser
);
44 SessionCrashedBubbleView(views::View
* anchor_view
,
46 content::WebContents
* web_contents
);
47 virtual ~SessionCrashedBubbleView();
49 // WidgetDelegateView methods.
50 virtual views::View
* GetInitiallyFocusedView() OVERRIDE
;
52 // views::BubbleDelegateView methods.
53 virtual void Init() OVERRIDE
;
55 // views::ButtonListener methods.
56 virtual void ButtonPressed(views::Button
* sender
,
57 const ui::Event
& event
) OVERRIDE
;
59 // views::StyledLabelListener methods.
60 virtual void StyledLabelLinkClicked(const gfx::Range
& range
,
61 int event_flags
) OVERRIDE
;
63 // content::WebContentsObserver methods.
64 virtual void DidStartNavigationToPendingEntry(
66 content::NavigationController::ReloadType reload_type
) OVERRIDE
;
67 virtual void DidFinishLoad(
69 const GURL
& validated_url
,
71 content::RenderViewHost
* render_view_host
) OVERRIDE
;
72 virtual void WasShown() OVERRIDE
;
73 virtual void WasHidden() OVERRIDE
;
75 // content::NotificationObserver methods.
78 const content::NotificationSource
& source
,
79 const content::NotificationDetails
& details
) OVERRIDE
;
81 // TabStripModelObserver methods.
82 // When the tab with current bubble is being dragged and dropped to a new
83 // window or to another window, the bubble will be dismissed as if the user
84 // chose not to restore the previous session.
85 virtual void TabDetachedAt(
86 content::WebContents
* contents
,
89 // Create the view for user to opt in to Uma.
90 void CreateUmaOptinView(views::GridLayout
* layout
);
92 // Restore previous session after user selects so.
93 void RestorePreviousSession(views::Button
* sender
);
95 // Close and destroy the bubble.
98 content::NotificationRegistrar registrar_
;
100 // Used for opening the question mark link as well as access the tab strip.
103 // The web content associated with current bubble.
104 content::WebContents
* web_contents_
;
106 // Button for the user to confirm a session restore.
107 views::LabelButton
* restore_button_
;
109 // Button for the user to close this bubble.
110 views::LabelButton
* close_
;
112 // Checkbox for the user to opt-in to UMA reporting.
113 views::Checkbox
* uma_option_
;
115 // Whether or not a navigation has started on current tab.
116 bool started_navigation_
;
118 DISALLOW_COPY_AND_ASSIGN(SessionCrashedBubbleView
);
121 #endif // CHROME_BROWSER_UI_VIEWS_SESSION_CRASHED_BUBBLE_VIEW_H_