Upstream version 8.36.169.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / browser / application_service.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_SERVICE_H_
6 #define XWALK_APPLICATION_BROWSER_APPLICATION_SERVICE_H_
7
8 #include <string>
9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/observer_list.h"
13 #include "xwalk/application/browser/application.h"
14 #include "xwalk/application/common/permission_policy_manager.h"
15 #include "xwalk/runtime/browser/runtime_context.h"
16 #include "xwalk/application/common/application_data.h"
17
18 namespace xwalk {
19
20 class RuntimeContext;
21
22 namespace application {
23
24 class ApplicationStorage;
25 class PackageInstaller;
26
27 // The application service manages install, uninstall and updates of
28 // applications.
29 class ApplicationService : public Application::Observer {
30  public:
31   // Client code may use this class (and register with AddObserver below) to
32   // keep track of [un]installation of applications.
33   class Observer {
34    public:
35     // When we change the application locale, we might get a new name in
36     // the new locale.
37     virtual void OnApplicationNameChanged(const std::string& app_id,
38                                           const std::string& app_name) {}
39
40     virtual void DidLaunchApplication(Application* app) {}
41     virtual void WillDestroyApplication(Application* app) {}
42    protected:
43     virtual ~Observer() {}
44   };
45
46   ApplicationService(RuntimeContext* runtime_context,
47                      ApplicationStorage* app_storage);
48   virtual ~ApplicationService();
49
50   void ChangeLocale(const std::string& locale);
51
52   Application* Launch(scoped_refptr<ApplicationData> application_data,
53                       const Application::LaunchParams& launch_params);
54   // Launch an installed application using application id.
55   Application* Launch(
56       const std::string& id,
57       const Application::LaunchParams& params = Application::LaunchParams());
58   // Launch an unpacked application using path to a local directory which
59   // contains manifest file.
60   Application* Launch(
61       const base::FilePath& path,
62       const Application::LaunchParams& params = Application::LaunchParams());
63
64   Application* GetApplicationByRenderHostID(int id) const;
65   Application* GetApplicationByID(const std::string& app_id) const;
66
67   const ScopedVector<Application>& active_applications() const {
68       return applications_; }
69
70   void AddObserver(Observer* observer);
71   void RemoveObserver(Observer* observer);
72
73   // Check whether application has permission to access API of extension.
74   void CheckAPIAccessControl(const std::string& app_id,
75       const std::string& extension_name,
76       const std::string& api_name, const PermissionCallback& callback);
77   // Register APIs implemented by extension. This method will be called
78   // when application register extensions.
79   // Parameter perm_table is a string which is a map between extension
80   // and it includes APIs. For example perm_table is like '{"bluetooth":
81   // ["read", "write", "management"]}'.
82   bool RegisterPermissions(const std::string& app_id,
83       const std::string& extension_name,
84       const std::string& perm_table);
85
86  private:
87   // Implementation of Application::Observer.
88   virtual void OnApplicationTerminated(Application* app) OVERRIDE;
89
90   xwalk::RuntimeContext* runtime_context_;
91   ApplicationStorage* application_storage_;
92   ScopedVector<Application> applications_;
93   ObserverList<Observer> observers_;
94
95   DISALLOW_COPY_AND_ASSIGN(ApplicationService);
96 };
97
98 }  // namespace application
99 }  // namespace xwalk
100
101 #endif  // XWALK_APPLICATION_BROWSER_APPLICATION_SERVICE_H_