Index: extensions/browser/requirements_checker.cc |
diff --git a/extensions/browser/requirements_checker.cc b/extensions/browser/requirements_checker.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..29a85382ef26a384047aef62e4513931b41b3426 |
--- /dev/null |
+++ b/extensions/browser/requirements_checker.cc |
@@ -0,0 +1,85 @@ |
+// 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 "extensions/browser/requirements_checker.h" |
+ |
+// TODO |
+#include "base/bind.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "base/strings/string_util.h" |
+#include "build/build_config.h" |
+#include "content/public/browser/gpu_feature_checker.h" |
+#include "content/public/browser/browser_thread.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 { |
+ |
+RequirementsChecker::RequirementsChecker(const Extension* extension) |
+ : PreloadCheck(extension), weak_ptr_factory_(this) {} |
+ |
+RequirementsChecker::~RequirementsChecker() {} |
+ |
+void RequirementsChecker::Start(ResultCallback callback) { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ |
+ const RequirementsInfo& requirements = |
+ RequirementsInfo::GetRequirements(extension()); |
+ |
+#if defined(OS_POSIX) && !defined(OS_MACOSX) |
+ if (requirements.npapi) |
+ errors_.insert(NPAPI_NOT_SUPPORTED); |
+#endif |
+ |
+#if !defined(USE_AURA) |
+ if (requirements.window_shape) |
+ errors_.insert(WINDOW_SHAPE_NOT_SUPPORTED); |
+#endif |
+ |
+ if (requirements.webgl) { |
+ webgl_checker_ = content::GpuFeatureChecker::Create( |
+ gpu::GPU_FEATURE_TYPE_WEBGL, |
+ base::Bind(&RequirementsChecker::OnGetWebGLAvailability, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ webgl_checker_->CheckGpuFeatureAvailability(); |
+ callback_ = std::move(callback); |
+ } else { |
+ std::move(callback).Run(errors_); |
+ } |
+} |
+ |
+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)); |
+ } |
+#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 RequirementsChecker::OnGetWebGLAvailability(bool available) { |
+ if (!available) |
+ errors_.insert(WEBGL_NOT_SUPPORTED); |
+ std::move(callback_).Run(errors_); |
+} |
+ |
+} // namespace extensions |