XWalk WebView patchset, README and LICENSE files.
[platform/framework/web/xwalk_webview.git] / patchset / 0017-URL-changed-API.patch
1 From 8f389554f85471131da62f34f6f69b1d4d1ece16 Mon Sep 17 00:00:00 2001
2 From: Mikhail Pozdnyakov <mikhail.pozdnyakov@intel.com>
3 Date: Mon, 5 Aug 2013 17:40:09 +0300
4 Subject: [PATCH 17/33] URL changed API.
5
6 ---
7  efl_webview/examples/main.cc                   | 10 +++++++++
8  efl_webview/lib/web_contents_delegate_xwalk.cc |  5 +++++
9  efl_webview/lib/web_contents_delegate_xwalk.h  |  4 ++++
10  efl_webview/lib/webview.cc                     | 31 ++++++++++++++++++--------
11  efl_webview/lib/webview.h                      | 10 +++++++++
12  efl_webview/lib/webview_callbacks.h            |  5 +++--
13  efl_webview/public/xwalk_view.h                |  2 ++
14  7 files changed, 56 insertions(+), 11 deletions(-)
15
16 diff --git a/efl_webview/examples/main.cc b/efl_webview/examples/main.cc
17 index 0197d1a..7ea8738 100644
18 --- a/efl_webview/examples/main.cc
19 +++ b/efl_webview/examples/main.cc
20 @@ -59,6 +59,14 @@ on_title_changed(void *user_data, Evas_Object *xwalk_view, void *event_info)
21      elm_win_title_set((Evas_Object*)user_data, title);
22  }
23  
24 +static void
25 +on_url_changed(void *user_data, Evas_Object *xwalk_view, void *event_info)
26 +{
27 +    char *url = elm_entry_utf8_to_markup((const char *)event_info);
28 +    elm_entry_entry_set((Evas_Object*)user_data, url);
29 +    free(url);
30 +}
31 +
32  static void window_create()
33  {
34    /* Create elementary window */
35 @@ -137,6 +145,8 @@ static void window_create()
36                                   on_progress, elm_window);
37    evas_object_smart_callback_add(web_view, "title,changed",
38                                   on_title_changed, elm_window);
39 +  evas_object_smart_callback_add(web_view, "url,changed",
40 +                                 on_url_changed, url_entry);
41  
42    evas_object_resize(elm_window, window_width, window_height);
43    evas_object_show(elm_window);
44 diff --git a/efl_webview/lib/web_contents_delegate_xwalk.cc b/efl_webview/lib/web_contents_delegate_xwalk.cc
45 index 6272029..65024e6 100644
46 --- a/efl_webview/lib/web_contents_delegate_xwalk.cc
47 +++ b/efl_webview/lib/web_contents_delegate_xwalk.cc
48 @@ -39,4 +39,9 @@ bool WebContentsDelegateXWalk::TakeFocus(
49    return true;
50  }
51  
52 +void WebContentsDelegateXWalk::UpdateTargetURL(content::WebContents* source,
53 +                             int32 page_id, const GURL& url) {
54 +  web_view_->informURLChanged();
55 +}
56 +
57  }  // namespace xwalk
58 diff --git a/efl_webview/lib/web_contents_delegate_xwalk.h b/efl_webview/lib/web_contents_delegate_xwalk.h
59 index 1b3d972..7e143cb 100644
60 --- a/efl_webview/lib/web_contents_delegate_xwalk.h
61 +++ b/efl_webview/lib/web_contents_delegate_xwalk.h
62 @@ -28,6 +28,10 @@ class WebContentsDelegateXWalk : public content::WebContentsDelegate {
63    virtual bool TakeFocus(content::WebContents* source,
64                           bool reverse) OVERRIDE;
65  
66 +  virtual void UpdateTargetURL(content::WebContents* source,
67 +                               int32 page_id,
68 +                               const GURL& url) OVERRIDE;
69 +
70    content::WebContents* WebContents() { return web_contents_.get(); }
71  
72   private:
73 diff --git a/efl_webview/lib/webview.cc b/efl_webview/lib/webview.cc
74 index e9d51f9..3e4d467 100644
75 --- a/efl_webview/lib/webview.cc
76 +++ b/efl_webview/lib/webview.cc
77 @@ -8,6 +8,7 @@
78  #include "base/file_util.h"
79  #include "base/files/file_path.h"
80  #include "content/browser/web_contents/web_contents_view_efl.h"
81 +#include "content/public/browser/navigation_entry.h"
82  #include "content/public/browser/web_contents.h"
83  #include "efl_webview/lib/web_contents_delegate_xwalk.h"
84  #include "efl_webview/lib/web_contents_view_delegate_xwalk.h"
85 @@ -163,34 +164,46 @@ WebViewPrivate::~WebViewPrivate() {
86  }
87  
88  bool WebViewPrivate::CanGoBack() const {
89 -  return web_contents_delegate_->WebContents()->GetController().CanGoBack();
90 +  return NavigationController().CanGoBack();
91  }
92  
93  bool WebViewPrivate::CanGoForward() const {
94 -  return web_contents_delegate_->WebContents()->GetController().CanGoForward();
95 +  return NavigationController().CanGoForward();
96  }
97  
98  void WebViewPrivate::GoForward() {
99 -  web_contents_delegate_->WebContents()->GetController().GoForward();
100 +  NavigationController().GoForward();
101  }
102  
103  void WebViewPrivate::GoBack() {
104 -  web_contents_delegate_->WebContents()->GetController().GoBack();
105 +  NavigationController().GoBack();
106  }
107  
108  void WebViewPrivate::Reload() {
109 -  web_contents_delegate_->WebContents()->GetController().Reload(false);
110 +  NavigationController().Reload(false);
111  }
112  
113  void WebViewPrivate::LoadURL(const GURL& url) {
114 -  url_ = EinaSharedString(url.spec());
115    content::NavigationController::LoadURLParams params(url);
116    params.transition_type = content::PageTransitionFromInt(
117        content::PAGE_TRANSITION_TYPED |
118        content::PAGE_TRANSITION_FROM_ADDRESS_BAR);
119 -  web_contents_delegate_->WebContents()->
120 -      GetController().LoadURLWithParams(params);
121 -  web_contents_delegate_->WebContents()->GetView()->Focus();
122 +  NavigationController().LoadURLWithParams(params);
123 +}
124 +
125 +void WebViewPrivate::informURLChanged() {
126 +  const std::string& url_str = NavigationController().
127 +          GetActiveEntry()->GetURL().spec();
128 +  if (!url_str.compare(url_ ? url_ : ""))
129 +    return;
130 +
131 +  url_ = EinaSharedString(url_str);
132 +
133 +  SmartCallback<webviewcallbacks::URLChanged>().Call(url_);
134 +}
135 +
136 +inline content::NavigationController& WebViewPrivate::NavigationController() const {
137 +  return web_contents_delegate_->WebContents()->GetController();
138  }
139  
140  Evas_Object* WebViewPrivate::EvasObject() {
141 diff --git a/efl_webview/lib/webview.h b/efl_webview/lib/webview.h
142 index b5d9a7b..43b6183 100644
143 --- a/efl_webview/lib/webview.h
144 +++ b/efl_webview/lib/webview.h
145 @@ -14,6 +14,12 @@
146  #include "efl_webview/lib/webview_callbacks.h"
147  #include "googleurl/src/gurl.h"
148  
149 +namespace content {
150 +
151 +class NavigationController;
152 +
153 +}
154 +
155  namespace xwalk {
156  
157  class WebContentsDelegateXWalk;
158 @@ -41,9 +47,13 @@ class WebViewPrivate {  // FIXME : Consider renaming.
159        return webviewcallbacks::Callback<type>(view_object_);
160    }
161  
162 +  void informURLChanged();
163 +
164   private:
165    explicit WebViewPrivate(Evas_Object* evas_object);
166  
167 +  content::NavigationController& NavigationController() const;
168 +
169    Evas_Object* view_object_;
170    scoped_refptr<WebRuntimeContext> context_;
171    scoped_ptr<WebContentsDelegateXWalk> web_contents_delegate_;
172 diff --git a/efl_webview/lib/webview_callbacks.h b/efl_webview/lib/webview_callbacks.h
173 index a5f6092..241b1d6 100644
174 --- a/efl_webview/lib/webview_callbacks.h
175 +++ b/efl_webview/lib/webview_callbacks.h
176 @@ -13,7 +13,8 @@ namespace webviewcallbacks {
177  
178  enum CallbackType {
179    LoadProgress,
180 -  TitleChange
181 +  TitleChange,
182 +  URLChanged
183  };
184  
185  template <CallbackType>
186 @@ -71,7 +72,7 @@ struct CallBackInfo<callbackType> {                              \
187  // Note: type 'void' means that no arguments are expected.
188  DECLARE_XWALK_VIEW_CALLBACK(LoadProgress, "load,progress", double*);
189  DECLARE_XWALK_VIEW_CALLBACK(TitleChange, "title,changed", const char*);
190 -
191 +DECLARE_XWALK_VIEW_CALLBACK(URLChanged, "url,changed", const char*);
192  }  // namespace webviewcallbacks
193  
194  }  // namespace xwalk
195 diff --git a/efl_webview/public/xwalk_view.h b/efl_webview/public/xwalk_view.h
196 index 4758e41..1e9077d 100644
197 --- a/efl_webview/public/xwalk_view.h
198 +++ b/efl_webview/public/xwalk_view.h
199 @@ -7,7 +7,9 @@
200   *
201   * The following signals (see evas_object_smart_callback_add()) are emitted:
202   *
203 + * - "title,changed", const char*: title of the main frame was changed.
204   * - "load,progress", double*: load progress has changed (value from 0.0 to 1.0).
205 + * - "url,changed", const char*: url of the main frame was changed.
206   */
207  
208  #ifndef xwalk_view_h
209 -- 
210 1.8.1.2
211