Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: chrome/browser/extensions/extension_global_error.cc

Issue 8202011: Notify users about certain changes in installed extensions. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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
5 #include "chrome/browser/extensions/extension_global_error.h"
6
7 #include "base/logging.h"
8 #include "base/string16.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/ui/global_error.h"
12 #include "grit/generated_resources.h"
13 #include "ui/base/l10n/l10n_util.h"
14
15 ExtensionGlobalError::ExtensionGlobalError(
16 ExtensionService* extension_service)
17 : extension_service_(extension_service),
18 external_extension_ids_(new ExtensionIdSet),
19 blacklisted_extension_ids_(new ExtensionIdSet),
20 orphaned_extension_ids_(new ExtensionIdSet) {
21 }
22
23 ExtensionGlobalError::~ExtensionGlobalError() {
24 }
25
26 void ExtensionGlobalError::AddExternalExtension(const std::string& id) {
27 external_extension_ids_->insert(id);
28 }
29
30 void ExtensionGlobalError::AddBlacklistedExtension(const std::string& id) {
31 blacklisted_extension_ids_->insert(id);
32 }
33
34 void ExtensionGlobalError::AddOrphanedExtension(const std::string& id) {
35 orphaned_extension_ids_->insert(id);
36 }
37
38 const ExtensionIdSet*
39 ExtensionGlobalError::get_external_extension_ids() const {
40 return external_extension_ids_.get();
41 }
42
43 const ExtensionIdSet*
44 ExtensionGlobalError::get_blacklisted_extension_ids() const {
45 return blacklisted_extension_ids_.get();
46 }
47
48 const ExtensionIdSet*
49 ExtensionGlobalError::get_orphaned_extension_ids() const {
50 return orphaned_extension_ids_.get();
51 }
asargent_no_longer_on_chrome 2011/10/07 21:25:34 Simple getters like the 3 above can be inlined in
52
53 void ExtensionGlobalError::set_accept_callback(
54 ExtensionGlobalErrorCallback callback) {
55 accept_callback_ = callback;
56 }
57
58 void ExtensionGlobalError::set_cancel_callback(
59 ExtensionGlobalErrorCallback callback) {
60 cancel_callback_ = callback;
61 }
62
63 void ExtensionGlobalError::set_closed_callback(
64 ExtensionGlobalErrorCallback callback) {
65 cancel_callback_ = callback;
66 }
67
68 bool ExtensionGlobalError::HasBadge() {
69 return false;
70 }
71
72 bool ExtensionGlobalError::HasMenuItem() {
73 return false;
74 }
75
76 int ExtensionGlobalError::MenuItemCommandID() {
77 NOTREACHED();
78 return 0;
79 }
80
81 string16 ExtensionGlobalError::MenuItemLabel() {
82 NOTREACHED();
83 return NULL;
84 }
85
86 void ExtensionGlobalError::ExecuteMenuItem(Browser* browser) {
87 NOTREACHED();
88 }
89
90 bool ExtensionGlobalError::HasBubbleView() {
91 return true;
92 }
93
94 string16 ExtensionGlobalError::GetBubbleViewTitle() {
95 return l10n_util::GetStringUTF16(IDS_EXTENSION_NOTIFICATION_TITLE);
96 }
97
98 string16 ExtensionGlobalError::GenerateMessageSection(
99 const ExtensionIdSet* extensions,
100 int template_message_id) {
101 DCHECK(extensions);
asargent_no_longer_on_chrome 2011/10/07 21:25:34 Might as well make this a CHECK instead of DCHECK,
102 DCHECK(template_message_id);
103 string16 message;
104
105 for (ExtensionIdSet::const_iterator iter = extensions->begin();
106 iter != extensions->end(); ++iter) {
107 const Extension* e = extension_service_->GetExtensionById(*iter, true);
108 message += l10n_util::GetStringFUTF16(template_message_id,
109 string16(ASCIIToUTF16(e->name())));
110 }
111 return message;
112 }
113
114 string16 ExtensionGlobalError::GenerateMessage() {
115 return l10n_util::GetStringFUTF16(
116 IDS_EXTENSION_NOTIFICATION_BODY_TEMPLATE,
117 GenerateMessageSection(external_extension_ids_.get(),
118 IDS_EXTENSION_NOTIFICATION_ITEM_EXTERNAL) +
119 GenerateMessageSection(blacklisted_extension_ids_.get(),
120 IDS_EXTENSION_NOTIFICATION_ITEM_EXTERNAL) +
121 GenerateMessageSection(orphaned_extension_ids_.get(),
122 IDS_EXTENSION_NOTIFICATION_ITEM_EXTERNAL));
123 }
124
125 string16 ExtensionGlobalError::GetBubbleViewMessage() {
126 if (message_.empty()) {
127 message_ = GenerateMessage();
128 }
129 return message_;
130 }
131
132 string16 ExtensionGlobalError::GetBubbleViewAcceptButtonLabel() {
133 return l10n_util::GetStringUTF16(IDS_EXTENSION_NOTIFICATION_ITEM_OK);
134 }
135
136 string16 ExtensionGlobalError::GetBubbleViewCancelButtonLabel() {
137 return l10n_util::GetStringUTF16(IDS_EXTENSION_NOTIFICATION_ITEM_DETAILS);
138 }
139
140 void ExtensionGlobalError::BubbleViewDidClose() {
141 if (!closed_callback_.is_null()) {
142 closed_callback_.Run(*this);
143 }
144 }
145
146 void ExtensionGlobalError::BubbleViewAcceptButtonPressed() {
147 if (!accept_callback_.is_null()) {
148 accept_callback_.Run(*this);
149 }
150 }
151
152 void ExtensionGlobalError::BubbleViewCancelButtonPressed() {
153 if (!cancel_callback_.is_null()) {
154 cancel_callback_.Run(*this);
155 }
156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698