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

Side by Side 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 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 #ifndef CHROME_BROWSER_UI_JAVASCRIPT_DIALOGS_JAVASCRIPT_DIALOG_TAB_HELPER_H_ 5 #ifndef CHROME_BROWSER_UI_JAVASCRIPT_DIALOGS_JAVASCRIPT_DIALOG_TAB_HELPER_H_
6 #define CHROME_BROWSER_UI_JAVASCRIPT_DIALOGS_JAVASCRIPT_DIALOG_TAB_HELPER_H_ 6 #define CHROME_BROWSER_UI_JAVASCRIPT_DIALOGS_JAVASCRIPT_DIALOG_TAB_HELPER_H_
7 7
8 #include <memory>
9
8 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/ui/browser_list_observer.h"
9 #include "content/public/browser/javascript_dialog_manager.h" 13 #include "content/public/browser/javascript_dialog_manager.h"
10 #include "content/public/browser/web_contents_observer.h" 14 #include "content/public/browser/web_contents_observer.h"
11 #include "content/public/browser/web_contents_user_data.h" 15 #include "content/public/browser/web_contents_user_data.h"
12 16
17 class JavaScriptDialogViews;
18
19 // A class, attached to WebContentses in browser windows, that is the
20 // JavaScriptDialogManager for them and handles displaying their dialogs.
21 //
22 // This is the primary mechanism for implementing auto-dismissing dialogs,
23 // 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.
24 // are synchronous and block arbitrary sets of renderers, they cannot be made
25 // tab-modal. Therefore the next best option is to make them auto-closing, so
26 // that they never block the user's access to other renderers.
27 //
28 // See http://bit.ly/project-oldspice for more details. Note that only part
29 // one of that design is implemented.
13 class JavaScriptDialogTabHelper 30 class JavaScriptDialogTabHelper
14 : public content::WebContentsObserver, 31 : public content::JavaScriptDialogManager,
15 public content::JavaScriptDialogManager, 32 public content::WebContentsObserver,
33 public chrome::BrowserListObserver,
16 public content::WebContentsUserData<JavaScriptDialogTabHelper> { 34 public content::WebContentsUserData<JavaScriptDialogTabHelper> {
17 public: 35 public:
18 explicit JavaScriptDialogTabHelper(content::WebContents* web_contents); 36 explicit JavaScriptDialogTabHelper(content::WebContents* web_contents);
19 ~JavaScriptDialogTabHelper() override; 37 ~JavaScriptDialogTabHelper() override;
20 38
21 // JavaScriptDialogManager: 39 // JavaScriptDialogManager:
22 void RunJavaScriptDialog(content::WebContents* web_contents, 40 void RunJavaScriptDialog(content::WebContents* web_contents,
23 const GURL& origin_url, 41 const GURL& origin_url,
24 content::JavaScriptMessageType message_type, 42 content::JavaScriptMessageType message_type,
25 const base::string16& message_text, 43 const base::string16& message_text,
26 const base::string16& default_prompt_text, 44 const base::string16& default_prompt_text,
27 const DialogClosedCallback& callback, 45 const DialogClosedCallback& callback,
28 bool* did_suppress_message) override; 46 bool* did_suppress_message) override;
29 void RunBeforeUnloadDialog(content::WebContents* web_contents, 47 void RunBeforeUnloadDialog(content::WebContents* web_contents,
30 bool is_reload, 48 bool is_reload,
31 const DialogClosedCallback& callback) override; 49 const DialogClosedCallback& callback) override;
32 bool HandleJavaScriptDialog(content::WebContents* web_contents, 50 bool HandleJavaScriptDialog(content::WebContents* web_contents,
33 bool accept, 51 bool accept,
34 const base::string16* prompt_override) override; 52 const base::string16* prompt_override) override;
35 void CancelDialogs(content::WebContents* web_contents, 53 void CancelDialogs(content::WebContents* web_contents,
36 bool suppress_callbacks, 54 bool suppress_callbacks,
37 bool reset_state) override; 55 bool reset_state) override;
38 void WebContentsDestroyed() override; 56
57 // WebContentsObserver:
58 void WasHidden() override;
59
60 // BrowserListObserver:
61 void OnBrowserSetLastActive(Browser* browser) override;
39 62
40 private: 63 private:
41 friend class content::WebContentsUserData<JavaScriptDialogTabHelper>; 64 friend class content::WebContentsUserData<JavaScriptDialogTabHelper>;
42 65
66 void CloseDialog(bool suppress_callback,
67 bool success,
68 const base::string16& user_input);
69
70 // The dialog being displayed on the observed WebContents.
71 base::WeakPtr<JavaScriptDialogViews> dialog_;
72
73 // The callback provided for when the dialog is closed. Usually the dialog
74 // itself calls it, but in the cases where the dialog is closed not by the
75 // user's input but by a call to |CloseDialog|, this class will call it.
76 content::JavaScriptDialogManager::DialogClosedCallback dialog_callback_;
77
43 DISALLOW_COPY_AND_ASSIGN(JavaScriptDialogTabHelper); 78 DISALLOW_COPY_AND_ASSIGN(JavaScriptDialogTabHelper);
44 }; 79 };
45 80
46 #endif // CHROME_BROWSER_UI_JAVASCRIPT_DIALOGS_JAVASCRIPT_DIALOG_TAB_HELPER_H_ 81 #endif // CHROME_BROWSER_UI_JAVASCRIPT_DIALOGS_JAVASCRIPT_DIALOG_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698