diff options
author | rdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-10 01:50:44 +0000 |
---|---|---|
committer | rdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-10 01:50:44 +0000 |
commit | 373daf970e47a31cd49f516fa9a1ce9978140999 (patch) | |
tree | fc9f1fa4f719acb17551c07db3c3621b1e57636a /chrome/browser/extensions/extension_error_controller.cc | |
parent | 6683e1b251eb78a569fefcc15d1a64ca22a4421a (diff) | |
download | chromium_src-373daf970e47a31cd49f516fa9a1ce9978140999.zip chromium_src-373daf970e47a31cd49f516fa9a1ce9978140999.tar.gz chromium_src-373daf970e47a31cd49f516fa9a1ce9978140999.tar.bz2 |
Refactor ExtensionErrorUI to remove ExtensionService's work
Create an ExtensionErrorController to be in charge of ExtensionErrorUI so that
ExtensionService doens't have to know as much about it.
And, of course, add a few tests for otherwise untested behavior.
BUG=351891
Review URL: https://codereview.chromium.org/227373007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262893 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_error_controller.cc')
-rw-r--r-- | chrome/browser/extensions/extension_error_controller.cc | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_error_controller.cc b/chrome/browser/extensions/extension_error_controller.cc new file mode 100644 index 0000000..4c3d3a2 --- /dev/null +++ b/chrome/browser/extensions/extension_error_controller.cc @@ -0,0 +1,131 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/extensions/extension_error_controller.h" + +#include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/extensions/pending_extension_manager.h" +#include "extensions/browser/extension_prefs.h" +#include "extensions/browser/extension_registry.h" +#include "extensions/browser/extension_system.h" +#include "extensions/common/extension_set.h" + +namespace extensions { + +namespace { + +ExtensionErrorController::UICreateMethod g_create_ui = + ExtensionErrorUI::Create; + +} + +ExtensionErrorController::ExtensionErrorController( + content::BrowserContext* context, + bool is_first_run) + : browser_context_(context), + is_first_run_(is_first_run) {} + +ExtensionErrorController::~ExtensionErrorController() {} + +void ExtensionErrorController::ShowErrorIfNeeded() { + IdentifyAlertableExtensions(); + + if (!blacklisted_extensions_.is_empty()) { + if (!is_first_run_) { + error_ui_.reset(g_create_ui(this)); + if (!error_ui_->ShowErrorInBubbleView()) // Couldn't find a browser. + error_ui_.reset(); + } else { + // First run. Just acknowledge all the extensions, silently, by + // shortcutting the display of the UI and going straight to the + // callback for pressing the Accept button. + OnAlertClosed(); + } + } +} + +// static +void ExtensionErrorController::SetUICreateMethodForTesting( + UICreateMethod method) { + g_create_ui = method; +} + +content::BrowserContext* ExtensionErrorController::GetContext() { + return browser_context_; +} + +const ExtensionSet& ExtensionErrorController::GetExternalExtensions() { + return external_extensions_; +} + +const ExtensionSet& ExtensionErrorController::GetBlacklistedExtensions() { + return blacklisted_extensions_; +} + +void ExtensionErrorController::OnAlertAccept() { + error_ui_->Close(); +} + +void ExtensionErrorController::OnAlertDetails() { + error_ui_->ShowExtensions(); + + // ShowExtensions() may cause the error UI to close synchronously, e.g. if it + // causes a navigation. + if (error_ui_) + error_ui_->Close(); +} + +void ExtensionErrorController::OnAlertClosed() { + ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_); + for (ExtensionSet::const_iterator iter = blacklisted_extensions_.begin(); + iter != blacklisted_extensions_.end(); + ++iter) { + prefs->AcknowledgeBlacklistedExtension((*iter)->id()); + } + + error_ui_.reset(); +} + +void ExtensionErrorController::IdentifyAlertableExtensions() { + ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_); + ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_); + + // Build up the lists of extensions that require acknowledgment. If this is + // the first time, grandfather extensions that would have caused + // notification. + + const ExtensionSet& blacklisted_set = registry->blacklisted_extensions(); + for (ExtensionSet::const_iterator iter = blacklisted_set.begin(); + iter != blacklisted_set.end(); + ++iter) { + if (!prefs->IsBlacklistedExtensionAcknowledged((*iter)->id())) + blacklisted_extensions_.Insert(*iter); + } + + ExtensionSystem* system = ExtensionSystem::Get(browser_context_); + ManagementPolicy* management_policy = system->management_policy(); + PendingExtensionManager* pending_extension_manager = + system->extension_service()->pending_extension_manager(); + const ExtensionSet& enabled_set = registry->enabled_extensions(); + + for (ExtensionSet::const_iterator iter = enabled_set.begin(); + iter != enabled_set.end(); + ++iter) { + const Extension* extension = *iter; + + // Skip for extensions that have pending updates. They will be checked again + // once the pending update is finished. + if (pending_extension_manager->IsIdPending(extension->id())) + continue; + + // Extensions disabled by policy. Note: this no longer includes blacklisted + // extensions, though we still show the same UI. + if (!management_policy->UserMayLoad(extension, NULL /* ignore error */)) { + if (!prefs->IsBlacklistedExtensionAcknowledged(extension->id())) + blacklisted_extensions_.Insert(extension); + } + } +} + +} // namespace extensions |