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

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

Issue 862183002: Ensure speech synthesis and ChromeVox run outside of normal user sessions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IsNormalSession() Created 5 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 14 matching lines...) Expand all
25 #include "content/public/browser/plugin_service.h" 25 #include "content/public/browser/plugin_service.h"
26 #include "extensions/common/extension.h" 26 #include "extensions/common/extension.h"
27 #include "extensions/common/extension_l10n_util.h" 27 #include "extensions/common/extension_l10n_util.h"
28 #include "extensions/common/file_util.h" 28 #include "extensions/common/file_util.h"
29 #include "extensions/common/manifest_constants.h" 29 #include "extensions/common/manifest_constants.h"
30 #include "grit/browser_resources.h" 30 #include "grit/browser_resources.h"
31 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/base/resource/resource_bundle.h" 32 #include "ui/base/resource/resource_bundle.h"
33 33
34 #if defined(OS_CHROMEOS) 34 #if defined(OS_CHROMEOS)
35 #include "components/user_manager/user_manager.h"
35 #include "grit/keyboard_resources.h" 36 #include "grit/keyboard_resources.h"
36 #include "ui/file_manager/grit/file_manager_resources.h" 37 #include "ui/file_manager/grit/file_manager_resources.h"
37 #include "ui/keyboard/keyboard_util.h" 38 #include "ui/keyboard/keyboard_util.h"
38 #endif 39 #endif
39 40
40 #if defined(GOOGLE_CHROME_BUILD) 41 #if defined(GOOGLE_CHROME_BUILD)
41 #include "chrome/browser/defaults.h" 42 #include "chrome/browser/defaults.h"
42 #endif 43 #endif
43 44
44 #if defined(OS_CHROMEOS) 45 #if defined(OS_CHROMEOS)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); 80 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
80 std::string error; 81 std::string error;
81 scoped_ptr<base::DictionaryValue> manifest( 82 scoped_ptr<base::DictionaryValue> manifest(
82 file_util::LoadManifest(chromevox_path, manifest_filename, &error)); 83 file_util::LoadManifest(chromevox_path, manifest_filename, &error));
83 CHECK(manifest) << error; 84 CHECK(manifest) << error;
84 bool localized = extension_l10n_util::LocalizeExtension( 85 bool localized = extension_l10n_util::LocalizeExtension(
85 chromevox_path, manifest.get(), &error); 86 chromevox_path, manifest.get(), &error);
86 CHECK(localized) << error; 87 CHECK(localized) << error;
87 return manifest.Pass(); 88 return manifest.Pass();
88 } 89 }
90
91 bool IsNormalSession() {
92 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
93 chromeos::switches::kGuestSession) &&
94 user_manager::UserManager::Get()->IsUserLoggedIn();
95 }
89 #endif // defined(OS_CHROMEOS) 96 #endif // defined(OS_CHROMEOS)
90 97
91 } // namespace 98 } // namespace
92 99
93 ComponentLoader::ComponentExtensionInfo::ComponentExtensionInfo( 100 ComponentLoader::ComponentExtensionInfo::ComponentExtensionInfo(
94 const base::DictionaryValue* manifest, const base::FilePath& directory) 101 const base::DictionaryValue* manifest, const base::FilePath& directory)
95 : manifest(manifest), 102 : manifest(manifest),
96 root_directory(directory) { 103 root_directory(directory) {
97 if (!root_directory.IsAbsolute()) { 104 if (!root_directory.IsAbsolute()) {
98 CHECK(PathService::Get(chrome::DIR_RESOURCES, &root_directory)); 105 CHECK(PathService::Get(chrome::DIR_RESOURCES, &root_directory));
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 #if defined(OS_CHROMEOS) 356 #if defined(OS_CHROMEOS)
350 void ComponentLoader::AddChromeVoxExtension( 357 void ComponentLoader::AddChromeVoxExtension(
351 const base::Closure& done_cb) { 358 const base::Closure& done_cb) {
352 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 359 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
353 base::FilePath resources_path; 360 base::FilePath resources_path;
354 PathService::Get(chrome::DIR_RESOURCES, &resources_path); 361 PathService::Get(chrome::DIR_RESOURCES, &resources_path);
355 362
356 base::FilePath chromevox_path = 363 base::FilePath chromevox_path =
357 resources_path.Append(extension_misc::kChromeVoxExtensionPath); 364 resources_path.Append(extension_misc::kChromeVoxExtensionPath);
358 365
359 const base::CommandLine* command_line =
360 base::CommandLine::ForCurrentProcess();
361 bool is_guest = command_line->HasSwitch(chromeos::switches::kGuestSession);
362 const char* manifest_filename = 366 const char* manifest_filename =
363 is_guest ? extension_misc::kChromeVoxGuestManifestFilename 367 IsNormalSession() ? extension_misc::kChromeVoxManifestFilename
364 : extension_misc::kChromeVoxManifestFilename; 368 : extension_misc::kChromeVoxGuestManifestFilename;
365 369
366 BrowserThread::PostTaskAndReplyWithResult( 370 BrowserThread::PostTaskAndReplyWithResult(
367 BrowserThread::FILE, 371 BrowserThread::FILE,
368 FROM_HERE, 372 FROM_HERE,
369 base::Bind(&LoadManifestOnFileThread, chromevox_path, manifest_filename), 373 base::Bind(&LoadManifestOnFileThread, chromevox_path, manifest_filename),
370 base::Bind(&ComponentLoader::AddChromeVoxExtensionWithManifest, 374 base::Bind(&ComponentLoader::AddChromeVoxExtensionWithManifest,
371 weak_factory_.GetWeakPtr(), 375 weak_factory_.GetWeakPtr(),
372 chromevox_path, 376 chromevox_path,
373 done_cb)); 377 done_cb));
374 } 378 }
375 379
376 void ComponentLoader::AddChromeVoxExtensionWithManifest( 380 void ComponentLoader::AddChromeVoxExtensionWithManifest(
377 const base::FilePath& chromevox_path, 381 const base::FilePath& chromevox_path,
378 const base::Closure& done_cb, 382 const base::Closure& done_cb,
379 scoped_ptr<base::DictionaryValue> manifest) { 383 scoped_ptr<base::DictionaryValue> manifest) {
380 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 384 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
381 std::string extension_id = Add(manifest.release(), chromevox_path); 385 std::string extension_id = Add(manifest.release(), chromevox_path);
382 CHECK_EQ(extension_misc::kChromeVoxExtensionId, extension_id); 386 CHECK_EQ(extension_misc::kChromeVoxExtensionId, extension_id);
383 if (!done_cb.is_null()) 387 if (!done_cb.is_null())
384 done_cb.Run(); 388 done_cb.Run();
385 } 389 }
386 390
387 std::string ComponentLoader::AddChromeOsSpeechSynthesisExtension() { 391 std::string ComponentLoader::AddChromeOsSpeechSynthesisExtension() {
388 const base::CommandLine* command_line = 392 int idr = IsNormalSession() ? IDR_SPEECH_SYNTHESIS_MANIFEST
389 base::CommandLine::ForCurrentProcess(); 393 : IDR_SPEECH_SYNTHESIS_GUEST_MANIFEST;
390 int idr = command_line->HasSwitch(chromeos::switches::kGuestSession) ?
391 IDR_SPEECH_SYNTHESIS_GUEST_MANIFEST : IDR_SPEECH_SYNTHESIS_MANIFEST;
392 std::string id = Add(idr, 394 std::string id = Add(idr,
393 base::FilePath(extension_misc::kSpeechSynthesisExtensionPath)); 395 base::FilePath(extension_misc::kSpeechSynthesisExtensionPath));
394 EnableFileSystemInGuestMode(id); 396 EnableFileSystemInGuestMode(id);
395 return id; 397 return id;
396 } 398 }
397 #endif 399 #endif
398 400
399 void ComponentLoader::AddWithNameAndDescription( 401 void ComponentLoader::AddWithNameAndDescription(
400 int manifest_resource_id, 402 int manifest_resource_id,
401 const base::FilePath& root_directory, 403 const base::FilePath& root_directory,
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 void ComponentLoader::UnloadComponent(ComponentExtensionInfo* component) { 640 void ComponentLoader::UnloadComponent(ComponentExtensionInfo* component) {
639 delete component->manifest; 641 delete component->manifest;
640 if (extension_service_->is_ready()) { 642 if (extension_service_->is_ready()) {
641 extension_service_-> 643 extension_service_->
642 RemoveComponentExtension(component->extension_id); 644 RemoveComponentExtension(component->extension_id);
643 } 645 }
644 } 646 }
645 647
646 void ComponentLoader::EnableFileSystemInGuestMode(const std::string& id) { 648 void ComponentLoader::EnableFileSystemInGuestMode(const std::string& id) {
647 #if defined(OS_CHROMEOS) 649 #if defined(OS_CHROMEOS)
648 const base::CommandLine* command_line = 650 if (!IsNormalSession()) {
649 base::CommandLine::ForCurrentProcess();
650 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) {
651 // TODO(dpolukhin): Hack to enable HTML5 temporary file system for 651 // TODO(dpolukhin): Hack to enable HTML5 temporary file system for
652 // the extension. Some component extensions don't work without temporary 652 // the extension. Some component extensions don't work without temporary
653 // file system access. Make sure temporary file system is enabled in the off 653 // file system access. Make sure temporary file system is enabled in the off
654 // the record browser context (as that is the one used in guest session). 654 // the record browser context (as that is the one used in guest session).
655 content::BrowserContext* off_the_record_context = 655 content::BrowserContext* off_the_record_context =
656 ExtensionsBrowserClient::Get()->GetOffTheRecordContext( 656 ExtensionsBrowserClient::Get()->GetOffTheRecordContext(
657 browser_context_); 657 browser_context_);
658 GURL site = content::SiteInstance::GetSiteForURL( 658 GURL site = content::SiteInstance::GetSiteForURL(
659 off_the_record_context, Extension::GetBaseURLFromExtensionId(id)); 659 off_the_record_context, Extension::GetBaseURLFromExtensionId(id));
660 storage::FileSystemContext* file_system_context = 660 storage::FileSystemContext* file_system_context =
661 content::BrowserContext::GetStoragePartitionForSite( 661 content::BrowserContext::GetStoragePartitionForSite(
662 off_the_record_context, site)->GetFileSystemContext(); 662 off_the_record_context, site)->GetFileSystemContext();
663 file_system_context->EnableTemporaryFileSystemInIncognito(); 663 file_system_context->EnableTemporaryFileSystemInIncognito();
664 } 664 }
665 #endif 665 #endif
666 } 666 }
667 667
668 } // namespace extensions 668 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698