summaryrefslogtreecommitdiffstats
path: root/content/browser/javascript_dialogs.h
blob: cc17a714a747b29bd86f69b316c83ade67ff6f1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_JAVASCRIPT_DIALOG_DELEGATE_H_
#define CONTENT_BROWSER_JAVASCRIPT_DIALOG_DELEGATE_H_
#pragma once

#include "base/string16.h"
#include "ui/gfx/native_widget_types.h"

class GURL;
class TabContents;

namespace IPC {
class Message;
}

namespace content {

class DialogDelegate {
 public:
  // Returns the root native window with which to associate the dialog.
  virtual gfx::NativeWindow GetDialogRootWindow() = 0;

  // Called right before the dialog is shown.
  virtual void OnDialogShown() {}

 protected:
  virtual ~DialogDelegate() {}
};

// A class that invokes a JavaScript dialog must implement this interface to
// allow the dialog implementation to get needed information and return results.
class JavaScriptDialogDelegate : public DialogDelegate {
 public:
  // This callback is invoked when the dialog is closed.
  virtual void OnDialogClosed(IPC::Message* reply_msg,
                              bool success,
                              const string16& user_input) = 0;

 protected:
  virtual ~JavaScriptDialogDelegate() {}
};

// An interface consisting of methods that can be called to produce JavaScript
// dialogs.
class JavaScriptDialogCreator {
 public:
  enum TitleType {
    DIALOG_TITLE_NONE,
    DIALOG_TITLE_PLAIN_STRING,
    DIALOG_TITLE_FORMATTED_URL
  };

  // Displays a JavaScript dialog. |did_suppress_message| will not be nil; if
  // |true| is returned in it, the caller will handle faking the reply.
  virtual void RunJavaScriptDialog(JavaScriptDialogDelegate* delegate,
                                   TitleType title_type,
                                   const string16& title,
                                   int dialog_flags,
                                   const string16& message_text,
                                   const string16& default_prompt_text,
                                   IPC::Message* reply_message,
                                   bool* did_suppress_message) = 0;

  // Displays a dialog asking the user if they want to leave a page.
  virtual void RunBeforeUnloadDialog(JavaScriptDialogDelegate* delegate,
                                     const string16& message_text,
                                     IPC::Message* reply_message) = 0;

  // Cancels all pending dialogs and resets any saved JavaScript dialog state
  // for the delegate.
  virtual void ResetJavaScriptState(JavaScriptDialogDelegate* delegate) = 0;

 protected:
  virtual ~JavaScriptDialogCreator() {}
};

}  // namespace content

#endif  // CONTENT_BROWSER_JAVASCRIPT_DIALOG_DELEGATE_H_