1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "xwalk/application/browser/application_system.h"
8 #include "base/command_line.h"
9 #include "base/files/file_util.h"
10 #include "content/public/browser/render_process_host.h"
11 #include "content/public/common/content_switches.h"
12 #include "net/base/filename_util.h"
13 #include "xwalk/application/browser/application.h"
14 #include "xwalk/application/browser/application_service.h"
15 #include "xwalk/application/common/application_manifest_constants.h"
16 #include "xwalk/application/common/id_util.h"
17 #include "xwalk/application/extension/application_runtime_extension.h"
18 #include "xwalk/application/extension/application_widget_extension.h"
19 #include "xwalk/runtime/browser/xwalk_browser_context.h"
20 #include "xwalk/runtime/common/xwalk_switches.h"
23 #include "xwalk/application/browser/application_system_linux.h"
27 #include "xwalk/application/browser/application_service_tizen.h"
31 namespace application {
33 ApplicationSystem::ApplicationSystem(XWalkBrowserContext* browser_context)
34 : browser_context_(browser_context),
35 application_service_(ApplicationService::Create(
38 ApplicationSystem::~ApplicationSystem() {
42 scoped_ptr<ApplicationSystem> ApplicationSystem::Create(
43 XWalkBrowserContext* browser_context) {
44 scoped_ptr<ApplicationSystem> app_system;
46 app_system.reset(new ApplicationSystemLinux(browser_context));
48 app_system.reset(new ApplicationSystem(browser_context));
50 return app_system.Pass();
55 Application::LaunchParams launch_params(
56 const base::CommandLine& cmd_line) {
57 Application::LaunchParams params = {
59 cmd_line.HasSwitch(switches::kFullscreen),
60 cmd_line.HasSwitch(switches::kRemoteDebuggingPort)};
66 bool ApplicationSystem::LaunchFromCommandLine(
67 const base::CommandLine& cmd_line, const GURL& url,
68 bool& run_default_message_loop) { // NOLINT
71 // Handles raw app_id passed as first non-switch argument.
72 const base::CommandLine::StringVector& args = cmd_line.GetArgs();
74 std::string app_id = std::string(args[0].begin(), args[0].end());
75 if (IsValidApplicationID(app_id)) {
76 ApplicationServiceTizen* app_service_tizen =
77 ToApplicationServiceTizen(application_service_.get());
78 run_default_message_loop = app_service_tizen->LaunchFromAppID(
79 app_id, launch_params(cmd_line));
88 bool is_local = url.SchemeIsFile() && net::FileURLToFilePath(url, &path);
89 if (!is_local) { // Handles external URL.
90 run_default_message_loop = application_service_->LaunchHostedURL(
91 url, launch_params(cmd_line));
95 if (!base::PathExists(path))
98 if (path.MatchesExtension(FILE_PATH_LITERAL(".xpk")) ||
99 path.MatchesExtension(FILE_PATH_LITERAL(".wgt"))) {
100 run_default_message_loop = application_service_->LaunchFromPackagePath(
101 path, launch_params(cmd_line));
105 if (path.MatchesExtension(FILE_PATH_LITERAL(".json"))) {
106 run_default_message_loop = application_service_->LaunchFromManifestPath(
107 path, Manifest::TYPE_MANIFEST, launch_params(cmd_line));
111 if (path.MatchesExtension(FILE_PATH_LITERAL(".xml"))) {
112 run_default_message_loop = application_service_->LaunchFromManifestPath(
113 path, Manifest::TYPE_WIDGET, launch_params(cmd_line));
120 void ApplicationSystem::CreateExtensions(
121 content::RenderProcessHost* host,
122 extensions::XWalkExtensionVector* extensions) {
123 Application* application =
124 application_service_->GetApplicationByRenderHostID(host->GetID());
126 return; // We might be in browser mode.
128 extensions->push_back(new ApplicationRuntimeExtension(application));
129 extensions->push_back(new ApplicationWidgetExtension(application));
132 } // namespace application