Implemented progressbar for web application
[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   void Exit();
57   void ProcessClosingPage();
58
59   std::string data_path() const { return app_data_path_; }
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 #ifdef PROFILE_MOBILE
74   virtual void OnLoadProgress(WebView* view, double persent);
75 #endif
76   virtual void OnLoadFinished(WebView* view);
77   virtual void OnRendered(WebView* view);
78   virtual void OnLanguageChanged();
79   virtual void OnLowMemory();
80   virtual void OnTimeTick(long time);
81   virtual void OnAmbientTick(long time);
82   virtual void OnAmbientChanged(bool ambient_mode);
83   virtual bool OnContextMenuDisabled(WebView* view);
84   virtual bool OnDidNavigation(WebView* view, const std::string& url);
85   virtual void OnNotificationPermissionRequest(
86       WebView* view, const std::string& url,
87       std::function<void(bool)> result_handler);
88   virtual void OnGeolocationPermissionRequest(
89       WebView* view, const std::string& url,
90       std::function<void(bool)> result_handler);
91   virtual void OnQuotaExceed(WebView* view, const std::string& url,
92                              std::function<void(bool)> result_handler);
93   virtual void OnAuthenticationRequest(
94       WebView* view, const std::string& url, const std::string& message,
95       std::function<void(bool submit, const std::string& id,
96                          const std::string& password)> result_handler);
97   virtual void OnCertificateAllowRequest(
98       WebView* view, const std::string& url, const std::string& pem,
99       std::function<void(bool allow)> result_handler);
100   virtual void OnUsermediaPermissionRequest(
101       WebView* view, const std::string& url,
102       std::function<void(bool)> result_handler);
103   virtual void OnSoftKeyboardChangeEvent(
104       WebView* view, SoftKeyboardChangeEventValue softkeyboard_value);
105 #ifdef ROTARY_EVENT_FEATURE_SUPPORT
106   virtual void OnRotaryEvent(
107       WebView* view, RotaryEventType type);
108 #endif  // ROTARY_EVENT_FEATURE_SUPPORT
109 #ifdef MANUAL_ROTATE_FEATURE_SUPPORT
110   virtual void OnRotatePrepared(WebView* view);
111 #endif // MANUAL_ROTATE_FEATURE_SUPPORT
112   static Eina_Bool CheckPluginSession(void* user_data);
113   static Eina_Bool ClosePageInExtendedMainLoop(void* user_data);
114   struct Timer
115   {
116     WebApplication* application;
117     Ecore_Timer* timer;
118   } main_loop, session_counter;
119
120  private:
121   bool Initialize();
122
123   void ClearViewStack();
124   void SendAppControlEvent();
125   void LaunchInspector(common::AppControl* appcontrol);
126   void SetupWebView(WebView* view);
127   void SetupWebViewCompatibilitySettings(WebView* view);
128   void RemoveWebViewFromStack(WebView* view);
129
130   void SetupTizenVersion();
131   bool tizenWebKitCompatibilityEnabled() const;
132   struct {
133       unsigned m_major;
134       unsigned m_minor;
135       unsigned m_release;
136       bool tizenWebKitCompatibilityEnabled() const { return (m_major && m_major < 3); }
137   } m_tizenCompatibilitySettings;
138
139   bool launched_;
140   bool debug_mode_;
141   bool verbose_mode_;
142   bool lang_changed_mode_;
143   bool is_terminate_called_;
144   bool is_close_page_called_;
145   Ewk_Context* ewk_context_;
146   bool has_ownership_of_ewk_context_;
147   NativeWindow* window_;
148   std::string appid_;
149   std::string app_data_path_;
150   common::ApplicationData* app_data_;
151   std::list<WebView*> view_stack_;
152   std::unique_ptr<SplashScreen> splash_screen_;
153   std::unique_ptr<common::LocaleManager> locale_manager_;
154   std::unique_ptr<common::ResourceManager> resource_manager_;
155   int security_model_version_;
156   std::string csp_rule_;
157   std::string csp_report_rule_;
158 };
159
160 }  // namespace runtime
161
162 #endif  // XWALK_RUNTIME_BROWSER_WEB_APPLICATION_H_