Implements extension loader and server
[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 <efl_assist.h>
10 #include <ewk_ipc_message.h>
11 #include <string>
12
13 class Ewk_Context;
14
15 namespace wrt {
16 class NativeWindow;
17
18 class WebView {
19  public:
20   class EventListener {
21    public:
22     virtual void OnLoadStart(WebView* /*view*/) {}
23     virtual void OnLoadProgress(WebView* /*view*/, double /*persent*/ ) {}
24     virtual void OnLoadFinished(WebView* /*view*/) {}
25     virtual void OnRendered(WebView* /*view*/) {}
26     virtual void OnCreatedNewWebView(WebView* /*view*/,
27                                      WebView* /*new_view*/) {}
28     virtual void OnClosedWebView(WebView* /*view*/) {}
29     virtual void OnCrashed(WebView* /*view*/) {}
30     virtual bool OnDidOpenWindow(
31         WebView* /*view*/, const std::string& /*url*/) { return true; }
32     virtual bool OnDidNavigation(
33         WebView* /*view*/, const std::string& /*url*/) { return true; }
34     virtual void OnHardwareKey(
35         WebView* /*view*/, const std::string& /*keyname*/) {}
36     virtual void OnReceivedWrtMessage(
37         WebView* /*view*/, Ewk_IPC_Wrt_Message_Data* /*msg*/) {}
38     virtual void OnOrientationLock(
39         WebView* /*view*/,
40         bool /*lock*/,
41         int /*preferred_rotation*/) {}
42   };
43
44   WebView(wrt::NativeWindow* window, Ewk_Context* context);
45   virtual ~WebView();
46
47   void LoadUrl(const std::string& url);
48   std::string GetUrl();
49
50   void Suspend();
51   void Resume();
52   void Reload();
53   void SetVisibility(bool show);
54   bool EvalJavascript(const std::string& script);
55
56   void SetEventListener(EventListener* listener);
57   Evas_Object* evas_object() const;
58
59  private:
60   void OnKeyEvent(Ea_Callback_Type key_type);
61   void OnRotation(int degree);
62   void Initialize();
63   NativeWindow* window_;
64   Ewk_Context* context_;
65   Evas_Object* ewk_view_;
66   EventListener* listener_;
67   int rotation_handler_id_;
68 };
69
70 }  // namespace wrt
71
72 #endif  // WRT_RUNTIME_WEB_VIEW_H_