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

Side by Side Diff: chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc

Issue 2541173003: Allow navigation while a JavaScript dialog is up. (Closed)
Patch Set: Created 4 years 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/javascript_dialogs/javascript_dialog_tab_helper.h" 5 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/feature_list.h" 9 #include "base/feature_list.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "chrome/browser/engagement/site_engagement_service.h" 11 #include "chrome/browser/engagement/site_engagement_service.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_list.h" 14 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" 15 #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/common/chrome_features.h" 17 #include "chrome/common/chrome_features.h"
18 #include "components/app_modal/javascript_dialog_manager.h" 18 #include "components/app_modal/javascript_dialog_manager.h"
19 #include "content/public/browser/navigation_handle.h"
19 #include "content/public/browser/render_frame_host.h" 20 #include "content/public/browser/render_frame_host.h"
20 21
21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper); 22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper);
22 23
23 namespace { 24 namespace {
24 25
25 bool IsEnabled() { 26 bool IsEnabled() {
26 return base::FeatureList::IsEnabled(features::kAutoDismissingDialogs); 27 return base::FeatureList::IsEnabled(features::kAutoDismissingDialogs);
27 } 28 }
28 29
(...skipping 30 matching lines...) Expand all
59 enum class JavaScriptDialogTabHelper::DismissalCause { 60 enum class JavaScriptDialogTabHelper::DismissalCause {
60 // This is used for a UMA histogram. Please never alter existing values, only 61 // This is used for a UMA histogram. Please never alter existing values, only
61 // append new ones. 62 // append new ones.
62 TAB_HELPER_DESTROYED = 0, 63 TAB_HELPER_DESTROYED = 0,
63 SUBSEQUENT_DIALOG_SHOWN = 1, 64 SUBSEQUENT_DIALOG_SHOWN = 1,
64 HANDLE_DIALOG_CALLED = 2, 65 HANDLE_DIALOG_CALLED = 2,
65 CANCEL_DIALOGS_CALLED = 3, 66 CANCEL_DIALOGS_CALLED = 3,
66 TAB_HIDDEN = 4, 67 TAB_HIDDEN = 4,
67 BROWSER_SWITCHED = 5, 68 BROWSER_SWITCHED = 5,
68 DIALOG_BUTTON_CLICKED = 6, 69 DIALOG_BUTTON_CLICKED = 6,
70 TAB_NAVIGATED = 7,
69 MAX, 71 MAX,
70 }; 72 };
71 73
72 JavaScriptDialogTabHelper::JavaScriptDialogTabHelper( 74 JavaScriptDialogTabHelper::JavaScriptDialogTabHelper(
73 content::WebContents* web_contents) 75 content::WebContents* web_contents)
74 : content::WebContentsObserver(web_contents) { 76 : content::WebContentsObserver(web_contents) {
75 } 77 }
76 78
77 JavaScriptDialogTabHelper::~JavaScriptDialogTabHelper() { 79 JavaScriptDialogTabHelper::~JavaScriptDialogTabHelper() {
78 if (dialog_) { 80 if (dialog_) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 return AppModalDialogManager()->CancelDialogs( 254 return AppModalDialogManager()->CancelDialogs(
253 web_contents, suppress_callbacks, reset_state); 255 web_contents, suppress_callbacks, reset_state);
254 } 256 }
255 257
256 void JavaScriptDialogTabHelper::WasHidden() { 258 void JavaScriptDialogTabHelper::WasHidden() {
257 if (dialog_) { 259 if (dialog_) {
258 CloseDialog(false, false, base::string16(), DismissalCause::TAB_HIDDEN); 260 CloseDialog(false, false, base::string16(), DismissalCause::TAB_HIDDEN);
259 } 261 }
260 } 262 }
261 263
264 // This function handles the case where browser-side navigation (PlzNavigate) is
265 // enabled. DidStartNavigationToPendingEntry, below, handles the case where
266 // PlzNavigate is not enabled. TODO(avi): When the non-PlzNavigate code is
267 // removed, remove DidStartNavigationToPendingEntry.
268 void JavaScriptDialogTabHelper::DidStartNavigation(
269 content::NavigationHandle* navigation_handle) {
270 // Close the dialog if the user started a new navigation. This allows reloads
271 // and history navigations to proceed.
272 if (dialog_ && navigation_handle->IsInMainFrame()) {
Charlie Reis 2016/12/01 21:36:48 nit: No braces? What's the reason for the IsInMai
Avi (use Gerrit) 2016/12/01 23:20:08 Done.
Charlie Reis 2016/12/01 23:30:26 Cool! I thought I needed a flag, but yes, it work
Avi (use Gerrit) 2016/12/02 01:32:26 Acknowledged.
273 CloseDialog(false, false, base::string16(), DismissalCause::TAB_NAVIGATED);
274 }
275 }
276
277 // This function handles the case where browser-side navigation (PlzNavigate) is
278 // not enabled. DidStartNavigation, above, handles the case where PlzNavigate is
279 // enabled. TODO(avi): When the non-PlzNavigate code is removed, remove
280 // DidStartNavigationToPendingEntry.
281 void JavaScriptDialogTabHelper::DidStartNavigationToPendingEntry(
Charlie Reis 2016/12/01 21:36:48 Sanity check: This is only called for browser-init
Avi (use Gerrit) 2016/12/01 23:20:07 This is intended to deal with the user clicking th
Charlie Reis 2016/12/01 23:30:26 Sounds good. (Presumably you also care about omni
Avi (use Gerrit) 2016/12/02 01:32:26 This fixes navigations that happen within the same
282 const GURL& url,
283 content::ReloadType reload_type) {
284 // Close the dialog if the user started a new navigation. This allows reloads
285 // and history navigations to proceed.
286 if (dialog_) {
Charlie Reis 2016/12/01 21:36:48 nit: No braces? Interesting that this doesn't che
Avi (use Gerrit) 2016/12/01 23:20:08 I'm agreeing that we should drop main frame checks
287 CloseDialog(false, false, base::string16(), DismissalCause::TAB_NAVIGATED);
288 }
289 }
290
262 void JavaScriptDialogTabHelper::OnBrowserSetLastActive(Browser* browser) { 291 void JavaScriptDialogTabHelper::OnBrowserSetLastActive(Browser* browser) {
263 if (dialog_ && !IsWebContentsForemost(web_contents())) { 292 if (dialog_ && !IsWebContentsForemost(web_contents())) {
264 CloseDialog(false, false, base::string16(), 293 CloseDialog(false, false, base::string16(),
265 DismissalCause::BROWSER_SWITCHED); 294 DismissalCause::BROWSER_SWITCHED);
266 } 295 }
267 } 296 }
268 297
269 void JavaScriptDialogTabHelper::LogDialogDismissalCause( 298 void JavaScriptDialogTabHelper::LogDialogDismissalCause(
270 JavaScriptDialogTabHelper::DismissalCause cause) { 299 JavaScriptDialogTabHelper::DismissalCause cause) {
271 switch (message_type_) { 300 switch (message_type_) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 dialog_callback_.Run(success, user_input); 338 dialog_callback_.Run(success, user_input);
310 339
311 ClearDialogInfo(); 340 ClearDialogInfo();
312 } 341 }
313 342
314 void JavaScriptDialogTabHelper::ClearDialogInfo() { 343 void JavaScriptDialogTabHelper::ClearDialogInfo() {
315 dialog_.reset(); 344 dialog_.reset();
316 dialog_callback_.Reset(); 345 dialog_callback_.Reset();
317 BrowserList::RemoveObserver(this); 346 BrowserList::RemoveObserver(this);
318 } 347 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698