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

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: 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" 17 #include "chrome/browser/browser_process.h"
msw 2017/01/25 18:52:44 nit: remove
sky 2017/01/25 21:47:07 Done.
18 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
msw 2017/01/25 18:52:44 nit: remove
sky 2017/01/25 21:47:07 Done.
19 #include "chrome/browser/metrics/metrics_reporting_state.h" 19 #include "chrome/browser/metrics/metrics_reporting_state.h"
20 #include "chrome/browser/sessions/session_restore.h" 20 #include "chrome/browser/sessions/session_restore.h"
21 #include "chrome/browser/ui/browser_list.h" 21 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/browser/ui/browser_list_observer.h" 22 #include "chrome/browser/ui/browser_list_observer.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" 23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
msw 2017/01/25 18:52:44 nit: remove (if active web contents is no longer n
sky 2017/01/25 21:47:07 Active web contents check is still worth while, so
24 #include "chrome/browser/ui/views/frame/browser_view.h" 24 #include "chrome/browser/ui/views/frame/browser_view.h"
25 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" 25 #include "chrome/browser/ui/views/toolbar/app_menu_button.h"
26 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 26 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
27 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
msw 2017/01/25 18:52:44 nit: remove
sky 2017/01/25 21:47:07 Done.
28 #include "chrome/grit/chromium_strings.h" 28 #include "chrome/grit/chromium_strings.h"
29 #include "chrome/grit/generated_resources.h" 29 #include "chrome/grit/generated_resources.h"
30 #include "chrome/installer/util/google_update_settings.h" 30 #include "chrome/installer/util/google_update_settings.h"
31 #include "components/strings/grit/components_chromium_strings.h" 31 #include "components/strings/grit/components_chromium_strings.h"
32 #include "components/strings/grit/components_strings.h" 32 #include "components/strings/grit/components_strings.h"
33 #include "content/public/browser/browser_context.h" 33 #include "content/public/browser/browser_context.h"
34 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
35 #include "content/public/browser/notification_source.h" 35 #include "content/public/browser/notification_source.h"
msw 2017/01/25 18:52:44 nit: remove
sky 2017/01/25 21:47:07 Done.
36 #include "content/public/browser/render_frame_host.h" 36 #include "content/public/browser/render_frame_host.h"
msw 2017/01/25 18:52:44 nit: remove
sky 2017/01/25 21:47:07 Done.
37 #include "content/public/browser/web_contents.h"
38 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/views/bubble/bubble_frame_view.h" 38 #include "ui/views/bubble/bubble_frame_view.h"
msw 2017/01/25 18:52:44 nit: remove
sky 2017/01/25 21:47:07 Done.
40 #include "ui/views/controls/button/checkbox.h" 39 #include "ui/views/controls/button/checkbox.h"
41 #include "ui/views/controls/label.h" 40 #include "ui/views/controls/label.h"
42 #include "ui/views/controls/separator.h" 41 #include "ui/views/controls/separator.h"
43 #include "ui/views/controls/styled_label.h" 42 #include "ui/views/controls/styled_label.h"
44 #include "ui/views/layout/fill_layout.h" 43 #include "ui/views/layout/fill_layout.h"
45 #include "ui/views/layout/grid_layout.h" 44 #include "ui/views/layout/grid_layout.h"
46 #include "ui/views/layout/layout_constants.h" 45 #include "ui/views/layout/layout_constants.h"
47 #include "ui/views/widget/widget.h" 46 #include "ui/views/widget/widget.h"
48 47
49 using views::GridLayout; 48 using views::GridLayout;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // and the preference is modifiable by the user. 156 // and the preference is modifiable by the user.
158 bool offer_uma_optin = false; 157 bool offer_uma_optin = false;
159 158
160 #if defined(GOOGLE_CHROME_BUILD) 159 #if defined(GOOGLE_CHROME_BUILD)
161 if (!uma_opted_in_already) 160 if (!uma_opted_in_already)
162 offer_uma_optin = !IsMetricsReportingPolicyManaged(); 161 offer_uma_optin = !IsMetricsReportingPolicyManaged();
163 #endif // defined(GOOGLE_CHROME_BUILD) 162 #endif // defined(GOOGLE_CHROME_BUILD)
164 163
165 Browser* browser = browser_observer->browser(); 164 Browser* browser = browser_observer->browser();
166 165
167 if (!browser) { 166 if (!browser || !browser->tab_strip_model()->GetActiveWebContents()) {
msw 2017/01/25 18:52:44 q: can we now show the bubble without a valid acti
sky 2017/01/25 21:47:07 Generally if there isn't an active web contents th
168 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ERROR); 167 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ERROR);
169 return; 168 return;
170 } 169 }
171 170
172 views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser) 171 views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser)
173 ->toolbar() 172 ->toolbar()
174 ->app_menu_button(); 173 ->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 = 174 SessionCrashedBubbleView* crash_bubble =
184 new SessionCrashedBubbleView(anchor_view, browser, web_contents, 175 new SessionCrashedBubbleView(anchor_view, browser, offer_uma_optin);
185 offer_uma_optin);
186 views::BubbleDialogDelegateView::CreateBubble(crash_bubble)->Show(); 176 views::BubbleDialogDelegateView::CreateBubble(crash_bubble)->Show();
187 177
188 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_SHOWN); 178 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_SHOWN);
189 if (uma_opted_in_already) 179 if (uma_opted_in_already)
190 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ALREADY_UMA_OPTIN); 180 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ALREADY_UMA_OPTIN);
191 } 181 }
192 182
193 SessionCrashedBubbleView::SessionCrashedBubbleView( 183 SessionCrashedBubbleView::SessionCrashedBubbleView(
194 views::View* anchor_view, 184 views::View* anchor_view,
195 Browser* browser, 185 Browser* browser,
196 content::WebContents* web_contents,
197 bool offer_uma_optin) 186 bool offer_uma_optin)
198 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 187 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
199 content::WebContentsObserver(web_contents),
200 browser_(browser), 188 browser_(browser),
201 web_contents_(web_contents),
202 uma_option_(NULL), 189 uma_option_(NULL),
203 offer_uma_optin_(offer_uma_optin), 190 offer_uma_optin_(offer_uma_optin),
204 first_navigation_ignored_(false),
205 restored_(false) { 191 restored_(false) {
206 set_close_on_deactivate(false); 192 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 } 193 }
214 194
215 SessionCrashedBubbleView::~SessionCrashedBubbleView() { 195 SessionCrashedBubbleView::~SessionCrashedBubbleView() {
216 browser_->tab_strip_model()->RemoveObserver(this);
217 } 196 }
218 197
219 base::string16 SessionCrashedBubbleView::GetWindowTitle() const { 198 base::string16 SessionCrashedBubbleView::GetWindowTitle() const {
220 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_BUBBLE_TITLE); 199 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_BUBBLE_TITLE);
221 } 200 }
222 201
223 bool SessionCrashedBubbleView::ShouldShowWindowTitle() const { 202 bool SessionCrashedBubbleView::ShouldShowWindowTitle() const {
224 return true; 203 return true;
225 } 204 }
226 205
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 void SessionCrashedBubbleView::StyledLabelLinkClicked(views::StyledLabel* label, 307 void SessionCrashedBubbleView::StyledLabelLinkClicked(views::StyledLabel* label,
329 const gfx::Range& range, 308 const gfx::Range& range,
330 int event_flags) { 309 int event_flags) {
331 browser_->OpenURL(content::OpenURLParams( 310 browser_->OpenURL(content::OpenURLParams(
332 GURL("https://support.google.com/chrome/answer/96817"), 311 GURL("https://support.google.com/chrome/answer/96817"),
333 content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, 312 content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
334 ui::PAGE_TRANSITION_LINK, false)); 313 ui::PAGE_TRANSITION_LINK, false));
335 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_HELP); 314 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_HELP);
336 } 315 }
337 316
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() { 317 void SessionCrashedBubbleView::RestorePreviousSession() {
378 SessionRestore::RestoreSessionAfterCrash(browser_); 318 SessionRestore::RestoreSessionAfterCrash(browser_);
379 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_RESTORED); 319 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_RESTORED);
380 restored_ = true; 320 restored_ = true;
381 321
382 // Record user's choice for opt-in in to UMA. 322 // Record user's choice for opt-in in to UMA.
383 // There's no opt-out choice in the crash restore bubble. 323 // There's no opt-out choice in the crash restore bubble.
384 if (uma_option_ && uma_option_->checked()) { 324 if (uma_option_ && uma_option_->checked()) {
385 ChangeMetricsReportingState(true); 325 ChangeMetricsReportingState(true);
386 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN); 326 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN);
387 } 327 }
388 CloseBubble();
389 }
390
391 void SessionCrashedBubbleView::CloseBubble() {
392 GetWidget()->Close(); 328 GetWidget()->Close();
393 } 329 }
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