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_SERVICE_H_
6 #define XWALK_APPLICATION_BROWSER_APPLICATION_SERVICE_H_
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"
20 class XWalkBrowserContext;
22 namespace application {
24 // The application service manages launch and termination of the applications.
25 class ApplicationService : public Application::Observer {
27 // Client code may use this class (and register with AddObserver below) to
28 // keep track of applications life cycle.
31 virtual void DidLaunchApplication(Application* app) {}
32 virtual void WillDestroyApplication(Application* app) {}
34 virtual ~Observer() {}
37 virtual ~ApplicationService();
39 static scoped_ptr<ApplicationService> Create(
40 XWalkBrowserContext* browser_context);
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());
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());
55 // Launch an application from an arbitrary URL.
56 // Creates a "dummy" application.
57 Application* LaunchHostedURL(
59 const Application::LaunchParams& params = Application::LaunchParams());
61 Application* GetApplicationByRenderHostID(int id) const;
62 Application* GetApplicationByID(const std::string& app_id) const;
64 const ScopedVector<Application>& active_applications() const {
65 return applications_; }
67 void AddObserver(Observer* observer);
68 void RemoveObserver(Observer* observer);
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);
84 explicit ApplicationService(XWalkBrowserContext* browser_context);
86 Application* Launch(scoped_refptr<ApplicationData> application_data,
87 const Application::LaunchParams& launch_params);
90 // Implementation of Application::Observer.
91 virtual void OnApplicationTerminated(Application* app) OVERRIDE;
93 XWalkBrowserContext* browser_context_;
94 ScopedVector<Application> applications_;
95 ObserverList<Observer> observers_;
97 DISALLOW_COPY_AND_ASSIGN(ApplicationService);
100 } // namespace application
103 #endif // XWALK_APPLICATION_BROWSER_APPLICATION_SERVICE_H_