Change the chromium header from ewk_chromium.h to EWebKit.h/Ewebkit_internal.h
[platform/framework/web/crosswalk-tizen.git] / runtime / browser / web_view.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_VIEW_H_
18 #define XWALK_RUNTIME_BROWSER_WEB_VIEW_H_
19
20 #include <Elementary.h>
21 #include <EWebKit.h>
22 #include <EWebKit_internal.h>
23 #include <functional>
24 #include <string>
25
26 #include "runtime/browser/native_window.h"
27
28 class Ewk_Context;
29
30 namespace runtime {
31 class WebViewImpl;
32
33 enum class RotaryEventType {
34   CLOCKWISE,  // Rotary is rotated clockwise direction
35   COUNTER_CLOCKWISE  // Rotary is rotated counter clockwise direction
36 };
37
38 class SoftKeyboardChangeEventValue {
39  public:
40   std::string state;
41   int width;
42   int height;
43 };
44
45 class WebView {
46  public:
47   class EventListener {
48    public:
49     virtual void OnLoadStart(WebView* /*view*/) {}
50     virtual void OnLoadProgress(WebView* /*view*/, double /*persent*/ ) {}
51     virtual void OnLoadFinished(WebView* /*view*/) {}
52     virtual void OnRendered(WebView* /*view*/) {}
53     virtual void OnCreatedNewWebView(WebView* /*view*/,
54                                      WebView* /*new_view*/) {}
55     virtual void OnClosedWebView(WebView* /*view*/) {}
56     virtual void OnCrashed(WebView* /*view*/) {}
57     virtual bool OnDidOpenWindow(
58         WebView* /*view*/, const std::string& /*url*/) { return true; }
59     virtual bool OnDidNavigation(
60         WebView* /*view*/, const std::string& /*url*/) { return true; }
61     virtual void OnHardwareKey(
62         WebView* /*view*/, const std::string& /*keyname*/) {}
63     virtual void OnReceivedWrtMessage(
64         WebView* /*view*/, Ewk_IPC_Wrt_Message_Data* /*msg*/) {}
65     virtual void OnOrientationLock(
66         WebView* /*view*/,
67         bool /*lock*/,
68         NativeWindow::ScreenOrientation /*preferred_rotation*/) {}
69     virtual void OnConsoleMessage(const std::string& /*msg*/, int /*level*/) {}
70     virtual bool OnContextMenuDisabled(WebView* /*view*/) { return false; }
71
72     virtual void OnNotificationPermissionRequest(
73         WebView* /*view*/,
74         const std::string& /*url*/,
75         std::function<void(bool)> /*result_handler*/) {}
76     virtual void OnGeolocationPermissionRequest(
77         WebView* /*view*/,
78         const std::string& /*url*/,
79         std::function<void(bool)> /*result_handler*/) {}
80     virtual void OnQuotaExceed(
81         WebView* /*view*/,
82         const std::string& /*url*/,
83         std::function<void(bool)> /*result_handler*/) {}
84     virtual void OnAuthenticationRequest(
85         WebView* /*view*/,
86         const std::string& /*url*/,
87         const std::string& /*message*/,
88         std::function<void(bool /*submit*/,
89                            const std::string& /*id*/,
90                            const std::string& /*password*/)
91                      > /*result_handler*/) {}
92     virtual void OnCertificateAllowRequest(
93         WebView* /*view*/,
94         const std::string& /*url*/,
95         const std::string& /*pem*/,
96         std::function<void(bool allow)> result_handler) {
97       result_handler(false);
98     }
99     virtual void OnUsermediaPermissionRequest(
100         WebView* /*view*/,
101         const std::string& /*url*/,
102         std::function<void(bool)> /*result_handler*/) {}
103     virtual void OnSoftKeyboardChangeEvent(
104         WebView* /*view*/,
105         SoftKeyboardChangeEventValue /*softkeyboard_value*/) {}
106 #ifdef ROTARY_EVENT_FEATURE_SUPPORT
107     virtual void OnRotaryEvent(
108         WebView* /*view*/,
109         RotaryEventType /*type*/) {}
110 #endif  // ROTARY_EVENT_FEATURE_SUPPORT
111 #ifdef MANUAL_ROTATE_FEATURE_SUPPORT
112     virtual void OnRotatePrepared(WebView* /*view*/) {}
113 #endif // MANUAL_ROTATE_FEATURE_SUPPORT
114   };
115
116   WebView(NativeWindow* window, Ewk_Context* context);
117   virtual ~WebView();
118
119   void LoadUrl(const std::string& url, const std::string& mime = std::string());
120   std::string GetUrl();
121
122   void Suspend();
123   void Resume();
124   void Reload();
125   bool Backward();
126   void SetVisibility(bool show);
127   bool EvalJavascript(const std::string& script);
128   void SetAppInfo(const std::string& app_name, const std::string& version);
129   bool SetUserAgent(const std::string& user_agent);
130   void SetCSPRule(const std::string& rule, bool report_only);
131   void SetDefaultEncoding(const std::string& encoding);
132 #ifdef PROFILE_WEARABLE
133   void SetBGColor(int r, int g, int b, int a);
134 #endif
135
136   void SetEventListener(EventListener* listener);
137   Evas_Object* evas_object() const;
138
139  private:
140   WebViewImpl* impl_;
141 };
142
143 }  // namespace runtime
144
145 #endif  // XWALK_RUNTIME_BROWSER_WEB_VIEW_H_