blob: 83720151b5ebbb1ee97f4bcc061c7e15492a8e84 [file] [log] [blame]
oshima758abebc2014-11-06 10:55:501// 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
oshimaf65398422014-11-18 23:30:425#ifndef COMPONENTS_APP_MODAL_JAVASCRIPT_DIALOG_MANAGER_H_
6#define COMPONENTS_APP_MODAL_JAVASCRIPT_DIALOG_MANAGER_H_
oshima758abebc2014-11-06 10:55:507
8#include "base/memory/scoped_ptr.h"
oshima0929be2a2014-11-19 22:21:039#include "base/memory/singleton.h"
10#include "components/app_modal/javascript_app_modal_dialog.h"
11#include "content/public/browser/javascript_dialog_manager.h"
oshima758abebc2014-11-06 10:55:5012
oshima0929be2a2014-11-19 22:21:0313namespace app_modal {
oshima758abebc2014-11-06 10:55:5014
15class JavaScriptDialogExtensionsClient;
16class JavaScriptNativeDialogFactory;
17
oshima0929be2a2014-11-19 22:21:0318class JavaScriptDialogManager : public content::JavaScriptDialogManager {
19 public:
20 static JavaScriptDialogManager* GetInstance();
oshima758abebc2014-11-06 10:55:5021
oshima0929be2a2014-11-19 22:21:0322 JavaScriptNativeDialogFactory* native_dialog_factory() {
23 return native_dialog_factory_.get();
24 }
oshima758abebc2014-11-06 10:55:5025
oshima0929be2a2014-11-19 22:21:0326 // 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
oshima758abebc2014-11-06 10:55:5086
oshimaf65398422014-11-18 23:30:4287#endif // COMPONENTS_APP_MODAL_JAVASCRIPT_DIALOG_MANAGER_H_