XWalk WebView patchset, README and LICENSE files.
[platform/framework/web/xwalk_webview.git] / patchset / 0015-Load-progress-api.patch
1 From 7b21f6d20c6cde7f7309413a2176bc2fe0c70809 Mon Sep 17 00:00:00 2001
2 From: Mikhail Pozdnyakov <mikhail.pozdnyakov@intel.com>
3 Date: Fri, 2 Aug 2013 16:27:42 +0300
4 Subject: [PATCH 15/33] Load progress api.
5
6 ---
7  content/browser/web_contents/web_contents_impl.cc |  2 +-
8  content/public/browser/web_contents_delegate.h    |  2 +-
9  efl_webview/examples/main.cc                      | 13 +++-
10  efl_webview/lib/web_contents_delegate_xwalk.cc    | 18 ++++--
11  efl_webview/lib/web_contents_delegate_xwalk.h     | 17 +++--
12  efl_webview/lib/webview.cc                        | 26 ++++----
13  efl_webview/lib/webview.h                         |  8 ++-
14  efl_webview/lib/webview_callbacks.h               | 77 +++++++++++++++++++++++
15  efl_webview/public/xwalk_view.h                   | 12 +++-
16  9 files changed, 144 insertions(+), 31 deletions(-)
17  create mode 100644 efl_webview/lib/webview_callbacks.h
18
19 diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
20 index 43ec8e5..9e70e1e 100644
21 --- a/content/browser/web_contents/web_contents_impl.cc
22 +++ b/content/browser/web_contents/web_contents_impl.cc
23 @@ -2938,7 +2938,7 @@ void WebContentsImpl::DidCancelLoading() {
24  }
25  
26  void WebContentsImpl::DidChangeLoadProgress(double progress) {
27 -#if defined(OS_ANDROID)
28 +#if defined(OS_ANDROID) || defined(TOOLKIT_EFL)
29    if (delegate_)
30      delegate_->LoadProgressChanged(this, progress);
31  #endif
32 diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h
33 index 60732ce..866de0d 100644
34 --- a/content/public/browser/web_contents_delegate.h
35 +++ b/content/public/browser/web_contents_delegate.h
36 @@ -109,7 +109,7 @@ class CONTENT_EXPORT WebContentsDelegate {
37    // loading feedback. See WebContents::IsLoading()
38    virtual void LoadingStateChanged(WebContents* source) {}
39  
40 -#if defined(OS_ANDROID)
41 +#if defined(OS_ANDROID) || defined(TOOLKIT_EFL)
42    // Notifies the delegate that the page has made some progress loading.
43    // |progress| is a value between 0.0 (nothing loaded) to 1.0 (page fully
44    // loaded).
45 diff --git a/efl_webview/examples/main.cc b/efl_webview/examples/main.cc
46 index b9ece50..f1c06d2 100644
47 --- a/efl_webview/examples/main.cc
48 +++ b/efl_webview/examples/main.cc
49 @@ -41,10 +41,16 @@ static void
50  on_url_entry_activated(void *user_data, Evas_Object *url_entry,
51                         void *event_info)
52  {
53 -    const char* url = elm_entry_entry_get(url_entry);
54 -    xwalk_view_url_set((Evas_Object*)user_data, url);
55 +  const char* url = elm_entry_entry_get(url_entry);
56 +  xwalk_view_url_set((Evas_Object*)user_data, url);
57  }
58  
59 +static void
60 +on_progress(void *user_data, Evas_Object *xwalk_view, void *event_info)
61 +{
62 +  /* double progress = *(double *)event_info; */
63 +  /* FIXME : implement. */
64 +}
65  
66  static void window_create()
67  {
68 @@ -120,6 +126,9 @@ static void window_create()
69    evas_object_smart_callback_add(url_entry, "activated",
70                                   on_url_entry_activated, web_view);
71  
72 +  evas_object_smart_callback_add(web_view, "load,progress",
73 +                                 on_progress, elm_window);
74 +
75    evas_object_resize(elm_window, window_width, window_height);
76    evas_object_show(elm_window);
77  }
78 diff --git a/efl_webview/lib/web_contents_delegate_xwalk.cc b/efl_webview/lib/web_contents_delegate_xwalk.cc
79 index a6cb3a3..6272029 100644
80 --- a/efl_webview/lib/web_contents_delegate_xwalk.cc
81 +++ b/efl_webview/lib/web_contents_delegate_xwalk.cc
82 @@ -7,18 +7,19 @@
83  #include <Elementary.h>
84  #include "content/public/browser/web_contents.h"
85  #include "efl_webview/lib/web_contents_view_delegate_xwalk.h"
86 +#include "efl_webview/lib/webview.h"
87  
88  namespace xwalk {
89  
90  namespace {
91  const int g_window_width = 800;
92  const int g_window_height = 600;
93 -} // namespace
94 +
95 +}  // namespace
96  
97  WebContentsDelegateXWalk::WebContentsDelegateXWalk(
98 -    content::BrowserContext* browser_context, Evas_Object* view_box)
99 -    : view_box_(view_box)
100 -{
101 +    content::BrowserContext* browser_context, WebViewPrivate* web_view)
102 +    : web_view_(web_view) {
103    content::WebContents::CreateParams create_params(browser_context, 0);
104    create_params.initial_size = gfx::Size(g_window_width, g_window_height);
105  
106 @@ -26,10 +27,15 @@ WebContentsDelegateXWalk::WebContentsDelegateXWalk(
107    web_contents_->SetDelegate(this);
108  }
109  
110 +void WebContentsDelegateXWalk::LoadProgressChanged(content::WebContents* source,
111 +                                 double progress) {
112 +  web_view_->SmartCallback<webviewcallbacks::LoadProgress>().Call(&progress);
113 +}
114 +
115  bool WebContentsDelegateXWalk::TakeFocus(
116      content::WebContents* source, bool reverse) {
117 -  elm_object_focus_next(view_box_,
118 -                        reverse ? ELM_FOCUS_PREVIOUS : ELM_FOCUS_NEXT);
119 +//  elm_object_focus_next(web_view_,
120 +//                        reverse ? ELM_FOCUS_PREVIOUS : ELM_FOCUS_NEXT);
121    return true;
122  }
123  
124 diff --git a/efl_webview/lib/web_contents_delegate_xwalk.h b/efl_webview/lib/web_contents_delegate_xwalk.h
125 index 182d2e8..1b3d972 100644
126 --- a/efl_webview/lib/web_contents_delegate_xwalk.h
127 +++ b/efl_webview/lib/web_contents_delegate_xwalk.h
128 @@ -16,20 +16,25 @@ class WebContentsViewDelegate;
129  
130  namespace xwalk {
131  
132 -class WebContentsDelegateXWalk : public content::WebContentsDelegate
133 -{
134 +class WebViewPrivate;
135 +
136 +class WebContentsDelegateXWalk : public content::WebContentsDelegate {
137   public:
138 -  WebContentsDelegateXWalk(content::BrowserContext*, Evas_Object*);
139 +  WebContentsDelegateXWalk(content::BrowserContext*, WebViewPrivate*);
140 +
141 +  virtual void LoadProgressChanged(content::WebContents* source,
142 +                                   double progress) OVERRIDE;
143 +
144    virtual bool TakeFocus(content::WebContents* source,
145                           bool reverse) OVERRIDE;
146  
147    content::WebContents* WebContents() { return web_contents_.get(); }
148  
149   private:
150 -  Evas_Object* view_box_;
151 +  WebViewPrivate* web_view_;
152    scoped_ptr<content::WebContents> web_contents_;
153  };
154  
155 -} // namespace xwalk
156 +}  // namespace xwalk
157  
158 -#endif // EFL_WEBVIEW_LIB_WEB_CONTENTS_DELEGATE_XWALK_H_
159 +#endif  // EFL_WEBVIEW_LIB_WEB_CONTENTS_DELEGATE_XWALK_H_
160 diff --git a/efl_webview/lib/webview.cc b/efl_webview/lib/webview.cc
161 index bb48b59..c9d559f 100644
162 --- a/efl_webview/lib/webview.cc
163 +++ b/efl_webview/lib/webview.cc
164 @@ -16,11 +16,17 @@
165  
166  namespace {
167  
168 +namespace callbacks = xwalk::webviewcallbacks;
169 +
170  const char evas_smart_xwalk_view_type[] = "Evas_Smart_Xwalk_View";
171  
172 +const Evas_Smart_Cb_Description g_smart_callbacks[] = {
173 +  {callbacks::CallbackName<callbacks::LoadProgress>(), "d"},
174 +  {NULL, NULL}};
175 +
176  struct XWalk_View_Smart_Data {
177 -    Evas_Object_Box_Data base_;
178 -    xwalk::WebViewPrivate* priv_;
179 +  Evas_Object_Box_Data base_;
180 +  xwalk::WebViewPrivate* priv_;
181  };
182  
183  bool IsXWalkViewEvasObject(const Evas_Object* evas_object) {
184 @@ -60,7 +66,7 @@ inline XWalk_View_Smart_Data* ToSmartData(const Evas_Object* evas_object) {
185  
186  EVAS_SMART_SUBCLASS_NEW(evas_smart_xwalk_view_type, xwalk_view,
187                          Evas_Object_Box_Api, Evas_Object_Box_Api,
188 -                        evas_object_box_smart_class_get, 0);
189 +                        evas_object_box_smart_class_get, g_smart_callbacks);
190  
191  void xwalk_view_smart_add(Evas_Object* o) {
192    XWalk_View_Smart_Data* smart_data =
193 @@ -135,17 +141,13 @@ void WebViewPrivate::CommandLineInit(int argc, char** argv) {
194  
195  WebViewPrivate::WebViewPrivate(Evas_Object* view_object)
196      : view_object_(view_object)
197 -    , context_(WebRuntimeContext::current()) {
198 -  {
199 -    if (!WebViewPrivate::s_startup_url.is_valid())
200 -      WebViewPrivate::s_startup_url = GURL("about:blank");
201 -  }
202 +    , context_(WebRuntimeContext::current())
203 +    , web_contents_delegate_(
204 +          new WebContentsDelegateXWalk(context_->BrowserContext(), this)) {
205 +  if (!WebViewPrivate::s_startup_url.is_valid())
206 +    WebViewPrivate::s_startup_url = GURL("about:blank");
207  
208    DCHECK(view_object_);
209 -  content::BrowserContext* browser_context =
210 -      context_->BrowserContext();
211 -  web_contents_delegate_.reset(
212 -      new WebContentsDelegateXWalk(browser_context, view_object_));
213  
214    content::WebContentsViewEfl* content_view =
215        static_cast<content::WebContentsViewEfl*>(web_contents_delegate_->
216 diff --git a/efl_webview/lib/webview.h b/efl_webview/lib/webview.h
217 index 62a5772..b5d9a7b 100644
218 --- a/efl_webview/lib/webview.h
219 +++ b/efl_webview/lib/webview.h
220 @@ -11,6 +11,7 @@
221  #include "base/memory/ref_counted.h"
222  #include "base/memory/scoped_ptr.h"
223  #include "base/strings/efl/eina_shared_string.h"
224 +#include "efl_webview/lib/webview_callbacks.h"
225  #include "googleurl/src/gurl.h"
226  
227  namespace xwalk {
228 @@ -18,7 +19,7 @@ namespace xwalk {
229  class WebContentsDelegateXWalk;
230  class WebRuntimeContext;
231  
232 -class WebViewPrivate {
233 +class WebViewPrivate {  // FIXME : Consider renaming.
234   public:
235    static void CommandLineInit(int argc, char** argv);
236  
237 @@ -35,6 +36,11 @@ class WebViewPrivate {
238  
239    const char* url() const { return url_; }
240  
241 +  template<webviewcallbacks::CallbackType type>
242 +  webviewcallbacks::Callback<type> SmartCallback() const {
243 +      return webviewcallbacks::Callback<type>(view_object_);
244 +  }
245 +
246   private:
247    explicit WebViewPrivate(Evas_Object* evas_object);
248  
249 diff --git a/efl_webview/lib/webview_callbacks.h b/efl_webview/lib/webview_callbacks.h
250 new file mode 100644
251 index 0000000..af67471
252 --- /dev/null
253 +++ b/efl_webview/lib/webview_callbacks.h
254 @@ -0,0 +1,77 @@
255 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
256 +// Use of this source code is governed by a BSD-style license that can be
257 +// found in the LICENSE file.
258 +
259 +#ifndef EFL_WEBVIEW_LIB_WEBVIEW_CALLBACKS_H_
260 +#define EFL_WEBVIEW_LIB_WEBVIEW_CALLBACKS_H_
261 +
262 +#include <Evas.h>
263 +
264 +namespace xwalk {
265 +
266 +namespace webviewcallbacks {
267 +
268 +enum CallbackType {
269 +    LoadProgress
270 +};
271 +
272 +template <CallbackType>
273 +struct CallBackInfo;
274 +
275 +template <CallbackType type>
276 +const char* CallbackName() { return CallBackInfo<type>::name(); }
277 +
278 +class EvasObjectHolder {
279 + protected:
280 +  explicit EvasObjectHolder(Evas_Object* object)
281 +    : m_object(object) {
282 +  }
283 +
284 +  Evas_Object* m_object;
285 +};
286 +
287 +template <CallbackType callbackType,
288 +          typename ArgType = typename CallBackInfo<callbackType>::Type>
289 +struct Callback: public EvasObjectHolder {
290 +  explicit Callback(Evas_Object* view) : EvasObjectHolder(view) { }
291 +
292 +  void Call(ArgType argument) {
293 +    evas_object_smart_callback_call(m_object, CallbackName<callbackType>(),
294 +                                    static_cast<void*>(argument));
295 +  }
296 +};
297 +
298 +template <CallbackType callbackType>
299 +struct Callback <callbackType, void> : public EvasObjectHolder {
300 +  explicit Callback(Evas_Object* view) : EvasObjectHolder(view) { }
301 +
302 +  void Call() {
303 +    evas_object_smart_callback_call(m_object, CallbackName<callbackType>(), 0);
304 +  }
305 +};
306 +
307 +template <CallbackType callbackType>
308 +struct Callback <callbackType, const char*> : public EvasObjectHolder {
309 +  explicit Callback(Evas_Object* view) : EvasObjectHolder(view) { }
310 +
311 +  void Call(const char* arg) {
312 +    evas_object_smart_callback_call(m_object, CallbackName<callbackType>(),
313 +                                    const_cast<char*>(arg));
314 +  }
315 +};
316 +
317 +#define DECLARE_XWALK_VIEW_CALLBACK(callbackType, literal, type) \
318 +template <>                                                      \
319 +struct CallBackInfo<callbackType> {                              \
320 +    typedef type Type;                                           \
321 +    static const char* name() { return literal; }                \
322 +}
323 +
324 +// Note: type 'void' means that no arguments are expected.
325 +DECLARE_XWALK_VIEW_CALLBACK(LoadProgress, "load,progress", double*);
326 +
327 +}  // namespace webviewcallbacks
328 +
329 +}  // namespace xwalk
330 +
331 +#endif  // EFL_WEBVIEW_LIB_WEBVIEW_CALLBACKS_H_
332 diff --git a/efl_webview/public/xwalk_view.h b/efl_webview/public/xwalk_view.h
333 index fbde786..4758e41 100644
334 --- a/efl_webview/public/xwalk_view.h
335 +++ b/efl_webview/public/xwalk_view.h
336 @@ -2,8 +2,16 @@
337  // Use of this source code is governed by a BSD-style license that can be
338  // found in the LICENSE file.
339  
340 -#ifndef EFL_WEBVIEW_PUBLIC_XWALK_VIEW_H_
341 -#define EFL_WEBVIEW_PUBLIC_XWALK_VIEW_H_
342 +/**
343 + * @file xwalk_view.h
344 + *
345 + * The following signals (see evas_object_smart_callback_add()) are emitted:
346 + *
347 + * - "load,progress", double*: load progress has changed (value from 0.0 to 1.0).
348 + */
349 +
350 +#ifndef xwalk_view_h
351 +#define xwalk_view_h
352  
353  #include <Evas.h>
354  
355 -- 
356 1.8.1.2
357