blob: e58e00de741d07fa327d4454c9805013b60f5830 (
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
// Copyright (c) 2012 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 CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_
#define CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/strings/string16.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/base/window_open_disposition.h"
namespace content {
class WebContents;
}
namespace gfx {
class Image;
}
class TabModalConfirmDialogCloseDelegate {
public:
TabModalConfirmDialogCloseDelegate() {}
virtual ~TabModalConfirmDialogCloseDelegate() {}
virtual void CloseDialog() = 0;
private:
DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogCloseDelegate);
};
// This class acts as the delegate for a simple tab-modal dialog confirming
// whether the user wants to execute a certain action.
class TabModalConfirmDialogDelegate : public content::NotificationObserver {
public:
explicit TabModalConfirmDialogDelegate(content::WebContents* web_contents);
virtual ~TabModalConfirmDialogDelegate();
void set_close_delegate(TabModalConfirmDialogCloseDelegate* close_delegate) {
close_delegate_ = close_delegate;
}
// Accepts the confirmation prompt and calls |OnAccepted|.
// This method is safe to call even from an |OnAccepted| or |OnCanceled|
// callback.
void Accept();
// Cancels the confirmation prompt and calls |OnCanceled|.
// This method is safe to call even from an |OnAccepted| or |OnCanceled|
// callback.
void Cancel();
// Called when the link (if any) is clicked. Calls |OnLinkClicked| and closes
// the dialog. The |disposition| specifies how the resulting document should
// be loaded (based on the event flags present when the link was clicked).
void LinkClicked(WindowOpenDisposition disposition);
// The title of the dialog. Note that the title is not shown on all platforms.
virtual string16 GetTitle() = 0;
virtual string16 GetMessage() = 0;
// Icon to show for the dialog. If this method is not overridden, a default
// icon (like the application icon) is shown.
virtual gfx::Image* GetIcon();
// Title for the accept and the cancel buttons.
// The default implementation uses IDS_OK and IDS_CANCEL.
virtual string16 GetAcceptButtonTitle();
virtual string16 GetCancelButtonTitle();
// Returns the text of the link to be displayed, if any. Otherwise returns
// an empty string.
virtual string16 GetLinkText() const;
// GTK stock icon names for the accept and cancel buttons, respectively.
// The icons are only used on GTK. If these methods are not overriden,
// the buttons have no stock icons.
virtual const char* GetAcceptButtonIcon();
virtual const char* GetCancelButtonIcon();
protected:
TabModalConfirmDialogCloseDelegate* close_delegate() {
return close_delegate_;
}
// content::NotificationObserver implementation.
// Watch for a new load or a closed tab and dismiss the dialog if they occur.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
content::NotificationRegistrar registrar_;
private:
// It is guaranteed that exactly one of |OnAccepted|, |OnCanceled| or
// |OnLinkClicked| is eventually called. These method are private to
// enforce this guarantee. Access to them is controlled by |Accept|,
// |Cancel| and |LinkClicked|.
// Called when the user accepts or cancels the dialog, respectively.
virtual void OnAccepted();
virtual void OnCanceled();
// Called when the user clicks on the link (if any).
virtual void OnLinkClicked(WindowOpenDisposition disposition);
// Close the dialog.
void CloseDialog();
TabModalConfirmDialogCloseDelegate* close_delegate_;
// True iff we are in the process of closing, to avoid running callbacks
// multiple times.
bool closing_;
DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogDelegate);
};
#endif // CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_
|