XWalk WebView patchset, README and LICENSE files.
[platform/framework/web/xwalk_webview.git] / patchset / 0005-Implement-efl-webview-library-and-example-launcher.patch
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.
5
6 1. build efl_webview library
7 make efl_webview
8
9 2. build efl_webview_example executable
10 make efl_webview_example
11
12 Make sub process be able to launch
13 Add process executable to launch sub process (i.e. gpu process, zygote)
14 ---
15  AUTHORS                                            |   1 +
16  base/run_loop.h                                    |   8 +-
17  build/all.gyp                                      |   1 +
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
48
49 diff --git a/AUTHORS b/AUTHORS
50 index a0e975c..d6978e6 100644
51 --- a/AUTHORS
52 +++ b/AUTHORS
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
60 --- a/base/run_loop.h
61 +++ b/base/run_loop.h
62 @@ -72,6 +72,10 @@ class BASE_EXPORT RunLoop {
63    //   run_loop.Run();
64    base::Closure QuitClosure();
65  
66 +  // Return false to abort the Run.
67 +  bool BeforeRun();
68 +  void AfterRun();
69 +
70   private:
71    friend class MessageLoop;
72  #if defined(OS_ANDROID)
73 @@ -86,10 +90,6 @@ class BASE_EXPORT RunLoop {
74    friend class base::MessagePumpUIApplication;
75  #endif
76  
77 -  // Return false to abort the Run.
78 -  bool BeforeRun();
79 -  void AfterRun();
80 -
81    MessageLoop* loop_;
82  
83    // WeakPtrFactory for QuitClosure safety.
84 diff --git a/build/all.gyp b/build/all.gyp
85 index 14d4888..9043af8 100644
86 --- a/build/all.gyp
87 +++ b/build/all.gyp
88 @@ -14,6 +14,7 @@
89          '../chrome/chrome.gyp:*',
90          '../content/content.gyp:*',
91          '../crypto/crypto.gyp:*',
92 +        '../efl_webview/efl_webview.gyp:*',
93          '../media/media.gyp:*',
94          '../net/net.gyp:*',
95          '../sdch/sdch.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
100 @@ -29,6 +29,7 @@
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) {
109    DCHECK(!init_);
110    init_ = true;
111  
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);
118  
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
124 @@ -8,6 +8,7 @@
125  #include <string>
126  
127  #include "build/build_config.h"
128 +#include "content/common/content_export.h"
129  
130  #if defined(OS_WIN)
131  #include <windows.h>
132 @@ -22,7 +23,7 @@ namespace content {
133  class ContentMainDelegate;
134  
135  // This class is responsible for content initialization, running and shutdown.
136 -class ContentMainRunner {
137 +class CONTENT_EXPORT ContentMainRunner {
138   public:
139    virtual ~ContentMainRunner() {}
140  
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);
146  
147  #if defined(CONTENT_IMPLEMENTATION)
148  // Content's embedder API should only be used by content.
149 -ContentClient* GetContentClient();
150 +CONTENT_EXPORT ContentClient* GetContentClient();
151  #endif
152  
153  // Used for tests to override the relevant embedder interfaces. Each method
154 diff --git a/efl_webview/DEPS b/efl_webview/DEPS
155 new file mode 100644
156 index 0000000..dd8d329
157 --- /dev/null
158 +++ b/efl_webview/DEPS
159 @@ -0,0 +1,4 @@
160 +include_rules = [
161 +  "+content",
162 +  "+net",
163 +]
164 diff --git a/efl_webview/efl_webview.gyp b/efl_webview/efl_webview.gyp
165 new file mode 100644
166 index 0000000..b4d25d3
167 --- /dev/null
168 +++ b/efl_webview/efl_webview.gyp
169 @@ -0,0 +1,134 @@
170 +{
171 +  'variables': {
172 +    'efl_webview_product_name': 'EFL WebView',
173 +    # TODO: define efl webview version format.
174 +    'cameo_version': '0.28.0.1',
175 +    'conditions': [
176 +      ['OS=="linux"', {
177 +       'use_custom_freetype%': 1,
178 +      }, {
179 +       'use_custom_freetype%': 0,
180 +      }],
181 +    ], # conditions
182 +  },
183 +  'targets': [
184 +    {
185 +      'target_name': 'efl_webview',
186 +      'type': '<(component)',
187 +      'variables': {
188 +        'chromium_code': 1,
189 +      },
190 +      'dependencies': [
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',
213 +        '../ui/ui.gyp:ui',
214 +        '../v8/tools/gyp/v8.gyp:v8',
215 +        '../webkit/support/webkit_support.gyp:webkit_resources',
216 +        '../webkit/support/webkit_support.gyp:webkit_support',
217 +      ],
218 +      'include_dirs': [
219 +        '..',
220 +      ],
221 +      'sources': [
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',
229 +        'lib/webview.cc',
230 +        'lib/webview.h',
231 +      ],
232 +      'conditions': [
233 +        ['OS=="linux"', {
234 +          'dependencies': [
235 +            '../build/linux/system.gyp:fontconfig',
236 +          ],
237 +        }],  # OS=="linux"
238 +        ['os_posix==1 and linux_use_tcmalloc==1', {
239 +          'dependencies': [
240 +            # This is needed by content/app/content_main_runner.cc
241 +            '../base/allocator/allocator.gyp:allocator',
242 +          ],
243 +        }],  # os_posix==1 and linux_use_tcmalloc==1
244 +        ['use_custom_freetype==1', {
245 +          'dependencies': [
246 +             '../third_party/freetype2/freetype2.gyp:freetype2',
247 +          ],
248 +        }],  # use_custom_freetype==1
249 +        ['toolkit_uses_gtk == 1', {
250 +          'dependencies': [
251 +            '<(DEPTH)/build/linux/system.gyp:gtk',
252 +          ],
253 +        }],  # toolkit_uses_gtk
254 +        ['toolkit_uses_efl == 1', {
255 +          'dependencies': [
256 +            '../build/linux/system.gyp:efl',
257 +          ],
258 +        }],
259 +      ],
260 +    },
261 +    {
262 +      'target_name': 'efl_webview_example',
263 +      'type': 'executable',
264 +      'dependencies': [
265 +        'efl_webview',
266 +        'efl_process',
267 +      ],
268 +      'include_dirs': [
269 +        '..',
270 +      ],
271 +      'sources': [
272 +        'examples/main.cc',
273 +      ],
274 +      'conditions': [
275 +        ['toolkit_uses_efl == 1', {
276 +          'dependencies': [
277 +            '../build/linux/system.gyp:efl',
278 +          ],
279 +        }],
280 +      ],
281 +    },
282 +    {
283 +      'target_name': 'efl_process',
284 +      'type': 'executable',
285 +      'dependencies': [
286 +        'efl_webview',
287 +      ],
288 +      'include_dirs': [
289 +        '..',
290 +      ],
291 +      'sources': [
292 +        'process/main.cc',
293 +      ],
294 +      'conditions': [
295 +        ['toolkit_uses_efl == 1', {
296 +          'dependencies': [
297 +            '../build/linux/system.gyp:efl',
298 +          ],
299 +        }],
300 +      ],
301 +    },
302 +  ],
303 +}
304 diff --git a/efl_webview/examples/main.cc b/efl_webview/examples/main.cc
305 new file mode 100644
306 index 0000000..ee610fb
307 --- /dev/null
308 +++ b/efl_webview/examples/main.cc
309 @@ -0,0 +1,102 @@
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.
313 +
314 +#include <Ecore.h>
315 +#include <Ecore_Evas.h>
316 +#include <Elementary.h>
317 +
318 +#include "efl_webview/lib/process_main.h"
319 +#include "efl_webview/lib/webview.h"
320 +
321 +static const char APP_NAME[] = "EFL WebView Example";
322 +
323 +static int window_width = 800;
324 +static int window_height = 600;
325 +
326 +static void
327 +on_back_button_clicked(void *user_data, Evas_Object *back_button, void *event_info)
328 +{
329 +  xwalk::WebView* webview = static_cast<xwalk::WebView*>(user_data);
330 +  webview->Back();
331 +}
332 +
333 +static void
334 +on_forward_button_clicked(void *user_data, Evas_Object *forward_button, void *event_info)
335 +{
336 +  xwalk::WebView* webview = static_cast<xwalk::WebView*>(user_data);
337 +  webview->Forward();
338 +}
339 +
340 +static void window_create()
341 +{
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);
345 +
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);
352 +
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);
360 +
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);
368 +
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);
376 +
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);
385 +
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);
390 +
391 +  evas_object_resize(elm_window, window_width, window_height);
392 +  evas_object_show(elm_window);
393 +}
394 +
395 +int main(int argc, char *argv[])
396 +{
397 +  // FIXME: Handle chrome command line and url.
398 +  // It is needed only in development stage.
399 +  xwalk::WebView::CommandLineInit(argc, argv);
400 +
401 +  elm_init(argc, argv);
402 +
403 +  elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
404 +
405 +  window_create();
406 +
407 +  elm_run();
408 +  elm_shutdown();
409 +
410 +  return 0;
411 +}
412 diff --git a/efl_webview/lib/browser_context_xwalk.h b/efl_webview/lib/browser_context_xwalk.h
413 new file mode 100644
414 index 0000000..869fa82
415 --- /dev/null
416 +++ b/efl_webview/lib/browser_context_xwalk.h
417 @@ -0,0 +1,30 @@
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.
421 +
422 +#ifndef EFL_WEBVIEW_LIBBROWSER_CONTEXT_XWALK_H_
423 +#define EFL_WEBVIEW_LIBBROWSER_CONTEXT_XWALK_H_
424 +
425 +#include "content/shell/shell_browser_context.h"
426 +
427 +namespace xwalk {
428 +
429 +class BrowserContextXWalk : public content::ShellBrowserContext {
430 + public:
431 +  BrowserContextXWalk()
432 +      : content::ShellBrowserContext(false)
433 +  { }
434 +  virtual ~BrowserContextXWalk() {}
435 +
436 +  net::URLRequestContextGetter* CreateRequestContext(
437 +      content::ProtocolHandlerMap* protocol_handlers) {
438 +    return content::ShellBrowserContext::CreateRequestContext(protocol_handlers);
439 +  }
440 +
441 + private:
442 +  DISALLOW_COPY_AND_ASSIGN(BrowserContextXWalk);
443 +};
444 +
445 +}  // namespace xwalk
446 +
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
449 new file mode 100644
450 index 0000000..7a14c99
451 --- /dev/null
452 +++ b/efl_webview/lib/content_browser_client_xwalk.cc
453 @@ -0,0 +1,60 @@
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.
457 +
458 +#include "efl_webview/lib/content_browser_client_xwalk.h"
459 +
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"
464 +
465 +namespace xwalk {
466 +
467 +class BrowserMainPartsXWalk : public content::BrowserMainParts
468 +{
469 + public:
470 +  BrowserMainPartsXWalk(const content::MainFunctionParams& parameters)
471 +      : content::BrowserMainParts()
472 +      , parameters_(parameters)
473 +      , run_message_loop_(true)
474 +  { }
475 +
476 +  virtual void PreMainMessageLoopStart() OVERRIDE { }
477 +  virtual void PostMainMessageLoopStart() OVERRIDE { }
478 +  virtual void PreEarlyInitialization() OVERRIDE { }
479 +
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;
485 +    }
486 +  }
487 +
488 +  virtual bool MainMessageLoopRun(int* result_code) OVERRIDE {
489 +    return !run_message_loop_;
490 +  }
491 +
492 +  virtual void PostMainMessageLoopRun() OVERRIDE { }
493 +
494 + private:
495 +  const content::MainFunctionParams& parameters_;
496 +  bool run_message_loop_;
497 +
498 +  DISALLOW_COPY_AND_ASSIGN(BrowserMainPartsXWalk);
499 +};
500 +
501 +content::BrowserMainParts *ContentBrowserClientXWalk::CreateBrowserMainParts(
502 +    const content::MainFunctionParams &parameters) {
503 +  return new BrowserMainPartsXWalk(parameters);
504 +}
505 +
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);
511 +}
512 +
513 +} // namespace xwalk
514 diff --git a/efl_webview/lib/content_browser_client_xwalk.h b/efl_webview/lib/content_browser_client_xwalk.h
515 new file mode 100644
516 index 0000000..c5c235d
517 --- /dev/null
518 +++ b/efl_webview/lib/content_browser_client_xwalk.h
519 @@ -0,0 +1,29 @@
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.
523 +
524 +#ifndef EFL_WEBVIEW_LIBCONTENT_BROWSER_CLIENT_XWALK_H_
525 +#define EFL_WEBVIEW_LIBCONTENT_BROWSER_CLIENT_XWALK_H_
526 +
527 +#include "content/public/browser/content_browser_client.h"
528 +
529 +namespace xwalk {
530 +
531 +class ContentBrowserClientXWalk : public content::ContentBrowserClient {
532 + public:
533 +  ContentBrowserClientXWalk() { }
534 +
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;
541 +
542 + private:
543 +  DISALLOW_COPY_AND_ASSIGN(ContentBrowserClientXWalk);
544 +};
545 +
546 +} // namespace xwalk
547 +
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
550 new file mode 100644
551 index 0000000..132b35c
552 --- /dev/null
553 +++ b/efl_webview/lib/process_main.cc
554 @@ -0,0 +1,24 @@
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.
558 +
559 +#include "efl_webview/lib/process_main.h"
560 +
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"
565 +
566 +namespace xwalk {
567 +
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 != "");
574 +
575 +  return content::ContentMain(argc, const_cast<const char**>(argv), 0);
576 +}
577 +
578 +}  // namespace xwalk
579 diff --git a/efl_webview/lib/process_main.h b/efl_webview/lib/process_main.h
580 new file mode 100644
581 index 0000000..8e47949
582 --- /dev/null
583 +++ b/efl_webview/lib/process_main.h
584 @@ -0,0 +1,16 @@
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.
588 +
589 +#ifndef EFL_WEBVIEW_LIB_PROCESS_MAIN_H_
590 +#define EFL_WEBVIEW_LIB_PROCESS_MAIN_H_
591 +
592 +#include <Eina.h>
593 +
594 +namespace xwalk {
595 +
596 +EAPI int ProcessMain(int argc, char** argv);
597 +
598 +}  // namespace xwalk
599 +
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
602 new file mode 100644
603 index 0000000..b2ad541
604 --- /dev/null
605 +++ b/efl_webview/lib/web_runtime_context.cc
606 @@ -0,0 +1,118 @@
607 +/*
608 + * Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
609 + * Copyright (c) 2013 Intel Corporation. All rights reserved.
610 + *
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.
615 + *
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.
620 + *
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
624 + */
625 +
626 +#include "efl_webview/lib/web_runtime_context.h"
627 +
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"
638 +
639 +namespace xwalk {
640 +
641 +namespace {
642 +
643 +class ContentMainDelegateXWalk : public content::ContentMainDelegate {
644 + public:
645 +  ContentMainDelegateXWalk() { }
646 +
647 +  content::ContentBrowserClient* CreateContentBrowserClient()   {
648 +    browser_client_.reset(new ContentBrowserClientXWalk);
649 +    return browser_client_.get();
650 +  }
651 +
652 + private:
653 +  scoped_ptr<ContentBrowserClientXWalk> browser_client_;
654 +
655 +  DISALLOW_COPY_AND_ASSIGN(ContentMainDelegateXWalk);
656 +};
657 +
658 +WebRuntimeContext* g_context = 0;
659 +// TODO: it should be passed via build system.
660 +const char g_sub_process_name[] = "efl_process";
661 +
662 +void SubprocessPathInit() {
663 +  base::FilePath current_directory;
664 +  CHECK(PathService::Get(base::FILE_EXE, &current_directory));
665 +  current_directory = current_directory.DirName();
666 +
667 +  // TODO: use more elegant way.
668 +  base::FilePath subprocess_path(
669 +      current_directory.value() + "/" + g_sub_process_name);
670 +
671 +  CommandLine::ForCurrentProcess()->
672 +      AppendSwitchPath(switches::kBrowserSubprocessPath, subprocess_path);
673 +}
674 +
675 +} // namespace
676 +
677 +WebRuntimeContext::WebRuntimeContext() {
678 +  DCHECK(!g_context);
679 +  g_context = this;
680 +
681 +  static content::ContentMainRunner *runner = 0;
682 +  if (!runner) {
683 +    runner = content::ContentMainRunner::Create();
684 +    runner->Initialize(0, 0, new ContentMainDelegateXWalk);
685 +  }
686 +
687 +  SubprocessPathInit();
688 +
689 +  static content::BrowserMainRunner *browserRunner = 0;
690 +  if (!browserRunner) {
691 +    browserRunner = content::BrowserMainRunner::Create();
692 +    browserRunner->Initialize(content::MainFunctionParams(
693 +        *CommandLine::ForCurrentProcess()));
694 +  }
695 +
696 +  base::ThreadRestrictions::SetIOAllowed(true);
697 +
698 +  // Once the MessageLoop has been created, attach a top-level RunLoop.
699 +  run_loop_.reset(new base::RunLoop);
700 +  run_loop_->BeforeRun();
701 +
702 +  browser_context_.reset(new BrowserContextXWalk);
703 +}
704 +
705 +WebRuntimeContext::~WebRuntimeContext() {
706 +  run_loop_->AfterRun();
707 +
708 +  DCHECK(g_context == this);
709 +  g_context = 0;
710 +}
711 +
712 +scoped_refptr<WebRuntimeContext> WebRuntimeContext::current() {
713 +  scoped_refptr<WebRuntimeContext> current = g_context;
714 +  if (!current)
715 +    current = new WebRuntimeContext;
716 +  DCHECK(g_context == current);
717 +  return current;
718 +}
719 +
720 +content::BrowserContext* WebRuntimeContext::BrowserContext() {
721 +  return browser_context_.get();
722 +}
723 +
724 +}  // namespace xwalk
725 diff --git a/efl_webview/lib/web_runtime_context.h b/efl_webview/lib/web_runtime_context.h
726 new file mode 100644
727 index 0000000..a0341fe
728 --- /dev/null
729 +++ b/efl_webview/lib/web_runtime_context.h
730 @@ -0,0 +1,37 @@
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.
734 +
735 +#ifndef EFL_WEBVIEW_LIBWEB_RUNTIME_CONTEXT_H_
736 +#define EFL_WEBVIEW_LIBWEB_RUNTIME_CONTEXT_H_
737 +
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"
742 +
743 +namespace content {
744 +class BrowserContext;
745 +}
746 +
747 +namespace xwalk {
748 +
749 +class WebRuntimeContext : public base::RefCounted<WebRuntimeContext> {
750 + public:
751 +  static scoped_refptr<WebRuntimeContext> current();
752 +  content::BrowserContext* BrowserContext();
753 +
754 + private:
755 +  friend class base::RefCounted<WebRuntimeContext>;
756 +  WebRuntimeContext();
757 +  ~WebRuntimeContext();
758 +
759 +  scoped_ptr<base::RunLoop> run_loop_;
760 +  scoped_ptr<content::BrowserContext> browser_context_;
761 +
762 +  DISALLOW_COPY_AND_ASSIGN(WebRuntimeContext);
763 +};
764 +
765 +}  // namespace xwalk
766 +
767 +#endif  // EFL_WEBVIEW_LIBWEB_RUNTIME_CONTEXT_H_
768 diff --git a/efl_webview/lib/webview.cc b/efl_webview/lib/webview.cc
769 new file mode 100644
770 index 0000000..510f452
771 --- /dev/null
772 +++ b/efl_webview/lib/webview.cc
773 @@ -0,0 +1,91 @@
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.
777 +
778 +#include "efl_webview/lib/webview.h"
779 +
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"
786 +
787 +namespace xwalk {
788 +
789 +namespace {
790 +const int g_window_width = 800;
791 +const int g_window_height = 600;
792 +
793 +class WebContentsDelegateXWalk : public content::WebContentsDelegate
794 +{
795 + public:
796 +  explicit WebContentsDelegateXWalk(content::BrowserContext*);
797 +  content::WebContents* WebContents() { return web_contents_.get(); }
798 +
799 + private:
800 +  scoped_ptr<content::WebContents> web_contents_;
801 +};
802 +
803 +WebContentsDelegateXWalk::WebContentsDelegateXWalk(
804 +    content::BrowserContext* browser_context)
805 +{
806 +  content::WebContents::CreateParams create_params(browser_context, 0);
807 +  create_params.initial_size = gfx::Size(g_window_width, g_window_height);
808 +
809 +  web_contents_.reset(content::WebContents::Create(create_params));
810 +  web_contents_->SetDelegate(this);
811 +}
812 +
813 +} // namespace
814 +
815 +struct WebView::Private {
816 +  Evas_Object* root_window;
817 +  Evas_Object* view_box;
818 +  scoped_refptr<WebRuntimeContext> context;
819 +  scoped_ptr<WebContentsDelegateXWalk> webContentsDelegate;
820 +};
821 +
822 +// static
823 +WebView* WebView::Create(Evas_Object* root_window) {
824 +  return new WebView(root_window);
825 +}
826 +
827 +// static
828 +void WebView::CommandLineInit(int argc, char** argv) {
829 +  CommandLine::Init(argc, argv);
830 +}
831 +
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));
840 +
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);
846 +}
847 +
848 +WebView::~WebView() {
849 +  evas_object_del(private_->view_box);
850 +}
851 +
852 +void WebView::Forward() {
853 +  private_->webContentsDelegate->WebContents()->GetController().GoForward();
854 +}
855 +
856 +void WebView::Back() {
857 +  private_->webContentsDelegate->WebContents()->GetController().GoBack();
858 +}
859 +
860 +Evas_Object* WebView::EvasObject() {
861 +  return private_->view_box;
862 +}
863 +
864 +}  // namespace xwalk
865 diff --git a/efl_webview/lib/webview.h b/efl_webview/lib/webview.h
866 new file mode 100644
867 index 0000000..2d4b352
868 --- /dev/null
869 +++ b/efl_webview/lib/webview.h
870 @@ -0,0 +1,40 @@
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.
874 +
875 +#ifndef EFL_WEBVIEW_LIBWINDOW_H_
876 +#define EFL_WEBVIEW_LIBWINDOW_H_
877 +
878 +#include <Evas.h>
879 +
880 +#include "base/basictypes.h"
881 +#include "base/memory/scoped_ptr.h"
882 +
883 +namespace xwalk {
884 +
885 +class EAPI WebView {
886 + public:
887 +  EAPI static WebView* Create(Evas_Object* root_window);
888 +  EAPI static void CommandLineInit(int argc, char** argv);
889 +
890 +  ~WebView();
891 +
892 +  EAPI Evas_Object* EvasObject();
893 +
894 +  EAPI void Forward();
895 +  EAPI void Back();
896 +
897 + private:
898 +  explicit WebView(Evas_Object*);
899 +
900 +  struct Private;
901 +  scoped_ptr<Private> private_;
902 +
903 +  DISALLOW_COPY_AND_ASSIGN(WebView);
904 +};
905 +
906 +WebView* ToWebView(Evas_Object*);
907 +
908 +}  // namespace xwalk
909 +
910 +#endif  // EFL_WEBVIEW_LIBWINDOW_H_
911 diff --git a/efl_webview/process/main.cc b/efl_webview/process/main.cc
912 new file mode 100644
913 index 0000000..27ba835
914 --- /dev/null
915 +++ b/efl_webview/process/main.cc
916 @@ -0,0 +1,10 @@
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.
920 +
921 +#include "efl_webview/lib/process_main.h"
922 +
923 +int main(int argc, char **argv)
924 +{
925 +    return xwalk::ProcessMain(argc, argv);
926 +}
927 -- 
928 1.8.1.2
929