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 #ifndef XWALK_APPLICATION_BROWSER_APPLICATION_H_
6 #define XWALK_APPLICATION_BROWSER_APPLICATION_H_
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_vector.h"
16 #include "base/observer_list.h"
17 #include "xwalk/application/browser/event_observer.h"
18 #include "xwalk/application/common/application_data.h"
19 #include "xwalk/runtime/browser/runtime.h"
25 namespace application {
27 class ApplicationHost;
30 // The Application class is representing an active (running) application.
31 // Application instances are owned by ApplicationService.
32 // ApplicationService will delete an Application instance when it is
34 // There's one-to-one correspondence between Application and Render Process
35 // Host, obtained from its "runtimes" (pages).
36 class Application : public Runtime::Observer {
38 virtual ~Application();
42 // Invoked when application is terminated - all its pages (runtimes)
44 virtual void OnApplicationTerminated(Application* app) {}
47 virtual ~Observer() {}
50 // Manifest keys that can be used as application entry points.
51 enum LaunchEntryPoint {
52 AppMainKey = 1 << 0, // app.main
53 LaunchLocalPathKey = 1 << 1, // app.launch.local_path
54 // NOTE: The following key is only used for "dummy" hosted apps,
55 // which can be using any arbitrary URL, incl. remote ones.
56 // For now this should be disabled for all other cases as this will
57 // require special care with permissions etc.
58 URLKey = 1 << 2, // url
59 Default = AppMainKey | LaunchLocalPathKey
61 typedef unsigned LaunchEntryPoints;
65 entry_points(Default) {}
67 LaunchEntryPoints entry_points;
70 // Closes all the application's runtimes (application pages).
71 // NOTE: ApplicationService deletes an Application instance
72 // immediately after its termination.
75 // Returns Runtime (application page) containing the application's
76 // 'main document'. The main document is the main entry point of
77 // the application to the system. This method will return 'NULL'
78 // if application has different entry point (local path manifest key).
79 // See http://anssiko.github.io/runtime/app-lifecycle.html#dfn-main-document
80 // The main document never has a visible window on its own.
81 Runtime* GetMainDocumentRuntime() const;
83 const std::set<Runtime*>& runtimes() const { return runtimes_; }
85 // Returns the unique application id which is used to distinguish the
86 // application amoung both running applications and installed ones
87 // (ApplicationData objects).
88 std::string id() const { return application_data_->ID(); }
89 bool HasMainDocument() const { return application_data_->HasMainDocument(); }
90 int GetRenderProcessHostID() const;
92 const ApplicationData* data() const { return application_data_; }
93 ApplicationData* data() { return application_data_; }
96 // Runtime::Observer implementation.
97 virtual void OnRuntimeAdded(Runtime* runtime) OVERRIDE;
98 virtual void OnRuntimeRemoved(Runtime* runtime) OVERRIDE;
100 // We enforce ApplicationService ownership.
101 friend class ApplicationService;
102 Application(scoped_refptr<ApplicationData> data,
103 RuntimeContext* context,
105 bool Launch(const LaunchParams& launch_params);
107 template<LaunchEntryPoint>
110 friend class FinishEventObserver;
111 void CloseMainDocument();
112 bool IsOnSuspendHandlerRegistered() const;
114 RuntimeContext* runtime_context_;
115 const scoped_refptr<ApplicationData> application_data_;
116 Runtime* main_runtime_;
117 std::set<Runtime*> runtimes_;
118 scoped_ptr<EventObserver> finish_observer_;
121 DISALLOW_COPY_AND_ASSIGN(Application);
124 } // namespace application
127 #endif // XWALK_APPLICATION_BROWSER_APPLICATION_H_