8608c75d7ffc0e5e102bc339a5fe36b11b8b4da4
[platform/framework/web/crosswalk-tizen.git] / src / runtime / web_view.h
1 // Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef WRT_RUNTIME_WEB_VIEW_H_
6 #define WRT_RUNTIME_WEB_VIEW_H_
7
8 #include <Elementary.h>
9 #include <ewk_ipc_message.h>
10 #include <string>
11 #include <functional>
12
13 class Ewk_Context;
14
15 namespace wrt {
16 class NativeWindow;
17 class WebViewImpl;
18
19 class WebView {
20  public:
21   class EventListener {
22    public:
23     virtual void OnLoadStart(WebView* /*view*/) {}
24     virtual void OnLoadProgress(WebView* /*view*/, double /*persent*/ ) {}
25     virtual void OnLoadFinished(WebView* /*view*/) {}
26     virtual void OnRendered(WebView* /*view*/) {}
27     virtual void OnCreatedNewWebView(WebView* /*view*/,
28                                      WebView* /*new_view*/) {}
29     virtual void OnClosedWebView(WebView* /*view*/) {}
30     virtual void OnCrashed(WebView* /*view*/) {}
31     virtual bool OnDidOpenWindow(
32         WebView* /*view*/, const std::string& /*url*/) { return true; }
33     virtual bool OnDidNavigation(
34         WebView* /*view*/, const std::string& /*url*/) { return true; }
35     virtual void OnHardwareKey(
36         WebView* /*view*/, const std::string& /*keyname*/) {}
37     virtual void OnReceivedWrtMessage(
38         WebView* /*view*/, Ewk_IPC_Wrt_Message_Data* /*msg*/) {}
39     virtual void OnOrientationLock(
40         WebView* /*view*/,
41         bool /*lock*/,
42         int /*preferred_rotation*/) {}
43     virtual void OnConsoleMessage(const std::string& /*msg*/, int /*level*/) {}
44     virtual bool OnContextMenuDisabled(WebView* /*view*/) { return false; }
45
46     virtual void OnNotificationPermissionRequest(
47         WebView* /*view*/,
48         const std::string& /*url*/,
49         std::function<void(bool)> /*result_handler*/) {}
50     virtual void OnGeolocationPermissionRequest(
51         WebView* /*view*/,
52         const std::string& /*url*/,
53         std::function<void(bool)> /*result_handler*/) {}
54     virtual void OnQuotaExceed(
55         WebView* /*view*/,
56         const std::string& /*url*/,
57         std::function<void(bool)> /*result_handler*/) {}
58     virtual void OnAuthenticationRequest(
59         WebView* /*view*/,
60         const std::string& /*url*/,
61         const std::string& /*message*/,
62         std::function<void(bool /*submit*/,
63                            const std::string& /*id*/,
64                            const std::string& /*password*/)
65                      > /*result_handler*/) {}
66     virtual void OnCertificateAllowRequest(
67         WebView* /*view*/,
68         const std::string& /*url*/,
69         const std::string& /*pem*/,
70         std::function<void(bool allow)> result_handler) {
71       result_handler(false);
72     }
73   };
74
75   WebView(wrt::NativeWindow* window, Ewk_Context* context);
76   virtual ~WebView();
77
78   void LoadUrl(const std::string& url);
79   std::string GetUrl();
80
81   void Suspend();
82   void Resume();
83   void Reload();
84   void SetVisibility(bool show);
85   bool EvalJavascript(const std::string& script);
86   void SetAppInfo(const std::string& app_name, const std::string& version);
87   bool SetUserAgent(const std::string& user_agent);
88
89   void SetEventListener(EventListener* listener);
90   Evas_Object* evas_object() const;
91
92  private:
93   WebViewImpl* impl_;
94 };
95
96 }  // namespace wrt
97
98 #endif  // WRT_RUNTIME_WEB_VIEW_H_