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/chrome_requirements_checker.h"
8 #include "chrome/browser/gpu/gpu_feature_checker.h"
9 #include "chrome/grit/generated_resources.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "extensions/common/extension.h"
12 #include "extensions/common/manifest.h"
13 #include "extensions/common/manifest_handlers/requirements_info.h"
14 #include "gpu/config/gpu_feature_type.h"
15 #include "ui/base/l10n/l10n_util.h"
18 #include "base/win/metro.h"
21 namespace extensions
{
23 ChromeRequirementsChecker::ChromeRequirementsChecker()
24 : pending_requirement_checks_(0), weak_ptr_factory_(this) {
27 ChromeRequirementsChecker::~ChromeRequirementsChecker() {
30 void ChromeRequirementsChecker::Check(
31 const scoped_refptr
<const Extension
>& extension
,
32 const RequirementsCheckedCallback
& callback
) {
33 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
36 const RequirementsInfo
& requirements
=
37 RequirementsInfo::GetRequirements(extension
.get());
39 if (requirements
.npapi
) {
40 #if defined(OS_POSIX) && !defined(OS_MACOSX)
42 l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED
));
45 if (base::win::IsMetroProcess()) {
47 l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED
));
52 if (requirements
.window_shape
) {
53 #if !defined(USE_AURA)
55 l10n_util::GetStringUTF8(IDS_EXTENSION_WINDOW_SHAPE_NOT_SUPPORTED
));
59 if (requirements
.webgl
) {
60 ++pending_requirement_checks_
;
61 webgl_checker_
= new GPUFeatureChecker(
62 gpu::GPU_FEATURE_TYPE_WEBGL
,
63 base::Bind(&ChromeRequirementsChecker::SetWebGLAvailability
,
64 weak_ptr_factory_
.GetWeakPtr()));
67 if (pending_requirement_checks_
== 0) {
68 content::BrowserThread::PostTask(content::BrowserThread::UI
, FROM_HERE
,
69 base::Bind(callback_
, errors_
));
70 // Reset the callback so any ref-counted bound parameters will get released.
74 // Running the GPU checkers down here removes any race condition that arises
75 // from the use of pending_requirement_checks_.
76 if (webgl_checker_
.get())
77 webgl_checker_
->CheckGPUFeatureAvailability();
80 void ChromeRequirementsChecker::SetWebGLAvailability(bool available
) {
83 l10n_util::GetStringUTF8(IDS_EXTENSION_WEBGL_NOT_SUPPORTED
));
88 void ChromeRequirementsChecker::MaybeRunCallback() {
89 if (--pending_requirement_checks_
== 0) {
90 content::BrowserThread::PostTask(content::BrowserThread::UI
, FROM_HERE
,
91 base::Bind(callback_
, errors_
));
92 // Reset the callback so any ref-counted bound parameters will get released.
98 } // namespace extensions