Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/browser/extensions/component_loader.cc

Issue 1162283002: Load the Chrome OS TTS engine manifest from the file system isntead of resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/component_loader.h" 5 #include "chrome/browser/extensions/component_loader.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/search/hotword_service_factory.h" 21 #include "chrome/browser/search/hotword_service_factory.h"
22 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/chrome_version_info.h" 24 #include "chrome/common/chrome_version_info.h"
25 #include "chrome/common/extensions/extension_constants.h" 25 #include "chrome/common/extensions/extension_constants.h"
26 #include "chrome/grit/generated_resources.h" 26 #include "chrome/grit/generated_resources.h"
27 #include "components/crx_file/id_util.h" 27 #include "components/crx_file/id_util.h"
28 #include "content/public/browser/browser_context.h" 28 #include "content/public/browser/browser_context.h"
29 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/plugin_service.h" 30 #include "content/public/browser/plugin_service.h"
31 #include "extensions/common/constants.h"
31 #include "extensions/common/extension.h" 32 #include "extensions/common/extension.h"
32 #include "extensions/common/extension_l10n_util.h" 33 #include "extensions/common/extension_l10n_util.h"
33 #include "extensions/common/file_util.h" 34 #include "extensions/common/file_util.h"
34 #include "extensions/common/manifest_constants.h" 35 #include "extensions/common/manifest_constants.h"
35 #include "grit/browser_resources.h" 36 #include "grit/browser_resources.h"
36 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/base/resource/resource_bundle.h" 38 #include "ui/base/resource/resource_bundle.h"
38 39
39 #if defined(OS_CHROMEOS) 40 #if defined(OS_CHROMEOS)
40 #include "components/chrome_apps/grit/chrome_apps_resources.h" 41 #include "components/chrome_apps/grit/chrome_apps_resources.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 std::string id_input; 80 std::string id_input;
80 CHECK(manifest->GetString(manifest_keys::kPublicKey, &raw_key)); 81 CHECK(manifest->GetString(manifest_keys::kPublicKey, &raw_key));
81 CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input)); 82 CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input));
82 std::string id = crx_file::id_util::GenerateId(id_input); 83 std::string id = crx_file::id_util::GenerateId(id_input);
83 return id; 84 return id;
84 } 85 }
85 86
86 #if defined(OS_CHROMEOS) 87 #if defined(OS_CHROMEOS)
87 scoped_ptr<base::DictionaryValue> 88 scoped_ptr<base::DictionaryValue>
88 LoadManifestOnFileThread( 89 LoadManifestOnFileThread(
89 const base::FilePath& chromevox_path, const char* manifest_filename) { 90 const base::FilePath& root_directory,
91 const base::FilePath::CharType* manifest_filename) {
90 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); 92 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
91 std::string error; 93 std::string error;
92 scoped_ptr<base::DictionaryValue> manifest( 94 scoped_ptr<base::DictionaryValue> manifest(
93 file_util::LoadManifest(chromevox_path, manifest_filename, &error)); 95 file_util::LoadManifest(root_directory, manifest_filename, &error));
94 CHECK(manifest) << error; 96 if (!manifest) {
97 LOG(ERROR) << "Can't load "
98 << root_directory.Append(manifest_filename).AsUTF8Unsafe()
not at google - send to devlin 2015/06/01 17:39:37 Annoying that FilePath doesn't define <<
99 << ": " << error;
100 return nullptr;
101 }
95 bool localized = extension_l10n_util::LocalizeExtension( 102 bool localized = extension_l10n_util::LocalizeExtension(
96 chromevox_path, manifest.get(), &error); 103 root_directory, manifest.get(), &error);
97 CHECK(localized) << error; 104 CHECK(localized) << error;
98 return manifest.Pass(); 105 return manifest.Pass();
99 } 106 }
100 107
101 bool IsNormalSession() { 108 bool IsNormalSession() {
102 return !base::CommandLine::ForCurrentProcess()->HasSwitch( 109 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
103 chromeos::switches::kGuestSession) && 110 chromeos::switches::kGuestSession) &&
104 user_manager::UserManager::IsInitialized() && 111 user_manager::UserManager::IsInitialized() &&
105 user_manager::UserManager::Get()->IsUserLoggedIn(); 112 user_manager::UserManager::Get()->IsUserLoggedIn();
106 } 113 }
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 375 }
369 376
370 void ComponentLoader::AddNetworkSpeechSynthesisExtension() { 377 void ComponentLoader::AddNetworkSpeechSynthesisExtension() {
371 Add(IDR_NETWORK_SPEECH_SYNTHESIS_MANIFEST, 378 Add(IDR_NETWORK_SPEECH_SYNTHESIS_MANIFEST,
372 base::FilePath(FILE_PATH_LITERAL("network_speech_synthesis"))); 379 base::FilePath(FILE_PATH_LITERAL("network_speech_synthesis")));
373 } 380 }
374 381
375 #if defined(OS_CHROMEOS) 382 #if defined(OS_CHROMEOS)
376 void ComponentLoader::AddChromeVoxExtension( 383 void ComponentLoader::AddChromeVoxExtension(
377 const base::Closure& done_cb) { 384 const base::Closure& done_cb) {
378 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
379 base::FilePath resources_path; 385 base::FilePath resources_path;
380 PathService::Get(chrome::DIR_RESOURCES, &resources_path); 386 CHECK(PathService::Get(chrome::DIR_RESOURCES, &resources_path));
381 387
382 base::FilePath chromevox_path = 388 base::FilePath chromevox_path =
383 resources_path.Append(extension_misc::kChromeVoxExtensionPath); 389 resources_path.Append(extension_misc::kChromeVoxExtensionPath);
384 390
385 const char* manifest_filename = 391 const base::FilePath::CharType* manifest_filename =
386 IsNormalSession() ? extension_misc::kChromeVoxManifestFilename 392 IsNormalSession() ? extensions::kManifestFilename
387 : extension_misc::kChromeVoxGuestManifestFilename; 393 : extension_misc::kGuestManifestFilename;
388 394 AddWithManifestFile(
389 BrowserThread::PostTaskAndReplyWithResult( 395 manifest_filename,
390 BrowserThread::FILE, 396 chromevox_path,
391 FROM_HERE, 397 extension_misc::kChromeVoxExtensionId,
392 base::Bind(&LoadManifestOnFileThread, chromevox_path, manifest_filename), 398 done_cb);
393 base::Bind(&ComponentLoader::AddChromeVoxExtensionWithManifest,
394 weak_factory_.GetWeakPtr(),
395 chromevox_path,
396 done_cb));
397 } 399 }
398 400
399 void ComponentLoader::AddChromeVoxExtensionWithManifest( 401 void ComponentLoader::AddChromeOsSpeechSynthesisExtension() {
400 const base::FilePath& chromevox_path, 402 const base::FilePath::CharType* manifest_filename =
401 const base::Closure& done_cb, 403 IsNormalSession() ? extensions::kManifestFilename
402 scoped_ptr<base::DictionaryValue> manifest) { 404 : extension_misc::kGuestManifestFilename;
403 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 405 AddWithManifestFile(
404 std::string extension_id = Add(manifest.release(), chromevox_path); 406 manifest_filename,
405 CHECK_EQ(extension_misc::kChromeVoxExtensionId, extension_id); 407 base::FilePath(extension_misc::kSpeechSynthesisExtensionPath),
406 if (!done_cb.is_null()) 408 extension_misc::kSpeechSynthesisExtensionId,
407 done_cb.Run(); 409 base::Bind(&ComponentLoader::EnableFileSystemInGuestMode,
408 } 410 weak_factory_.GetWeakPtr(),
409 411 extension_misc::kChromeVoxExtensionId));
410 std::string ComponentLoader::AddChromeOsSpeechSynthesisExtension() {
411 int idr = IsNormalSession() ? IDR_SPEECH_SYNTHESIS_MANIFEST
412 : IDR_SPEECH_SYNTHESIS_GUEST_MANIFEST;
413 std::string id = Add(idr,
414 base::FilePath(extension_misc::kSpeechSynthesisExtensionPath));
415 EnableFileSystemInGuestMode(id);
416 return id;
417 } 412 }
418 #endif 413 #endif
419 414
420 void ComponentLoader::AddWithNameAndDescription( 415 void ComponentLoader::AddWithNameAndDescription(
421 int manifest_resource_id, 416 int manifest_resource_id,
422 const base::FilePath& root_directory, 417 const base::FilePath& root_directory,
423 int name_string_id, 418 int name_string_id,
424 int description_string_id) { 419 int description_string_id) {
425 std::string manifest_contents = 420 std::string manifest_contents =
426 ResourceBundle::GetSharedInstance().GetRawDataResource( 421 ResourceBundle::GetSharedInstance().GetRawDataResource(
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 GURL site = content::SiteInstance::GetSiteForURL( 682 GURL site = content::SiteInstance::GetSiteForURL(
688 off_the_record_context, Extension::GetBaseURLFromExtensionId(id)); 683 off_the_record_context, Extension::GetBaseURLFromExtensionId(id));
689 storage::FileSystemContext* file_system_context = 684 storage::FileSystemContext* file_system_context =
690 content::BrowserContext::GetStoragePartitionForSite( 685 content::BrowserContext::GetStoragePartitionForSite(
691 off_the_record_context, site)->GetFileSystemContext(); 686 off_the_record_context, site)->GetFileSystemContext();
692 file_system_context->EnableTemporaryFileSystemInIncognito(); 687 file_system_context->EnableTemporaryFileSystemInIncognito();
693 } 688 }
694 #endif 689 #endif
695 } 690 }
696 691
692 #if defined(OS_CHROMEOS)
693 void ComponentLoader::AddWithManifestFile(
694 const base::FilePath::CharType* manifest_filename,
695 const base::FilePath& root_directory,
696 const char* extension_id,
697 const base::Closure& done_cb) {
698 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
699 BrowserThread::PostTaskAndReplyWithResult(
700 BrowserThread::FILE,
701 FROM_HERE,
702 base::Bind(&LoadManifestOnFileThread, root_directory, manifest_filename),
703 base::Bind(&ComponentLoader::FinishAddWithManifestFile,
704 weak_factory_.GetWeakPtr(),
705 root_directory,
706 extension_id,
707 done_cb));
708 }
709
710 void ComponentLoader::FinishAddWithManifestFile(
711 const base::FilePath& root_directory,
712 const char* extension_id,
713 const base::Closure& done_cb,
714 scoped_ptr<base::DictionaryValue> manifest) {
715 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
716 if (!manifest)
717 return; // Error already logged.
718 std::string actual_extension_id = Add(manifest.release(), root_directory);
719 CHECK_EQ(extension_id, actual_extension_id);
720 if (!done_cb.is_null())
721 done_cb.Run();
722 }
723 #endif
724
697 } // namespace extensions 725 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698