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.
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(-)
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);
25 +on_url_changed(void *user_data, Evas_Object *xwalk_view, void *event_info)
27 + char *url = elm_entry_utf8_to_markup((const char *)event_info);
28 + elm_entry_entry_set((Evas_Object*)user_data, url);
32 static void window_create()
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);
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(
52 +void WebContentsDelegateXWalk::UpdateTargetURL(content::WebContents* source,
53 + int32 page_id, const GURL& url) {
54 + web_view_->informURLChanged();
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;
66 + virtual void UpdateTargetURL(content::WebContents* source,
68 + const GURL& url) OVERRIDE;
70 content::WebContents* WebContents() { return web_contents_.get(); }
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
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() {
88 bool WebViewPrivate::CanGoBack() const {
89 - return web_contents_delegate_->WebContents()->GetController().CanGoBack();
90 + return NavigationController().CanGoBack();
93 bool WebViewPrivate::CanGoForward() const {
94 - return web_contents_delegate_->WebContents()->GetController().CanGoForward();
95 + return NavigationController().CanGoForward();
98 void WebViewPrivate::GoForward() {
99 - web_contents_delegate_->WebContents()->GetController().GoForward();
100 + NavigationController().GoForward();
103 void WebViewPrivate::GoBack() {
104 - web_contents_delegate_->WebContents()->GetController().GoBack();
105 + NavigationController().GoBack();
108 void WebViewPrivate::Reload() {
109 - web_contents_delegate_->WebContents()->GetController().Reload(false);
110 + NavigationController().Reload(false);
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);
125 +void WebViewPrivate::informURLChanged() {
126 + const std::string& url_str = NavigationController().
127 + GetActiveEntry()->GetURL().spec();
128 + if (!url_str.compare(url_ ? url_ : ""))
131 + url_ = EinaSharedString(url_str);
133 + SmartCallback<webviewcallbacks::URLChanged>().Call(url_);
136 +inline content::NavigationController& WebViewPrivate::NavigationController() const {
137 + return web_contents_delegate_->WebContents()->GetController();
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
146 #include "efl_webview/lib/webview_callbacks.h"
147 #include "googleurl/src/gurl.h"
151 +class NavigationController;
157 class WebContentsDelegateXWalk;
158 @@ -41,9 +47,13 @@ class WebViewPrivate { // FIXME : Consider renaming.
159 return webviewcallbacks::Callback<type>(view_object_);
162 + void informURLChanged();
165 explicit WebViewPrivate(Evas_Object* evas_object);
167 + content::NavigationController& NavigationController() const;
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 {
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*);
191 +DECLARE_XWALK_VIEW_CALLBACK(URLChanged, "url,changed", const char*);
192 } // namespace webviewcallbacks
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
201 * The following signals (see evas_object_smart_callback_add()) are emitted:
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.