Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
|
Aaron Boodman
2012/08/21 23:04:21
This change needs lots of tests:
- manifest tests
eaugusti
2012/08/24 19:30:52
TEST TIME!
| |
| 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 keys = extension_manifest_keys; | |
| 19 | |
| 20 namespace extensions { | |
| 21 | |
| 22 RequirementsChecker::RequirementsChecker() | |
| 23 : pending_requirement_checks_(0) { | |
| 24 } | |
| 25 | |
| 26 RequirementsChecker::~RequirementsChecker() { | |
| 27 } | |
| 28 | |
| 29 void RequirementsChecker::Check(scoped_refptr<const Extension> extension, | |
| 30 base::Callback<void(std::vector<std::string>)> callback) { | |
| 31 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 32 | |
| 33 callback_ = callback; | |
| 34 const Extension::Requirements& requirements = extension->requirements(); | |
| 35 | |
| 36 if (requirements.npapi) { | |
| 37 #if defined(OS_CHROMEOS) | |
| 38 errors_.push_back( | |
| 39 l10n_util::GetStringUTF8(IDS_EXTENSION_PLUGINS_NOT_SUPPORTED)); | |
| 40 #endif | |
| 41 } | |
| 42 | |
| 43 if (requirements.webgl) { | |
| 44 ++pending_requirement_checks_; | |
| 45 webgl_checker_ = new GPUFeatureChecker( | |
| 46 content::GPU_FEATURE_TYPE_WEBGL, | |
| 47 base::Bind(&RequirementsChecker::SetWebGLAvailability, | |
| 48 AsWeakPtr())); | |
| 49 } | |
| 50 | |
| 51 if (requirements.css3d) { | |
| 52 ++pending_requirement_checks_; | |
| 53 css3d_checker_ = new GPUFeatureChecker( | |
| 54 content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING, | |
| 55 base::Bind(&RequirementsChecker::SetCSS3DAvailability, | |
| 56 AsWeakPtr())); | |
| 57 } | |
| 58 | |
| 59 if (pending_requirement_checks_ == 0) { | |
| 60 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 61 base::Bind(callback_, errors_)); | |
| 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 } | |
| 93 } | |
| 94 | |
| 95 } // namespace extensions | |
| OLD | NEW |