Call terminator of WebApplication when receive tizen://exit
[platform/framework/web/crosswalk-tizen.git] / runtime / browser / web_application.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef XWALK_RUNTIME_BROWSER_WEB_APPLICATION_H_
18 #define XWALK_RUNTIME_BROWSER_WEB_APPLICATION_H_
19
20 #include <functional>
21 #include <list>
22 #include <memory>
23 #include <string>
24
25 #include "runtime/browser/web_view.h"
26
27 class Ewk_Context;
28
29 namespace common {
30 class AppControl;
31 class ApplicationData;
32 class LocaleManager;
33 class ResourceManager;
34 }  // namespace common
35
36 namespace runtime {
37 class NativeWindow;
38
39 class WebApplication : public WebView::EventListener {
40  public:
41   WebApplication(NativeWindow* window,
42                  std::unique_ptr<common::ApplicationData> app_data);
43   virtual ~WebApplication();
44
45   void AppControl(std::unique_ptr<common::AppControl> appcontrol);
46   void Launch(std::unique_ptr<common::AppControl> appcontrol);
47   void Resume();
48   void Suspend();
49   void Terminate();
50
51   std::string data_path() const { return app_data_path_; }
52   void set_terminator(std::function<void(void)> terminator)
53       { terminator_ = terminator; }
54   bool launched() const { return launched_; }
55
56   virtual void OnCreatedNewWebView(WebView* view, WebView* new_view);
57   virtual void OnClosedWebView(WebView * view);
58   virtual void OnReceivedWrtMessage(
59       WebView* view,
60       Ewk_IPC_Wrt_Message_Data* msg);
61   virtual void OnOrientationLock(
62       WebView* view,
63       bool lock,
64       NativeWindow::ScreenOrientation preferred_rotation);
65   virtual void OnHardwareKey(WebView* view, const std::string& keyname);
66   virtual void OnConsoleMessage(const std::string& msg, int level);
67   virtual void OnLoadStart(WebView* view);
68   virtual void OnLoadFinished(WebView* view);
69   virtual void OnRendered(WebView* view);
70   virtual void OnLanguageChanged();
71   virtual void OnLowMemory();
72   virtual bool OnContextMenuDisabled(WebView* view);
73   virtual bool OnDidNavigation(WebView* view, const std::string& url);
74   virtual void OnNotificationPermissionRequest(
75       WebView* view,
76       const std::string& url,
77       std::function<void(bool)> result_handler);
78   virtual void OnGeolocationPermissionRequest(
79       WebView* view,
80       const std::string& url,
81       std::function<void(bool)> result_handler);
82   virtual void OnQuotaExceed(
83       WebView* view,
84       const std::string& url,
85       std::function<void(bool)> result_handler);
86   virtual void OnAuthenticationRequest(
87       WebView* view,
88       const std::string& url,
89       const std::string& message,
90       std::function<void(bool submit,
91                          const std::string& id,
92                          const std::string& password)
93                    > result_handler);
94   virtual void OnCertificateAllowRequest(
95       WebView* view,
96       const std::string& url,
97       const std::string& pem,
98       std::function<void(bool allow)> result_handler);
99   virtual void OnUsermediaPermissionRequest(
100       WebView* view,
101       const std::string& url,
102       std::function<void(bool)> result_handler);
103
104  private:
105   bool Initialize();
106
107   void ClearViewStack();
108   void SendAppControlEvent();
109   void LaunchInspector(common::AppControl* appcontrol);
110   void SetupWebView(WebView* view);
111
112   bool launched_;
113   bool debug_mode_;
114   Ewk_Context* ewk_context_;
115   NativeWindow* window_;
116   std::string appid_;
117   std::string app_data_path_;
118   std::list<WebView*> view_stack_;
119   std::unique_ptr<common::LocaleManager> locale_manager_;
120   std::unique_ptr<common::ApplicationData> app_data_;
121   std::unique_ptr<common::ResourceManager> resource_manager_;
122   std::function<void(void)> terminator_;
123   int security_model_version_;
124   std::string csp_rule_;
125   std::string csp_report_rule_;
126 };
127
128 }  // namespace runtime
129
130 #endif  // XWALK_RUNTIME_BROWSER_WEB_APPLICATION_H_