update wrt_0.8.107
[platform/framework/web/wrt.git] / src / api_new / i_runnable_widget_object.h
1 /*
2  * Copyright (c) 2011 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  * @file    i_runnable_widget_object.h
18  * @author  Przemyslaw Ciezkowski (p.ciezkowski@samsung.com)
19  * @version 1.0
20  * @brief   File contains declaration of IRunnableWidgetObject interface.
21  */
22
23 #ifndef RUNNABLE_WIDGET_OBJECT_INTERFACE_H_
24 #define RUNNABLE_WIDGET_OBJECT_INTERFACE_H_
25
26 #include <dpl/wrt-dao-ro/wrt_db_types.h>
27 #include <dpl/fast_delegate.h>
28 #include <memory>
29 #include <Evas.h>
30 #include <widget_model.h>
31
32 #include <dpl/exception.h>
33
34 namespace WRT {
35
36 typedef DPL::FastDelegate0<void> ProgressFinishCB;
37 typedef DPL::FastDelegate1<bool, void> LoadFinishCB;
38 typedef DPL::FastDelegate0<void> WebCrashCB;
39 typedef DPL::FastDelegate0<void> WindowCloseCB;
40 typedef DPL::FastDelegate1<bool, void> ResumeCB;
41 typedef DPL::FastDelegate1<bool, void> SuspendCB;
42 typedef DPL::FastDelegate1<bool, void> ResetCB;
43 typedef DPL::FastDelegate1<Evas_Object*, void> BufferUnsetCB;
44 typedef DPL::FastDelegate1<Evas_Object*, void> BufferSetCB;
45 typedef DPL::FastDelegate1<bool, void> ToggleFullscreenCB;
46
47 typedef struct UserDelegates {
48     ProgressFinishCB progressFinish;
49     LoadFinishCB loadFinish;
50     WebCrashCB webCrash;
51     WindowCloseCB windowClose;
52     ResumeCB resume;
53     SuspendCB suspend;
54     ResetCB reset;
55     BufferUnsetCB bufferUnset;
56     BufferSetCB bufferSet;
57     ToggleFullscreenCB toggleFullscreen;
58 } UserDelegates;
59
60 typedef std::shared_ptr<UserDelegates> UserDelegatesPtr;
61 typedef std::shared_ptr<WidgetModel> WidgetModelPtr;
62
63 /**
64  * @brief The IRunnableWidgetObject class Runnable object interface
65  *
66  * Interface for managing WRT widgets runnable object.
67  * Methods should be called in approopriatte order. Check graph below.
68  *
69  *    /----------->(INITIAL)
70  *    |                |
71  *    |                | PrepareView()
72  *    |                V
73  *    |            (PREPARED)
74  *    |                |
75  *    | Reset()        | CheckBeforeLaunch()
76  *    |                V
77  *    |           (SECCHECKED)
78  *    |                |
79  *    |                | Show()
80  *    |                V
81  *    |             (SHOWED)
82  *    |               /  ^
83  *    |     Suspend() |  | Resume()
84  *    |               V  /
85  *    |            (SUSPENDED)
86  *    |
87  *    |
88  *    |     (any state besides INITIAL)
89  *    |                |
90  *    |                | Hide()
91  *    |                V
92  *    \-------------(HIDDEN)
93  *
94  */
95 class IRunnableWidgetObject {
96 public:
97     // IRunnableWidgetObject base exception
98     DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
99
100     // Throwed by any method if it is called in wrong state
101     DECLARE_EXCEPTION_TYPE(Base, MethodInvocationForbidden)
102
103     /**
104      * Runs OCSPCheck
105      * @return false when widget is already running or
106      * when security check fails
107      */
108     virtual bool CheckBeforeLaunch() = 0;
109     /**
110      * Prepares view to launch. You MUST call elm_init before calling
111      * this method.
112      * @param window
113      * @param callbacks passed to viewLogic
114      */
115     virtual void PrepareView(const std::string &startUrl,
116                              Evas_Object *window) = 0;
117     /**
118      * Shows widget asynchronously. Callback will be called when
119      * webkit generates website.
120      * @param callback
121      */
122     virtual void Show() = 0;
123     /**
124      * Hides widget. To show it again Reset must be called.
125      */
126     virtual void Hide() = 0;
127     /**
128      * Stops widget's javascript. If widget has set background_enabled
129      * then this method has no effect. To resume use Resume();
130      */
131     virtual void Suspend() = 0;
132     /**
133      * Resumes widget's javascript after calling Suspend(). Resumes only if
134      * widget is in suspend state.
135      */
136     virtual void Resume() = 0;
137     /**
138      * Resets widgets after calling Hide().
139      */
140     virtual void Reset() = 0;
141     /**
142      * Reload start page on widget.
143      */
144     virtual void ReloadStartPage() = 0;
145     /**
146      * Retrieve widget's top level webview
147      * @return Evas_Object*
148      */
149     virtual Evas_Object* GetCurrentWebview() = 0;
150     /**
151      * Register widget's delegates
152      */
153     virtual void SetUserDelegates(const UserDelegatesPtr& cbs) = 0;
154     /**
155      * Call goBack() on webkit
156      */
157     virtual void Backward() = 0;
158     virtual void Reload() = 0;
159     virtual void Forward() = 0;
160
161     virtual ~IRunnableWidgetObject() {};
162 };
163
164 typedef std::shared_ptr<IRunnableWidgetObject> RunnableWidgetObjectPtr;
165
166 }
167 #endif /* RUNNABLE_WIDGET_OBJECT_INTERFACE_H_ */
168