Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / extensions / shell / browser / shell_extension_system.cc
index 47db358..ef7bc57 100644 (file)
@@ -6,8 +6,8 @@
 
 #include <string>
 
-#include "base/file_util.h"
 #include "base/files/file_path.h"
+#include "base/files/file_util.h"
 #include "content/public/browser/browser_context.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/notification_details.h"
 #include "extensions/browser/info_map.h"
 #include "extensions/browser/lazy_background_task_queue.h"
 #include "extensions/browser/notification_types.h"
-#include "extensions/browser/process_manager.h"
 #include "extensions/browser/quota_service.h"
 #include "extensions/browser/runtime_data.h"
+#include "extensions/common/constants.h"
 #include "extensions/common/file_util.h"
-#include "extensions/shell/browser/api/shell/shell_api.h"
 
 using content::BrowserContext;
 using content::BrowserThread;
@@ -38,21 +37,20 @@ ShellExtensionSystem::ShellExtensionSystem(BrowserContext* browser_context)
 ShellExtensionSystem::~ShellExtensionSystem() {
 }
 
-bool ShellExtensionSystem::LoadApp(const base::FilePath& app_dir) {
+const Extension* ShellExtensionSystem::LoadApp(const base::FilePath& app_dir) {
   // app_shell only supports unpacked extensions.
   // NOTE: If you add packed extension support consider removing the flag
   // FOLLOW_SYMLINKS_ANYWHERE below. Packed extensions should not have symlinks.
   CHECK(base::DirectoryExists(app_dir)) << app_dir.AsUTF8Unsafe();
   int load_flags = Extension::FOLLOW_SYMLINKS_ANYWHERE;
   std::string load_error;
-  extension_ = file_util::LoadExtension(
+  scoped_refptr<Extension> extension = file_util::LoadExtension(
       app_dir, Manifest::COMMAND_LINE, load_flags, &load_error);
-  if (!extension_) {
+  if (!extension.get()) {
     LOG(ERROR) << "Loading extension at " << app_dir.value()
                << " failed with: " << load_error;
-    return false;
+    return nullptr;
   }
-  app_id_ = extension_->id();
 
   // TODO(jamescook): We may want to do some of these things here:
   // * Create a PermissionsUpdater.
@@ -61,29 +59,37 @@ bool ShellExtensionSystem::LoadApp(const base::FilePath& app_dir) {
   // * Call ExtensionPrefs::OnExtensionInstalled().
   // * Send NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED.
 
-  ExtensionRegistry::Get(browser_context_)->AddEnabled(extension_);
+  ExtensionRegistry::Get(browser_context_)->AddEnabled(extension.get());
 
-  RegisterExtensionWithRequestContexts(extension_);
+  RegisterExtensionWithRequestContexts(extension.get());
 
   content::NotificationService::current()->Notify(
       extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
       content::Source<BrowserContext>(browser_context_),
-      content::Details<const Extension>(extension_));
+      content::Details<const Extension>(extension.get()));
 
+  return extension.get();
+}
+
+void ShellExtensionSystem::Init() {
   // Inform the rest of the extensions system to start.
   ready_.Signal();
   content::NotificationService::current()->Notify(
       extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
       content::Source<BrowserContext>(browser_context_),
       content::NotificationService::NoDetails());
-  return true;
 }
 
-void ShellExtensionSystem::LaunchApp() {
+void ShellExtensionSystem::LaunchApp(const ExtensionId& extension_id) {
   // Send the onLaunched event.
-  DCHECK(extension_.get());
-  AppRuntimeEventRouter::DispatchOnLaunchedEvent(browser_context_,
-                                                 extension_.get());
+  DCHECK(ExtensionRegistry::Get(browser_context_)
+             ->enabled_extensions()
+             .Contains(extension_id));
+  const Extension* extension = ExtensionRegistry::Get(browser_context_)
+                                   ->enabled_extensions()
+                                   .GetByID(extension_id);
+  AppRuntimeEventRouter::DispatchOnLaunchedEvent(
+      browser_context_, extension, extensions::SOURCE_UNTRACKED);
 }
 
 void ShellExtensionSystem::Shutdown() {
@@ -96,7 +102,6 @@ void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) {
       new LazyBackgroundTaskQueue(browser_context_));
   event_router_.reset(
       new EventRouter(browser_context_, ExtensionPrefs::Get(browser_context_)));
-  process_manager_.reset(ProcessManager::Create(browser_context_));
   quota_service_.reset(new QuotaService);
 }
 
@@ -116,10 +121,6 @@ SharedUserScriptMaster* ShellExtensionSystem::shared_user_script_master() {
   return NULL;
 }
 
-ProcessManager* ShellExtensionSystem::process_manager() {
-  return process_manager_.get();
-}
-
 StateStore* ShellExtensionSystem::state_store() {
   return NULL;
 }
@@ -131,7 +132,7 @@ StateStore* ShellExtensionSystem::rules_store() {
 InfoMap* ShellExtensionSystem::info_map() {
   if (!info_map_.get())
     info_map_ = new InfoMap;
-  return info_map_;
+  return info_map_.get();
 }
 
 LazyBackgroundTaskQueue* ShellExtensionSystem::lazy_background_task_queue() {
@@ -142,14 +143,6 @@ EventRouter* ShellExtensionSystem::event_router() {
   return event_router_.get();
 }
 
-ExtensionWarningService* ShellExtensionSystem::warning_service() {
-  return NULL;
-}
-
-Blacklist* ShellExtensionSystem::blacklist() {
-  return NULL;
-}
-
 ErrorConsole* ShellExtensionSystem::error_console() {
   return NULL;
 }
@@ -189,8 +182,7 @@ ContentVerifier* ShellExtensionSystem::content_verifier() {
 
 scoped_ptr<ExtensionSet> ShellExtensionSystem::GetDependentExtensions(
     const Extension* extension) {
-  scoped_ptr<ExtensionSet> empty(new ExtensionSet());
-  return empty.PassAs<ExtensionSet>();
+  return make_scoped_ptr(new ExtensionSet());
 }
 
 DeclarativeUserScriptMaster*