Tizen 2.1 base
[framework/osp/web.git] / src / controls / FWebCtrl_WebImpl.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FWebCtrl_WebImpl.h
20  * @brief               The file contains the declaration of _WebImpl class.
21  *
22  * The file contains the declaration of _WebImpl class.
23  */
24 #ifndef _FWEB_CTRL_INTERNAL_WEB_IMPL_H_
25 #define _FWEB_CTRL_INTERNAL_WEB_IMPL_H_
26
27 #include <unique_ptr.h>
28 #include <EWebKit2.h>
29 #include <FBaseString.h>
30 #include <FUiIActionEventListener.h>
31 #include <FUiIOrientationEventListener.h>
32 #include <FUiITextEventListener.h>
33 #include <FWebCtrlILoadingListener.h>
34 #include <FUi_ContainerImpl.h>
35 #include "FWebCtrl_IWebEventListener.h"
36
37 namespace Tizen { namespace Base {  namespace Collection
38 {
39 template< class KeyType, class ValueType > class HashMapT;
40 }}} // Tizen::Base::Collection
41
42 namespace Tizen { namespace Base { namespace Runtime
43 {
44 class Mutex;
45 }}} // Tizen::Base::Runtime
46
47 namespace Tizen { namespace Graphics
48 {
49 class Dimension;
50 class Point;
51 class Rectangle;
52 }} // Tizen::Graphics
53
54 namespace Tizen { namespace Net { namespace Http {
55 class HttpHeader;
56 }}} // Tizen::Net::Http
57
58 namespace Tizen { namespace Ui
59 {
60 class Contorl;
61 class _Contorl;
62 class _ContorlImpl;
63 }} // Tizen::Ui
64
65 namespace Tizen { namespace Ui {  namespace Controls
66 {
67 class Keypad;
68 class _Form;
69 }}} // Tizen::Ui::Controls
70
71 namespace Tizen { namespace Web { namespace Json
72 {
73 class IJsonValue;
74 }}} // Tizen::Web::Json
75
76 namespace Tizen { namespace Web { namespace Controls
77 {
78 class IJavaScriptBridge;
79 class ILoadingListener;
80 class ITextSearchListener;
81 class IWebDownloadListener;
82 class IWebKeypadEventListener;
83 class IWebUiEventListener;
84 class AuthenticationChallenge;
85 class HitElementResult;
86 class PageNavigationList;
87 class Web;
88 class WebSetting;
89 class _Web;
90 class _JsBridgeArg;
91 class _WebEvent;
92 class _WebPresenter;
93 class _JsBridgeComparer;
94 class _JsBridgeHashCodeProvider;
95 class _AuthConfirmPopup;
96 class _GeolocationConfirmPopup;
97 class _PromptPopup;
98 class _WebDataHandler;
99 class _SelectBox;
100 class _InputPickerPopup;
101
102 struct _TextSearch
103 {
104         bool __searchAll;
105         bool __searchForward;
106         bool __caseSensitive;
107         int __pending;
108         int __currentIndex;
109         int __totalCount;
110         Tizen::Base::String __text;
111         Tizen::Base::Collection::Queue __searchQueue;
112 };
113
114 enum _SearchType {
115         SEARCH_SYNC,
116         SEARCH_ALL_ASYNC,
117         SEARCH_NEXT_ASYNC
118 };
119
120 class _WebImpl
121         : public Tizen::Ui::_ContainerImpl
122         , public Tizen::Ui::ITextEventListener
123         , public Tizen::Web::Controls::_IWebEventListener
124         , virtual public Tizen::Base::Runtime::IEventListener
125 {
126 public:
127         _WebImpl(Web* pWeb, Tizen::Ui::_Control* pCore);
128
129         virtual ~_WebImpl(void);
130
131         result Construct(void);
132
133         bool HasValidNativeNode(void) const;
134
135         result SetZoomLevel(float level);
136
137         float GetZoomLevel(void) const;
138
139         result LoadUrl(const Tizen::Base::String& url) const;
140
141         result LoadUrl(const Tizen::Base::String& url, const Tizen::Net::Http::HttpHeader& header);
142
143         result LoadUrlWithPostRequest(const Tizen::Base::String& url, const Tizen::Net::Http::HttpHeader& header, const Tizen::Base::ByteBuffer& body) const;
144
145         result LoadData(const Tizen::Base::String& baseUrl, const Tizen::Base::ByteBuffer& content, const Tizen::Base::String& mime, const Tizen::Base::String& encoding) const;
146
147         bool CanGoBack(void) const;
148
149         bool CanGoForward(void) const;
150
151         void GoBack(void) const;
152
153         void GoForward(void) const;
154
155         bool IsLoading(void) const;
156
157         void StopLoading(void) const;
158
159         void Reload(void) const;
160
161         result AddCustomHeader(const Tizen::Net::Http::HttpHeader& header);
162
163         void RemoveAllCustomHeaders(void);
164
165         bool SearchText(const Tizen::Base::String& word, bool searchForward);
166
167         result SetSetting(const Tizen::Web::Controls::WebSetting& setting);
168
169         Tizen::Web::Controls::WebSetting GetSetting(void) const;
170
171         Tizen::Base::String GetUrl(void) const;
172
173         Tizen::Base::String GetTitle(void) const;
174
175         result SetBlockSelectionPosition(const Tizen::Graphics::Point& startPoint);
176
177         result ReleaseBlock(void);
178
179         result GetBlockRange(Tizen::Graphics::Point& startPoint, Tizen::Graphics::Point& endPoint) const;
180
181         void FireWebPageBlockSelectedEvent(void) const;
182
183         Tizen::Base::String GetTextFromBlock(void) const;
184
185         Tizen::Base::String* EvaluateJavascriptN(const Tizen::Base::String& scriptCode) const;
186
187         bool IsPrivateBrowsingEnabled(void) const;
188
189         result SetPrivateBrowsingEnabled(bool enable);
190
191         void ClearCache(void);
192
193         void ClearCookie(void);
194
195         bool IsCookieEnabled(void) const;
196
197         void SetCookieEnabled(bool enable);
198
199         result SavePageAsPdf(const Tizen::Base::String& filePath, const Tizen::Graphics::Dimension* pSize) const;
200
201         bool IsMimeSupported(const Tizen::Base::String& mime) const;
202
203         result SearchTextAllAsync(const Tizen::Base::String& text, bool caseSensitive);
204
205         result SearchNextAsync(bool searchForward);
206
207         result SynchronizeSearch(_SearchType type, Evas_Object* pView, Ewk_Find_Options condition, const Tizen::Base::String& text
208                 , bool searchForward, bool caseSensitive = false,  _WebPresenter* pWebPresenter = null);
209
210         void SetAsyncSearchResult(int totalCount);
211
212         _WebPresenter* GetSearchPresenter(void);
213
214          int GetPendingAsyncSearchCount(void) const;
215
216         void CalculateAsyncSearchOrdinal(void);
217
218         int GetAsyncSearchOrdinal(void) const;
219
220         void DisableAsyncSearch(void);
221
222         void SetTextSearchListener(Tizen::Web::Controls::ITextSearchListener* pTextSearchListener);
223
224         void SetLoadingListener(Tizen::Web::Controls::ILoadingListener* pLoadingListener);
225
226         void SetWebUiEventListener(Tizen::Web::Controls::IWebUiEventListener* pUiEventListener);
227
228         void SetWebKeypadEventListener(IWebKeypadEventListener* pKeypadEventListener);
229
230         void SetDownloadListener(Tizen::Web::Controls::IWebDownloadListener* pDownLoadListener);
231
232         Tizen::Web::Controls::ILoadingListener* GetLoadingListener(void) const;
233
234         Tizen::Web::Controls::IWebUiEventListener* GetUiEventListener(void) const;
235
236         Tizen::Web::Controls::ITextSearchListener* GetTextSearchListener(void) const;
237
238         Tizen::Web::Controls::IWebKeypadEventListener* GetWebKeypadEventListener(void) const;
239
240         const Tizen::Web::Controls::PageNavigationList* GetBackForwardListN(void) const;
241
242         const Tizen::Web::Controls::HitElementResult* GetElementByPointN(const Tizen::Graphics::Point& point) const;
243
244         result AddJavaScriptBridge(const IJavaScriptBridge& jsBridge);
245
246         result RemoveJavaScriptBridge(const IJavaScriptBridge& jsBridge);
247
248         result SetScrollEnabled(bool enable);
249
250         bool IsScrollEnabled(void) const;
251
252         virtual bool IsLayoutable(void) const;
253
254         void SetEventListenerCallback(void) const;
255
256         void RemoveEventListenerCallback(void) const;
257
258         _WebEvent* GetWebEvent(void) const;
259
260         _WebDataHandler* GetDownloadHandler(void) const;
261
262         result SetFullScreenKeypad(void);
263
264         void RemoveFullScreenKeypad(void);
265
266         void SetCurrentEvent(Tizen::Base::Runtime::IEventArg* arg);
267
268         void SetLoadingErrorOccurred(bool arg);
269
270         bool IsLoadingErrorOccurred(void) const;
271
272         void SetRedirectRequested(bool arg);
273
274         bool IsRedirectRequested(void) const;
275
276         bool IsFooterVisible(void) const;
277
278         void SetFooterVisibleState(bool isFooterVisible);
279
280         bool IsKeypadVisible(void) const;
281
282         void SetKeypadVisibleState(bool isKeypadVisible);
283
284         bool IsKeypadOpened(void) const;
285
286         void SetKeypadOpened(bool isKeypadOpened);
287
288         int GetKeypadHeight(void) const;
289
290         void SetKeypadHeight(int keypadHeight);
291
292         Tizen::Ui::_ControlOrientation GetPreviousOrientation(void) const;
293
294         void SetPreviousOrientation(Tizen::Ui::_ControlOrientation orientation);
295
296         result HttpAuthenticationRequested(Ewk_Auth_Challenge* pChallenge);
297
298         result ShowGeolocationPopup(Ewk_Geolocation_Permission_Data* pPermissionData);
299
300         Tizen::Ui::Controls::_Form* GetParentFormCore(Tizen::Ui::_Control* pControlCore);
301
302         Tizen::Graphics::Bitmap* GetFaviconN(void) const;
303
304         void Pause(void);
305
306         void Resume(void);
307
308         void SetSelectBox(_SelectBox* pSelectBox);
309
310         _SelectBox* GetSelectBox(void);
311
312         void DeleteSelectBox(void);
313
314         result ShowColorPicker(int r, int g, int b, int a,Tizen::Graphics::Color& color);
315         Eina_Bool HideColorPicker();
316         _InputPickerPopup* GetColorpicker(void);
317
318         result ShowDatePicker(Ewk_Input_Type inputType, const char* inputValue,Tizen::Base::String& dateStr);
319         _InputPickerPopup* GetDatepicker(void);
320
321
322         void SetPolicyDecision(DecisionPolicy policy);
323
324         DecisionPolicy GetPolicyDecision(void) const;
325
326         virtual bool OnFocusGained(const Tizen::Ui::_ControlImpl& source);
327
328         virtual bool OnFocusLost(const Tizen::Ui::_ControlImpl& source);
329
330         virtual void OnTextValueChangeCanceled(const Tizen::Ui::Control& source);
331
332         virtual void OnTextValueChanged(const Tizen::Ui::Control& source);
333
334         virtual result OnAttachedToMainTree(void);
335
336         virtual void OnChangeLayout(Tizen::Ui::_ControlOrientation orientation);
337
338         static _WebImpl* CreateWebImplN(Web* pControl, const Tizen::Graphics::Rectangle& bounds);
339
340         static _WebImpl* GetInstance(Web* pWeb);
341
342         static const _WebImpl* GetInstance(const Web* pWeb);
343
344 private:
345         result InitializeSetting(void);
346         result InitJsBridgeList(void);
347         result InitWebEvent(void);
348
349         IJavaScriptBridge* FindJsInterface(const Tizen::Web::Json::IJsonValue* pValue) const;
350         result LaunchAppControl(const Tizen::Base::Runtime::IEventArg& arg);
351
352         result ShowAuthenticationPopup(const Tizen::Base::String& host, const Tizen::Base::String& realm, AuthenticationChallenge* pAuthChallenge);
353
354         Eina_Hash* ConvertToSlpHeaderN(const Tizen::Net::Http::HttpHeader& header) const;
355
356         result OnHandleJavaScriptRequestByEventArg(const Tizen::Base::Runtime::IEventArg& arg);
357         result OnHandleLoadingEvent(const Tizen::Base::Runtime::IEventArg& arg);
358         result OnHandleWebDownloadEvent(const Tizen::Base::Runtime::IEventArg& arg);
359         result OnHandleWebUiEvent(const Tizen::Base::Runtime::IEventArg& arg);
360         result OnHandleTextSearchEvent(const Tizen::Base::Runtime::IEventArg& arg);
361
362 private:
363         bool __isFooterVisible;
364         bool __isKeypadVisible;
365         bool __isKeypadOpened;
366         bool __isLoadingErrorOccurred;
367         bool __isRedirectRequested;
368         int __keypadHeight;
369
370         _Web* __pWebCore;
371
372         ILoadingListener* __pUserLoadingListener;
373         IWebUiEventListener* __pUserUiListener;
374         IWebKeypadEventListener* __pUserKeypadEventListener;
375         ITextSearchListener* __pTextSearchListener;
376
377         std::unique_ptr<Tizen::Ui::Controls::Keypad> __pKeypad;
378
379         std::unique_ptr<WebSetting> __pWebSetting;
380
381         std::unique_ptr<Tizen::Base::Collection::HashMapT< Tizen::Base::String, IJavaScriptBridge* > > __pJsBridgeList;
382         std::unique_ptr<_JsBridgeHashCodeProvider> __pJsProvider;
383         std::unique_ptr<_JsBridgeComparer> __pJsComparer;
384
385         std::unique_ptr<_WebDataHandler> __pWebDownloadHandler;
386
387         std::unique_ptr<_WebEvent> __pWebEvent;
388
389         std::unique_ptr<AuthenticationChallenge> __pAuthChallenge;
390         std::unique_ptr<_AuthConfirmPopup> __pAuthPopup;
391
392         std::unique_ptr<_GeolocationConfirmPopup> __pGeolocationPopup;
393
394         std::unique_ptr<_SelectBox> __pSelectBox;
395         std::unique_ptr<_InputPickerPopup> __pDatePicker;
396         std::unique_ptr<_InputPickerPopup> __pColorPicker;
397
398         Tizen::Ui::_ControlOrientation __orientation;
399
400         Tizen::Base::Runtime::Mutex __mutex;
401
402         _TextSearch __textSearch;
403
404         DecisionPolicy __policy;
405 }; // _WebImpl
406
407 }}} // Tizen::Web::Controls
408 #endif // _FWEB_CTRL_INTERNAL_WEB_IMPL_H_