Locate ewk_view_page_close in extended main loop
[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   void ClosePage();
56   std::string data_path() const { return app_data_path_; }
57   void set_terminator(std::function<void(void)> terminator) {
58     terminator_ = terminator;
59   }
60   bool launched() const { return launched_; }
61   std::list<WebView*> view_stack() const { return view_stack_; }
62
63   virtual void OnCreatedNewWebView(WebView* view, WebView* new_view);
64   virtual void OnClosedWebView(WebView* view);
65   virtual void OnReceivedWrtMessage(WebView* view,
66                                     Ewk_IPC_Wrt_Message_Data* msg);
67   virtual void OnOrientationLock(
68       WebView* view, bool lock,
69       NativeWindow::ScreenOrientation preferred_rotation);
70   virtual void OnHardwareKey(WebView* view, const std::string& keyname);
71   virtual void OnConsoleMessage(const std::string& msg, int level);
72   virtual void OnLoadStart(WebView* view);
73   virtual void OnLoadFinished(WebView* view);
74   virtual void OnRendered(WebView* view);
75   virtual void OnLanguageChanged();
76   virtual void OnLowMemory();
77   virtual void OnTimeTick(long time);
78   virtual void OnAmbientTick(long time);
79   virtual void OnAmbientChanged(bool ambient_mode);
80   virtual bool OnContextMenuDisabled(WebView* view);
81   virtual bool OnDidNavigation(WebView* view, const std::string& url);
82   virtual void OnNotificationPermissionRequest(
83       WebView* view, const std::string& url,
84       std::function<void(bool)> result_handler);
85   virtual void OnGeolocationPermissionRequest(
86       WebView* view, const std::string& url,
87       std::function<void(bool)> result_handler);
88   virtual void OnQuotaExceed(WebView* view, const std::string& url,
89                              std::function<void(bool)> result_handler);
90   virtual void OnAuthenticationRequest(
91       WebView* view, const std::string& url, const std::string& message,
92       std::function<void(bool submit, const std::string& id,
93                          const std::string& password)> result_handler);
94   virtual void OnCertificateAllowRequest(
95       WebView* view, const std::string& url, const std::string& pem,
96       std::function<void(bool allow)> result_handler);
97   virtual void OnUsermediaPermissionRequest(
98       WebView* view, const std::string& url,
99       std::function<void(bool)> result_handler);
100   virtual void OnSoftKeyboardChangeEvent(
101       WebView* view, SoftKeyboardChangeEventValue softkeyboard_value);
102 #ifdef ROTARY_EVENT_FEATURE_SUPPORT
103   virtual void OnRotaryEvent(
104       WebView* view, RotaryEventType type);
105 #endif  // ROTARY_EVENT_FEATURE_SUPPORT
106 #ifdef MANUAL_ROTATE_FEATURE_SUPPORT
107   virtual void OnRotatePrepared(WebView* view);
108 #endif // MANUAL_ROTATE_FEATURE_SUPPORT
109   static Eina_Bool CheckPluginSession(void* user_data);
110
111  private:
112   bool Initialize();
113
114   void ClearViewStack();
115   void SendAppControlEvent();
116   void LaunchInspector(common::AppControl* appcontrol);
117   void SetupWebView(WebView* view);
118   void SetupWebViewCompatibilitySettings(WebView* view);
119   void RemoveWebViewFromStack(WebView* view);
120
121   void SetupTizenVersion();
122   bool tizenWebKitCompatibilityEnabled() const;
123   struct {
124       unsigned m_major;
125       unsigned m_minor;
126       unsigned m_release;
127       bool tizenWebKitCompatibilityEnabled() const { return (m_major && m_major < 3); }
128   } m_tizenCompatibilitySettings;
129
130   bool launched_;
131   bool debug_mode_;
132   bool verbose_mode_;
133   bool lang_changed_mode_;
134   bool is_terminate_called_;
135   Ewk_Context* ewk_context_;
136   bool has_ownership_of_ewk_context_;
137   NativeWindow* window_;
138   std::string appid_;
139   std::string app_data_path_;
140   common::ApplicationData* app_data_;
141   std::list<WebView*> view_stack_;
142   std::unique_ptr<SplashScreen> splash_screen_;
143   std::unique_ptr<common::LocaleManager> locale_manager_;
144   std::unique_ptr<common::ResourceManager> resource_manager_;
145   std::function<void(void)> terminator_;
146   int security_model_version_;
147   std::string csp_rule_;
148   std::string csp_report_rule_;
149 };
150
151 }  // namespace runtime
152
153 #endif  // XWALK_RUNTIME_BROWSER_WEB_APPLICATION_H_