OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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/settings_api_bubble_controller.h" | 5 #include "chrome/browser/extensions/settings_api_bubble_controller.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/settings_api_helpers.h" |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 11 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
11 #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.
h" | 12 #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.
h" |
12 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
13 #include "extensions/browser/extension_registry.h" | 14 #include "extensions/browser/extension_registry.h" |
14 #include "extensions/browser/extension_system.h" | 15 #include "extensions/browser/extension_system.h" |
15 #include "grit/chromium_strings.h" | 16 #include "grit/chromium_strings.h" |
16 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
18 | 19 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | 87 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
87 const extensions::Extension* extension = | 88 const extensions::Extension* extension = |
88 registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); | 89 registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); |
89 if (!extension) | 90 if (!extension) |
90 return false; // The extension provided is no longer enabled. | 91 return false; // The extension provided is no longer enabled. |
91 | 92 |
92 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_); | 93 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_); |
93 if (prefs->HasSettingsApiBubbleBeenAcknowledged(extension_id)) | 94 if (prefs->HasSettingsApiBubbleBeenAcknowledged(extension_id)) |
94 return false; | 95 return false; |
95 | 96 |
96 const SettingsOverrides* settings = SettingsOverrides::Get(extension); | 97 const extensions::Extension* override = NULL; |
97 if (!settings) | |
98 return false; | |
99 | |
100 bool should_include = false; | |
101 switch (type_) { | 98 switch (type_) { |
102 case extensions::BUBBLE_TYPE_HOME_PAGE: | 99 case extensions::BUBBLE_TYPE_HOME_PAGE: |
103 should_include = settings->homepage != NULL; | 100 override = extensions::OverridesHomepage(profile_, NULL); |
104 break; | 101 break; |
105 case extensions::BUBBLE_TYPE_STARTUP_PAGES: | 102 case extensions::BUBBLE_TYPE_STARTUP_PAGES: |
106 should_include = !settings->startup_pages.empty(); | 103 override = extensions::OverridesStartupPages(profile_, NULL); |
107 break; | 104 break; |
108 case extensions::BUBBLE_TYPE_SEARCH_ENGINE: | 105 case extensions::BUBBLE_TYPE_SEARCH_ENGINE: |
109 should_include = settings->search_engine != NULL; | 106 override = extensions::OverridesSearchEngine(profile_, NULL); |
110 break; | 107 break; |
111 } | 108 } |
112 | 109 |
113 if (should_include && extension_id_ != extension_id) { | 110 if (!override || override->id() != extension->id()) |
114 DCHECK(extension_id_.empty()); | 111 return false; |
115 extension_id_ = extension_id; | 112 |
116 } | 113 extension_id_ = extension_id; |
117 return should_include; | 114 return true; |
118 } | 115 } |
119 | 116 |
120 void SettingsApiBubbleDelegate::AcknowledgeExtension( | 117 void SettingsApiBubbleDelegate::AcknowledgeExtension( |
121 const std::string& extension_id, | 118 const std::string& extension_id, |
122 ExtensionMessageBubbleController::BubbleAction user_action) { | 119 ExtensionMessageBubbleController::BubbleAction user_action) { |
123 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_); | 120 if (user_action != ExtensionMessageBubbleController::ACTION_EXECUTE) { |
124 prefs->SetSettingsApiBubbleBeenAcknowledged(extension_id, true); | 121 extensions::ExtensionPrefs* prefs = |
| 122 extensions::ExtensionPrefs::Get(profile_); |
| 123 prefs->SetSettingsApiBubbleBeenAcknowledged(extension_id, true); |
| 124 } |
125 } | 125 } |
126 | 126 |
127 void SettingsApiBubbleDelegate::PerformAction( | 127 void SettingsApiBubbleDelegate::PerformAction( |
128 const extensions::ExtensionIdList& list) { | 128 const extensions::ExtensionIdList& list) { |
129 for (size_t i = 0; i < list.size(); ++i) { | 129 for (size_t i = 0; i < list.size(); ++i) { |
130 service_->DisableExtension(list[i], | 130 service_->DisableExtension(list[i], |
131 extensions::Extension::DISABLE_USER_ACTION); | 131 extensions::Extension::DISABLE_USER_ACTION); |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 return true; | 291 return true; |
292 } | 292 } |
293 | 293 |
294 bool SettingsApiBubbleController::CloseOnDeactivate() { | 294 bool SettingsApiBubbleController::CloseOnDeactivate() { |
295 // Startup bubbles tend to get lost in the focus storm that happens on | 295 // Startup bubbles tend to get lost in the focus storm that happens on |
296 // startup. Other types should dismiss on focus loss. | 296 // startup. Other types should dismiss on focus loss. |
297 return type_ != BUBBLE_TYPE_STARTUP_PAGES; | 297 return type_ != BUBBLE_TYPE_STARTUP_PAGES; |
298 } | 298 } |
299 | 299 |
300 } // namespace extensions | 300 } // namespace extensions |
OLD | NEW |