summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 23:57:57 +0000
committerjbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 23:57:57 +0000
commitdf353ab1855fca65c4d5e26985f139a26b15240d (patch)
treed38d7188651c44bb7a682724a01bb133df61bbce
parenteb6ba338db0ac03b8ab8dfcd90ba4da41213ddea (diff)
downloadchromium_src-df353ab1855fca65c4d5e26985f139a26b15240d.zip
chromium_src-df353ab1855fca65c4d5e26985f139a26b15240d.tar.gz
chromium_src-df353ab1855fca65c4d5e26985f139a26b15240d.tar.bz2
Download SwiftShader component if WebGL is blacklisted
Register with the component updater service if it's discovered that WebGL is blacklisted. Then register the swiftshader library with the GPU data manager. BUG=26001 TEST=Start up chrome on a blacklisted windows machine, wait a while, and open a webgl page Review URL: http://codereview.chromium.org/8897008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114885 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--build/common.gypi3
-rw-r--r--chrome/browser/component_updater/swiftshader_component_installer.cc215
-rw-r--r--chrome/browser/component_updater/swiftshader_component_installer.h17
-rw-r--r--chrome/browser/ui/browser_init.cc2
-rw-r--r--chrome/chrome_browser.gypi2
5 files changed, 239 insertions, 0 deletions
diff --git a/build/common.gypi b/build/common.gypi
index c59f931..5ce9eec 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -1180,6 +1180,9 @@
'ENABLE_WEB_INTENTS=1',
],
}],
+ ['OS=="win" and branding=="Chrome"', {
+ 'defines': ['ENABLE_SWIFTSHADER'],
+ }],
], # conditions for 'target_defaults'
'target_conditions': [
['enable_wexit_time_destructors==1', {
diff --git a/chrome/browser/component_updater/swiftshader_component_installer.cc b/chrome/browser/component_updater/swiftshader_component_installer.cc
new file mode 100644
index 0000000..c663e4d
--- /dev/null
+++ b/chrome/browser/component_updater/swiftshader_component_installer.cc
@@ -0,0 +1,215 @@
+// Copyright (c) 2011 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/component_updater/swiftshader_component_installer.h"
+
+#include "base/bind.h"
+#include "base/base_paths.h"
+#include "base/compiler_specific.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "base/string_util.h"
+#include "base/values.h"
+#include "chrome/browser/component_updater/component_updater_service.h"
+#include "chrome/common/chrome_paths.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/browser/gpu/gpu_data_manager.h"
+
+using content::BrowserThread;
+
+namespace {
+
+// CRX hash. The extension id is: nhfgdggnnopgbfdlpeoalgcjdgfafocg.
+const uint8 sha2_hash[] = {0xd7, 0x56, 0x36, 0x6d, 0xde, 0xf6, 0x15, 0x3b,
+ 0xf4, 0xe0, 0xb6, 0x29, 0x36, 0x50, 0x5e, 0x26,
+ 0xbd, 0x77, 0x8b, 0x8e, 0x35, 0xc2, 0x7e, 0x43,
+ 0x52, 0x47, 0x62, 0xed, 0x12, 0xca, 0xcc, 0x6a};
+
+// File name of the internal SwiftShader plugin on different platforms.
+const FilePath::CharType kSwiftShaderEglName[] =
+ FILE_PATH_LITERAL("libegl.dll");
+const FilePath::CharType kSwiftShaderGlesName[] =
+ FILE_PATH_LITERAL("libglesv2.dll");
+
+const char kSwiftShaderManifestName[] = "SwiftShader";
+
+const FilePath::CharType kSwiftShaderBaseDirectory[] =
+ FILE_PATH_LITERAL("SwiftShader");
+
+// If we don't have a SwiftShader component, this is the version we claim.
+const char kNullVersion[] = "0.0.0.0";
+
+// The base directory on windows looks like:
+// <profile>\AppData\Local\Google\Chrome\User Data\SwiftShader\.
+FilePath GetSwiftShaderBaseDirectory() {
+ FilePath result;
+ PathService::Get(chrome::DIR_USER_DATA, &result);
+ return result.Append(kSwiftShaderBaseDirectory);
+}
+
+// SwiftShader has version encoded in the path itself
+// so we need to enumerate the directories to find the full path.
+// On success it returns something like:
+// <profile>\AppData\Local\Google\Chrome\User Data\SwiftShader\10.3.44.555\.
+bool GetLatestSwiftShaderDirectory(FilePath* result, Version* latest) {
+ *result = GetSwiftShaderBaseDirectory();
+ bool found = false;
+ file_util::FileEnumerator
+ file_enumerator(*result, false, file_util::FileEnumerator::DIRECTORIES);
+ for (FilePath path = file_enumerator.Next(); !path.value().empty();
+ path = file_enumerator.Next()) {
+ Version version(path.BaseName().MaybeAsASCII());
+ if (!version.IsValid())
+ continue;
+ if (version.CompareTo(*latest) > 0 &&
+ file_util::PathExists(path.Append(kSwiftShaderEglName)) &&
+ file_util::PathExists(path.Append(kSwiftShaderGlesName))) {
+ *latest = version;
+ *result = path;
+ found = true;
+ }
+ }
+ return found;
+}
+
+void RegisterSwiftShaderWithChrome(const FilePath& path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ GpuDataManager::GetInstance()->RegisterSwiftShaderPath(path);
+}
+
+} // namespace
+
+class SwiftShaderComponentInstaller : public ComponentInstaller {
+ public:
+ explicit SwiftShaderComponentInstaller(const Version& version);
+
+ virtual ~SwiftShaderComponentInstaller() {}
+
+ virtual void OnUpdateError(int error) OVERRIDE;
+
+ virtual bool Install(base::DictionaryValue* manifest,
+ const FilePath& unpack_path) OVERRIDE;
+
+ private:
+ Version current_version_;
+};
+
+SwiftShaderComponentInstaller::SwiftShaderComponentInstaller(
+ const Version& version) : current_version_(version) {
+ DCHECK(version.IsValid());
+}
+
+void SwiftShaderComponentInstaller::OnUpdateError(int error) {
+ NOTREACHED() << "SwiftShader update error: " << error;
+}
+
+bool SwiftShaderComponentInstaller::Install(base::DictionaryValue* manifest,
+ const FilePath& unpack_path) {
+ std::string name;
+ manifest->GetStringASCII("name", &name);
+ if (name != kSwiftShaderManifestName)
+ return false;
+ std::string proposed_version;
+ manifest->GetStringASCII("version", &proposed_version);
+ Version version(proposed_version.c_str());
+ if (!version.IsValid())
+ return false;
+ if (current_version_.CompareTo(version) >= 0)
+ return false;
+ if (!file_util::PathExists(unpack_path.Append(kSwiftShaderEglName)) ||
+ !file_util::PathExists(unpack_path.Append(kSwiftShaderGlesName)))
+ return false;
+ // Passed the basic tests. Time to install it.
+ FilePath path =
+ GetSwiftShaderBaseDirectory().AppendASCII(version.GetString());
+ if (file_util::PathExists(path))
+ return false;
+ if (!file_util::Move(unpack_path, path))
+ return false;
+ // Installation is done. Now tell the rest of chrome.
+ current_version_ = version;
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&RegisterSwiftShaderWithChrome, path));
+ return true;
+}
+
+void FinishSwiftShaderUpdateRegistration(ComponentUpdateService* cus,
+ const Version& version) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ CrxComponent swiftshader;
+ swiftshader.name = "Swift Shader";
+ swiftshader.installer = new SwiftShaderComponentInstaller(version);
+ swiftshader.version = version;
+ swiftshader.pk_hash.assign(sha2_hash, &sha2_hash[sizeof(sha2_hash)]);
+ if (cus->RegisterComponent(swiftshader) != ComponentUpdateService::kOk) {
+ NOTREACHED() << "SwiftShader component registration fail";
+ }
+}
+
+class UpdateChecker : public GpuDataManager::Observer {
+ public:
+ explicit UpdateChecker(ComponentUpdateService* cus);
+
+ virtual void OnGpuInfoUpdate() OVERRIDE;
+
+ private:
+ ComponentUpdateService* cus_;
+};
+
+UpdateChecker::UpdateChecker(ComponentUpdateService* cus)
+ : cus_(cus) {
+}
+
+void UpdateChecker::OnGpuInfoUpdate() {
+ GpuDataManager *gpu_data_manager = GpuDataManager::GetInstance();
+
+ if (!gpu_data_manager->GpuAccessAllowed() ||
+ (gpu_data_manager->GetGpuFeatureFlags().flags() &
+ GpuFeatureFlags::kGpuFeatureWebgl) ||
+ gpu_data_manager->software_rendering()) {
+ gpu_data_manager->RemoveObserver(this);
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ FilePath path = GetSwiftShaderBaseDirectory();
+
+ Version version(kNullVersion);
+ GetLatestSwiftShaderDirectory(&path, &version);
+
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&FinishSwiftShaderUpdateRegistration, cus_, version));
+ }
+}
+
+// Check if there already is a version of swiftshader installed,
+// and if so register it.
+void RegisterSwiftShaderPath(ComponentUpdateService* cus) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ FilePath path = GetSwiftShaderBaseDirectory();
+ if (!file_util::PathExists(path)) {
+ if (!file_util::CreateDirectory(path)) {
+ NOTREACHED() << "Could not create SwiftShader directory.";
+ return;
+ }
+ }
+
+ Version version(kNullVersion);
+ if (GetLatestSwiftShaderDirectory(&path, &version))
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&RegisterSwiftShaderWithChrome, path));
+
+ UpdateChecker *update_checker = new UpdateChecker(cus);
+ GpuDataManager::GetInstance()->AddObserver(update_checker);
+ update_checker->OnGpuInfoUpdate();
+ // We leak update_checker here, because it has to stick around for the life
+ // of the GpuDataManager.
+}
+
+void RegisterSwiftShaderComponent(ComponentUpdateService* cus) {
+#if defined(ENABLE_SWIFTSHADER)
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ base::Bind(&RegisterSwiftShaderPath, cus));
+#endif
+}
diff --git a/chrome/browser/component_updater/swiftshader_component_installer.h b/chrome/browser/component_updater/swiftshader_component_installer.h
new file mode 100644
index 0000000..b7aa3f0
--- /dev/null
+++ b/chrome/browser/component_updater/swiftshader_component_installer.h
@@ -0,0 +1,17 @@
+// Copyright (c) 2011 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.
+
+#ifndef CHROME_BROWSER_COMPONENT_UPDATER_SWIFTSHADER_COMPONENT_INSTALLER_H_
+#define CHROME_BROWSER_COMPONENT_UPDATER_SWIFTSHADER_COMPONENT_INSTALLER_H_
+#pragma once
+
+class ComponentUpdateService;
+
+// Our job is to 1) find what version of SwiftShader is installed (if any)
+// and 2) register with the gpu data manager and then register with the
+// component updater if the current gpu is blacklisted.
+void RegisterSwiftShaderComponent(ComponentUpdateService* cus);
+
+
+#endif // CHROME_BROWSER_COMPONENT_UPDATER_SWIFTSHADER_COMPONENT_INSTALLER_H_
diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc
index 23c05e1..fc4b418 100644
--- a/chrome/browser/ui/browser_init.cc
+++ b/chrome/browser/ui/browser_init.cc
@@ -29,6 +29,7 @@
#include "chrome/browser/component_updater/component_updater_service.h"
#include "chrome/browser/component_updater/flash_component_installer.h"
#include "chrome/browser/component_updater/recovery_component_installer.h"
+#include "chrome/browser/component_updater/swiftshader_component_installer.h"
#include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "chrome/browser/defaults.h"
@@ -623,6 +624,7 @@ void RegisterComponentsForUpdate(const CommandLine& command_line) {
RegisterRecoveryComponent(cus, g_browser_process->local_state());
RegisterPepperFlashComponent(cus);
RegisterNPAPIFlashComponent(cus);
+ RegisterSwiftShaderComponent(cus);
// CRLSetFetcher attempts to load a CRL set from either the local disk or
// network.
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 79c1b71..7e46c902 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -855,6 +855,8 @@
'browser/component_updater/pnacl/pnacl_component_installer.h',
'browser/component_updater/recovery_component_installer.cc',
'browser/component_updater/recovery_component_installer.h',
+ 'browser/component_updater/swiftshader_component_installer.cc',
+ 'browser/component_updater/swiftshader_component_installer.h',
'browser/content_settings/content_settings_default_provider.cc',
'browser/content_settings/content_settings_default_provider.h',
'browser/content_settings/content_settings_details.cc',