OLD | NEW |
---|---|
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. | |
Peter Kasting
2016/10/18 04:31:03
Nit: Might be nice to expand this some to talk abo
Avi (use Gerrit)
2016/10/18 16:31:49
Done.
| |
13 class JavaScriptDialogTabHelper | 21 class JavaScriptDialogTabHelper |
14 : public content::WebContentsObserver, | 22 : public content::JavaScriptDialogManager, |
15 public content::JavaScriptDialogManager, | 23 public content::WebContentsObserver, |
24 public chrome::BrowserListObserver, | |
16 public content::WebContentsUserData<JavaScriptDialogTabHelper> { | 25 public content::WebContentsUserData<JavaScriptDialogTabHelper> { |
17 public: | 26 public: |
18 explicit JavaScriptDialogTabHelper(content::WebContents* web_contents); | 27 explicit JavaScriptDialogTabHelper(content::WebContents* web_contents); |
19 ~JavaScriptDialogTabHelper() override; | 28 ~JavaScriptDialogTabHelper() override; |
20 | 29 |
21 // JavaScriptDialogManager: | 30 // JavaScriptDialogManager: |
22 void RunJavaScriptDialog(content::WebContents* web_contents, | 31 void RunJavaScriptDialog(content::WebContents* web_contents, |
23 const GURL& origin_url, | 32 const GURL& origin_url, |
24 content::JavaScriptMessageType message_type, | 33 content::JavaScriptMessageType message_type, |
25 const base::string16& message_text, | 34 const base::string16& message_text, |
26 const base::string16& default_prompt_text, | 35 const base::string16& default_prompt_text, |
27 const DialogClosedCallback& callback, | 36 const DialogClosedCallback& callback, |
28 bool* did_suppress_message) override; | 37 bool* did_suppress_message) override; |
29 void RunBeforeUnloadDialog(content::WebContents* web_contents, | 38 void RunBeforeUnloadDialog(content::WebContents* web_contents, |
30 bool is_reload, | 39 bool is_reload, |
31 const DialogClosedCallback& callback) override; | 40 const DialogClosedCallback& callback) override; |
32 bool HandleJavaScriptDialog(content::WebContents* web_contents, | 41 bool HandleJavaScriptDialog(content::WebContents* web_contents, |
33 bool accept, | 42 bool accept, |
34 const base::string16* prompt_override) override; | 43 const base::string16* prompt_override) override; |
35 void CancelDialogs(content::WebContents* web_contents, | 44 void CancelDialogs(content::WebContents* web_contents, |
36 bool suppress_callbacks, | 45 bool suppress_callbacks, |
37 bool reset_state) override; | 46 bool reset_state) override; |
38 void WebContentsDestroyed() override; | 47 |
48 // WebContentsObserver: | |
49 void WasHidden() override; | |
50 | |
51 // BrowserListObserver: | |
52 void OnBrowserSetLastActive(Browser* browser) override; | |
39 | 53 |
40 private: | 54 private: |
41 friend class content::WebContentsUserData<JavaScriptDialogTabHelper>; | 55 friend class content::WebContentsUserData<JavaScriptDialogTabHelper>; |
42 | 56 |
57 void CloseDialog(bool suppress_callback, | |
58 bool success, | |
59 const base::string16& user_input); | |
60 | |
61 // The dialog being displayed on the observed WebContents. | |
62 base::WeakPtr<JavaScriptDialogViews> dialog_; | |
63 | |
64 // The callback provided for when the dialog is closed. Usually the dialog | |
65 // itself calls it, but in the cases where the dialog is closed not by the | |
66 // user's input but by a call to |CloseDialog()|, this class will call it. | |
Peter Kasting
2016/10/18 04:31:03
Nit: No || on function names (the () is the marker
Avi (use Gerrit)
2016/10/18 16:31:49
Done.
Peter Kasting
2016/10/18 16:59:55
Oh, I was suggesting removing the || rather than r
| |
67 content::JavaScriptDialogManager::DialogClosedCallback dialog_callback_; | |
68 | |
43 DISALLOW_COPY_AND_ASSIGN(JavaScriptDialogTabHelper); | 69 DISALLOW_COPY_AND_ASSIGN(JavaScriptDialogTabHelper); |
44 }; | 70 }; |
45 | 71 |
46 #endif // CHROME_BROWSER_UI_JAVASCRIPT_DIALOGS_JAVASCRIPT_DIALOG_TAB_HELPER_H_ | 72 #endif // CHROME_BROWSER_UI_JAVASCRIPT_DIALOGS_JAVASCRIPT_DIALOG_TAB_HELPER_H_ |
OLD | NEW |