Upstream version 11.39.256.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
10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/observer_list.h"
14 #include "xwalk/application/browser/application.h"
15 #include "xwalk/application/common/permission_policy_manager.h"
16 #include "xwalk/application/common/application_data.h"
17
18 namespace xwalk {
19
20 class XWalkBrowserContext;
21
22 namespace application {
23
24 // The application service manages launch and termination of the applications.
25 class ApplicationService : public Application::Observer {
26  public:
27   // Client code may use this class (and register with AddObserver below) to
28   // keep track of applications life cycle.
29   class Observer {
30    public:
31     virtual void DidLaunchApplication(Application* app) {}
32     virtual void WillDestroyApplication(Application* app) {}
33    protected:
34     virtual ~Observer() {}
35   };
36
37   virtual ~ApplicationService();
38
39   static scoped_ptr<ApplicationService> Create(
40     XWalkBrowserContext* browser_context);
41
42   // Launch an unpacked application using path to the manifest file
43   // of an unpacked application.
44   Application* LaunchFromManifestPath(
45       const base::FilePath& path, Manifest::Type manifest_type,
46       const Application::LaunchParams& params = Application::LaunchParams());
47
48   // Launch an application using path to its package file.
49   // Note: the given package is unpacked to a temporary folder,
50   // which is deleted after the application terminates.
51   Application* LaunchFromPackagePath(
52       const base::FilePath& path,
53       const Application::LaunchParams& params = Application::LaunchParams());
54
55   // Launch an application from an arbitrary URL.
56   // Creates a "dummy" application.
57   Application* LaunchHostedURL(
58       const GURL& url,
59       const Application::LaunchParams& params = Application::LaunchParams());
60
61   Application* GetApplicationByRenderHostID(int id) const;
62   Application* GetApplicationByID(const std::string& app_id) const;
63
64   const ScopedVector<Application>& active_applications() const {
65       return applications_; }
66
67   void AddObserver(Observer* observer);
68   void RemoveObserver(Observer* observer);
69
70   // Check whether application has permission to access API of extension.
71   void CheckAPIAccessControl(const std::string& app_id,
72       const std::string& extension_name,
73       const std::string& api_name, const PermissionCallback& callback);
74   // Register APIs implemented by extension. This method will be called
75   // when application register extensions.
76   // Parameter perm_table is a string which is a map between extension
77   // and it includes APIs. For example perm_table is like '{"bluetooth":
78   // ["read", "write", "management"]}'.
79   bool RegisterPermissions(const std::string& app_id,
80       const std::string& extension_name,
81       const std::string& perm_table);
82
83  protected:
84   explicit ApplicationService(XWalkBrowserContext* browser_context);
85
86   Application* Launch(scoped_refptr<ApplicationData> application_data,
87                       const Application::LaunchParams& launch_params);
88
89  private:
90   // Implementation of Application::Observer.
91   virtual void OnApplicationTerminated(Application* app) OVERRIDE;
92
93   XWalkBrowserContext* browser_context_;
94   ScopedVector<Application> applications_;
95   ObserverList<Observer> observers_;
96
97   DISALLOW_COPY_AND_ASSIGN(ApplicationService);
98 };
99
100 }  // namespace application
101 }  // namespace xwalk
102
103 #endif  // XWALK_APPLICATION_BROWSER_APPLICATION_SERVICE_H_