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/link_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::LinkListener
,
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::LinkListener methods.
60 virtual void LinkClicked(views::Link
* source
, int event_floags
) OVERRIDE
;
62 // content::WebContentsObserver methods.
63 virtual void DidStartNavigationToPendingEntry(
65 content::NavigationController::ReloadType reload_type
) OVERRIDE
;
66 virtual void DidFinishLoad(
68 const GURL
& validated_url
,
70 content::RenderViewHost
* render_view_host
) OVERRIDE
;
71 virtual void WasShown() OVERRIDE
;
72 virtual void WasHidden() OVERRIDE
;
74 // content::NotificationObserver methods.
77 const content::NotificationSource
& source
,
78 const content::NotificationDetails
& details
) OVERRIDE
;
80 // TabStripModelObserver methods.
81 // When the tab with current bubble is being dragged and dropped to a new
82 // window or to another window, the bubble will be dismissed as if the user
83 // chose not to restore the previous session.
84 virtual void TabDetachedAt(
85 content::WebContents
* contents
,
88 // Create the view for user to opt in to Uma.
89 void CreateUmaOptinView(views::GridLayout
* layout
);
91 // Restore previous session after user selects so.
92 void RestorePreviousSession(views::Button
* sender
);
94 // Close and destroy the bubble.
97 content::NotificationRegistrar registrar_
;
99 // Used for opening the question mark link as well as access the tab strip.
102 // The web content associated with current bubble.
103 content::WebContents
* web_contents_
;
105 // Button for the user to confirm a session restore.
106 views::LabelButton
* restore_button_
;
108 // Button for the user to close this bubble.
109 views::LabelButton
* close_
;
111 // Checkbox for the user to opt-in to UMA reporting.
112 views::Checkbox
* uma_option_
;
114 // Whether or not a navigation has started on current tab.
115 bool started_navigation_
;
117 DISALLOW_COPY_AND_ASSIGN(SessionCrashedBubbleView
);
120 #endif // CHROME_BROWSER_UI_VIEWS_SESSION_CRASHED_BUBBLE_VIEW_H_