Fix the terminate routine to avoid deadlock in ewk_shutdown
[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 class SplashScreen;
39
40 class WebApplication : public WebView::EventListener {
41  public:
42   WebApplication(NativeWindow* window,
43                  common::ApplicationData* app_data);
44   WebApplication(NativeWindow* window,
45                  common::ApplicationData* app_data,
46                  Ewk_Context* context);
47   virtual ~WebApplication();
48
49   void AppControl(std::unique_ptr<common::AppControl> appcontrol);
50   void Launch(std::unique_ptr<common::AppControl> appcontrol);
51   void Resume();
52   void Suspend();
53   void Terminate();
54
55   std::string data_path() const { return app_data_path_; }
56   void set_terminator(std::function<void(void)> terminator) {
57     terminator_ = terminator;
58   }
59   bool launched() const { return launched_; }
60   std::list<WebView*> view_stack() const { return view_stack_; }
61
62   virtual void OnCreatedNewWebView(WebView* view, WebView* new_view);
63   virtual void OnClosedWebView(WebView* view);
64   virtual void OnReceivedWrtMessage(WebView* view,
65                                     Ewk_IPC_Wrt_Message_Data* msg);
66   virtual void OnOrientationLock(
67       WebView* view, bool lock,
68       NativeWindow::ScreenOrientation preferred_rotation);
69   virtual void OnHardwareKey(WebView* view, const std::string& keyname);
70   virtual void OnConsoleMessage(const std::string& msg, int level);
71   virtual void OnLoadStart(WebView* view);
72   virtual void OnLoadFinished(WebView* view);
73   virtual void OnRendered(WebView* view);
74   virtual void OnLanguageChanged();
75   virtual void OnLowMemory();
76   virtual void OnTimeTick(long time);
77   virtual void OnAmbientTick(long time);
78   virtual void OnAmbientChanged(bool ambient_mode);
79   virtual bool OnContextMenuDisabled(WebView* view);
80   virtual bool OnDidNavigation(WebView* view, const std::string& url);
81   virtual void OnNotificationPermissionRequest(
82       WebView* view, const std::string& url,
83       std::function<void(bool)> result_handler);
84   virtual void OnGeolocationPermissionRequest(
85       WebView* view, const std::string& url,
86       std::function<void(bool)> result_handler);
87   virtual void OnQuotaExceed(WebView* view, const std::string& url,
88                              std::function<void(bool)> result_handler);
89   virtual void OnAuthenticationRequest(
90       WebView* view, const std::string& url, const std::string& message,
91       std::function<void(bool submit, const std::string& id,
92                          const std::string& password)> result_handler);
93   virtual void OnCertificateAllowRequest(
94       WebView* view, const std::string& url, const std::string& pem,
95       std::function<void(bool allow)> result_handler);
96   virtual void OnUsermediaPermissionRequest(
97       WebView* view, const std::string& url,
98       std::function<void(bool)> result_handler);
99   virtual void OnSoftKeyboardChangeEvent(
100       WebView* view, SoftKeyboardChangeEventValue softkeyboard_value);
101 #ifdef ROTARY_EVENT_FEATURE_SUPPORT
102   virtual void OnRotaryEvent(
103       WebView* view, RotaryEventType type);
104 #endif  // ROTARY_EVENT_FEATURE_SUPPORT
105 #ifdef MANUAL_ROTATE_FEATURE_SUPPORT
106   virtual void OnRotatePrepared(WebView* view);
107 #endif // MANUAL_ROTATE_FEATURE_SUPPORT
108
109  private:
110   bool Initialize();
111
112   void ClearViewStack();
113   void SendAppControlEvent();
114   void LaunchInspector(common::AppControl* appcontrol);
115   void SetupWebView(WebView* view);
116   void SetupWebViewTizenApplicationInfo(WebView* view);
117   void RemoveWebViewFromStack(WebView* view);
118
119   bool launched_;
120   bool debug_mode_;
121   bool verbose_mode_;
122   bool lang_changed_mode_;
123   Ewk_Context* ewk_context_;
124   bool has_ownership_of_ewk_context_;
125   bool is_terminated_by_callback_;
126   NativeWindow* window_;
127   std::string appid_;
128   std::string app_data_path_;
129   common::ApplicationData* app_data_;
130   std::list<WebView*> view_stack_;
131   std::unique_ptr<SplashScreen> splash_screen_;
132   std::unique_ptr<common::LocaleManager> locale_manager_;
133   std::unique_ptr<common::ResourceManager> resource_manager_;
134   std::function<void(void)> terminator_;
135   int security_model_version_;
136   std::string csp_rule_;
137   std::string csp_report_rule_;
138 };
139
140 }  // namespace runtime
141
142 #endif  // XWALK_RUNTIME_BROWSER_WEB_APPLICATION_H_