oshima | 758abebc | 2014-11-06 10:55:50 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | |
oshima | f6539842 | 2014-11-18 23:30:42 | [diff] [blame] | 5 | #ifndef COMPONENTS_APP_MODAL_JAVASCRIPT_DIALOG_MANAGER_H_ |
| 6 | #define COMPONENTS_APP_MODAL_JAVASCRIPT_DIALOG_MANAGER_H_ |
oshima | 758abebc | 2014-11-06 10:55:50 | [diff] [blame] | 7 | |
| 8 | #include "base/memory/scoped_ptr.h" |
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 9 | #include "base/memory/singleton.h" |
| 10 | #include "components/app_modal/javascript_app_modal_dialog.h" |
| 11 | #include "content/public/browser/javascript_dialog_manager.h" |
oshima | 758abebc | 2014-11-06 10:55:50 | [diff] [blame] | 12 | |
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 13 | namespace app_modal { |
oshima | 758abebc | 2014-11-06 10:55:50 | [diff] [blame] | 14 | |
| 15 | class JavaScriptDialogExtensionsClient; |
| 16 | class JavaScriptNativeDialogFactory; |
| 17 | |
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 18 | class JavaScriptDialogManager : public content::JavaScriptDialogManager { |
| 19 | public: |
| 20 | static JavaScriptDialogManager* GetInstance(); |
oshima | 758abebc | 2014-11-06 10:55:50 | [diff] [blame] | 21 | |
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 22 | JavaScriptNativeDialogFactory* native_dialog_factory() { |
| 23 | return native_dialog_factory_.get(); |
| 24 | } |
oshima | 758abebc | 2014-11-06 10:55:50 | [diff] [blame] | 25 | |
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 26 | // Sets the JavaScriptNativeDialogFactory used to create platform specific |
| 27 | // dialog window instances. |
| 28 | void SetNativeDialogFactory( |
| 29 | scoped_ptr<JavaScriptNativeDialogFactory> factory); |
| 30 | |
| 31 | // JavaScript dialogs may be opened by an extensions/app, thus they need |
| 32 | // access to extensions functionality. This sets a client interface to |
| 33 | // access //extensions. |
| 34 | void SetExtensionsClient( |
| 35 | scoped_ptr<JavaScriptDialogExtensionsClient> extensions_client); |
| 36 | |
| 37 | private: |
| 38 | friend struct DefaultSingletonTraits<JavaScriptDialogManager>; |
| 39 | |
| 40 | JavaScriptDialogManager(); |
| 41 | ~JavaScriptDialogManager() override; |
| 42 | |
| 43 | // JavaScriptDialogManager: |
| 44 | void RunJavaScriptDialog(content::WebContents* web_contents, |
| 45 | const GURL& origin_url, |
| 46 | const std::string& accept_lang, |
| 47 | content::JavaScriptMessageType message_type, |
| 48 | const base::string16& message_text, |
| 49 | const base::string16& default_prompt_text, |
| 50 | const DialogClosedCallback& callback, |
| 51 | bool* did_suppress_message) override; |
| 52 | void RunBeforeUnloadDialog(content::WebContents* web_contents, |
| 53 | const base::string16& message_text, |
| 54 | bool is_reload, |
| 55 | const DialogClosedCallback& callback) override; |
| 56 | bool HandleJavaScriptDialog(content::WebContents* web_contents, |
| 57 | bool accept, |
| 58 | const base::string16* prompt_override) override; |
| 59 | void CancelActiveAndPendingDialogs( |
| 60 | content::WebContents* web_contents) override; |
| 61 | void WebContentsDestroyed(content::WebContents* web_contents) override; |
| 62 | |
| 63 | base::string16 GetTitle(content::WebContents* web_contents, |
| 64 | const GURL& origin_url, |
| 65 | const std::string& accept_lang, |
| 66 | bool is_alert); |
| 67 | |
| 68 | // Wrapper around a DialogClosedCallback so that we can intercept it before |
| 69 | // passing it onto the original callback. |
| 70 | void OnDialogClosed(content::WebContents* web_contents, |
| 71 | DialogClosedCallback callback, |
| 72 | bool success, |
| 73 | const base::string16& user_input); |
| 74 | |
| 75 | // Mapping between the WebContents and their extra data. The key |
| 76 | // is a void* because the pointer is just a cookie and is never dereferenced. |
| 77 | JavaScriptAppModalDialog::ExtraDataMap javascript_dialog_extra_data_; |
| 78 | |
| 79 | scoped_ptr<JavaScriptNativeDialogFactory> native_dialog_factory_; |
| 80 | scoped_ptr<JavaScriptDialogExtensionsClient> extensions_client_; |
| 81 | |
| 82 | DISALLOW_COPY_AND_ASSIGN(JavaScriptDialogManager); |
| 83 | }; |
| 84 | |
| 85 | } // namespace app_modal |
oshima | 758abebc | 2014-11-06 10:55:50 | [diff] [blame] | 86 | |
oshima | f6539842 | 2014-11-18 23:30:42 | [diff] [blame] | 87 | #endif // COMPONENTS_APP_MODAL_JAVASCRIPT_DIALOG_MANAGER_H_ |