| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/dev_mode_bubble_controller.h" | 5 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
| 10 #include "chrome/browser/extensions/extension_message_bubble.h" | 10 #include "chrome/browser/extensions/extension_message_bubble.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_toolbar_model.h" | 12 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/common/chrome_version_info.h" | |
| 16 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 18 #include "extensions/browser/extension_prefs.h" | 17 #include "extensions/browser/extension_prefs.h" |
| 19 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
| 20 #include "extensions/common/feature_switch.h" | |
| 21 #include "grit/components_strings.h" | 19 #include "grit/components_strings.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 23 | 21 |
| 24 namespace extensions { | 22 namespace extensions { |
| 25 | 23 |
| 26 namespace { | 24 namespace { |
| 27 | 25 |
| 28 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles = | 26 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles = |
| 29 LAZY_INSTANCE_INITIALIZER; | 27 LAZY_INSTANCE_INITIALIZER; |
| 30 | 28 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 68 } |
| 71 | 69 |
| 72 DevModeBubbleDelegate::~DevModeBubbleDelegate() { | 70 DevModeBubbleDelegate::~DevModeBubbleDelegate() { |
| 73 } | 71 } |
| 74 | 72 |
| 75 bool DevModeBubbleDelegate::ShouldIncludeExtension( | 73 bool DevModeBubbleDelegate::ShouldIncludeExtension( |
| 76 const std::string& extension_id) { | 74 const std::string& extension_id) { |
| 77 const Extension* extension = service_->GetExtensionById(extension_id, false); | 75 const Extension* extension = service_->GetExtensionById(extension_id, false); |
| 78 if (!extension) | 76 if (!extension) |
| 79 return false; | 77 return false; |
| 80 return DevModeBubbleController::IsDevModeExtension(extension); | 78 return (extension->location() == Manifest::UNPACKED || |
| 79 extension->location() == Manifest::COMMAND_LINE); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void DevModeBubbleDelegate::AcknowledgeExtension( | 82 void DevModeBubbleDelegate::AcknowledgeExtension( |
| 84 const std::string& extension_id, | 83 const std::string& extension_id, |
| 85 ExtensionMessageBubbleController::BubbleAction user_action) { | 84 ExtensionMessageBubbleController::BubbleAction user_action) { |
| 86 } | 85 } |
| 87 | 86 |
| 88 void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) { | 87 void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) { |
| 89 for (size_t i = 0; i < list.size(); ++i) | 88 for (size_t i = 0; i < list.size(); ++i) |
| 90 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION); | 89 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } // namespace | 146 } // namespace |
| 148 | 147 |
| 149 //////////////////////////////////////////////////////////////////////////////// | 148 //////////////////////////////////////////////////////////////////////////////// |
| 150 // DevModeBubbleController | 149 // DevModeBubbleController |
| 151 | 150 |
| 152 // static | 151 // static |
| 153 void DevModeBubbleController::ClearProfileListForTesting() { | 152 void DevModeBubbleController::ClearProfileListForTesting() { |
| 154 g_shown_for_profiles.Get().clear(); | 153 g_shown_for_profiles.Get().clear(); |
| 155 } | 154 } |
| 156 | 155 |
| 157 // static | |
| 158 bool DevModeBubbleController::IsDevModeExtension( | |
| 159 const Extension* extension) { | |
| 160 if (!FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) { | |
| 161 if (chrome::VersionInfo::GetChannel() < chrome::VersionInfo::CHANNEL_BETA) | |
| 162 return false; | |
| 163 } | |
| 164 return extension->location() == Manifest::UNPACKED || | |
| 165 extension->location() == Manifest::COMMAND_LINE; | |
| 166 } | |
| 167 | |
| 168 DevModeBubbleController::DevModeBubbleController(Profile* profile) | 156 DevModeBubbleController::DevModeBubbleController(Profile* profile) |
| 169 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile), | 157 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile), |
| 170 profile), | 158 profile), |
| 171 profile_(profile) {} | 159 profile_(profile) {} |
| 172 | 160 |
| 173 DevModeBubbleController::~DevModeBubbleController() { | 161 DevModeBubbleController::~DevModeBubbleController() { |
| 174 } | 162 } |
| 175 | 163 |
| 176 bool DevModeBubbleController::ShouldShow() { | 164 bool DevModeBubbleController::ShouldShow() { |
| 177 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) && | 165 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) && |
| 178 !GetExtensionList().empty(); | 166 !GetExtensionList().empty(); |
| 179 } | 167 } |
| 180 | 168 |
| 181 void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) { | 169 void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) { |
| 182 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile()); | 170 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile()); |
| 183 ExtensionMessageBubbleController::Show(bubble); | 171 ExtensionMessageBubbleController::Show(bubble); |
| 184 } | 172 } |
| 185 | 173 |
| 186 } // namespace extensions | 174 } // namespace extensions |
| OLD | NEW |