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

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

Issue 165414: Disable an extension when it is upgraded to a version that requires more (Closed)
Patch Set: more comments Created 11 years, 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2009 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_disabled_infobar_delegate.h"
6
7 #include "app/l10n_util.h"
8 #include "chrome/browser/extensions/extensions_service.h"
9 #include "chrome/browser/tab_contents/infobar_delegate.h"
10 #include "chrome/browser/tab_contents/tab_contents.h"
11 #include "chrome/browser/browser_list.h"
12 #include "chrome/common/notification_registrar.h"
13 #include "chrome/common/notification_service.h"
14 #include "grit/generated_resources.h"
15
16 class ExtensionDisabledInfobarDelegate
17 : public ConfirmInfoBarDelegate,
18 public NotificationObserver {
19 public:
20 ExtensionDisabledInfobarDelegate(TabContents* tab_contents,
21 ExtensionsService* service,
22 const std::string& extension_id,
23 const std::string& extension_name)
24 : ConfirmInfoBarDelegate(tab_contents),
25 tab_contents_(tab_contents),
26 service_(service),
27 extension_id_(extension_id),
28 extension_name_(extension_name) {
29 // The user might re-enable the extension in other ways, so watch for that.
30 registrar_.Add(this, NotificationType::EXTENSIONS_LOADED,
31 Source<ExtensionsService>(service));
32 }
33 virtual void InfoBarClosed() {
34 delete this;
35 }
36 virtual std::wstring GetMessageText() const {
37 return l10n_util::GetStringF(IDS_EXTENSION_DISABLED_INFOBAR_LABEL,
38 UTF8ToWide(extension_name_));
39 }
40 virtual SkBitmap* GetIcon() const {
41 return NULL;
42 }
43 virtual int GetButtons() const {
44 return BUTTON_OK;
45 }
46 virtual std::wstring GetButtonLabel(
47 ConfirmInfoBarDelegate::InfoBarButton button) const {
48 return l10n_util::GetString(IDS_EXTENSION_DISABLED_INFOBAR_ENABLE_BUTTON);
49 }
50 virtual bool Accept() {
51 service_->EnableExtension(extension_id_);
52 return true;
53 }
54
55 virtual void Observe(NotificationType type,
56 const NotificationSource& source,
57 const NotificationDetails& details) {
58 DCHECK(type == NotificationType::EXTENSIONS_LOADED);
59 ExtensionList* extensions = Details<ExtensionList>(details).ptr();
60
61 for (ExtensionList::iterator iter = extensions->begin();
62 iter != extensions->end(); ++iter) {
63 if ((*iter)->id() == extension_id_) {
64 // TODO(mpcomplete): This doesn't seem to always result in us getting
65 // deleted.
66 tab_contents_->RemoveInfoBar(this);
67 return;
68 }
69 }
70 }
71
72 private:
73 NotificationRegistrar registrar_;
74 TabContents* tab_contents_;
75 ExtensionsService* service_;
76 std::string extension_id_;
77 std::string extension_name_;
78 };
79
80 void ShowExtensionDisabledUI(ExtensionsService* service, Profile* profile,
81 Extension* extension) {
82 Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
83 if (!browser)
84 return;
85
86 TabContents* tab_contents = browser->GetSelectedTabContents();
87 if (!tab_contents)
88 return;
89
90 tab_contents->AddInfoBar(new ExtensionDisabledInfobarDelegate(
91 tab_contents, service, extension->id(), extension->name()));
92 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_disabled_infobar_delegate.h ('k') | chrome/browser/extensions/extension_prefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698