1 // Copyright 2014 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.
5 #include "chrome/browser/extensions/extension_error_controller.h"
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/pending_extension_manager.h"
9 #include "extensions/browser/extension_prefs.h"
10 #include "extensions/browser/extension_registry.h"
11 #include "extensions/browser/extension_system.h"
12 #include "extensions/common/extension_set.h"
14 namespace extensions
{
18 ExtensionErrorController::UICreateMethod g_create_ui
=
19 ExtensionErrorUI::Create
;
23 ExtensionErrorController::ExtensionErrorController(
24 content::BrowserContext
* context
,
26 : browser_context_(context
),
27 is_first_run_(is_first_run
) {}
29 ExtensionErrorController::~ExtensionErrorController() {}
31 void ExtensionErrorController::ShowErrorIfNeeded() {
32 IdentifyAlertableExtensions();
34 // Make sure there's something to show, and that there isn't currently a
36 if (!blacklisted_extensions_
.is_empty() && !error_ui_
.get()) {
38 error_ui_
.reset(g_create_ui(this));
39 if (!error_ui_
->ShowErrorInBubbleView()) // Couldn't find a browser.
42 // First run. Just acknowledge all the extensions, silently, by
43 // shortcutting the display of the UI and going straight to the
44 // callback for pressing the Accept button.
51 void ExtensionErrorController::SetUICreateMethodForTesting(
52 UICreateMethod method
) {
56 content::BrowserContext
* ExtensionErrorController::GetContext() {
57 return browser_context_
;
60 const ExtensionSet
& ExtensionErrorController::GetExternalExtensions() {
61 return external_extensions_
;
64 const ExtensionSet
& ExtensionErrorController::GetBlacklistedExtensions() {
65 return blacklisted_extensions_
;
68 void ExtensionErrorController::OnAlertAccept() {
72 void ExtensionErrorController::OnAlertDetails() {
73 error_ui_
->ShowExtensions();
75 // ShowExtensions() may cause the error UI to close synchronously, e.g. if it
76 // causes a navigation.
81 void ExtensionErrorController::OnAlertClosed() {
82 ExtensionPrefs
* prefs
= ExtensionPrefs::Get(browser_context_
);
83 for (ExtensionSet::const_iterator iter
= blacklisted_extensions_
.begin();
84 iter
!= blacklisted_extensions_
.end();
86 prefs
->AcknowledgeBlacklistedExtension((*iter
)->id());
89 blacklisted_extensions_
.Clear();
93 void ExtensionErrorController::IdentifyAlertableExtensions() {
94 ExtensionRegistry
* registry
= ExtensionRegistry::Get(browser_context_
);
95 ExtensionPrefs
* prefs
= ExtensionPrefs::Get(browser_context_
);
97 // This should be clear, but in case a bubble crashed somewhere along the
98 // line, let's make sure we start fresh.
99 blacklisted_extensions_
.Clear();
101 // Build up the lists of extensions that require acknowledgment. If this is
102 // the first time, grandfather extensions that would have caused
105 const ExtensionSet
& blacklisted_set
= registry
->blacklisted_extensions();
106 for (ExtensionSet::const_iterator iter
= blacklisted_set
.begin();
107 iter
!= blacklisted_set
.end();
109 if (!prefs
->IsBlacklistedExtensionAcknowledged((*iter
)->id()))
110 blacklisted_extensions_
.Insert(*iter
);
113 ExtensionSystem
* system
= ExtensionSystem::Get(browser_context_
);
114 ManagementPolicy
* management_policy
= system
->management_policy();
115 PendingExtensionManager
* pending_extension_manager
=
116 system
->extension_service()->pending_extension_manager();
117 const ExtensionSet
& enabled_set
= registry
->enabled_extensions();
119 for (ExtensionSet::const_iterator iter
= enabled_set
.begin();
120 iter
!= enabled_set
.end();
122 const Extension
* extension
= iter
->get();
124 // Skip for extensions that have pending updates. They will be checked again
125 // once the pending update is finished.
126 if (pending_extension_manager
->IsIdPending(extension
->id()))
129 // Extensions disabled by policy. Note: this no longer includes blacklisted
130 // extensions, though we still show the same UI.
131 if (!management_policy
->UserMayLoad(extension
, NULL
/* ignore error */)) {
132 if (!prefs
->IsBlacklistedExtensionAcknowledged(extension
->id()))
133 blacklisted_extensions_
.Insert(extension
);
138 } // namespace extensions