| Index: extensions/browser/requirements_checker.cc
|
| diff --git a/chrome/browser/extensions/chrome_requirements_checker.cc b/extensions/browser/requirements_checker.cc
|
| similarity index 35%
|
| rename from chrome/browser/extensions/chrome_requirements_checker.cc
|
| rename to extensions/browser/requirements_checker.cc
|
| index 3aeacef8b262a1024659b832aca336e36abf85b3..a70b04346edb19214996387926b9a75e1f152bcc 100644
|
| --- a/chrome/browser/extensions/chrome_requirements_checker.cc
|
| +++ b/extensions/browser/requirements_checker.cc
|
| @@ -1,89 +1,99 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright 2017 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/chrome_requirements_checker.h"
|
| +#include "extensions/browser/requirements_checker.h"
|
|
|
| #include "base/bind.h"
|
| +#include "base/strings/string_util.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| #include "build/build_config.h"
|
| -#include "chrome/grit/generated_resources.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/gpu_feature_checker.h"
|
| #include "extensions/common/extension.h"
|
| -#include "extensions/common/manifest.h"
|
| #include "extensions/common/manifest_handlers/requirements_info.h"
|
| +#include "extensions/strings/grit/extensions_strings.h"
|
| #include "gpu/config/gpu_feature_type.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| namespace extensions {
|
|
|
| -ChromeRequirementsChecker::ChromeRequirementsChecker()
|
| - : pending_requirement_checks_(0), weak_ptr_factory_(this) {
|
| -}
|
| +RequirementsChecker::RequirementsChecker(
|
| + scoped_refptr<const Extension> extension)
|
| + : PreloadCheck(extension), weak_ptr_factory_(this) {}
|
|
|
| -ChromeRequirementsChecker::~ChromeRequirementsChecker() {
|
| -}
|
| +RequirementsChecker::~RequirementsChecker() {}
|
|
|
| -void ChromeRequirementsChecker::Check(
|
| - const scoped_refptr<const Extension>& extension,
|
| - const RequirementsCheckedCallback& callback) {
|
| +void RequirementsChecker::Start(ResultCallback callback) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
| - callback_ = callback;
|
| const RequirementsInfo& requirements =
|
| - RequirementsInfo::GetRequirements(extension.get());
|
| + RequirementsInfo::GetRequirements(extension());
|
|
|
| - if (requirements.npapi) {
|
| #if defined(OS_POSIX) && !defined(OS_MACOSX)
|
| - errors_.push_back(
|
| - l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED));
|
| + if (requirements.npapi)
|
| + errors_.insert(NPAPI_NOT_SUPPORTED);
|
| #endif
|
| - }
|
|
|
| - if (requirements.window_shape) {
|
| #if !defined(USE_AURA)
|
| - errors_.push_back(
|
| - l10n_util::GetStringUTF8(IDS_EXTENSION_WINDOW_SHAPE_NOT_SUPPORTED));
|
| + if (requirements.window_shape)
|
| + errors_.insert(WINDOW_SHAPE_NOT_SUPPORTED);
|
| #endif
|
| - }
|
|
|
| + callback_ = std::move(callback);
|
| if (requirements.webgl) {
|
| - ++pending_requirement_checks_;
|
| webgl_checker_ = content::GpuFeatureChecker::Create(
|
| gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL,
|
| - base::Bind(&ChromeRequirementsChecker::SetWebGLAvailability,
|
| + base::Bind(&RequirementsChecker::VerifyWebGLAvailability,
|
| weak_ptr_factory_.GetWeakPtr()));
|
| - }
|
| -
|
| - if (pending_requirement_checks_ == 0) {
|
| - content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
| - base::Bind(callback_, errors_));
|
| - // Reset the callback so any ref-counted bound parameters will get released.
|
| - callback_.Reset();
|
| - return;
|
| - }
|
| - // Running the GPU checkers down here removes any race condition that arises
|
| - // from the use of pending_requirement_checks_.
|
| - if (webgl_checker_.get())
|
| webgl_checker_->CheckGpuFeatureAvailability();
|
| + } else {
|
| + PostRunCallback();
|
| + }
|
| }
|
|
|
| -void ChromeRequirementsChecker::SetWebGLAvailability(bool available) {
|
| - if (!available) {
|
| - errors_.push_back(
|
| +base::string16 RequirementsChecker::GetErrorMessage() const {
|
| + // Join the error messages into one string.
|
| + std::vector<std::string> messages;
|
| +#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
| + if (errors_.count(NPAPI_NOT_SUPPORTED)) {
|
| + messages.push_back(
|
| + l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED));
|
| + }
|
| +#endif
|
| + if (errors_.count(WEBGL_NOT_SUPPORTED)) {
|
| + messages.push_back(
|
| l10n_util::GetStringUTF8(IDS_EXTENSION_WEBGL_NOT_SUPPORTED));
|
| }
|
| - MaybeRunCallback();
|
| +#if !defined(USE_AURA)
|
| + if (errors_.count(WINDOW_SHAPE_NOT_SUPPORTED)) {
|
| + messages.push_back(
|
| + l10n_util::GetStringUTF8(IDS_EXTENSION_WINDOW_SHAPE_NOT_SUPPORTED));
|
| + }
|
| +#endif
|
| +
|
| + return base::UTF8ToUTF16(base::JoinString(messages, " "));
|
| }
|
|
|
| -void ChromeRequirementsChecker::MaybeRunCallback() {
|
| - if (--pending_requirement_checks_ == 0) {
|
| - content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
| - base::Bind(callback_, errors_));
|
| - // Reset the callback so any ref-counted bound parameters will get released.
|
| - callback_.Reset();
|
| - errors_.clear();
|
| - }
|
| +void RequirementsChecker::VerifyWebGLAvailability(bool available) {
|
| + if (!available)
|
| + errors_.insert(WEBGL_NOT_SUPPORTED);
|
| + PostRunCallback();
|
| +}
|
| +
|
| +void RequirementsChecker::PostRunCallback() {
|
| + // TODO(michaelpg): This always forces the callback to run asynchronously
|
| + // to maintain the assumption in
|
| + // ExtensionService::LoadExtensionsFromCommandLineFlag(). Remove these helper
|
| + // functions after crbug.com/708354 is addressed.
|
| + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&RequirementsChecker::RunCallback,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| +}
|
| +
|
| +void RequirementsChecker::RunCallback() {
|
| + DCHECK(callback_);
|
| + std::move(callback_).Run(errors_);
|
| }
|
|
|
| } // namespace extensions
|
|
|