Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/extensions/requirements_checker.cc

Issue 10689097: Enforce the 'requirements' field in manifests. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed UnpackedInstller issue Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/extensions/requirements_checker.h"
6
7 #include "base/bind.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/gpu_feature_checker.h"
10 #include "chrome/common/extensions/extension_manifest_constants.h"
11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/manifest.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/common/gpu_feature_type.h"
15 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17
18 namespace extensions {
19
20 RequirementsChecker::RequirementsChecker()
21 : pending_requirement_checks_(0) {
22 }
23
24 RequirementsChecker::~RequirementsChecker() {
25 }
26
27 void RequirementsChecker::Check(scoped_refptr<const Extension> extension,
28 base::Callback<void(std::vector<std::string> errors)> callback) {
29 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
30
31 callback_ = callback;
32 const Extension::Requirements& requirements = extension->requirements();
33
34 if (requirements.npapi) {
35 #if defined(OS_CHROMEOS)
36 errors_.push_back(
37 l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED));
38 #endif // defined(OS_CHROMEOS)
39 }
40
41 if (requirements.webgl) {
42 ++pending_requirement_checks_;
43 webgl_checker_ = new GPUFeatureChecker(
44 content::GPU_FEATURE_TYPE_WEBGL,
45 base::Bind(&RequirementsChecker::SetWebGLAvailability,
46 AsWeakPtr()));
47 }
48
49 if (requirements.css3d) {
50 ++pending_requirement_checks_;
51 css3d_checker_ = new GPUFeatureChecker(
52 content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING,
53 base::Bind(&RequirementsChecker::SetCSS3DAvailability,
54 AsWeakPtr()));
55 }
56
57 if (pending_requirement_checks_ == 0) {
58 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
59 base::Bind(callback_, errors_));
60 // Reset the callback so any ref-counted bound parameters will get released.
61 callback_.Reset();
62 return;
63 }
64 // Running the GPU checkers down here removes any race condition that arises
65 // from the use of pending_requirement_checks_.
66 if (webgl_checker_.get())
67 webgl_checker_->CheckGPUFeatureAvailability();
68 if (css3d_checker_.get())
69 css3d_checker_->CheckGPUFeatureAvailability();
70 }
71
72 void RequirementsChecker::SetWebGLAvailability(bool available) {
73 if (!available) {
74 errors_.push_back(
75 l10n_util::GetStringUTF8(IDS_EXTENSION_WEBGL_NOT_SUPPORTED));
76 }
77 MaybeRunCallback();
78 }
79
80 void RequirementsChecker::SetCSS3DAvailability(bool available) {
81 if (!available) {
82 errors_.push_back(
83 l10n_util::GetStringUTF8(IDS_EXTENSION_CSS3D_NOT_SUPPORTED));
84 }
85 MaybeRunCallback();
86 }
87
88 void RequirementsChecker::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.
93 callback_.Reset();
94 errors_.clear();
95 }
96 }
97
98 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/requirements_checker.h ('k') | chrome/browser/extensions/requirements_checker_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698