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

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

Issue 95133002: Add an extension bubble explaining which extensions are in dev mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'ed Created 7 years 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) 2013 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/dev_mode_bubble_controller.h"
6
7 #include "base/bind.h"
8 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/extensions/extension_action_manager.h"
12 #include "chrome/browser/extensions/extension_message_bubble.h"
13 #include "chrome/browser/extensions/extension_prefs.h"
14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_finder.h"
17 #include "chrome/common/url_constants.h"
18 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/user_metrics.h"
20 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h"
22 #include "ui/base/l10n/l10n_util.h"
23
24 namespace {
25
26 static base::LazyInstance<extensions::ProfileKeyedAPIFactory<
27 extensions::DevModeBubbleController> >
28 g_factory = LAZY_INSTANCE_INITIALIZER;
29
30 } // namespace
31
32 namespace extensions {
33
34 ////////////////////////////////////////////////////////////////////////////////
35 // DevModeBubbleController
36
37 DevModeBubbleController::DevModeBubbleController(
38 Profile* profile)
39 : ExtensionMessageBubbleController(DEV_MODE_EXTENSIONS, profile) {
40 }
41
42 DevModeBubbleController::~DevModeBubbleController() {
43 }
44
45 // static
46 ProfileKeyedAPIFactory<DevModeBubbleController>*
47 DevModeBubbleController::GetFactoryInstance() {
48 return &g_factory.Get();
49 }
50
51 // static
52 DevModeBubbleController* DevModeBubbleController::Get(Profile* profile) {
53 return ProfileKeyedAPIFactory<
54 DevModeBubbleController>::GetForProfile(profile);
55 }
56
57 bool DevModeBubbleController::ShouldIncludeExtension(
58 const std::string& extension_id) {
59 const Extension* extension = service_->GetExtensionById(extension_id, false);
60 ExtensionPrefs* prefs = service_->extension_prefs();
61 if (!extension)
62 return false;
63 if (!extension->IsDevModeExtension())
64 return false;
65 return !prefs->HasDevModeBeenAcknowledged(extension_id);
66 }
67
68 void DevModeBubbleController::AcknowledgeExtension(
69 const std::string& extension_id) {
70 // Clicking Learn More closes the bubble without taking action. In that case
71 // we don't want to acknowledge the extension but instead show the bubble
72 // again on next startup. Also, since we want to show the bubble again when
73 // the extension gets disabled by the bubble and enabled by the user, we might
74 // as well skip the writing of the acknowledged flag here.
75 if (user_action_ == ACTION_LEARN_MORE || user_action_ == ACTION_EXECUTE)
76 return;
77
78 // User clicked cancel, that means we need to record that they don't want to
79 // be notified about this extension again.
80 ExtensionPrefs* prefs = service_->extension_prefs();
81 prefs->SetDevModeAcknowledged(extension_id, true);
82
83 // We'll need to let the browser action know that the state has been updated
84 // so the highlighting on the badge can be removed (if the extension has a
85 // browser action).
86 const Extension* extension = service_->GetExtensionById(extension_id, false);
87 if (!extension)
88 return;
89 ExtensionAction* action = ExtensionActionManager::Get(profile_)->
90 GetBrowserAction(*extension);
91 if (!action)
92 return;
93
94 content::NotificationService::current()->Notify(
95 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED,
96 content::Source<ExtensionAction>(action),
97 content::Details<Profile>(profile_));
98 }
99
100 void DevModeBubbleController::PerformAction() {
101 for (size_t i = 0; i < extension_list_.size(); ++i) {
102 service_->DisableExtension(
103 extension_list_[i], Extension::DISABLE_USER_ACTION);
104 }
105 }
106
107 template <>
108 void ProfileKeyedAPIFactory<
109 DevModeBubbleController>::DeclareFactoryDependencies() {
110 DependsOn(extensions::ExtensionSystemFactory::GetInstance());
111 }
112
113 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698