a032f26f241ac54af5af6ead6bf844a9c6523ffd
[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<Evas_Object*, void> LoadStartCB;
38 typedef DPL::FastDelegate1<Evas_Object*, void> LoadFinishCB;
39 typedef DPL::FastDelegate0<void> WebCrashCB;
40 typedef DPL::FastDelegate2<Evas**, Evas_Object*, void> WindowCreateBeforeCB;
41 typedef DPL::FastDelegate2<Evas_Object*, Evas_Object*, void> WindowCreateAfterCB;
42 typedef DPL::FastDelegate1<Evas_Object*, void> WindowCloseCB;
43 typedef DPL::FastDelegate0<void> WebkitExitCB;
44 typedef DPL::FastDelegate1<bool, void> ResumeCB;
45 typedef DPL::FastDelegate1<bool, void> SuspendCB;
46 typedef DPL::FastDelegate1<bool, void> ResetCB;
47 typedef DPL::FastDelegate1<Evas_Object*, void> BufferUnsetCB;
48 typedef DPL::FastDelegate1<Evas_Object*, void> BufferSetCB;
49 typedef DPL::FastDelegate1<bool, void> ToggleFullscreenCB;
50
51 typedef struct UserDelegates {
52     ProgressFinishCB progressFinish;
53     LoadStartCB loadStart;
54     LoadFinishCB loadFinish;
55     WebCrashCB webCrash;
56     WindowCreateBeforeCB windowCreateBefore;
57     WindowCreateAfterCB windowCreateAfter;
58     WindowCloseCB windowClose;
59     WebkitExitCB webkitExit;
60     ResumeCB resume;
61     SuspendCB suspend;
62     ResetCB reset;
63     BufferUnsetCB bufferUnset;
64     BufferSetCB bufferSet;
65     ToggleFullscreenCB toggleFullscreen;
66 } UserDelegates;
67
68 typedef std::shared_ptr<UserDelegates> UserDelegatesPtr;
69 typedef std::shared_ptr<WidgetModel> WidgetModelPtr;
70
71 /**
72  * @brief The IRunnableWidgetObject class Runnable object interface
73  *
74  * Interface for managing WRT widgets runnable object.
75  * Methods should be called in approopriatte order. Check graph below.
76  *
77  *    /----------->(INITIAL)
78  *    |                |
79  *    |                | PrepareView()
80  *    |                V
81  *    |            (PREPARED)
82  *    |                |
83  *    | Reset()        | CheckBeforeLaunch()
84  *    |                V
85  *    |           (SECCHECKED)
86  *    |                |
87  *    |                | Show()
88  *    |                V
89  *    |             (SHOWED)
90  *    |               /  ^
91  *    |     Suspend() |  | Resume()
92  *    |               V  /
93  *    |            (SUSPENDED)
94  *    |
95  *    |
96  *    |     (any state besides INITIAL)
97  *    |                |
98  *    |                | Hide()
99  *    |                V
100  *    \-------------(HIDDEN)
101  *
102  */
103 class IRunnableWidgetObject {
104 public:
105     // IRunnableWidgetObject base exception
106     DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
107
108     // Throwed by any method if it is called in wrong state
109     DECLARE_EXCEPTION_TYPE(Base, MethodInvocationForbidden)
110
111     /**
112      * Runs OCSPCheck
113      * @return false when widget is already running or
114      * when security check fails
115      */
116     virtual bool CheckBeforeLaunch() = 0;
117     /**
118      * Prepares view to launch. You MUST call elm_init before calling
119      * this method.
120      * @param window
121      * @param callbacks passed to viewLogic
122      */
123     virtual bool PrepareView(const std::string &startUrl,
124                              Evas_Object *window) = 0;
125     /**
126      * Shows widget asynchronously. Callback will be called when
127      * webkit generates website.
128      * @param callback
129      */
130     virtual void Show() = 0;
131     /**
132      * Hides widget. To show it again Reset must be called.
133      */
134     virtual void Hide() = 0;
135     /**
136      * Stops widget's javascript. If widget has set background_enabled
137      * then this method has no effect. To resume use Resume();
138      */
139     virtual void Suspend() = 0;
140     /**
141      * Resumes widget's javascript after calling Suspend(). Resumes only if
142      * widget is in suspend state.
143      */
144     virtual void Resume() = 0;
145     /**
146      * Resets widgets after calling Hide().
147      */
148     virtual void Reset() = 0;
149     /**
150      * Reload start page on widget.
151      */
152     virtual void ReloadStartPage() = 0;
153     /**
154      * Retrieve widget's top level webview
155      * @return Evas_Object*
156      */
157     virtual Evas_Object* GetCurrentWebview() = 0;
158     /**
159      * Register widget's delegates
160      */
161     virtual void SetUserDelegates(const UserDelegatesPtr& cbs) = 0;
162     /**
163      * Call goBack() on webkit
164      */
165     virtual void Backward() = 0;
166     /**
167      * fire custom javascript event
168      */
169     virtual void FireJavascriptEvent(int event, void* data) = 0;
170
171
172     virtual ~IRunnableWidgetObject() {};
173 };
174
175 typedef std::shared_ptr<IRunnableWidgetObject> RunnableWidgetObjectPtr;
176
177 }
178 #endif /* RUNNABLE_WIDGET_OBJECT_INTERFACE_H_ */
179