blob: f6f7b3f37247a892ad80536831ffdb5f81f1d7a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// Copyright (c) 2012 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/requirements_checker.h"
#include "base/bind.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/gpu/gpu_feature_checker.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/manifest.h"
#include "chrome/common/extensions/manifest_handlers/requirements_handler.h"
#include "content/public/browser/browser_thread.h"
#include "gpu/config/gpu_feature_type.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#if defined(OS_WIN)
#include "base/win/metro.h"
#endif // defined(OS_WIN)
namespace extensions {
RequirementsChecker::RequirementsChecker()
: pending_requirement_checks_(0) {
}
RequirementsChecker::~RequirementsChecker() {
}
void RequirementsChecker::Check(scoped_refptr<const Extension> extension,
base::Callback<void(std::vector<std::string> errors)> callback) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
callback_ = callback;
const RequirementsInfo& requirements =
RequirementsInfo::GetRequirements(extension);
if (requirements.npapi) {
#if defined(OS_CHROMEOS)
errors_.push_back(
l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED));
#endif // defined(OS_CHROMEOS)
#if defined(OS_WIN)
if (base::win::IsMetroProcess()) {
errors_.push_back(
l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED));
}
#endif // defined(OS_WIN)
}
if (requirements.webgl) {
++pending_requirement_checks_;
webgl_checker_ = new GPUFeatureChecker(
gpu::GPU_FEATURE_TYPE_WEBGL,
base::Bind(&RequirementsChecker::SetWebGLAvailability,
AsWeakPtr()));
}
if (requirements.css3d) {
++pending_requirement_checks_;
css3d_checker_ = new GPUFeatureChecker(
gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING,
base::Bind(&RequirementsChecker::SetCSS3DAvailability,
AsWeakPtr()));
}
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_)
webgl_checker_->CheckGPUFeatureAvailability();
if (css3d_checker_)
css3d_checker_->CheckGPUFeatureAvailability();
}
void RequirementsChecker::SetWebGLAvailability(bool available) {
if (!available) {
errors_.push_back(
l10n_util::GetStringUTF8(IDS_EXTENSION_WEBGL_NOT_SUPPORTED));
}
MaybeRunCallback();
}
void RequirementsChecker::SetCSS3DAvailability(bool available) {
if (!available) {
errors_.push_back(
l10n_util::GetStringUTF8(IDS_EXTENSION_CSS3D_NOT_SUPPORTED));
}
MaybeRunCallback();
}
void RequirementsChecker::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();
}
}
} // namespace extensions
|