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

Unified Diff: chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc

Issue 2179923002: Add a JavaScript dialog tab helper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc
diff --git a/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc b/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..86199c0a73b23835851d915851406c43bc56f667
--- /dev/null
+++ b/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc
@@ -0,0 +1,97 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h"
+
+#include "base/feature_list.h"
+#include "components/app_modal/javascript_dialog_manager.h"
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper);
+
+namespace {
+
+const base::Feature kAutoDismissingDialogsFeature{
+ "AutoDismissingDialogs", base::FEATURE_DISABLED_BY_DEFAULT};
+
+bool IsEnabled() {
+ return base::FeatureList::IsEnabled(kAutoDismissingDialogsFeature);
+}
+
+content::JavaScriptDialogManager* AppModalDialogManager() {
+ return app_modal::JavaScriptDialogManager::GetInstance();
+}
+
+} // namespace
+
+JavaScriptDialogTabHelper::JavaScriptDialogTabHelper(
+ content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents) {
+}
+
+JavaScriptDialogTabHelper::~JavaScriptDialogTabHelper() {
+}
+
+void JavaScriptDialogTabHelper::WebContentsDestroyed() {
+}
+
+void JavaScriptDialogTabHelper::RunJavaScriptDialog(
+ content::WebContents* web_contents,
+ const GURL& origin_url,
+ content::JavaScriptMessageType message_type,
+ const base::string16& message_text,
+ const base::string16& default_prompt_text,
+ const DialogClosedCallback& callback,
+ bool* did_suppress_message) {
+ if (!IsEnabled()) {
+ return AppModalDialogManager()->RunJavaScriptDialog(
+ web_contents, origin_url, message_type, message_text,
+ default_prompt_text, callback, did_suppress_message);
+ }
+
+ NOTREACHED() << "auto-dismissing dialog code does not yet exist";
+}
+
+void JavaScriptDialogTabHelper::RunBeforeUnloadDialog(
+ content::WebContents* web_contents,
+ bool is_reload,
+ const DialogClosedCallback& callback) {
+ // onbeforeunload dialogs are always handled with an app-modal dialog, because
+ // - they are critical to the user not losing data
+ // - they can be requested for tabs that are not foremost
+ // - they can be requested for many tabs at the same time
+ // and therefore auto-dismissal is inappropriate for them.
+
+ return AppModalDialogManager()->RunBeforeUnloadDialog(web_contents, is_reload,
+ callback);
+}
+
+bool JavaScriptDialogTabHelper::HandleJavaScriptDialog(
+ content::WebContents* web_contents,
+ bool accept,
+ const base::string16* prompt_override) {
+ if (!IsEnabled()) {
+ return AppModalDialogManager()->HandleJavaScriptDialog(web_contents, accept,
+ prompt_override);
+ }
+
+ NOTREACHED() << "auto-dismissing dialog code does not yet exist";
+ return false;
+}
+
+void JavaScriptDialogTabHelper::CancelActiveAndPendingDialogs(
+ content::WebContents* web_contents) {
+ // Cancel any app-modal dialogs that may be going.
+ AppModalDialogManager()->CancelActiveAndPendingDialogs(web_contents);
+
+ // More work here for the auto-dismissing dialogs.
+}
+
+void JavaScriptDialogTabHelper::ResetDialogState(
+ content::WebContents* web_contents) {
+ // Reset any app-modal dialog state that may exist.
+ if (!IsEnabled())
+ return AppModalDialogManager()->ResetDialogState(web_contents);
+
+ // More work here for the auto-dismissing dialogs.
+}
« no previous file with comments | « chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h ('k') | chrome/browser/ui/tab_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698