blob: 77301256effbe82caffd9526d7581e1ba37922e3 (
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
|
// 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_GLOBAL_ERROR_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_GLOBAL_ERROR_H_
#pragma once
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/global_error.h"
#include "chrome/common/extensions/extension.h"
class Browser;
class ExtensionService;
// This class encapsulates the UI we want to show users when certain events
// occur related to installed extensions.
class ExtensionGlobalError : public GlobalError {
public:
explicit ExtensionGlobalError(
base::WeakPtr<ExtensionService> extension_service);
virtual ~ExtensionGlobalError();
// Indicate whether this instance should manage its own lifetime. Because
// the GlobalError class can be used in several different ways, it's
// important to understand who has responsibility for memory management.
//
// Briefly: if the GlobalError has a menu item, or if it's added to the
// GlobalErrorService queue, then it's externally managed. If your code
// calls ShowBubbleView(), then you manage it.
//
// The default value is true; in case the default is wrong, we prefer to
// crash during development than to leak in production (fail fast).
//
// TODO(sail): This could be handled automatically with a few changes to the
// GlobalError interface.
void set_should_delete_self_on_close(bool value) {
should_delete_self_on_close_ = value;
}
// Inform us that a given extension is of a certain type that the user
// hasn't yet acknowledged.
void AddExternalExtension(const std::string& id);
void AddBlacklistedExtension(const std::string& id);
void AddOrphanedExtension(const std::string& id);
// Returns sets replaying the IDs that have been added with the
// Add[...]Extension methods.
const ExtensionIdSet* get_external_extension_ids() const {
return external_extension_ids_.get();
}
const ExtensionIdSet* get_blacklisted_extension_ids() const {
return blacklisted_extension_ids_.get();
}
const ExtensionIdSet* get_orphaned_extension_ids() const {
return orphaned_extension_ids_.get();
}
typedef base::Callback<void(const ExtensionGlobalError&, Browser* browser)>
ExtensionGlobalErrorCallback;
// Called when the user presses the "Accept" button on the alert.
void set_accept_callback(ExtensionGlobalErrorCallback callback);
// Called when the user presses the "Cancel" button on the alert.
void set_cancel_callback(ExtensionGlobalErrorCallback callback);
// Called when the alert is dismissed with no direct user action
// (e.g., the browser exits).
void set_closed_callback(ExtensionGlobalErrorCallback callback);
// GlobalError methods.
virtual bool HasBadge() OVERRIDE;
virtual bool HasMenuItem() OVERRIDE;
virtual int MenuItemCommandID() OVERRIDE;
virtual string16 MenuItemLabel() OVERRIDE;
virtual void ExecuteMenuItem(Browser* browser) OVERRIDE;
virtual bool HasBubbleView() OVERRIDE;
virtual void ShowBubbleView(Browser* browser) OVERRIDE;
virtual string16 GetBubbleViewTitle() OVERRIDE;
virtual string16 GetBubbleViewMessage() OVERRIDE;
virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE;
virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE;
virtual void BubbleViewDidClose() OVERRIDE;
virtual void BubbleViewAcceptButtonPressed() OVERRIDE;
virtual void BubbleViewCancelButtonPressed() OVERRIDE;
private:
Browser* current_browser_; // The browser passed to ShowBubbleView().
bool should_delete_self_on_close_;
base::WeakPtr<ExtensionService> extension_service_;
scoped_ptr<ExtensionIdSet> external_extension_ids_;
scoped_ptr<ExtensionIdSet> blacklisted_extension_ids_;
scoped_ptr<ExtensionIdSet> orphaned_extension_ids_;
ExtensionGlobalErrorCallback accept_callback_;
ExtensionGlobalErrorCallback cancel_callback_;
ExtensionGlobalErrorCallback closed_callback_;
string16 message_; // Displayed in the body of the alert.
// For a given set of extension IDs, generates appropriate text
// describing what the user needs to know about them.
string16 GenerateMessageSection(const ExtensionIdSet* extensions,
int template_message_id);
// Generates the message displayed in the body of the alert.
string16 GenerateMessage();
DISALLOW_COPY_AND_ASSIGN(ExtensionGlobalError);
};
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GLOBAL_ERROR_H_
|