OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" |
| 6 |
| 7 #include "base/feature_list.h" |
| 8 #include "components/app_modal/javascript_dialog_manager.h" |
| 9 |
| 10 DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper); |
| 11 |
| 12 namespace { |
| 13 |
| 14 const base::Feature kAutoDismissingDialogsFeature{ |
| 15 "AutoDismissingDialogs", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 16 |
| 17 bool IsEnabled() { |
| 18 return base::FeatureList::IsEnabled(kAutoDismissingDialogsFeature); |
| 19 } |
| 20 |
| 21 content::JavaScriptDialogManager* AppModalDialogManager() { |
| 22 return app_modal::JavaScriptDialogManager::GetInstance(); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 27 JavaScriptDialogTabHelper::JavaScriptDialogTabHelper( |
| 28 content::WebContents* web_contents) |
| 29 : content::WebContentsObserver(web_contents) { |
| 30 } |
| 31 |
| 32 JavaScriptDialogTabHelper::~JavaScriptDialogTabHelper() { |
| 33 } |
| 34 |
| 35 void JavaScriptDialogTabHelper::WebContentsDestroyed() { |
| 36 } |
| 37 |
| 38 void JavaScriptDialogTabHelper::RunJavaScriptDialog( |
| 39 content::WebContents* web_contents, |
| 40 const GURL& origin_url, |
| 41 content::JavaScriptMessageType message_type, |
| 42 const base::string16& message_text, |
| 43 const base::string16& default_prompt_text, |
| 44 const DialogClosedCallback& callback, |
| 45 bool* did_suppress_message) { |
| 46 if (!IsEnabled()) { |
| 47 return AppModalDialogManager()->RunJavaScriptDialog( |
| 48 web_contents, origin_url, message_type, message_text, |
| 49 default_prompt_text, callback, did_suppress_message); |
| 50 } |
| 51 |
| 52 NOTREACHED() << "auto-dismissing dialog code does not yet exist"; |
| 53 } |
| 54 |
| 55 void JavaScriptDialogTabHelper::RunBeforeUnloadDialog( |
| 56 content::WebContents* web_contents, |
| 57 bool is_reload, |
| 58 const DialogClosedCallback& callback) { |
| 59 // onbeforeunload dialogs are always handled with an app-modal dialog, because |
| 60 // - they are critical to the user not losing data |
| 61 // - they can be requested for tabs that are not foremost |
| 62 // - they can be requested for many tabs at the same time |
| 63 // and therefore auto-dismissal is inappropriate for them. |
| 64 |
| 65 return AppModalDialogManager()->RunBeforeUnloadDialog(web_contents, is_reload, |
| 66 callback); |
| 67 } |
| 68 |
| 69 bool JavaScriptDialogTabHelper::HandleJavaScriptDialog( |
| 70 content::WebContents* web_contents, |
| 71 bool accept, |
| 72 const base::string16* prompt_override) { |
| 73 if (!IsEnabled()) { |
| 74 return AppModalDialogManager()->HandleJavaScriptDialog(web_contents, accept, |
| 75 prompt_override); |
| 76 } |
| 77 |
| 78 NOTREACHED() << "auto-dismissing dialog code does not yet exist"; |
| 79 return false; |
| 80 } |
| 81 |
| 82 void JavaScriptDialogTabHelper::CancelActiveAndPendingDialogs( |
| 83 content::WebContents* web_contents) { |
| 84 // Cancel any app-modal dialogs that may be going. |
| 85 AppModalDialogManager()->CancelActiveAndPendingDialogs(web_contents); |
| 86 |
| 87 // More work here for the auto-dismissing dialogs. |
| 88 } |
| 89 |
| 90 void JavaScriptDialogTabHelper::ResetDialogState( |
| 91 content::WebContents* web_contents) { |
| 92 // Reset any app-modal dialog state that may exist. |
| 93 if (!IsEnabled()) |
| 94 return AppModalDialogManager()->ResetDialogState(web_contents); |
| 95 |
| 96 // More work here for the auto-dismissing dialogs. |
| 97 } |
OLD | NEW |