1 From 4acef7c4becad5d74cbdfda9045d968a8628eb27 Mon Sep 17 00:00:00 2001
2 From: Mikhail Pozdnyakov <mikhail.pozdnyakov@intel.com>
3 Date: Thu, 1 Aug 2013 13:57:05 +0300
4 Subject: [PATCH 12/33] WebView re-factoring: no dep to elm, memory management.
7 .../renderer_host/render_widget_host_view_efl.cc | 4 +-
8 .../renderer_host/render_widget_host_view_efl.h | 2 +-
9 efl_webview/examples/main.cc | 2 +-
10 efl_webview/lib/webview.cc | 192 ++++++++++++++-------
11 efl_webview/lib/webview.h | 29 +++-
12 efl_webview/public/xwalk_main.cc | 2 +-
13 efl_webview/public/xwalk_view.cc | 39 ++---
14 efl_webview/public/xwalk_view.h | 2 +-
15 8 files changed, 170 insertions(+), 102 deletions(-)
17 diff --git a/content/browser/renderer_host/render_widget_host_view_efl.cc b/content/browser/renderer_host/render_widget_host_view_efl.cc
18 index 1e12159..76b19f3 100644
19 --- a/content/browser/renderer_host/render_widget_host_view_efl.cc
20 +++ b/content/browser/renderer_host/render_widget_host_view_efl.cc
21 @@ -200,11 +200,11 @@ bool RenderWidgetHostViewEfl::OnMessageReceived(const IPC::Message& message) {
23 void RenderWidgetHostViewEfl::InitAsChild(
24 gfx::NativeView parent_view) {
25 - preserve_window_ = gfx::PreserveWindow::Create(this, evas_object_evas_get(parent_view));
26 + preserve_window_.reset(gfx::PreserveWindow::Create(this, evas_object_evas_get(parent_view)));
27 evas_object_size_hint_align_set(preserve_window_->SmartObject(), EVAS_HINT_FILL, EVAS_HINT_FILL);
28 evas_object_size_hint_weight_set(preserve_window_->SmartObject(), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
29 - elm_box_pack_end(parent_view, preserve_window_->SmartObject());
30 evas_object_show(preserve_window_->SmartObject());
31 + evas_object_box_append(parent_view, preserve_window_->SmartObject());
32 compositing_surface_ = preserve_window_->EmbeddedXWindow();
35 diff --git a/content/browser/renderer_host/render_widget_host_view_efl.h b/content/browser/renderer_host/render_widget_host_view_efl.h
36 index e20f51b..f047e35 100644
37 --- a/content/browser/renderer_host/render_widget_host_view_efl.h
38 +++ b/content/browser/renderer_host/render_widget_host_view_efl.h
39 @@ -287,7 +287,7 @@ class CONTENT_EXPORT RenderWidgetHostViewEfl
41 gfx::PluginWindowHandle compositing_surface_;
43 - gfx::PreserveWindow* preserve_window_;
44 + scoped_ptr<gfx::PreserveWindow> preserve_window_;
46 scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_;
48 diff --git a/efl_webview/examples/main.cc b/efl_webview/examples/main.cc
49 index 6dac4e8..b9ece50 100644
50 --- a/efl_webview/examples/main.cc
51 +++ b/efl_webview/examples/main.cc
52 @@ -103,7 +103,7 @@ static void window_create()
53 evas_object_show(url_entry);
56 - Evas_Object* web_view = xwalk_view_add(elm_window);
57 + Evas_Object* web_view = xwalk_view_add(evas_object_evas_get(elm_window));
58 evas_object_size_hint_weight_set(web_view, EVAS_HINT_EXPAND,
60 evas_object_size_hint_align_set(web_view, EVAS_HINT_FILL, EVAS_HINT_FILL);
61 diff --git a/efl_webview/lib/webview.cc b/efl_webview/lib/webview.cc
62 index 61ecb96..ae886e7 100644
63 --- a/efl_webview/lib/webview.cc
64 +++ b/efl_webview/lib/webview.cc
67 #include "efl_webview/lib/webview.h"
69 -#include <Elementary.h>
73 #include "base/command_line.h"
74 #include "base/file_util.h"
75 #include "base/files/file_path.h"
80 -typedef std::map<const Evas_Object*, xwalk::WebView*> EvasWebViewMap;
81 +const char evas_smart_xwalk_view_type[] = "Evas_Smart_Xwalk_View";
83 +struct XWalk_View_Smart_Data {
84 + Evas_Object_Box_Data base_;
85 + xwalk::WebViewPrivate* priv_;
88 +bool IsXWalkViewEvasObject(const Evas_Object* evas_object) {
89 + DCHECK(evas_object);
91 + const char* evas_object_type = evas_object_type_get(evas_object);
92 + if (!evas_object_smart_type_check(evas_object, evas_smart_xwalk_view_type)) {
93 + LOG(ERROR) << evas_object << " is not of an "
94 + << evas_object_type << "!";
98 + const Evas_Smart* evas_smart = evas_object_smart_smart_get(evas_object);
100 + LOG(ERROR) << evas_object << "("
101 + << evas_object_type << ") is not a smart object!";
105 + const Evas_Smart_Class* smart_class = evas_smart_class_get(evas_smart);
106 + if (!smart_class) {
107 + LOG(ERROR) << evas_object << "("
108 + << evas_object_type << ") is not a smart class object!";
115 +inline XWalk_View_Smart_Data* ToSmartData(const Evas_Object* evas_object) {
116 + DCHECK(evas_object);
117 + DCHECK(IsXWalkViewEvasObject(evas_object));
118 + CHECK(evas_object_smart_data_get(evas_object));
119 + return static_cast<XWalk_View_Smart_Data*>(
120 + evas_object_smart_data_get(evas_object));
123 +EVAS_SMART_SUBCLASS_NEW(evas_smart_xwalk_view_type, xwalk_view,
124 + Evas_Object_Box_Api, Evas_Object_Box_Api,
125 + evas_object_box_smart_class_get, 0);
127 +void xwalk_view_smart_add(Evas_Object* o) {
128 + XWalk_View_Smart_Data* smart_data =
129 + static_cast<XWalk_View_Smart_Data*>(evas_object_smart_data_get(o));
131 -inline EvasWebViewMap& EvasObjectToWebViewMap() {
132 -// FIXME: Temporary solution until web view has its own smart class.
133 - static EvasWebViewMap map;
136 + smart_data = static_cast<XWalk_View_Smart_Data*>(
137 + calloc(1, sizeof(XWalk_View_Smart_Data)));
139 + const Evas_Smart* smart = evas_object_smart_smart_get(o);
140 + const Evas_Smart_Class* smart_class = evas_smart_class_get(smart);
141 + smart_data->base_.api =
142 + reinterpret_cast<const Evas_Object_Box_Api*>(smart_class);
144 + smart_data->priv_ = 0;
146 + evas_object_smart_data_set(o, smart_data);
149 + xwalk_view_parent_sc->base.add(o);
152 +void xwalk_view_smart_del(Evas_Object* object) {
153 + XWalk_View_Smart_Data* smart_data = ToSmartData(object);
154 + DCHECK(smart_data->priv_);
155 + delete smart_data->priv_;
156 + xwalk_view_parent_sc->base.del(object);
159 +void xwalk_view_smart_set_user(Evas_Object_Box_Api* smart_class) {
160 + smart_class->base.add = xwalk_view_smart_add;
161 + smart_class->base.del = xwalk_view_smart_del;
168 -struct WebView::Private {
169 - Evas_Object* root_window;
170 - Evas_Object* view_box;
171 - scoped_refptr<WebRuntimeContext> context;
172 - scoped_ptr<WebContentsDelegateXWalk> webContentsDelegate;
173 - static GURL s_startup_url;
175 +GURL WebViewPrivate::s_startup_url = GURL();
177 -GURL WebView::Private::s_startup_url = GURL();
178 +Evas_Object* CreateWebView(Evas* canvas) {
182 -WebView* WebView::Create(Evas_Object* root_window) {
183 - return new WebView(root_window);
184 + Evas_Object* view_object =
185 + evas_object_smart_add(canvas, xwalk_view_smart_class_new());
187 + XWalk_View_Smart_Data* smart_data = ToSmartData(view_object);
188 + DCHECK(smart_data);
190 + DCHECK(!smart_data->priv_);
191 + smart_data->priv_ = new WebViewPrivate(view_object);
193 + return view_object;
197 -void WebView::CommandLineInit(int argc, char** argv) {
198 +void WebViewPrivate::CommandLineInit(int argc, char** argv) {
199 CommandLine::Init(argc, argv);
201 CommandLine* command_line = CommandLine::ForCurrentProcess();
202 @@ -61,86 +130,75 @@ void WebView::CommandLineInit(int argc, char** argv) {
203 if (!(url.is_valid() && url.has_scheme()))
204 url = net::FilePathToFileURL(base::FilePath(args[0]));
206 - WebView::Private::s_startup_url = GURL(url);
207 + WebViewPrivate::s_startup_url = GURL(url);
210 -WebView::WebView(Evas_Object* root_window)
211 - : private_(new Private) {
212 +WebViewPrivate::WebViewPrivate(Evas_Object* view_object)
213 + : view_object_(view_object)
214 + , context_(WebRuntimeContext::current()) {
216 - if (!WebView::Private::s_startup_url.is_valid())
217 - WebView::Private::s_startup_url = GURL("about:blank");
218 + if (!WebViewPrivate::s_startup_url.is_valid())
219 + WebViewPrivate::s_startup_url = GURL("about:blank");
222 - private_->root_window = root_window;
223 - private_->view_box = elm_box_add(private_->root_window);
224 - // FIXME: In future this has to be a separate Smart Class representing web view.
225 - // 'this' should be set as smart_data->priv
226 - EvasObjectToWebViewMap()[private_->view_box] = this;
228 - elm_object_focus_allow_set(private_->view_box, EINA_TRUE);
230 - private_->context = WebRuntimeContext::current();
231 + DCHECK(view_object_);
232 content::BrowserContext* browser_context =
233 - private_->context->BrowserContext();
234 - private_->webContentsDelegate.reset(
235 - new WebContentsDelegateXWalk(browser_context, private_->view_box));
236 + context_->BrowserContext();
237 + web_contents_delegate_.reset(
238 + new WebContentsDelegateXWalk(browser_context, view_object_));
240 content::WebContentsViewEfl* content_view =
241 - static_cast<content::WebContentsViewEfl*>(private_->
242 - webContentsDelegate->WebContents()->GetView());
243 - // FIXME: Don't pass elm_box to WebContentsViewEfl. Need focus handling of PreserveWindow evas object here.
244 - content_view->SetViewContainerBox(private_->view_box);
245 + static_cast<content::WebContentsViewEfl*>(web_contents_delegate_->
246 + WebContents()->GetView());
247 + content_view->SetViewContainerBox(view_object_);
248 static_cast<WebContentsViewDelegateXWalk*>(content_view->delegate())->
249 - SetViewContainerBox(private_->view_box);
250 + SetViewContainerBox(view_object_);
252 - LoadURL(WebView::Private::s_startup_url);
253 + LoadURL(WebViewPrivate::s_startup_url);
256 -WebView::~WebView() {
257 -// FIXME : And by the way who will invoke it?
258 - EvasObjectToWebViewMap().erase(private_->view_box);
259 - evas_object_del(private_->view_box);
260 +WebViewPrivate::~WebViewPrivate() {
263 -bool WebView::CanGoBack() const {
264 - return private_->webContentsDelegate->WebContents()->GetController().CanGoBack();
265 +bool WebViewPrivate::CanGoBack() const {
266 + return web_contents_delegate_->WebContents()->GetController().CanGoBack();
269 -bool WebView::CanGoForward() const {
270 - return private_->webContentsDelegate->WebContents()->GetController().CanGoForward();
271 +bool WebViewPrivate::CanGoForward() const {
272 + return web_contents_delegate_->WebContents()->GetController().CanGoForward();
275 -void WebView::GoForward() {
276 - private_->webContentsDelegate->WebContents()->GetController().GoForward();
277 +void WebViewPrivate::GoForward() {
278 + web_contents_delegate_->WebContents()->GetController().GoForward();
281 -void WebView::GoBack() {
282 - private_->webContentsDelegate->WebContents()->GetController().GoBack();
283 +void WebViewPrivate::GoBack() {
284 + web_contents_delegate_->WebContents()->GetController().GoBack();
287 -void WebView::Reload() {
288 - private_->webContentsDelegate->WebContents()->GetController().Reload(false);
289 +void WebViewPrivate::Reload() {
290 + web_contents_delegate_->WebContents()->GetController().Reload(false);
293 -void WebView::LoadURL(const GURL& url) {
294 +void WebViewPrivate::LoadURL(const GURL& url) {
295 url_ = EinaSharedString(url.spec());
296 content::NavigationController::LoadURLParams params(url);
297 params.transition_type = content::PageTransitionFromInt(
298 content::PAGE_TRANSITION_TYPED |
299 content::PAGE_TRANSITION_FROM_ADDRESS_BAR);
300 - private_->webContentsDelegate->WebContents()->
301 + web_contents_delegate_->WebContents()->
302 GetController().LoadURLWithParams(params);
303 - private_->webContentsDelegate->WebContents()->GetView()->Focus();
304 + web_contents_delegate_->WebContents()->GetView()->Focus();
307 -Evas_Object* WebView::EvasObject() {
308 - return private_->view_box;
309 +Evas_Object* WebViewPrivate::EvasObject() {
310 + return view_object_;
313 -WebView* ToWebView(const Evas_Object* evas_object) {
314 - EvasWebViewMap::iterator found = EvasObjectToWebViewMap().find(evas_object);
315 - if (found != EvasObjectToWebViewMap().end())
316 - return found->second;
317 +WebViewPrivate* ToWebViewPrivate(const Evas_Object* evas_object) {
318 + if (evas_object && IsXWalkViewEvasObject(evas_object))
319 + return ToSmartData(evas_object)->priv_;
324 diff --git a/efl_webview/lib/webview.h b/efl_webview/lib/webview.h
325 index ae4f98f..62a5772 100644
326 --- a/efl_webview/lib/webview.h
327 +++ b/efl_webview/lib/webview.h
331 #include "base/basictypes.h"
332 +#include "base/memory/ref_counted.h"
333 #include "base/memory/scoped_ptr.h"
334 #include "base/strings/efl/eina_shared_string.h"
335 #include "googleurl/src/gurl.h"
339 -class EAPI WebView {
340 +class WebContentsDelegateXWalk;
341 +class WebRuntimeContext;
343 +class WebViewPrivate {
345 - EAPI static WebView* Create(Evas_Object* root_window);
346 - EAPI static void CommandLineInit(int argc, char** argv);
347 + static void CommandLineInit(int argc, char** argv);
352 EAPI Evas_Object* EvasObject();
354 @@ -33,16 +36,24 @@ class EAPI WebView {
355 const char* url() const { return url_; }
358 - explicit WebView(Evas_Object* root_window);
359 + explicit WebViewPrivate(Evas_Object* evas_object);
362 - scoped_ptr<Private> private_;
363 + Evas_Object* view_object_;
364 + scoped_refptr<WebRuntimeContext> context_;
365 + scoped_ptr<WebContentsDelegateXWalk> web_contents_delegate_;
366 EinaSharedString url_;
368 - DISALLOW_COPY_AND_ASSIGN(WebView);
369 + static GURL s_startup_url;
371 + friend Evas_Object* CreateWebView(Evas* canvas);
373 + DISALLOW_COPY_AND_ASSIGN(WebViewPrivate);
376 -WebView* ToWebView(const Evas_Object*);
378 +Evas_Object* CreateWebView(Evas* canvas);
380 +WebViewPrivate* ToWebViewPrivate(const Evas_Object* web_view);
384 diff --git a/efl_webview/public/xwalk_main.cc b/efl_webview/public/xwalk_main.cc
385 index 218c55d..2dfc902 100644
386 --- a/efl_webview/public/xwalk_main.cc
387 +++ b/efl_webview/public/xwalk_main.cc
389 #include "efl_webview/lib/webview.h"
391 void xwalk_init(int argc, char *argv[]) {
392 - xwalk::WebView::CommandLineInit(argc, argv);
393 + xwalk::WebViewPrivate::CommandLineInit(argc, argv);
395 diff --git a/efl_webview/public/xwalk_view.cc b/efl_webview/public/xwalk_view.cc
396 index b000143..0acd334 100644
397 --- a/efl_webview/public/xwalk_view.cc
398 +++ b/efl_webview/public/xwalk_view.cc
400 #include "efl_webview/public/xwalk_view.h"
401 #include "efl_webview/lib/webview.h"
403 -using namespace xwalk;
405 -#define XWALK_VIEW_GET_IMPL_OR_RETURN(xwalk_view, impl, ...) \
406 - WebView* impl = ToWebView(xwalk_view); \
407 +#define XWALK_VIEW_GET_PRIVATE_OR_RETURN(xwalk_view, priv, ...) \
408 + xwalk::WebViewPrivate* priv = xwalk::ToWebViewPrivate(xwalk_view); \
412 EINA_LOG_CRIT("no private data for object %p", xwalk_view); \
413 return __VA_ARGS__; \
418 -Evas_Object* xwalk_view_add(Evas_Object* root_window) {
419 - return WebView::Create(root_window)->EvasObject();
420 +Evas_Object* xwalk_view_add(Evas* canvas) {
421 + EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
423 + return xwalk::CreateWebView(canvas);
426 Eina_Bool xwalk_view_url_set(Evas_Object* evas_object, const char* url) {
427 - XWALK_VIEW_GET_IMPL_OR_RETURN(evas_object, impl, false);
428 + XWALK_VIEW_GET_PRIVATE_OR_RETURN(evas_object, priv, false);
429 EINA_SAFETY_ON_NULL_RETURN_VAL(url, false);
431 - impl->LoadURL(GURL(url));
432 + priv->LoadURL(GURL(url));
436 const char* xwalk_view_url_get(const Evas_Object* evas_object) {
437 - XWALK_VIEW_GET_IMPL_OR_RETURN(evas_object, impl, "");
438 - return impl->url();
439 + XWALK_VIEW_GET_PRIVATE_OR_RETURN(evas_object, priv, "");
440 + return priv->url();
443 Eina_Bool xwalk_view_reload(Evas_Object* evas_object) {
444 - XWALK_VIEW_GET_IMPL_OR_RETURN(evas_object, impl, false);
447 + XWALK_VIEW_GET_PRIVATE_OR_RETURN(evas_object, priv, false);
452 Eina_Bool xwalk_view_back(Evas_Object* evas_object) {
453 - XWALK_VIEW_GET_IMPL_OR_RETURN(evas_object, impl, false);
454 - if (impl->CanGoBack()) {
456 + XWALK_VIEW_GET_PRIVATE_OR_RETURN(evas_object, priv, false);
457 + if (priv->CanGoBack()) {
464 Eina_Bool xwalk_view_forward(Evas_Object* evas_object) {
465 - XWALK_VIEW_GET_IMPL_OR_RETURN(evas_object, impl, false);
466 - if (impl->CanGoForward()) {
468 + XWALK_VIEW_GET_PRIVATE_OR_RETURN(evas_object, priv, false);
469 + if (priv->CanGoForward()) {
474 diff --git a/efl_webview/public/xwalk_view.h b/efl_webview/public/xwalk_view.h
475 index a4c85d58..fbde786 100644
476 --- a/efl_webview/public/xwalk_view.h
477 +++ b/efl_webview/public/xwalk_view.h
482 -EAPI Evas_Object *xwalk_view_add(Evas_Object *root_window);
483 +EAPI Evas_Object *xwalk_view_add(Evas *canvas);
485 EAPI Eina_Bool xwalk_view_url_set(Evas_Object *obj, const char *url);