summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-16 06:41:11 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-16 06:41:11 +0000
commitad63a79c308bfd146ed876b4a8f0ea1a88455841 (patch)
treeeccbd7cca7606b35865a1ca7907feecca7cd38ba
parent0dcc983e05894e48c258be3d156904220f56ccf2 (diff)
downloadchromium_src-ad63a79c308bfd146ed876b4a8f0ea1a88455841.zip
chromium_src-ad63a79c308bfd146ed876b4a8f0ea1a88455841.tar.gz
chromium_src-ad63a79c308bfd146ed876b4a8f0ea1a88455841.tar.bz2
Fix to make 'Enable accessibility features.' option change take effect immediately
Add loading and unloading code to SystemOptionsHandler Add unregister_component_extension to ExtensionService BUG=chromium-os:11887 TEST=manually confirmed that enabling/disabling a11y features works immediately Review URL: http://codereview.chromium.org/7129015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89302 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_service.cc38
-rw-r--r--chrome/browser/extensions/extension_service.h8
-rw-r--r--chrome/browser/profiles/profile_impl.cc2
-rw-r--r--chrome/browser/ui/webui/options/chromeos/system_options_handler.cc28
-rw-r--r--chrome/common/extensions/extension_constants.cc1
-rw-r--r--chrome/common/extensions/extension_constants.h1
6 files changed, 77 insertions, 1 deletions
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index a835f6a..63fc24b 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -191,6 +191,11 @@ void SimpleExtensionLoadPrompt::InstallUIAbort() {
} // namespace
+bool ExtensionService::ComponentExtensionInfo::Equals(
+ const ComponentExtensionInfo& other) const {
+ return other.manifest == manifest && other.root_directory == root_directory;
+}
+
ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData()
: background_page_ready(false),
being_upgraded(false) {
@@ -575,6 +580,18 @@ PendingExtensionManager* ExtensionService::pending_extension_manager() {
return &pending_extension_manager_;
}
+void ExtensionService::UnregisterComponentExtension(
+ const ComponentExtensionInfo& info) {
+ RegisteredComponentExtensions new_component_extension_manifests;
+ for (RegisteredComponentExtensions::iterator it =
+ component_extension_manifests_.begin();
+ it != component_extension_manifests_.end(); ++it) {
+ if (!it->Equals(info))
+ new_component_extension_manifests.push_back(*it);
+ }
+ component_extension_manifests_.swap(new_component_extension_manifests);
+}
+
ExtensionService::~ExtensionService() {
// No need to unload extensions here because they are profile-scoped, and the
// profile is in the process of being deleted.
@@ -967,6 +984,27 @@ const Extension* ExtensionService::LoadComponentExtension(
return extension;
}
+void ExtensionService::UnloadComponentExtension(
+ const ComponentExtensionInfo& info) {
+ JSONStringValueSerializer serializer(info.manifest);
+ scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL));
+ if (!manifest.get()) {
+ DLOG(ERROR) << "Failed to parse manifest for extension";
+ return;
+ }
+ std::string public_key;
+ std::string public_key_bytes;
+ std::string id;
+ if (!static_cast<DictionaryValue*>(manifest.get())->
+ GetString(extension_manifest_keys::kPublicKey, &public_key) ||
+ !Extension::ParsePEMKeyBytes(public_key, &public_key_bytes) ||
+ !Extension::GenerateId(public_key_bytes, &id)) {
+ DLOG(ERROR) << "Failed to get extension id";
+ return;
+ }
+ UnloadExtension(id, UnloadedExtensionInfo::DISABLE);
+}
+
void ExtensionService::LoadAllExtensions() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h
index 3bed716..7aae4ec 100644
--- a/chrome/browser/extensions/extension_service.h
+++ b/chrome/browser/extensions/extension_service.h
@@ -134,6 +134,8 @@ class ExtensionService
root_directory(root_directory) {
}
+ bool Equals(const ComponentExtensionInfo& other) const;
+
// The extension's manifest. This is required for component extensions so
// that ExtensionService doesn't need to go to disk to load them.
std::string manifest;
@@ -204,6 +206,9 @@ class ExtensionService
component_extension_manifests_.push_back(info);
}
+ // Unregisters a component extension from the list of extensions to be loaded
+ void UnregisterComponentExtension(const ComponentExtensionInfo& info);
+
const FilePath& install_directory() const { return install_directory_; }
AppsPromo* apps_promo() { return &apps_promo_; }
@@ -317,6 +322,9 @@ class ExtensionService
// Loads particular component extension.
const Extension* LoadComponentExtension(const ComponentExtensionInfo& info);
+ // Unloads particular component extension.
+ void UnloadComponentExtension(const ComponentExtensionInfo& info);
+
// Loads all known extensions (used by startup and testing code).
void LoadAllExtensions();
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index a87fec7..bce27ee 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -552,7 +552,7 @@ void ProfileImpl::RegisterComponentExtensions() {
if (g_browser_process->local_state()->
GetBoolean(prefs::kAccessibilityEnabled)) {
FilePath path = FilePath(extension_misc::kAccessExtensionPath)
- .AppendASCII("access_chromevox");
+ .AppendASCII(extension_misc::kChromeVoxDirectoryName);
std::string manifest =
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_CHROMEVOX_MANIFEST).as_string();
diff --git a/chrome/browser/ui/webui/options/chromeos/system_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/system_options_handler.cc
index 00d6133..45a2474 100644
--- a/chrome/browser/ui/webui/options/chromeos/system_options_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/system_options_handler.cc
@@ -11,16 +11,24 @@
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "content/browser/tab_contents/tab_contents.h"
+#include "content/common/json_value_serializer.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/language_preferences.h"
+#include "chrome/browser/extensions/extension_accessibility_api.h"
+#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h"
#include "chrome/common/pref_names.h"
+#include "chrome/common/extensions/extension.h"
+#include "grit/browser_resources.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
SystemOptionsHandler::SystemOptionsHandler()
: chromeos::CrosOptionsPageUIHandler(
@@ -96,6 +104,26 @@ void SystemOptionsHandler::AccessibilityChangeCallback(const ListValue* args) {
std::string checked_str;
args->GetString(0, &checked_str);
bool accessibility_enabled = (checked_str == "true");
+
PrefService* pref_service = g_browser_process->local_state();
pref_service->SetBoolean(prefs::kAccessibilityEnabled, accessibility_enabled);
+
+ ExtensionAccessibilityEventRouter::GetInstance()->
+ SetAccessibilityEnabled(accessibility_enabled);
+
+ // Load/Unload ChromeVox
+ ExtensionService* extension_service =
+ web_ui_->tab_contents()->profile()->GetExtensionService();
+ std::string manifest = ResourceBundle::GetSharedInstance().
+ GetRawDataResource(IDR_CHROMEVOX_MANIFEST).as_string();
+ FilePath path = FilePath(extension_misc::kAccessExtensionPath)
+ .AppendASCII(extension_misc::kChromeVoxDirectoryName);
+ ExtensionService::ComponentExtensionInfo info(manifest, path);
+ if (accessibility_enabled) { // Load ChromeVox
+ extension_service->register_component_extension(info);
+ extension_service->LoadComponentExtension(info);
+ } else { // Unload ChromeVox
+ extension_service->UnloadComponentExtension(info);
+ extension_service->UnregisterComponentExtension(info);
+ }
}
diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc
index ab59539..4761639 100644
--- a/chrome/common/extensions/extension_constants.cc
+++ b/chrome/common/extensions/extension_constants.cc
@@ -412,5 +412,6 @@ const char* kAppLaunchHistogram = "Extensions.AppLaunch";
#if defined(OS_CHROMEOS)
const char* kAccessExtensionPath =
"/usr/share/chromeos-assets/accessibility/extensions";
+const char* kChromeVoxDirectoryName = "access_chromevox";
#endif
}
diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h
index 66e039e..1fdd433 100644
--- a/chrome/common/extensions/extension_constants.h
+++ b/chrome/common/extensions/extension_constants.h
@@ -384,6 +384,7 @@ namespace extension_misc {
// The directory path on a ChromeOS device where accessibility extensions are
// stored.
extern const char* kAccessExtensionPath;
+ extern const char* kChromeVoxDirectoryName;
#endif
// What causes an extension to be installed? Used in histograms, so don't