Upstream version 9.38.204.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / browser / application_system.h
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.
4
5 #ifndef XWALK_APPLICATION_BROWSER_APPLICATION_SYSTEM_H_
6 #define XWALK_APPLICATION_BROWSER_APPLICATION_SYSTEM_H_
7
8 #include <map>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "xwalk/extensions/common/xwalk_extension_vector.h"
13
14 class GURL;
15
16 namespace base {
17 class CommandLine;
18 }
19
20 namespace content {
21 class RenderProcessHost;
22 }
23
24 namespace xwalk {
25 class RuntimeContext;
26 }
27
28 namespace xwalk {
29 namespace application {
30
31 class ApplicationService;
32
33 // The ApplicationSystem manages the creation and destruction of services which
34 // related to applications' runtime model.
35 // There's one-to-one correspondence between ApplicationSystem and
36 // RuntimeContext.
37 class ApplicationSystem {
38  public:
39   virtual ~ApplicationSystem();
40
41   static scoped_ptr<ApplicationSystem> Create(RuntimeContext* runtime_context);
42
43   // The ApplicationService is created at startup.
44   ApplicationService* application_service() {
45     return application_service_.get();
46   }
47
48   // Launches an application based on the given command line, there are
49   // different ways to inform which application should be launched
50   //
51   // (1) app_id from the binary name (used in Tizen);
52   // (2) app_id passed in the command line (used in Tizen);
53   // (3) launching a directory that contains an extracted package.
54   // (4) launching from the path to the packaged application file.
55   //
56   // The parameter `url` contains the current URL Crosswalk is considering to
57   // load, and the output parameter `run_default_message_loop` controls whether
58   // Crosswalk should run the mainloop or not.
59   //
60   // A return value of true indicates that ApplicationSystem handled the command
61   // line, so the caller shouldn't try to load the url by itself.
62   bool LaunchFromCommandLine(const base::CommandLine& cmd_line,
63                              const GURL& url,
64                              bool& run_default_message_loop_);  // NOLINT
65
66   void CreateExtensions(content::RenderProcessHost* host,
67                         extensions::XWalkExtensionVector* extensions);
68
69  protected:
70   explicit ApplicationSystem(RuntimeContext* runtime_context);
71
72  private:
73   // Note: initialization order matters.
74   RuntimeContext* runtime_context_;
75   scoped_ptr<ApplicationService> application_service_;
76
77   DISALLOW_COPY_AND_ASSIGN(ApplicationSystem);
78 };
79
80 }  // namespace application
81 }  // namespace xwalk
82
83 #endif  // XWALK_APPLICATION_BROWSER_APPLICATION_SYSTEM_H_