1 // Copyright (c) 2012 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/requirements_checker.h"
8 #include "chrome/browser/gpu/gpu_feature_checker.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "extensions/common/extension.h"
11 #include "extensions/common/manifest.h"
12 #include "extensions/common/manifest_handlers/requirements_info.h"
13 #include "gpu/config/gpu_feature_type.h"
14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h"
18 #include "base/win/metro.h"
21 namespace extensions
{
23 RequirementsChecker::RequirementsChecker()
24 : pending_requirement_checks_(0) {
27 RequirementsChecker::~RequirementsChecker() {
30 void RequirementsChecker::Check(scoped_refptr
<const Extension
> extension
,
31 base::Callback
<void(std::vector
<std::string
> errors
)> callback
) {
32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
35 const RequirementsInfo
& requirements
=
36 RequirementsInfo::GetRequirements(extension
.get());
38 if (requirements
.npapi
) {
39 #if defined(OS_POSIX) && !defined(OS_MACOSX)
41 l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED
));
44 if (base::win::IsMetroProcess()) {
46 l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED
));
51 if (requirements
.window_shape
) {
52 #if !defined(USE_AURA)
54 l10n_util::GetStringUTF8(IDS_EXTENSION_WINDOW_SHAPE_NOT_SUPPORTED
));
58 if (requirements
.webgl
) {
59 ++pending_requirement_checks_
;
60 webgl_checker_
= new GPUFeatureChecker(
61 gpu::GPU_FEATURE_TYPE_WEBGL
,
62 base::Bind(&RequirementsChecker::SetWebGLAvailability
,
66 if (pending_requirement_checks_
== 0) {
67 content::BrowserThread::PostTask(content::BrowserThread::UI
, FROM_HERE
,
68 base::Bind(callback_
, errors_
));
69 // Reset the callback so any ref-counted bound parameters will get released.
73 // Running the GPU checkers down here removes any race condition that arises
74 // from the use of pending_requirement_checks_.
75 if (webgl_checker_
.get())
76 webgl_checker_
->CheckGPUFeatureAvailability();
79 void RequirementsChecker::SetWebGLAvailability(bool available
) {
82 l10n_util::GetStringUTF8(IDS_EXTENSION_WEBGL_NOT_SUPPORTED
));
87 void RequirementsChecker::MaybeRunCallback() {
88 if (--pending_requirement_checks_
== 0) {
89 content::BrowserThread::PostTask(content::BrowserThread::UI
, FROM_HERE
,
90 base::Bind(callback_
, errors_
));
91 // Reset the callback so any ref-counted bound parameters will get released.
97 } // namespace extensions