Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 const base::Closure& done_cb) { | 352 const base::Closure& done_cb) { |
| 352 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 353 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 353 base::FilePath resources_path; | 354 base::FilePath resources_path; |
| 354 PathService::Get(chrome::DIR_RESOURCES, &resources_path); | 355 PathService::Get(chrome::DIR_RESOURCES, &resources_path); |
| 355 | 356 |
| 356 base::FilePath chromevox_path = | 357 base::FilePath chromevox_path = |
| 357 resources_path.Append(extension_misc::kChromeVoxExtensionPath); | 358 resources_path.Append(extension_misc::kChromeVoxExtensionPath); |
| 358 | 359 |
| 359 const base::CommandLine* command_line = | 360 const base::CommandLine* command_line = |
| 360 base::CommandLine::ForCurrentProcess(); | 361 base::CommandLine::ForCurrentProcess(); |
| 361 bool is_guest = command_line->HasSwitch(chromeos::switches::kGuestSession); | 362 bool is_normal_session = |
| 363 !command_line->HasSwitch(chromeos::switches::kGuestSession) && | |
| 364 user_manager::UserManager::Get()->IsUserLoggedIn(); | |
|
not at google - send to devlin
2015/01/21 23:57:52
How about adding an IsNormalSession() method and u
David Tseng
2015/01/22 00:49:38
Done.
| |
| 365 | |
| 362 const char* manifest_filename = | 366 const char* manifest_filename = |
| 363 is_guest ? extension_misc::kChromeVoxGuestManifestFilename | 367 is_normal_session ? 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 const base::CommandLine* command_line = |
| 389 base::CommandLine::ForCurrentProcess(); | 393 base::CommandLine::ForCurrentProcess(); |
| 390 int idr = command_line->HasSwitch(chromeos::switches::kGuestSession) ? | 394 int idr = user_manager::UserManager::Get()->IsUserLoggedIn() && |
| 391 IDR_SPEECH_SYNTHESIS_GUEST_MANIFEST : IDR_SPEECH_SYNTHESIS_MANIFEST; | 395 !command_line->HasSwitch(chromeos::switches::kGuestSession) |
| 396 ? IDR_SPEECH_SYNTHESIS_MANIFEST | |
| 397 : IDR_SPEECH_SYNTHESIS_GUEST_MANIFEST; | |
| 392 std::string id = Add(idr, | 398 std::string id = Add(idr, |
| 393 base::FilePath(extension_misc::kSpeechSynthesisExtensionPath)); | 399 base::FilePath(extension_misc::kSpeechSynthesisExtensionPath)); |
| 394 EnableFileSystemInGuestMode(id); | 400 EnableFileSystemInGuestMode(id); |
| 395 return id; | 401 return id; |
| 396 } | 402 } |
| 397 #endif | 403 #endif |
| 398 | 404 |
| 399 void ComponentLoader::AddWithNameAndDescription( | 405 void ComponentLoader::AddWithNameAndDescription( |
| 400 int manifest_resource_id, | 406 int manifest_resource_id, |
| 401 const base::FilePath& root_directory, | 407 const base::FilePath& root_directory, |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 if (extension_service_->is_ready()) { | 646 if (extension_service_->is_ready()) { |
| 641 extension_service_-> | 647 extension_service_-> |
| 642 RemoveComponentExtension(component->extension_id); | 648 RemoveComponentExtension(component->extension_id); |
| 643 } | 649 } |
| 644 } | 650 } |
| 645 | 651 |
| 646 void ComponentLoader::EnableFileSystemInGuestMode(const std::string& id) { | 652 void ComponentLoader::EnableFileSystemInGuestMode(const std::string& id) { |
| 647 #if defined(OS_CHROMEOS) | 653 #if defined(OS_CHROMEOS) |
| 648 const base::CommandLine* command_line = | 654 const base::CommandLine* command_line = |
| 649 base::CommandLine::ForCurrentProcess(); | 655 base::CommandLine::ForCurrentProcess(); |
| 650 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { | 656 if (command_line->HasSwitch(chromeos::switches::kGuestSession) || |
| 657 !user_manager::UserManager::Get()->IsUserLoggedIn()) { | |
| 651 // TODO(dpolukhin): Hack to enable HTML5 temporary file system for | 658 // TODO(dpolukhin): Hack to enable HTML5 temporary file system for |
| 652 // the extension. Some component extensions don't work without temporary | 659 // the extension. Some component extensions don't work without temporary |
| 653 // file system access. Make sure temporary file system is enabled in the off | 660 // 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). | 661 // the record browser context (as that is the one used in guest session). |
| 655 content::BrowserContext* off_the_record_context = | 662 content::BrowserContext* off_the_record_context = |
| 656 ExtensionsBrowserClient::Get()->GetOffTheRecordContext( | 663 ExtensionsBrowserClient::Get()->GetOffTheRecordContext( |
| 657 browser_context_); | 664 browser_context_); |
| 658 GURL site = content::SiteInstance::GetSiteForURL( | 665 GURL site = content::SiteInstance::GetSiteForURL( |
| 659 off_the_record_context, Extension::GetBaseURLFromExtensionId(id)); | 666 off_the_record_context, Extension::GetBaseURLFromExtensionId(id)); |
| 660 storage::FileSystemContext* file_system_context = | 667 storage::FileSystemContext* file_system_context = |
| 661 content::BrowserContext::GetStoragePartitionForSite( | 668 content::BrowserContext::GetStoragePartitionForSite( |
| 662 off_the_record_context, site)->GetFileSystemContext(); | 669 off_the_record_context, site)->GetFileSystemContext(); |
| 663 file_system_context->EnableTemporaryFileSystemInIncognito(); | 670 file_system_context->EnableTemporaryFileSystemInIncognito(); |
| 664 } | 671 } |
| 665 #endif | 672 #endif |
| 666 } | 673 } |
| 667 | 674 |
| 668 } // namespace extensions | 675 } // namespace extensions |
| OLD | NEW |