1 From 33d979ca744bb52d6c8490b9718ac6ee09f5ff7f Mon Sep 17 00:00:00 2001
2 From: Dongseong Hwang <dongseong.hwang@intel.com>
3 Date: Fri, 28 Jun 2013 14:25:43 +0300
4 Subject: [PATCH 05/33] Implement efl webview library and example launcher.
6 1. build efl_webview library
9 2. build efl_webview_example executable
10 make efl_webview_example
12 Make sub process be able to launch
13 Add process executable to launch sub process (i.e. gpu process, zygote)
16 base/run_loop.h | 8 +-
18 .../browser/zygote_host/zygote_host_impl_linux.cc | 6 +-
19 content/public/app/content_main_runner.h | 3 +-
20 content/public/common/content_client.h | 2 +-
21 efl_webview/DEPS | 4 +
22 efl_webview/efl_webview.gyp | 134 +++++++++++++++++++++
23 efl_webview/examples/main.cc | 102 ++++++++++++++++
24 efl_webview/lib/browser_context_xwalk.h | 30 +++++
25 efl_webview/lib/content_browser_client_xwalk.cc | 60 +++++++++
26 efl_webview/lib/content_browser_client_xwalk.h | 29 +++++
27 efl_webview/lib/process_main.cc | 24 ++++
28 efl_webview/lib/process_main.h | 16 +++
29 efl_webview/lib/web_runtime_context.cc | 118 ++++++++++++++++++
30 efl_webview/lib/web_runtime_context.h | 37 ++++++
31 efl_webview/lib/webview.cc | 91 ++++++++++++++
32 efl_webview/lib/webview.h | 40 ++++++
33 efl_webview/process/main.cc | 10 ++
34 19 files changed, 708 insertions(+), 8 deletions(-)
35 create mode 100644 efl_webview/DEPS
36 create mode 100644 efl_webview/efl_webview.gyp
37 create mode 100644 efl_webview/examples/main.cc
38 create mode 100644 efl_webview/lib/browser_context_xwalk.h
39 create mode 100644 efl_webview/lib/content_browser_client_xwalk.cc
40 create mode 100644 efl_webview/lib/content_browser_client_xwalk.h
41 create mode 100644 efl_webview/lib/process_main.cc
42 create mode 100644 efl_webview/lib/process_main.h
43 create mode 100644 efl_webview/lib/web_runtime_context.cc
44 create mode 100644 efl_webview/lib/web_runtime_context.h
45 create mode 100644 efl_webview/lib/webview.cc
46 create mode 100644 efl_webview/lib/webview.h
47 create mode 100644 efl_webview/process/main.cc
49 diff --git a/AUTHORS b/AUTHORS
50 index a0e975c..d6978e6 100644
53 @@ -251,3 +251,4 @@ Mihai Tica <mihai.o.tica@gmail.com>
54 Mihai Tica <mitica@adobe.com>
55 Bem Jones-Bey <bemajaniman@gmail.com>
56 Bem Jones-Bey <bjonesbe@adobe.com>
57 +Dongseong Hwang <dongseong.hwang@intel.com>
58 diff --git a/base/run_loop.h b/base/run_loop.h
59 index 380c8bf..469b8a7 100644
62 @@ -72,6 +72,10 @@ class BASE_EXPORT RunLoop {
64 base::Closure QuitClosure();
66 + // Return false to abort the Run.
71 friend class MessageLoop;
72 #if defined(OS_ANDROID)
73 @@ -86,10 +90,6 @@ class BASE_EXPORT RunLoop {
74 friend class base::MessagePumpUIApplication;
77 - // Return false to abort the Run.
83 // WeakPtrFactory for QuitClosure safety.
84 diff --git a/build/all.gyp b/build/all.gyp
85 index 14d4888..9043af8 100644
89 '../chrome/chrome.gyp:*',
90 '../content/content.gyp:*',
91 '../crypto/crypto.gyp:*',
92 + '../efl_webview/efl_webview.gyp:*',
93 '../media/media.gyp:*',
96 diff --git a/content/browser/zygote_host/zygote_host_impl_linux.cc b/content/browser/zygote_host/zygote_host_impl_linux.cc
97 index ba7884f8..1be62f0 100644
98 --- a/content/browser/zygote_host/zygote_host_impl_linux.cc
99 +++ b/content/browser/zygote_host/zygote_host_impl_linux.cc
101 #include "content/browser/renderer_host/render_sandbox_host_linux.h"
102 #include "content/common/zygote_commands_linux.h"
103 #include "content/public/browser/content_browser_client.h"
104 +#include "content/public/common/child_process_host.h"
105 #include "content/public/common/content_switches.h"
106 #include "content/public/common/result_codes.h"
107 #include "sandbox/linux/suid/client/setuid_sandbox_client.h"
108 @@ -68,8 +69,9 @@ void ZygoteHostImpl::Init(const std::string& sandbox_cmd) {
112 - base::FilePath chrome_path;
113 - CHECK(PathService::Get(base::FILE_EXE, &chrome_path));
114 + int child_flags = ChildProcessHost::CHILD_NORMAL;
115 + base::FilePath chrome_path = ChildProcessHost::GetChildPath(child_flags);
116 + CHECK(!chrome_path.empty());
117 CommandLine cmd_line(chrome_path);
119 cmd_line.AppendSwitchASCII(switches::kProcessType, switches::kZygoteProcess);
120 diff --git a/content/public/app/content_main_runner.h b/content/public/app/content_main_runner.h
121 index bed5ff2..992e0d0 100644
122 --- a/content/public/app/content_main_runner.h
123 +++ b/content/public/app/content_main_runner.h
127 #include "build/build_config.h"
128 +#include "content/common/content_export.h"
132 @@ -22,7 +23,7 @@ namespace content {
133 class ContentMainDelegate;
135 // This class is responsible for content initialization, running and shutdown.
136 -class ContentMainRunner {
137 +class CONTENT_EXPORT ContentMainRunner {
139 virtual ~ContentMainRunner() {}
141 diff --git a/content/public/common/content_client.h b/content/public/common/content_client.h
142 index 198ecad..778fcac 100644
143 --- a/content/public/common/content_client.h
144 +++ b/content/public/common/content_client.h
145 @@ -60,7 +60,7 @@ CONTENT_EXPORT void SetContentClient(ContentClient* client);
147 #if defined(CONTENT_IMPLEMENTATION)
148 // Content's embedder API should only be used by content.
149 -ContentClient* GetContentClient();
150 +CONTENT_EXPORT ContentClient* GetContentClient();
153 // Used for tests to override the relevant embedder interfaces. Each method
154 diff --git a/efl_webview/DEPS b/efl_webview/DEPS
156 index 0000000..dd8d329
158 +++ b/efl_webview/DEPS
164 diff --git a/efl_webview/efl_webview.gyp b/efl_webview/efl_webview.gyp
166 index 0000000..b4d25d3
168 +++ b/efl_webview/efl_webview.gyp
172 + 'efl_webview_product_name': 'EFL WebView',
173 + # TODO: define efl webview version format.
174 + 'cameo_version': '0.28.0.1',
177 + 'use_custom_freetype%': 1,
179 + 'use_custom_freetype%': 0,
185 + 'target_name': 'efl_webview',
186 + 'type': '<(component)',
188 + 'chromium_code': 1,
191 + '../base/base.gyp:base',
192 + '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
193 + '../build/temp_gyp/googleurl.gyp:googleurl',
194 + '../content/content.gyp:content_app',
195 + '../content/content.gyp:content_browser',
196 + '../content/content.gyp:content_common',
197 + '../content/content.gyp:content_gpu',
198 + '../content/content.gyp:content_plugin',
199 + '../content/content.gyp:content_ppapi_plugin',
200 + '../content/content.gyp:content_renderer',
201 + '../content/content.gyp:content_utility',
202 + '../content/content.gyp:content_worker',
203 + # BrowserContextXWalk depend on content_shell_lib
204 + '../content/content.gyp:content_shell_lib',
205 + '../content/content_resources.gyp:content_resources',
206 + '../ipc/ipc.gyp:ipc',
207 + '../media/media.gyp:media',
208 + '../net/net.gyp:net',
209 + '../net/net.gyp:net_resources',
210 + '../skia/skia.gyp:skia',
211 + '../third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit',
212 + '../ui/gl/gl.gyp:gl',
214 + '../v8/tools/gyp/v8.gyp:v8',
215 + '../webkit/support/webkit_support.gyp:webkit_resources',
216 + '../webkit/support/webkit_support.gyp:webkit_support',
222 + 'lib/content_browser_client_xwalk.cc',
223 + 'lib/content_browser_client_xwalk.h',
224 + 'lib/browser_context_xwalk.h',
225 + 'lib/process_main.cc',
226 + 'lib/process_main.h',
227 + 'lib/web_runtime_context.cc',
228 + 'lib/web_runtime_context.h',
235 + '../build/linux/system.gyp:fontconfig',
238 + ['os_posix==1 and linux_use_tcmalloc==1', {
240 + # This is needed by content/app/content_main_runner.cc
241 + '../base/allocator/allocator.gyp:allocator',
243 + }], # os_posix==1 and linux_use_tcmalloc==1
244 + ['use_custom_freetype==1', {
246 + '../third_party/freetype2/freetype2.gyp:freetype2',
248 + }], # use_custom_freetype==1
249 + ['toolkit_uses_gtk == 1', {
251 + '<(DEPTH)/build/linux/system.gyp:gtk',
253 + }], # toolkit_uses_gtk
254 + ['toolkit_uses_efl == 1', {
256 + '../build/linux/system.gyp:efl',
262 + 'target_name': 'efl_webview_example',
263 + 'type': 'executable',
272 + 'examples/main.cc',
275 + ['toolkit_uses_efl == 1', {
277 + '../build/linux/system.gyp:efl',
283 + 'target_name': 'efl_process',
284 + 'type': 'executable',
295 + ['toolkit_uses_efl == 1', {
297 + '../build/linux/system.gyp:efl',
304 diff --git a/efl_webview/examples/main.cc b/efl_webview/examples/main.cc
306 index 0000000..ee610fb
308 +++ b/efl_webview/examples/main.cc
310 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
311 +// Use of this source code is governed by a BSD-style license that can be
312 +// found in the LICENSE file.
315 +#include <Ecore_Evas.h>
316 +#include <Elementary.h>
318 +#include "efl_webview/lib/process_main.h"
319 +#include "efl_webview/lib/webview.h"
321 +static const char APP_NAME[] = "EFL WebView Example";
323 +static int window_width = 800;
324 +static int window_height = 600;
327 +on_back_button_clicked(void *user_data, Evas_Object *back_button, void *event_info)
329 + xwalk::WebView* webview = static_cast<xwalk::WebView*>(user_data);
334 +on_forward_button_clicked(void *user_data, Evas_Object *forward_button, void *event_info)
336 + xwalk::WebView* webview = static_cast<xwalk::WebView*>(user_data);
337 + webview->Forward();
340 +static void window_create()
342 + /* Create window */
343 + Evas_Object* elm_window = elm_win_util_standard_add("efl-webview-window", APP_NAME);
344 + elm_win_autodel_set(elm_window, EINA_TRUE);
346 + /* Create vertical layout */
347 + Evas_Object* vertical_layout = elm_box_add(elm_window);
348 + elm_box_padding_set(vertical_layout, 0, 2);
349 + evas_object_size_hint_weight_set(vertical_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
350 + elm_win_resize_object_add(elm_window, vertical_layout);
351 + evas_object_show(vertical_layout);
353 + /* Create horizontal layout for top bar */
354 + Evas_Object* horizontal_layout = elm_box_add(elm_window);
355 + elm_box_horizontal_set(horizontal_layout, EINA_TRUE);
356 + evas_object_size_hint_weight_set(horizontal_layout, EVAS_HINT_EXPAND, 0.0);
357 + evas_object_size_hint_align_set(horizontal_layout, EVAS_HINT_FILL, 0.0);
358 + elm_box_pack_end(vertical_layout, horizontal_layout);
359 + evas_object_show(horizontal_layout);
361 + /* Create Back button */
362 + Evas_Object* back_button = elm_button_add(elm_window);
363 + elm_object_text_set(back_button, "BACK");
364 + evas_object_size_hint_weight_set(back_button, 0.0, EVAS_HINT_EXPAND);
365 + evas_object_size_hint_align_set(back_button, 0.0, 0.5);
366 + elm_box_pack_end(horizontal_layout, back_button);
367 + evas_object_show(back_button);
369 + /* Create Forward button */
370 + Evas_Object* forward_button = elm_button_add(elm_window);
371 + elm_object_text_set(forward_button, "FORWARD");
372 + evas_object_size_hint_weight_set(forward_button, 0.0, EVAS_HINT_EXPAND);
373 + evas_object_size_hint_align_set(forward_button, 0.0, 0.5);
374 + elm_box_pack_end(horizontal_layout, forward_button);
375 + evas_object_show(forward_button);
377 + /* Create WebView */
378 + xwalk::WebView* webview_object = xwalk::WebView::Create(elm_window);
379 + Evas_Object* webview = webview_object->EvasObject();
380 + evas_object_size_hint_weight_set(webview, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
381 + evas_object_size_hint_align_set(webview, EVAS_HINT_FILL, EVAS_HINT_FILL);
382 + elm_box_pack_end(vertical_layout, webview);
383 + evas_object_focus_set(webview, EINA_TRUE);
384 + evas_object_show(webview);
386 + evas_object_smart_callback_add(back_button, "clicked",
387 + on_back_button_clicked, webview_object);
388 + evas_object_smart_callback_add(forward_button, "clicked",
389 + on_forward_button_clicked, webview_object);
391 + evas_object_resize(elm_window, window_width, window_height);
392 + evas_object_show(elm_window);
395 +int main(int argc, char *argv[])
397 + // FIXME: Handle chrome command line and url.
398 + // It is needed only in development stage.
399 + xwalk::WebView::CommandLineInit(argc, argv);
401 + elm_init(argc, argv);
403 + elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
412 diff --git a/efl_webview/lib/browser_context_xwalk.h b/efl_webview/lib/browser_context_xwalk.h
414 index 0000000..869fa82
416 +++ b/efl_webview/lib/browser_context_xwalk.h
418 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
419 +// Use of this source code is governed by a BSD-style license that can be
420 +// found in the LICENSE file.
422 +#ifndef EFL_WEBVIEW_LIBBROWSER_CONTEXT_XWALK_H_
423 +#define EFL_WEBVIEW_LIBBROWSER_CONTEXT_XWALK_H_
425 +#include "content/shell/shell_browser_context.h"
429 +class BrowserContextXWalk : public content::ShellBrowserContext {
431 + BrowserContextXWalk()
432 + : content::ShellBrowserContext(false)
434 + virtual ~BrowserContextXWalk() {}
436 + net::URLRequestContextGetter* CreateRequestContext(
437 + content::ProtocolHandlerMap* protocol_handlers) {
438 + return content::ShellBrowserContext::CreateRequestContext(protocol_handlers);
442 + DISALLOW_COPY_AND_ASSIGN(BrowserContextXWalk);
445 +} // namespace xwalk
447 +#endif // EFL_WEBVIEW_LIBBROWSER_CONTEXT_XWALK_H_
448 diff --git a/efl_webview/lib/content_browser_client_xwalk.cc b/efl_webview/lib/content_browser_client_xwalk.cc
450 index 0000000..7a14c99
452 +++ b/efl_webview/lib/content_browser_client_xwalk.cc
454 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
455 +// Use of this source code is governed by a BSD-style license that can be
456 +// found in the LICENSE file.
458 +#include "efl_webview/lib/content_browser_client_xwalk.h"
460 +#include "content/public/browser/browser_main_parts.h"
461 +#include "content/public/common/main_function_params.h"
462 +#include "efl_webview/lib/browser_context_xwalk.h"
463 +#include "efl_webview/lib/web_runtime_context.h"
467 +class BrowserMainPartsXWalk : public content::BrowserMainParts
470 + BrowserMainPartsXWalk(const content::MainFunctionParams& parameters)
471 + : content::BrowserMainParts()
472 + , parameters_(parameters)
473 + , run_message_loop_(true)
476 + virtual void PreMainMessageLoopStart() OVERRIDE { }
477 + virtual void PostMainMessageLoopStart() OVERRIDE { }
478 + virtual void PreEarlyInitialization() OVERRIDE { }
480 + virtual void PreMainMessageLoopRun() OVERRIDE {
481 + if (parameters_.ui_task) {
482 + parameters_.ui_task->Run();
483 + delete parameters_.ui_task;
484 + run_message_loop_ = false;
488 + virtual bool MainMessageLoopRun(int* result_code) OVERRIDE {
489 + return !run_message_loop_;
492 + virtual void PostMainMessageLoopRun() OVERRIDE { }
495 + const content::MainFunctionParams& parameters_;
496 + bool run_message_loop_;
498 + DISALLOW_COPY_AND_ASSIGN(BrowserMainPartsXWalk);
501 +content::BrowserMainParts *ContentBrowserClientXWalk::CreateBrowserMainParts(
502 + const content::MainFunctionParams ¶meters) {
503 + return new BrowserMainPartsXWalk(parameters);
506 +net::URLRequestContextGetter* ContentBrowserClientXWalk::CreateRequestContext(
507 + content::BrowserContext* content_browser_context,
508 + content::ProtocolHandlerMap* protocol_handlers) {
509 + DCHECK(content_browser_context == WebRuntimeContext::current()->BrowserContext());
510 + return static_cast<BrowserContextXWalk*>(content_browser_context)->CreateRequestContext(protocol_handlers);
513 +} // namespace xwalk
514 diff --git a/efl_webview/lib/content_browser_client_xwalk.h b/efl_webview/lib/content_browser_client_xwalk.h
516 index 0000000..c5c235d
518 +++ b/efl_webview/lib/content_browser_client_xwalk.h
520 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
521 +// Use of this source code is governed by a BSD-style license that can be
522 +// found in the LICENSE file.
524 +#ifndef EFL_WEBVIEW_LIBCONTENT_BROWSER_CLIENT_XWALK_H_
525 +#define EFL_WEBVIEW_LIBCONTENT_BROWSER_CLIENT_XWALK_H_
527 +#include "content/public/browser/content_browser_client.h"
531 +class ContentBrowserClientXWalk : public content::ContentBrowserClient {
533 + ContentBrowserClientXWalk() { }
535 + // ContentBrowserClient overrides.
536 + virtual content::BrowserMainParts* CreateBrowserMainParts(
537 + const content::MainFunctionParams& parameters) OVERRIDE;
538 + virtual net::URLRequestContextGetter* CreateRequestContext(
539 + content::BrowserContext* browser_context,
540 + content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
543 + DISALLOW_COPY_AND_ASSIGN(ContentBrowserClientXWalk);
546 +} // namespace xwalk
548 +#endif // EFL_WEBVIEW_LIBCONTENT_BROWSER_CLIENT_XWALK_H_
549 diff --git a/efl_webview/lib/process_main.cc b/efl_webview/lib/process_main.cc
551 index 0000000..132b35c
553 +++ b/efl_webview/lib/process_main.cc
555 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
556 +// Use of this source code is governed by a BSD-style license that can be
557 +// found in the LICENSE file.
559 +#include "efl_webview/lib/process_main.h"
561 +#include "base/command_line.h"
562 +#include "base/logging.h"
563 +#include "content/public/app/content_main.h"
564 +#include "content/public/common/content_switches.h"
568 +int ProcessMain(int argc, char** argv) {
569 + CommandLine::Init(argc, argv);
570 + const CommandLine& command_line = *CommandLine::ForCurrentProcess();
571 + std::string process_type =
572 + command_line.GetSwitchValueASCII(switches::kProcessType);
573 + CHECK(process_type != "");
575 + return content::ContentMain(argc, const_cast<const char**>(argv), 0);
578 +} // namespace xwalk
579 diff --git a/efl_webview/lib/process_main.h b/efl_webview/lib/process_main.h
581 index 0000000..8e47949
583 +++ b/efl_webview/lib/process_main.h
585 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
586 +// Use of this source code is governed by a BSD-style license that can be
587 +// found in the LICENSE file.
589 +#ifndef EFL_WEBVIEW_LIB_PROCESS_MAIN_H_
590 +#define EFL_WEBVIEW_LIB_PROCESS_MAIN_H_
596 +EAPI int ProcessMain(int argc, char** argv);
598 +} // namespace xwalk
600 +#endif // EFL_WEBVIEW_LIB_PROCESS_MAIN_H_
601 diff --git a/efl_webview/lib/web_runtime_context.cc b/efl_webview/lib/web_runtime_context.cc
603 index 0000000..b2ad541
605 +++ b/efl_webview/lib/web_runtime_context.cc
608 + * Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
609 + * Copyright (c) 2013 Intel Corporation. All rights reserved.
611 + * This library is free software; you can redistribute it and/or
612 + * modify it under the terms of the GNU Lesser General Public
613 + * License as published by the Free Software Foundation; either
614 + * version 2.1 of the License, or (at your option) any later version.
616 + * This library is distributed in the hope that it will be useful,
617 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
618 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
619 + * Lesser General Public License for more details.
621 + * You should have received a copy of the GNU Lesser General Public
622 + * License along with this library; if not, write to the Free Software
623 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
626 +#include "efl_webview/lib/web_runtime_context.h"
628 +#include "base/base_paths.h"
629 +#include "base/command_line.h"
630 +#include "base/path_service.h"
631 +#include "content/public/app/content_main_delegate.h"
632 +#include "content/public/app/content_main_runner.h"
633 +#include "content/public/browser/browser_main_runner.h"
634 +#include "content/public/common/content_switches.h"
635 +#include "content/public/common/main_function_params.h"
636 +#include "efl_webview/lib/browser_context_xwalk.h"
637 +#include "efl_webview/lib/content_browser_client_xwalk.h"
643 +class ContentMainDelegateXWalk : public content::ContentMainDelegate {
645 + ContentMainDelegateXWalk() { }
647 + content::ContentBrowserClient* CreateContentBrowserClient() {
648 + browser_client_.reset(new ContentBrowserClientXWalk);
649 + return browser_client_.get();
653 + scoped_ptr<ContentBrowserClientXWalk> browser_client_;
655 + DISALLOW_COPY_AND_ASSIGN(ContentMainDelegateXWalk);
658 +WebRuntimeContext* g_context = 0;
659 +// TODO: it should be passed via build system.
660 +const char g_sub_process_name[] = "efl_process";
662 +void SubprocessPathInit() {
663 + base::FilePath current_directory;
664 + CHECK(PathService::Get(base::FILE_EXE, ¤t_directory));
665 + current_directory = current_directory.DirName();
667 + // TODO: use more elegant way.
668 + base::FilePath subprocess_path(
669 + current_directory.value() + "/" + g_sub_process_name);
671 + CommandLine::ForCurrentProcess()->
672 + AppendSwitchPath(switches::kBrowserSubprocessPath, subprocess_path);
677 +WebRuntimeContext::WebRuntimeContext() {
678 + DCHECK(!g_context);
681 + static content::ContentMainRunner *runner = 0;
683 + runner = content::ContentMainRunner::Create();
684 + runner->Initialize(0, 0, new ContentMainDelegateXWalk);
687 + SubprocessPathInit();
689 + static content::BrowserMainRunner *browserRunner = 0;
690 + if (!browserRunner) {
691 + browserRunner = content::BrowserMainRunner::Create();
692 + browserRunner->Initialize(content::MainFunctionParams(
693 + *CommandLine::ForCurrentProcess()));
696 + base::ThreadRestrictions::SetIOAllowed(true);
698 + // Once the MessageLoop has been created, attach a top-level RunLoop.
699 + run_loop_.reset(new base::RunLoop);
700 + run_loop_->BeforeRun();
702 + browser_context_.reset(new BrowserContextXWalk);
705 +WebRuntimeContext::~WebRuntimeContext() {
706 + run_loop_->AfterRun();
708 + DCHECK(g_context == this);
712 +scoped_refptr<WebRuntimeContext> WebRuntimeContext::current() {
713 + scoped_refptr<WebRuntimeContext> current = g_context;
715 + current = new WebRuntimeContext;
716 + DCHECK(g_context == current);
720 +content::BrowserContext* WebRuntimeContext::BrowserContext() {
721 + return browser_context_.get();
724 +} // namespace xwalk
725 diff --git a/efl_webview/lib/web_runtime_context.h b/efl_webview/lib/web_runtime_context.h
727 index 0000000..a0341fe
729 +++ b/efl_webview/lib/web_runtime_context.h
731 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
732 +// Use of this source code is governed by a BSD-style license that can be
733 +// found in the LICENSE file.
735 +#ifndef EFL_WEBVIEW_LIBWEB_RUNTIME_CONTEXT_H_
736 +#define EFL_WEBVIEW_LIBWEB_RUNTIME_CONTEXT_H_
738 +#include "base/basictypes.h"
739 +#include "base/memory/ref_counted.h"
740 +#include "base/memory/scoped_ptr.h"
741 +#include "base/run_loop.h"
744 +class BrowserContext;
749 +class WebRuntimeContext : public base::RefCounted<WebRuntimeContext> {
751 + static scoped_refptr<WebRuntimeContext> current();
752 + content::BrowserContext* BrowserContext();
755 + friend class base::RefCounted<WebRuntimeContext>;
756 + WebRuntimeContext();
757 + ~WebRuntimeContext();
759 + scoped_ptr<base::RunLoop> run_loop_;
760 + scoped_ptr<content::BrowserContext> browser_context_;
762 + DISALLOW_COPY_AND_ASSIGN(WebRuntimeContext);
765 +} // namespace xwalk
767 +#endif // EFL_WEBVIEW_LIBWEB_RUNTIME_CONTEXT_H_
768 diff --git a/efl_webview/lib/webview.cc b/efl_webview/lib/webview.cc
770 index 0000000..510f452
772 +++ b/efl_webview/lib/webview.cc
774 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
775 +// Use of this source code is governed by a BSD-style license that can be
776 +// found in the LICENSE file.
778 +#include "efl_webview/lib/webview.h"
780 +#include <Elementary.h>
781 +#include "base/command_line.h"
782 +#include "content/browser/web_contents/web_contents_view_efl.h"
783 +#include "content/public/browser/web_contents.h"
784 +#include "content/public/browser/web_contents_delegate.h"
785 +#include "efl_webview/lib/web_runtime_context.h"
790 +const int g_window_width = 800;
791 +const int g_window_height = 600;
793 +class WebContentsDelegateXWalk : public content::WebContentsDelegate
796 + explicit WebContentsDelegateXWalk(content::BrowserContext*);
797 + content::WebContents* WebContents() { return web_contents_.get(); }
800 + scoped_ptr<content::WebContents> web_contents_;
803 +WebContentsDelegateXWalk::WebContentsDelegateXWalk(
804 + content::BrowserContext* browser_context)
806 + content::WebContents::CreateParams create_params(browser_context, 0);
807 + create_params.initial_size = gfx::Size(g_window_width, g_window_height);
809 + web_contents_.reset(content::WebContents::Create(create_params));
810 + web_contents_->SetDelegate(this);
815 +struct WebView::Private {
816 + Evas_Object* root_window;
817 + Evas_Object* view_box;
818 + scoped_refptr<WebRuntimeContext> context;
819 + scoped_ptr<WebContentsDelegateXWalk> webContentsDelegate;
823 +WebView* WebView::Create(Evas_Object* root_window) {
824 + return new WebView(root_window);
828 +void WebView::CommandLineInit(int argc, char** argv) {
829 + CommandLine::Init(argc, argv);
832 +WebView::WebView(Evas_Object* root_window)
833 + : private_(new Private) {
834 + private_->root_window = root_window;
835 + private_->context = WebRuntimeContext::current();
836 + content::BrowserContext* browser_context =
837 + private_->context->BrowserContext();
838 + private_->webContentsDelegate.reset(
839 + new WebContentsDelegateXWalk(browser_context));
841 + private_->view_box = elm_box_add(private_->root_window);
842 + content::WebContentsView* content_view =
843 + private_->webContentsDelegate->WebContents()->GetView();
844 + static_cast<content::WebContentsViewEfl*>(content_view)->
845 + SetViewContainerBox(private_->view_box);
848 +WebView::~WebView() {
849 + evas_object_del(private_->view_box);
852 +void WebView::Forward() {
853 + private_->webContentsDelegate->WebContents()->GetController().GoForward();
856 +void WebView::Back() {
857 + private_->webContentsDelegate->WebContents()->GetController().GoBack();
860 +Evas_Object* WebView::EvasObject() {
861 + return private_->view_box;
864 +} // namespace xwalk
865 diff --git a/efl_webview/lib/webview.h b/efl_webview/lib/webview.h
867 index 0000000..2d4b352
869 +++ b/efl_webview/lib/webview.h
871 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
872 +// Use of this source code is governed by a BSD-style license that can be
873 +// found in the LICENSE file.
875 +#ifndef EFL_WEBVIEW_LIBWINDOW_H_
876 +#define EFL_WEBVIEW_LIBWINDOW_H_
880 +#include "base/basictypes.h"
881 +#include "base/memory/scoped_ptr.h"
885 +class EAPI WebView {
887 + EAPI static WebView* Create(Evas_Object* root_window);
888 + EAPI static void CommandLineInit(int argc, char** argv);
892 + EAPI Evas_Object* EvasObject();
894 + EAPI void Forward();
898 + explicit WebView(Evas_Object*);
901 + scoped_ptr<Private> private_;
903 + DISALLOW_COPY_AND_ASSIGN(WebView);
906 +WebView* ToWebView(Evas_Object*);
908 +} // namespace xwalk
910 +#endif // EFL_WEBVIEW_LIBWINDOW_H_
911 diff --git a/efl_webview/process/main.cc b/efl_webview/process/main.cc
913 index 0000000..27ba835
915 +++ b/efl_webview/process/main.cc
917 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
918 +// Use of this source code is governed by a BSD-style license that can be
919 +// found in the LICENSE file.
921 +#include "efl_webview/lib/process_main.h"
923 +int main(int argc, char **argv)
925 + return xwalk::ProcessMain(argc, argv);