session_crashed_bubble_view.h revision 010d83a9304c5a91596085d917d248abff47903a
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. 4 5#ifndef CHROME_BROWSER_UI_VIEWS_SESSION_CRASHED_BUBBLE_VIEW_H_ 6#define CHROME_BROWSER_UI_VIEWS_SESSION_CRASHED_BUBBLE_VIEW_H_ 7 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 15namespace views { 16class Checkbox; 17class GridLayout; 18class LabelButton; 19class Widget; 20} 21 22namespace content { 23class WebContents; 24class RenderViewHost; 25} 26 27class Browser; 28 29// It creates a session restore request bubble when the previous session has 30// crashed. It also presents an option to enable metrics reporting, if it not 31// enabled already. 32class SessionCrashedBubbleView 33 : public views::BubbleDelegateView, 34 public views::ButtonListener, 35 public content::WebContentsObserver, 36 public content::NotificationObserver, 37 public TabStripModelObserver { 38 public: 39 static void Show(Browser* browser); 40 41 private: 42 SessionCrashedBubbleView(views::View* anchor_view, 43 Browser* browser, 44 content::WebContents* web_contents); 45 virtual ~SessionCrashedBubbleView(); 46 47 // WidgetDelegateView methods. 48 virtual views::View* GetInitiallyFocusedView() OVERRIDE; 49 50 // views::BubbleDelegateView methods. 51 virtual void Init() OVERRIDE; 52 53 // views::ButtonListener methods. 54 virtual void ButtonPressed(views::Button* sender, 55 const ui::Event& event) OVERRIDE; 56 57 // content::WebContentsObserver methods. 58 virtual void DidStartNavigationToPendingEntry( 59 const GURL& url, 60 content::NavigationController::ReloadType reload_type) OVERRIDE; 61 virtual void DidFinishLoad( 62 int64 frame_id, 63 const GURL& validated_url, 64 bool is_main_frame, 65 content::RenderViewHost* render_view_host) OVERRIDE; 66 virtual void WasShown() OVERRIDE; 67 virtual void WasHidden() OVERRIDE; 68 69 // content::NotificationObserver methods. 70 virtual void Observe( 71 int type, 72 const content::NotificationSource& source, 73 const content::NotificationDetails& details) OVERRIDE; 74 75 // TabStripModelObserver methods. 76 // When the tab with current bubble is being dragged and dropped to a new 77 // window or to another window, the bubble will be dismissed as if the user 78 // chose not to restore the previous session. 79 virtual void TabDetachedAt( 80 content::WebContents* contents, 81 int index) OVERRIDE; 82 83 // Create the view for user to opt in to Uma. 84 void CreateUmaOptinView(views::GridLayout* layout); 85 86 // Restore previous session after user selects so. 87 void RestorePreviousSession(views::Button* sender); 88 89 // Close and destroy the bubble. 90 void CloseBubble(); 91 92 content::NotificationRegistrar registrar_; 93 94 // Used for opening the question mark link as well as access the tab strip. 95 Browser* browser_; 96 97 // The web content associated with current bubble. 98 content::WebContents* web_contents_; 99 100 // Button for the user to confirm a session restore. 101 views::LabelButton* restore_button_; 102 103 // Button for the user to close this bubble. 104 views::LabelButton* close_; 105 106 // Checkbox for the user to opt-in to UMA reporting. 107 views::Checkbox* uma_option_; 108 109 // Whether or not a navigation has started on current tab. 110 bool started_navigation_; 111 112 DISALLOW_COPY_AND_ASSIGN(SessionCrashedBubbleView); 113}; 114 115#endif // CHROME_BROWSER_UI_VIEWS_SESSION_CRASHED_BUBBLE_VIEW_H_ 116