Add a webstorePrivate API to show a permission prompt for delegated bundle installs
[chromium-blink-merge.git] / chrome / browser / extensions / chrome_requirements_checker.cc
blob811bfdd40c51ff8ea6bf324f6658d4c3e5543b19
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"
7 #include "base/bind.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"
17 #if defined(OS_WIN)
18 #include "base/win/metro.h"
19 #endif
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);
35 callback_ = callback;
36 const RequirementsInfo& requirements =
37 RequirementsInfo::GetRequirements(extension.get());
39 if (requirements.npapi) {
40 #if defined(OS_POSIX) && !defined(OS_MACOSX)
41 errors_.push_back(
42 l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED));
43 #endif
44 #if defined(OS_WIN)
45 if (base::win::IsMetroProcess()) {
46 errors_.push_back(
47 l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED));
49 #endif
52 if (requirements.window_shape) {
53 #if !defined(USE_AURA)
54 errors_.push_back(
55 l10n_util::GetStringUTF8(IDS_EXTENSION_WINDOW_SHAPE_NOT_SUPPORTED));
56 #endif
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.
71 callback_.Reset();
72 return;
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) {
81 if (!available) {
82 errors_.push_back(
83 l10n_util::GetStringUTF8(IDS_EXTENSION_WEBGL_NOT_SUPPORTED));
85 MaybeRunCallback();
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.
93 callback_.Reset();
94 errors_.clear();
98 } // namespace extensions