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

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

Issue 2421943002: Make JavaScript dialogs auto-dismiss on tab switch. (Closed)
Patch Set: more commentary, nits Created 4 years, 2 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.h
diff --git a/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h b/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h
index 4a75f5bf94b4255cfe471d4263f7c1ec2d95d3ba..94b77e89e0f52a21c18097e0d3c8588e83589368 100644
--- a/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h
+++ b/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h
@@ -5,14 +5,32 @@
#ifndef CHROME_BROWSER_UI_JAVASCRIPT_DIALOGS_JAVASCRIPT_DIALOG_TAB_HELPER_H_
#define CHROME_BROWSER_UI_JAVASCRIPT_DIALOGS_JAVASCRIPT_DIALOG_TAB_HELPER_H_
+#include <memory>
+
#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "content/public/browser/javascript_dialog_manager.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
+class JavaScriptDialogViews;
+
+// A class, attached to WebContentses in browser windows, that is the
+// JavaScriptDialogManager for them and handles displaying their dialogs.
+//
+// This is the primary mechanism for implementing auto-dismissing dialogs,
+// dialogs that close when the user switches away. Because JavaScript dialogs
Peter Kasting 2016/10/18 16:59:55 Nit: away -> to another tab?
Avi (use Gerrit) 2016/10/18 17:06:07 Done.
+// are synchronous and block arbitrary sets of renderers, they cannot be made
+// tab-modal. Therefore the next best option is to make them auto-closing, so
+// that they never block the user's access to other renderers.
+//
+// See http://bit.ly/project-oldspice for more details. Note that only part
+// one of that design is implemented.
class JavaScriptDialogTabHelper
- : public content::WebContentsObserver,
- public content::JavaScriptDialogManager,
+ : public content::JavaScriptDialogManager,
+ public content::WebContentsObserver,
+ public chrome::BrowserListObserver,
public content::WebContentsUserData<JavaScriptDialogTabHelper> {
public:
explicit JavaScriptDialogTabHelper(content::WebContents* web_contents);
@@ -35,11 +53,28 @@ class JavaScriptDialogTabHelper
void CancelDialogs(content::WebContents* web_contents,
bool suppress_callbacks,
bool reset_state) override;
- void WebContentsDestroyed() override;
+
+ // WebContentsObserver:
+ void WasHidden() override;
+
+ // BrowserListObserver:
+ void OnBrowserSetLastActive(Browser* browser) override;
private:
friend class content::WebContentsUserData<JavaScriptDialogTabHelper>;
+ void CloseDialog(bool suppress_callback,
+ bool success,
+ const base::string16& user_input);
+
+ // The dialog being displayed on the observed WebContents.
+ base::WeakPtr<JavaScriptDialogViews> dialog_;
+
+ // The callback provided for when the dialog is closed. Usually the dialog
+ // itself calls it, but in the cases where the dialog is closed not by the
+ // user's input but by a call to |CloseDialog|, this class will call it.
+ content::JavaScriptDialogManager::DialogClosedCallback dialog_callback_;
+
DISALLOW_COPY_AND_ASSIGN(JavaScriptDialogTabHelper);
};

Powered by Google App Engine
This is Rietveld 408576698