Extensions: requirements.npapi should report not available on non-Mac POSIX platforms.
[chromium-blink-merge.git] / chrome / browser / extensions / requirements_checker.cc
blob5bc3da5071b7f8fe801cb5ada01f6c5df4b0cbfe
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"
7 #include "base/bind.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"
17 #if defined(OS_WIN)
18 #include "base/win/metro.h"
19 #endif
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);
34 callback_ = callback;
35 const RequirementsInfo& requirements =
36 RequirementsInfo::GetRequirements(extension.get());
38 if (requirements.npapi) {
39 #if defined(OS_POSIX) && !defined(OS_MACOSX)
40 errors_.push_back(
41 l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED));
42 #endif
43 #if defined(OS_WIN)
44 if (base::win::IsMetroProcess()) {
45 errors_.push_back(
46 l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED));
48 #endif
51 if (requirements.window_shape) {
52 #if !defined(USE_AURA)
53 errors_.push_back(
54 l10n_util::GetStringUTF8(IDS_EXTENSION_WINDOW_SHAPE_NOT_SUPPORTED));
55 #endif
58 if (requirements.webgl) {
59 ++pending_requirement_checks_;
60 webgl_checker_ = new GPUFeatureChecker(
61 gpu::GPU_FEATURE_TYPE_WEBGL,
62 base::Bind(&RequirementsChecker::SetWebGLAvailability,
63 AsWeakPtr()));
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.
70 callback_.Reset();
71 return;
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) {
80 if (!available) {
81 errors_.push_back(
82 l10n_util::GetStringUTF8(IDS_EXTENSION_WEBGL_NOT_SUPPORTED));
84 MaybeRunCallback();
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.
92 callback_.Reset();
93 errors_.clear();
97 } // namespace extensions