Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: chrome/browser/ui/views/session_crashed_bubble_view.cc

Issue 2650293002: Make the session restore bubble not close on navigation (Closed)
Patch Set: prune includes Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/session_crashed_bubble_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/ui/views/session_crashed_bubble_view.h" 5 #include "chrome/browser/ui/views/session_crashed_bubble_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/metrics/metrics_reporting_state.h" 17 #include "chrome/browser/metrics/metrics_reporting_state.h"
20 #include "chrome/browser/sessions/session_restore.h" 18 #include "chrome/browser/sessions/session_restore.h"
21 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/browser/ui/browser_list_observer.h" 20 #include "chrome/browser/ui/browser_list_observer.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
24 #include "chrome/browser/ui/views/frame/browser_view.h" 22 #include "chrome/browser/ui/views/frame/browser_view.h"
25 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" 23 #include "chrome/browser/ui/views/toolbar/app_menu_button.h"
26 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 24 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
27 #include "chrome/common/url_constants.h"
28 #include "chrome/grit/chromium_strings.h" 25 #include "chrome/grit/chromium_strings.h"
29 #include "chrome/grit/generated_resources.h" 26 #include "chrome/grit/generated_resources.h"
30 #include "chrome/installer/util/google_update_settings.h" 27 #include "chrome/installer/util/google_update_settings.h"
31 #include "components/strings/grit/components_chromium_strings.h" 28 #include "components/strings/grit/components_chromium_strings.h"
32 #include "components/strings/grit/components_strings.h" 29 #include "components/strings/grit/components_strings.h"
33 #include "content/public/browser/browser_context.h" 30 #include "content/public/browser/browser_context.h"
34 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
35 #include "content/public/browser/notification_source.h"
36 #include "content/public/browser/render_frame_host.h"
37 #include "content/public/browser/web_contents.h"
38 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/views/bubble/bubble_frame_view.h"
40 #include "ui/views/controls/button/checkbox.h" 33 #include "ui/views/controls/button/checkbox.h"
41 #include "ui/views/controls/label.h" 34 #include "ui/views/controls/label.h"
42 #include "ui/views/controls/separator.h" 35 #include "ui/views/controls/separator.h"
43 #include "ui/views/controls/styled_label.h" 36 #include "ui/views/controls/styled_label.h"
44 #include "ui/views/layout/fill_layout.h" 37 #include "ui/views/layout/fill_layout.h"
45 #include "ui/views/layout/grid_layout.h" 38 #include "ui/views/layout/grid_layout.h"
46 #include "ui/views/layout/layout_constants.h" 39 #include "ui/views/layout/layout_constants.h"
47 #include "ui/views/widget/widget.h" 40 #include "ui/views/widget/widget.h"
48 41
49 using views::GridLayout; 42 using views::GridLayout;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // and the preference is modifiable by the user. 150 // and the preference is modifiable by the user.
158 bool offer_uma_optin = false; 151 bool offer_uma_optin = false;
159 152
160 #if defined(GOOGLE_CHROME_BUILD) 153 #if defined(GOOGLE_CHROME_BUILD)
161 if (!uma_opted_in_already) 154 if (!uma_opted_in_already)
162 offer_uma_optin = !IsMetricsReportingPolicyManaged(); 155 offer_uma_optin = !IsMetricsReportingPolicyManaged();
163 #endif // defined(GOOGLE_CHROME_BUILD) 156 #endif // defined(GOOGLE_CHROME_BUILD)
164 157
165 Browser* browser = browser_observer->browser(); 158 Browser* browser = browser_observer->browser();
166 159
167 if (!browser) { 160 if (!browser || !browser->tab_strip_model()->GetActiveWebContents()) {
168 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ERROR); 161 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ERROR);
169 return; 162 return;
170 } 163 }
171 164
172 views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser) 165 views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser)
173 ->toolbar() 166 ->toolbar()
174 ->app_menu_button(); 167 ->app_menu_button();
175 content::WebContents* web_contents =
176 browser->tab_strip_model()->GetActiveWebContents();
177
178 if (!web_contents) {
179 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ERROR);
180 return;
181 }
182
183 SessionCrashedBubbleView* crash_bubble = 168 SessionCrashedBubbleView* crash_bubble =
184 new SessionCrashedBubbleView(anchor_view, browser, web_contents, 169 new SessionCrashedBubbleView(anchor_view, browser, offer_uma_optin);
185 offer_uma_optin);
186 views::BubbleDialogDelegateView::CreateBubble(crash_bubble)->Show(); 170 views::BubbleDialogDelegateView::CreateBubble(crash_bubble)->Show();
187 171
188 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_SHOWN); 172 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_SHOWN);
189 if (uma_opted_in_already) 173 if (uma_opted_in_already)
190 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ALREADY_UMA_OPTIN); 174 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ALREADY_UMA_OPTIN);
191 } 175 }
192 176
193 SessionCrashedBubbleView::SessionCrashedBubbleView( 177 SessionCrashedBubbleView::SessionCrashedBubbleView(
194 views::View* anchor_view, 178 views::View* anchor_view,
195 Browser* browser, 179 Browser* browser,
196 content::WebContents* web_contents,
197 bool offer_uma_optin) 180 bool offer_uma_optin)
198 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 181 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
199 content::WebContentsObserver(web_contents),
200 browser_(browser), 182 browser_(browser),
201 web_contents_(web_contents),
202 uma_option_(NULL), 183 uma_option_(NULL),
203 offer_uma_optin_(offer_uma_optin), 184 offer_uma_optin_(offer_uma_optin),
204 first_navigation_ignored_(false),
205 restored_(false) { 185 restored_(false) {
206 set_close_on_deactivate(false); 186 set_close_on_deactivate(false);
207 registrar_.Add(
208 this,
209 chrome::NOTIFICATION_TAB_CLOSING,
210 content::Source<content::NavigationController>(&(
211 web_contents->GetController())));
212 browser->tab_strip_model()->AddObserver(this);
213 } 187 }
214 188
215 SessionCrashedBubbleView::~SessionCrashedBubbleView() { 189 SessionCrashedBubbleView::~SessionCrashedBubbleView() {
216 browser_->tab_strip_model()->RemoveObserver(this);
217 } 190 }
218 191
219 base::string16 SessionCrashedBubbleView::GetWindowTitle() const { 192 base::string16 SessionCrashedBubbleView::GetWindowTitle() const {
220 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_BUBBLE_TITLE); 193 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_BUBBLE_TITLE);
221 } 194 }
222 195
223 bool SessionCrashedBubbleView::ShouldShowWindowTitle() const { 196 bool SessionCrashedBubbleView::ShouldShowWindowTitle() const {
224 return true; 197 return true;
225 } 198 }
226 199
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 void SessionCrashedBubbleView::StyledLabelLinkClicked(views::StyledLabel* label, 301 void SessionCrashedBubbleView::StyledLabelLinkClicked(views::StyledLabel* label,
329 const gfx::Range& range, 302 const gfx::Range& range,
330 int event_flags) { 303 int event_flags) {
331 browser_->OpenURL(content::OpenURLParams( 304 browser_->OpenURL(content::OpenURLParams(
332 GURL("https://support.google.com/chrome/answer/96817"), 305 GURL("https://support.google.com/chrome/answer/96817"),
333 content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, 306 content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
334 ui::PAGE_TRANSITION_LINK, false)); 307 ui::PAGE_TRANSITION_LINK, false));
335 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_HELP); 308 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_HELP);
336 } 309 }
337 310
338 void SessionCrashedBubbleView::DidFinishLoad(
339 content::RenderFrameHost* render_frame_host,
340 const GURL& validated_url) {
341 // We want to close the bubble if the user navigates the first tab away after
342 // a crash. Ignore subframe navigations since they're noise and don't affect
343 // the desired behavior.
344 if (render_frame_host->GetParent())
345 return;
346
347 if (!first_navigation_ignored_) {
348 first_navigation_ignored_ = true;
349 return;
350 }
351
352 CloseBubble();
353 }
354
355 void SessionCrashedBubbleView::WasShown() {
356 GetWidget()->Show();
357 }
358
359 void SessionCrashedBubbleView::WasHidden() {
360 GetWidget()->Hide();
361 }
362
363 void SessionCrashedBubbleView::Observe(
364 int type,
365 const content::NotificationSource& source,
366 const content::NotificationDetails& details) {
367 DCHECK_EQ(chrome::NOTIFICATION_TAB_CLOSING, type);
368 CloseBubble();
369 }
370
371 void SessionCrashedBubbleView::TabDetachedAt(content::WebContents* contents,
372 int index) {
373 if (web_contents_ == contents)
374 CloseBubble();
375 }
376
377 void SessionCrashedBubbleView::RestorePreviousSession() { 311 void SessionCrashedBubbleView::RestorePreviousSession() {
378 SessionRestore::RestoreSessionAfterCrash(browser_); 312 SessionRestore::RestoreSessionAfterCrash(browser_);
379 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_RESTORED); 313 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_RESTORED);
380 restored_ = true; 314 restored_ = true;
381 315
382 // Record user's choice for opt-in in to UMA. 316 // Record user's choice for opt-in in to UMA.
383 // There's no opt-out choice in the crash restore bubble. 317 // There's no opt-out choice in the crash restore bubble.
384 if (uma_option_ && uma_option_->checked()) { 318 if (uma_option_ && uma_option_->checked()) {
385 ChangeMetricsReportingState(true); 319 ChangeMetricsReportingState(true);
386 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN); 320 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN);
387 } 321 }
388 CloseBubble();
389 }
390
391 void SessionCrashedBubbleView::CloseBubble() {
392 GetWidget()->Close(); 322 GetWidget()->Close();
393 } 323 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/session_crashed_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698