Merge "Refactoring - pause/resume , show, hiden related code" into devel/wrt2
[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*/, const Ewk_IPC_Wrt_Message_Data& /*msg*/) {}
38   };
39
40   WebView(wrt::NativeWindow* window, Ewk_Context* context);
41   virtual ~WebView();
42
43   void LoadUrl(const std::string& url);
44   std::string GetUrl();
45
46   void Suspend();
47   void Resume();
48   void Reload();
49   void SetVisibility(bool show);
50   bool EvalJavascript(const std::string& script);
51
52   void SetEventListener(EventListener* listener);
53   Evas_Object* evas_object() const;
54
55  private:
56   void OnKeyEvent(Ea_Callback_Type key_type);
57   void OnRotation(int degree);
58   void Initialize();
59   NativeWindow* window_;
60   Ewk_Context* context_;
61   Evas_Object* ewk_view_;
62   EventListener* listener_;
63   int rotation_handler_id_;
64 };
65
66 }  // namespace wrt
67
68 #endif  // WRT_RUNTIME_WEB_VIEW_H_