#include "base/command_line.h"
#include "base/file_util.h"
#include "content/public/browser/render_process_host.h"
-#include "net/base/net_util.h"
+#include "net/base/filename_util.h"
#include "xwalk/application/browser/application.h"
-#include "xwalk/application/browser/application_event_manager.h"
#include "xwalk/application/browser/application_service.h"
-#include "xwalk/application/browser/application_storage.h"
-#include "xwalk/application/common/event_names.h"
-#include "xwalk/application/extension/application_event_extension.h"
+#include "xwalk/application/common/application_storage.h"
+#include "xwalk/application/common/application_manifest_constants.h"
+#include "xwalk/application/common/id_util.h"
#include "xwalk/application/extension/application_runtime_extension.h"
+#include "xwalk/application/extension/application_widget_extension.h"
#include "xwalk/runtime/browser/runtime_context.h"
#include "xwalk/runtime/common/xwalk_switches.h"
ApplicationSystem::ApplicationSystem(RuntimeContext* runtime_context)
: runtime_context_(runtime_context),
application_storage_(new ApplicationStorage(runtime_context->GetPath())),
- event_manager_(new ApplicationEventManager()),
application_service_(new ApplicationService(
runtime_context,
- application_storage_.get(),
- event_manager_.get())) {}
+ application_storage_.get())) {}
ApplicationSystem::~ApplicationSystem() {
}
return app_system.Pass();
}
-bool ApplicationSystem::HandleApplicationManagementCommands(
- const CommandLine& cmd_line, const GURL& url,
- bool& run_default_message_loop) {
- run_default_message_loop = false;
- if (cmd_line.HasSwitch(switches::kListApplications)) {
- const ApplicationData::ApplicationDataMap& apps =
- application_storage_->GetInstalledApplications();
- LOG(INFO) << "Application ID Application Name";
- LOG(INFO) << "-----------------------------------------------------";
- ApplicationData::ApplicationDataMap::const_iterator it;
- for (it = apps.begin(); it != apps.end(); ++it)
- LOG(INFO) << it->first << " " << it->second->Name();
- LOG(INFO) << "-----------------------------------------------------";
- return true;
- }
-
- if (cmd_line.HasSwitch(switches::kUninstall)) {
- const CommandLine::StringVector& args = cmd_line.GetArgs();
- if (args.empty())
- return false;
-
- std::string app_id = std::string(args[0].begin(), args[0].end());
- if (!ApplicationData::IsIDValid(app_id))
- return false;
-
- if (application_service_->Uninstall(app_id)) {
- LOG(INFO) << "[OK] Application uninstalled successfully: " << app_id;
- } else {
- LOG(ERROR) << "[ERR] An error occurred when uninstalling application "
- << app_id;
- }
- return true;
- }
-
- if (cmd_line.HasSwitch(switches::kInstall)) {
- base::FilePath path;
- if (!net::FileURLToFilePath(url, &path))
- return false;
-
- if (!base::PathExists(path))
- return false;
-
- std::string app_id;
- if (application_service_->Install(path, &app_id)) {
- LOG(INFO) << "[OK] Application installed: " << app_id;
- if (application_storage_->GetApplicationData(app_id)->HasMainDocument())
- run_default_message_loop = true;
- } else {
- LOG(ERROR) << "[ERR] Application install failure: " << path.value();
- }
- return true;
- }
+template <typename T>
+bool ApplicationSystem::LaunchWithCommandLineParam(
+ const T& param, const base::CommandLine& cmd_line) {
+ Application::LaunchParams launch_params;
+ launch_params.force_fullscreen = cmd_line.HasSwitch(switches::kFullscreen);
- run_default_message_loop = true;
- return false;
+ return application_service_->Launch(param, launch_params);
}
-template <typename T>
-bool ApplicationSystem::LaunchWithCommandLineParam(const T& param) {
- scoped_refptr<Event> event = Event::CreateEvent(
- kOnLaunched, scoped_ptr<base::ListValue>(new base::ListValue));
- if (Application* application = application_service_->Launch(param)) {
- event_manager_->SendEvent(application->id(), event);
- return true;
+// Launch an application created from arbitrary url.
+// FIXME: This application should have the same strict permissions
+// as common browser apps.
+template <>
+bool ApplicationSystem::LaunchWithCommandLineParam<GURL>(
+ const GURL& url, const base::CommandLine& cmd_line) {
+ std::string error;
+ scoped_refptr<ApplicationData> application_data =
+ ApplicationData::Create(url, &error);
+ if (!application_data) {
+ LOG(ERROR) << "Error occurred while trying to launch application: "
+ << error;
+ return false;
}
- return false;
-}
-template <>
-bool ApplicationSystem::LaunchWithCommandLineParam<GURL>(const GURL& url) {
- return !!application_service_->Launch(url);
+ Application::LaunchParams launch_params;
+ launch_params.force_fullscreen = cmd_line.HasSwitch(switches::kFullscreen);
+ launch_params.entry_points = Application::URLKey;
+
+ return !!application_service_->Launch(application_data, launch_params);
}
bool ApplicationSystem::LaunchFromCommandLine(
- const CommandLine& cmd_line, const GURL& url,
- bool& run_default_message_loop) {
- // On Tizen, applications are launched by a symbolic link named like the
- // application ID.
- // FIXME(cmarcelo): Remove when we move to a separate launcher on Tizen.
-#if defined(OS_TIZEN_MOBILE)
- std::string command_name = cmd_line.GetProgram().BaseName().MaybeAsASCII();
- if (ApplicationData::IsIDValid(command_name)) {
- run_default_message_loop = LaunchWithCommandLineParam(command_name);
- return true;
- }
-#endif
+ const base::CommandLine& cmd_line, const GURL& url,
+ bool& run_default_message_loop) { // NOLINT
// Handles raw app_id passed as first non-switch argument.
- const CommandLine::StringVector& args = cmd_line.GetArgs();
+ const base::CommandLine::StringVector& args = cmd_line.GetArgs();
if (!args.empty()) {
std::string app_id = std::string(args[0].begin(), args[0].end());
- if (ApplicationData::IsIDValid(app_id)) {
- run_default_message_loop = LaunchWithCommandLineParam(app_id);
+ if (IsValidApplicationID(app_id)) {
+ run_default_message_loop = LaunchWithCommandLineParam(app_id, cmd_line);
return true;
}
}
if (url.SchemeIsFile() &&
net::FileURLToFilePath(url, &path) &&
base::DirectoryExists(path)) { // Handles local directory.
- run_default_message_loop = LaunchWithCommandLineParam(path);
+ run_default_message_loop = LaunchWithCommandLineParam(path, cmd_line);
} else { // Handles external URL.
- run_default_message_loop = LaunchWithCommandLineParam(url);
+ run_default_message_loop = LaunchWithCommandLineParam(url, cmd_line);
}
return true;
return; // We might be in browser mode.
extensions->push_back(new ApplicationRuntimeExtension(application));
- extensions->push_back(new ApplicationEventExtension(
- event_manager_.get(), application_storage_.get(), application));
+ extensions->push_back(new ApplicationWidgetExtension(application));
}
} // namespace application