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

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: Change #if false to #if 0 for win compiler. 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 base::WeakPtr<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 void ExtensionGlobalError::set_accept_callback(
39 ExtensionGlobalErrorCallback callback) {
40 accept_callback_ = callback;
41 }
42
43 void ExtensionGlobalError::set_cancel_callback(
44 ExtensionGlobalErrorCallback callback) {
45 cancel_callback_ = callback;
46 }
47
48 void ExtensionGlobalError::set_closed_callback(
49 ExtensionGlobalErrorCallback callback) {
50 cancel_callback_ = callback;
51 }
52
53 bool ExtensionGlobalError::HasBadge() {
54 return false;
55 }
56
57 bool ExtensionGlobalError::HasMenuItem() {
58 return false;
59 }
60
61 int ExtensionGlobalError::MenuItemCommandID() {
62 NOTREACHED();
63 return 0;
64 }
65
66 string16 ExtensionGlobalError::MenuItemLabel() {
67 NOTREACHED();
68 return NULL;
69 }
70
71 void ExtensionGlobalError::ExecuteMenuItem(Browser* browser) {
72 NOTREACHED();
73 }
74
75 bool ExtensionGlobalError::HasBubbleView() {
76 return true;
77 }
78
79 string16 ExtensionGlobalError::GetBubbleViewTitle() {
80 return l10n_util::GetStringUTF16(IDS_EXTENSION_NOTIFICATION_TITLE);
81 }
82
83 string16 ExtensionGlobalError::GenerateMessageSection(
84 const ExtensionIdSet* extensions,
85 int template_message_id) {
86 CHECK(extensions);
87 CHECK(template_message_id);
88 string16 message;
89
90 for (ExtensionIdSet::const_iterator iter = extensions->begin();
91 iter != extensions->end(); ++iter) {
92 const Extension* e = extension_service_->GetExtensionById(*iter, true);
93 message += l10n_util::GetStringFUTF16(template_message_id,
94 string16(ASCIIToUTF16(e->name())));
95 }
96 return message;
97 }
98
99 string16 ExtensionGlobalError::GenerateMessage() {
100 if (extension_service_.get()) {
101 return l10n_util::GetStringFUTF16(
102 IDS_EXTENSION_NOTIFICATION_BODY_TEMPLATE,
103 GenerateMessageSection(external_extension_ids_.get(),
104 IDS_EXTENSION_NOTIFICATION_ITEM_EXTERNAL) +
105 GenerateMessageSection(blacklisted_extension_ids_.get(),
106 IDS_EXTENSION_NOTIFICATION_ITEM_EXTERNAL) +
107 GenerateMessageSection(orphaned_extension_ids_.get(),
108 IDS_EXTENSION_NOTIFICATION_ITEM_EXTERNAL));
109 } else {
110 return string16();
111 }
112 }
113
114 string16 ExtensionGlobalError::GetBubbleViewMessage() {
115 if (message_.empty()) {
116 message_ = GenerateMessage();
117 }
118 return message_;
119 }
120
121 string16 ExtensionGlobalError::GetBubbleViewAcceptButtonLabel() {
122 return l10n_util::GetStringUTF16(IDS_EXTENSION_NOTIFICATION_ITEM_OK);
123 }
124
125 string16 ExtensionGlobalError::GetBubbleViewCancelButtonLabel() {
126 return l10n_util::GetStringUTF16(IDS_EXTENSION_NOTIFICATION_ITEM_DETAILS);
127 }
128
129 void ExtensionGlobalError::BubbleViewDidClose() {
130 if (!closed_callback_.is_null()) {
131 closed_callback_.Run(*this);
132 }
133 }
134
135 void ExtensionGlobalError::BubbleViewAcceptButtonPressed() {
136 if (!accept_callback_.is_null()) {
137 accept_callback_.Run(*this);
138 }
139 }
140
141 void ExtensionGlobalError::BubbleViewCancelButtonPressed() {
142 if (!cancel_callback_.is_null()) {
143 cancel_callback_.Run(*this);
144 }
145 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_global_error.h ('k') | chrome/browser/extensions/extension_prefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698