Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / component_loader.cc
index cae250a..7929617 100644 (file)
@@ -16,6 +16,7 @@
 #include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/extensions/extension_service.h"
 #include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/search/hotword_service_factory.h"
 #include "chrome/common/chrome_paths.h"
 #include "chrome/common/chrome_switches.h"
 #include "chrome/common/chrome_version_info.h"
@@ -32,7 +33,7 @@
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/base/resource/resource_bundle.h"
 
-#if defined(USE_AURA)
+#if defined(OS_CHROMEOS)
 #include "grit/keyboard_resources.h"
 #include "ui/keyboard/keyboard_util.h"
 #endif
@@ -288,12 +289,20 @@ void ComponentLoader::AddFileManagerExtension() {
 }
 
 void ComponentLoader::AddHangoutServicesExtension() {
-#if defined(GOOGLE_CHROME_BUILD)
+#if defined(GOOGLE_CHROME_BUILD) || defined(ENABLE_HANGOUT_SERVICES_EXTENSION)
   Add(IDR_HANGOUT_SERVICES_MANIFEST,
       base::FilePath(FILE_PATH_LITERAL("hangout_services")));
 #endif
 }
 
+void ComponentLoader::AddHotwordHelperExtension() {
+  Profile* profile = static_cast<Profile*>(browser_context_);
+  if (HotwordServiceFactory::IsHotwordAllowed(profile)) {
+    Add(IDR_HOTWORD_HELPER_MANIFEST,
+        base::FilePath(FILE_PATH_LITERAL("hotword_helper")));
+  }
+}
+
 void ComponentLoader::AddImageLoaderExtension() {
 #if defined(IMAGE_LOADER_EXTENSION)
 #ifndef NDEBUG
@@ -325,9 +334,21 @@ void ComponentLoader::AddNetworkSpeechSynthesisExtension() {
 }
 
 #if defined(OS_CHROMEOS)
-void ComponentLoader::AddChromeOsSpeechSynthesisExtension() {
-  Add(IDR_SPEECH_SYNTHESIS_MANIFEST,
+std::string ComponentLoader::AddChromeVoxExtension() {
+  const CommandLine* command_line = CommandLine::ForCurrentProcess();
+  int idr = command_line->HasSwitch(chromeos::switches::kGuestSession) ?
+      IDR_CHROMEVOX_GUEST_MANIFEST : IDR_CHROMEVOX_MANIFEST;
+  return Add(idr, base::FilePath(extension_misc::kChromeVoxExtensionPath));
+}
+
+std::string ComponentLoader::AddChromeOsSpeechSynthesisExtension() {
+  const CommandLine* command_line = CommandLine::ForCurrentProcess();
+  int idr = command_line->HasSwitch(chromeos::switches::kGuestSession) ?
+      IDR_SPEECH_SYNTHESIS_GUEST_MANIFEST : IDR_SPEECH_SYNTHESIS_MANIFEST;
+  std::string id = Add(idr,
       base::FilePath(extension_misc::kSpeechSynthesisExtensionPath));
+  EnableFileSystemInGuestMode(id);
+  return id;
 }
 #endif
 
@@ -358,9 +379,8 @@ void ComponentLoader::AddChromeApp() {
 }
 
 void ComponentLoader::AddKeyboardApp() {
-#if defined(USE_AURA)
-  if (keyboard::IsKeyboardEnabled())
-    Add(IDR_KEYBOARD_MANIFEST, base::FilePath(FILE_PATH_LITERAL("keyboard")));
+#if defined(OS_CHROMEOS)
+  Add(IDR_KEYBOARD_MANIFEST, base::FilePath(FILE_PATH_LITERAL("keyboard")));
 #endif
 }
 
@@ -425,6 +445,9 @@ void ComponentLoader::AddDefaultComponentExtensionsForKioskMode(
 
   // Component extensions needed for kiosk apps.
   AddFileManagerExtension();
+
+  // Add virtual keyboard.
+  AddKeyboardApp();
 }
 
 void ComponentLoader::AddDefaultComponentExtensionsWithBackgroundPages(
@@ -453,6 +476,7 @@ void ComponentLoader::AddDefaultComponentExtensionsWithBackgroundPages(
   if (!skip_session_components) {
     AddFileManagerExtension();
     AddHangoutServicesExtension();
+    AddHotwordHelperExtension();
     AddImageLoaderExtension();
 
 #if defined(ENABLE_SETTINGS_APP)
@@ -475,27 +499,9 @@ void ComponentLoader::AddDefaultComponentExtensionsWithBackgroundPages(
 #if defined(GOOGLE_CHROME_BUILD)
     if (!command_line->HasSwitch(
             chromeos::switches::kDisableQuickofficeComponentApp)) {
-      int manifest_id = IDR_QUICKOFFICE_EDITOR_MANIFEST;
-      if (command_line->HasSwitch(switches::kEnableQuickofficeViewing)) {
-        manifest_id = IDR_QUICKOFFICE_VIEWING_MANIFEST;
-      }
-      std::string id = Add(manifest_id, base::FilePath(
+      std::string id = Add(IDR_QUICKOFFICE_MANIFEST, base::FilePath(
           FILE_PATH_LITERAL("/usr/share/chromeos-assets/quick_office")));
-      if (command_line->HasSwitch(chromeos::switches::kGuestSession)) {
-        // TODO(dpolukhin): Hack to enable HTML5 temporary file system for
-        // Quickoffice. It doesn't work without temporary file system access.
-        // Make sure temporary file system is enabled in the off the record
-        // browser context (as that is the one used in guest session).
-        content::BrowserContext* off_the_record_context =
-            ExtensionsBrowserClient::Get()->GetOffTheRecordContext(
-                browser_context_);
-        GURL site = content::SiteInstance::GetSiteForURL(
-            off_the_record_context, Extension::GetBaseURLFromExtensionId(id));
-        fileapi::FileSystemContext* file_system_context =
-            content::BrowserContext::GetStoragePartitionForSite(
-                off_the_record_context, site)->GetFileSystemContext();
-        file_system_context->EnableTemporaryFileSystemInIncognito();
-      }
+      EnableFileSystemInGuestMode(id);
     }
 #endif  // defined(GOOGLE_CHROME_BUILD)
 
@@ -529,9 +535,7 @@ void ComponentLoader::AddDefaultComponentExtensionsWithBackgroundPages(
   // Load ChromeVox extension now if spoken feedback is enabled.
   if (chromeos::AccessibilityManager::Get() &&
       chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled()) {
-    base::FilePath path =
-        base::FilePath(extension_misc::kChromeVoxExtensionPath);
-    Add(IDR_CHROMEVOX_MANIFEST, path);
+    AddChromeVoxExtension();
   }
 #endif  // defined(OS_CHROMEOS)
 
@@ -576,10 +580,6 @@ void ComponentLoader::AddDefaultComponentExtensionsWithBackgroundPages(
 #endif
 #endif  // defined(GOOGLE_CHROME_BUILD)
 
-#if defined(OS_CHROMEOS)
-  AddChromeOsSpeechSynthesisExtension();
-#endif  // defined(OS_CHROMEOS)
-
 #if defined(ENABLE_PLUGINS)
   base::FilePath pdf_path;
   content::PluginService* plugin_service =
@@ -600,4 +600,25 @@ void ComponentLoader::UnloadComponent(ComponentExtensionInfo* component) {
   }
 }
 
+void ComponentLoader::EnableFileSystemInGuestMode(const std::string& id) {
+#if defined(OS_CHROMEOS)
+  const CommandLine* command_line = CommandLine::ForCurrentProcess();
+  if (command_line->HasSwitch(chromeos::switches::kGuestSession)) {
+    // TODO(dpolukhin): Hack to enable HTML5 temporary file system for
+    // the extension. Some component extensions don't work without temporary
+    // file system access. Make sure temporary file system is enabled in the off
+    // the record browser context (as that is the one used in guest session).
+    content::BrowserContext* off_the_record_context =
+        ExtensionsBrowserClient::Get()->GetOffTheRecordContext(
+            browser_context_);
+    GURL site = content::SiteInstance::GetSiteForURL(
+        off_the_record_context, Extension::GetBaseURLFromExtensionId(id));
+    fileapi::FileSystemContext* file_system_context =
+        content::BrowserContext::GetStoragePartitionForSite(
+            off_the_record_context, site)->GetFileSystemContext();
+    file_system_context->EnableTemporaryFileSystemInIncognito();
+  }
+#endif
+}
+
 }  // namespace extensions