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

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

Issue 10696210: Making ExtensionService less dependent on Browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update based on discussion with Yoyo Created 8 years, 5 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_global_error.h" 5 #include "chrome/browser/extensions/extension_error_ui.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/ui/global_error/global_error.h" 11 #include "chrome/browser/ui/global_error/global_error.h"
12 #include "grit/chromium_strings.h" 12 #include "grit/chromium_strings.h"
13 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
15 15
16 using extensions::ExtensionIdSet; 16 using extensions::ExtensionIdSet;
17 17
18 ExtensionGlobalError::ExtensionGlobalError(ExtensionService* extension_service) 18 ExtensionErrorUI::ExtensionErrorUI(ExtensionService* extension_service)
19 : extension_service_(extension_service), 19 : extension_service_(extension_service),
20 external_extension_ids_(new ExtensionIdSet), 20 external_extension_ids_(new ExtensionIdSet),
21 blacklisted_extension_ids_(new ExtensionIdSet), 21 blacklisted_extension_ids_(new ExtensionIdSet),
22 orphaned_extension_ids_(new ExtensionIdSet) { 22 orphaned_extension_ids_(new ExtensionIdSet) {
23 DCHECK(extension_service_); 23 DCHECK(extension_service_);
24 } 24 }
25 25
26 ExtensionGlobalError::~ExtensionGlobalError() { 26 ExtensionErrorUI::~ExtensionErrorUI() {
27 } 27 }
28 28
29 void ExtensionGlobalError::AddExternalExtension(const std::string& id) { 29 void ExtensionErrorUI::AddExternalExtension(const std::string& id) {
30 external_extension_ids_->insert(id); 30 external_extension_ids_->insert(id);
31 } 31 }
32 32
33 void ExtensionGlobalError::AddBlacklistedExtension(const std::string& id) { 33 void ExtensionErrorUI::AddBlacklistedExtension(const std::string& id) {
34 blacklisted_extension_ids_->insert(id); 34 blacklisted_extension_ids_->insert(id);
35 } 35 }
36 36
37 void ExtensionGlobalError::AddOrphanedExtension(const std::string& id) { 37 void ExtensionErrorUI::AddOrphanedExtension(const std::string& id) {
38 orphaned_extension_ids_->insert(id); 38 orphaned_extension_ids_->insert(id);
39 } 39 }
40 40
41 bool ExtensionGlobalError::HasBadge() { 41 string16 ExtensionErrorUI::GenerateMessageSection(
42 return false;
43 }
44
45 bool ExtensionGlobalError::HasMenuItem() {
46 return false;
47 }
48
49 int ExtensionGlobalError::MenuItemCommandID() {
50 NOTREACHED();
51 return 0;
52 }
53
54 string16 ExtensionGlobalError::MenuItemLabel() {
55 NOTREACHED();
56 return NULL;
57 }
58
59 void ExtensionGlobalError::ExecuteMenuItem(Browser* browser) {
60 NOTREACHED();
61 }
62
63 bool ExtensionGlobalError::HasBubbleView() {
64 return true;
65 }
66
67 string16 ExtensionGlobalError::GetBubbleViewTitle() {
68 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_TITLE);
69 }
70
71 string16 ExtensionGlobalError::GenerateMessageSection(
72 const ExtensionIdSet* extensions, 42 const ExtensionIdSet* extensions,
73 int template_message_id) { 43 int template_message_id) {
74 CHECK(extensions); 44 CHECK(extensions);
75 CHECK(template_message_id); 45 CHECK(template_message_id);
76 string16 message; 46 string16 message;
77 47
78 for (ExtensionIdSet::const_iterator iter = extensions->begin(); 48 for (ExtensionIdSet::const_iterator iter = extensions->begin();
79 iter != extensions->end(); ++iter) { 49 iter != extensions->end(); ++iter) {
80 const extensions::Extension* e = extension_service_->GetExtensionById(*iter, 50 const extensions::Extension* e = extension_service_->GetExtensionById(*iter,
81 true); 51 true);
82 message += l10n_util::GetStringFUTF16(template_message_id, 52 message += l10n_util::GetStringFUTF16(template_message_id,
83 string16(ASCIIToUTF16(e->name()))); 53 string16(ASCIIToUTF16(e->name())));
84 } 54 }
85 return message; 55 return message;
86 } 56 }
87 57
88 string16 ExtensionGlobalError::GenerateMessage() { 58 string16 ExtensionErrorUI::GenerateMessage() {
89 return GenerateMessageSection(external_extension_ids_.get(), 59 return GenerateMessageSection(external_extension_ids_.get(),
90 IDS_EXTENSION_ALERT_ITEM_EXTERNAL) + 60 IDS_EXTENSION_ALERT_ITEM_EXTERNAL) +
91 GenerateMessageSection(blacklisted_extension_ids_.get(), 61 GenerateMessageSection(blacklisted_extension_ids_.get(),
92 IDS_EXTENSION_ALERT_ITEM_BLACKLISTED) + 62 IDS_EXTENSION_ALERT_ITEM_BLACKLISTED) +
93 GenerateMessageSection(orphaned_extension_ids_.get(), 63 GenerateMessageSection(orphaned_extension_ids_.get(),
94 IDS_EXTENSION_ALERT_ITEM_ORPHANED); 64 IDS_EXTENSION_ALERT_ITEM_ORPHANED);
95 } 65 }
96 66
97 string16 ExtensionGlobalError::GetBubbleViewMessage() { 67 string16 ExtensionErrorUI::GetBubbleViewMessage() {
98 if (message_.empty()) { 68 if (message_.empty()) {
99 message_ = GenerateMessage(); 69 message_ = GenerateMessage();
100 if (message_[message_.size()-1] == '\n') 70 if (message_[message_.size()-1] == '\n')
101 message_.resize(message_.size()-1); 71 message_.resize(message_.size()-1);
102 } 72 }
103 return message_; 73 return message_;
104 } 74 }
105 75
106 string16 ExtensionGlobalError::GetBubbleViewAcceptButtonLabel() { 76 string16 ExtensionErrorUI::GetBubbleViewTitle() {
77 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_TITLE);
78 }
79
80 string16 ExtensionErrorUI::GetBubbleViewAcceptButtonLabel() {
107 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_OK); 81 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_OK);
108 } 82 }
109 83
110 string16 ExtensionGlobalError::GetBubbleViewCancelButtonLabel() { 84 string16 ExtensionErrorUI::GetBubbleViewCancelButtonLabel() {
111 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_DETAILS); 85 return l10n_util::GetStringUTF16(IDS_EXTENSION_ALERT_ITEM_DETAILS);
112 } 86 }
113 87
114 void ExtensionGlobalError::OnBubbleViewDidClose(Browser* browser) { 88 void ExtensionErrorUI::BubbleViewDidClose() {
115 extension_service_->HandleExtensionAlertClosed(); 89 extension_service_->HandleExtensionAlertClosed();
116 } 90 }
117 91
118 void ExtensionGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { 92 void ExtensionErrorUI::BubbleViewAcceptButtonPressed() {
119 extension_service_->HandleExtensionAlertAccept(); 93 extension_service_->HandleExtensionAlertAccept();
120 } 94 }
121 95
122 void ExtensionGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { 96 void ExtensionErrorUI::BubbleViewCancelButtonPressed() {
123 extension_service_->HandleExtensionAlertDetails(browser); 97 extension_service_->HandleExtensionAlertDetails();
124 } 98 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_error_ui.h ('k') | chrome/browser/extensions/extension_error_ui_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698