| OLD | NEW |
| (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/chrome_requirements_checker.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "build/build_config.h" | |
| 9 #include "chrome/grit/generated_resources.h" | |
| 10 #include "content/public/browser/browser_thread.h" | |
| 11 #include "content/public/browser/gpu_feature_checker.h" | |
| 12 #include "extensions/common/extension.h" | |
| 13 #include "extensions/common/manifest.h" | |
| 14 #include "extensions/common/manifest_handlers/requirements_info.h" | |
| 15 #include "gpu/config/gpu_feature_type.h" | |
| 16 #include "ui/base/l10n/l10n_util.h" | |
| 17 | |
| 18 namespace extensions { | |
| 19 | |
| 20 ChromeRequirementsChecker::ChromeRequirementsChecker() | |
| 21 : pending_requirement_checks_(0), weak_ptr_factory_(this) { | |
| 22 } | |
| 23 | |
| 24 ChromeRequirementsChecker::~ChromeRequirementsChecker() { | |
| 25 } | |
| 26 | |
| 27 void ChromeRequirementsChecker::Check( | |
| 28 const scoped_refptr<const Extension>& extension, | |
| 29 const RequirementsCheckedCallback& callback) { | |
| 30 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 31 | |
| 32 callback_ = callback; | |
| 33 const RequirementsInfo& requirements = | |
| 34 RequirementsInfo::GetRequirements(extension.get()); | |
| 35 | |
| 36 if (requirements.npapi) { | |
| 37 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 38 errors_.push_back( | |
| 39 l10n_util::GetStringUTF8(IDS_EXTENSION_NPAPI_NOT_SUPPORTED)); | |
| 40 #endif | |
| 41 } | |
| 42 | |
| 43 if (requirements.window_shape) { | |
| 44 #if !defined(USE_AURA) | |
| 45 errors_.push_back( | |
| 46 l10n_util::GetStringUTF8(IDS_EXTENSION_WINDOW_SHAPE_NOT_SUPPORTED)); | |
| 47 #endif | |
| 48 } | |
| 49 | |
| 50 if (requirements.webgl) { | |
| 51 ++pending_requirement_checks_; | |
| 52 webgl_checker_ = content::GpuFeatureChecker::Create( | |
| 53 gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL, | |
| 54 base::Bind(&ChromeRequirementsChecker::SetWebGLAvailability, | |
| 55 weak_ptr_factory_.GetWeakPtr())); | |
| 56 } | |
| 57 | |
| 58 if (pending_requirement_checks_ == 0) { | |
| 59 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 60 base::Bind(callback_, errors_)); | |
| 61 // Reset the callback so any ref-counted bound parameters will get released. | |
| 62 callback_.Reset(); | |
| 63 return; | |
| 64 } | |
| 65 // Running the GPU checkers down here removes any race condition that arises | |
| 66 // from the use of pending_requirement_checks_. | |
| 67 if (webgl_checker_.get()) | |
| 68 webgl_checker_->CheckGpuFeatureAvailability(); | |
| 69 } | |
| 70 | |
| 71 void ChromeRequirementsChecker::SetWebGLAvailability(bool available) { | |
| 72 if (!available) { | |
| 73 errors_.push_back( | |
| 74 l10n_util::GetStringUTF8(IDS_EXTENSION_WEBGL_NOT_SUPPORTED)); | |
| 75 } | |
| 76 MaybeRunCallback(); | |
| 77 } | |
| 78 | |
| 79 void ChromeRequirementsChecker::MaybeRunCallback() { | |
| 80 if (--pending_requirement_checks_ == 0) { | |
| 81 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 82 base::Bind(callback_, errors_)); | |
| 83 // Reset the callback so any ref-counted bound parameters will get released. | |
| 84 callback_.Reset(); | |
| 85 errors_.clear(); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 } // namespace extensions | |
| OLD | NEW |