1 From 8bee019d38339e687bbdde6654c36193510c21b8 Mon Sep 17 00:00:00 2001
2 From: Dongseong Hwang <dongseong.hwang@intel.com>
3 Date: Wed, 3 Jul 2013 15:26:51 +0300
4 Subject: [PATCH 06/33] Add message_pump_xwalk for embedder.
6 This message pump does not have main loop. This message pump works with
9 After this patch, app can use content_api like common elm_object.
13 make efl_webview_example
14 ./out/[Debug|Release]/efl_webview_example
16 There are only two api classes:
18 2. xwalk::ProcessMain() <- function
21 1. make elm_websomething using xwalk::WebView
22 2. all xwalk changes get together into efl_webview/lib directory
25 efl_webview/efl_webview.gyp | 2 +
26 efl_webview/lib/browser_context_xwalk.h | 3 +-
27 efl_webview/lib/content_browser_client_xwalk.cc | 6 +-
28 efl_webview/lib/message_pump_xwalk.cc | 119 ++++++++++++++++++++++++
29 efl_webview/lib/message_pump_xwalk.h | 57 ++++++++++++
30 efl_webview/lib/web_runtime_context.cc | 9 ++
31 6 files changed, 193 insertions(+), 3 deletions(-)
32 create mode 100644 efl_webview/lib/message_pump_xwalk.cc
33 create mode 100644 efl_webview/lib/message_pump_xwalk.h
35 diff --git a/efl_webview/efl_webview.gyp b/efl_webview/efl_webview.gyp
36 index b4d25d3..3037aa2 100644
37 --- a/efl_webview/efl_webview.gyp
38 +++ b/efl_webview/efl_webview.gyp
40 'lib/content_browser_client_xwalk.cc',
41 'lib/content_browser_client_xwalk.h',
42 'lib/browser_context_xwalk.h',
43 + 'lib/message_pump_xwalk.cc',
44 + 'lib/message_pump_xwalk.h',
45 'lib/process_main.cc',
47 'lib/web_runtime_context.cc',
48 diff --git a/efl_webview/lib/browser_context_xwalk.h b/efl_webview/lib/browser_context_xwalk.h
49 index 869fa82..0bd3cda 100644
50 --- a/efl_webview/lib/browser_context_xwalk.h
51 +++ b/efl_webview/lib/browser_context_xwalk.h
52 @@ -18,7 +18,8 @@ class BrowserContextXWalk : public content::ShellBrowserContext {
54 net::URLRequestContextGetter* CreateRequestContext(
55 content::ProtocolHandlerMap* protocol_handlers) {
56 - return content::ShellBrowserContext::CreateRequestContext(protocol_handlers);
57 + return content::ShellBrowserContext::CreateRequestContext(
62 diff --git a/efl_webview/lib/content_browser_client_xwalk.cc b/efl_webview/lib/content_browser_client_xwalk.cc
63 index 7a14c99..b640320 100644
64 --- a/efl_webview/lib/content_browser_client_xwalk.cc
65 +++ b/efl_webview/lib/content_browser_client_xwalk.cc
66 @@ -53,8 +53,10 @@ content::BrowserMainParts *ContentBrowserClientXWalk::CreateBrowserMainParts(
67 net::URLRequestContextGetter* ContentBrowserClientXWalk::CreateRequestContext(
68 content::BrowserContext* content_browser_context,
69 content::ProtocolHandlerMap* protocol_handlers) {
70 - DCHECK(content_browser_context == WebRuntimeContext::current()->BrowserContext());
71 - return static_cast<BrowserContextXWalk*>(content_browser_context)->CreateRequestContext(protocol_handlers);
72 + DCHECK(content_browser_context ==
73 + WebRuntimeContext::current()->BrowserContext());
74 + return static_cast<BrowserContextXWalk*>(content_browser_context)->
75 + CreateRequestContext(protocol_handlers);
79 diff --git a/efl_webview/lib/message_pump_xwalk.cc b/efl_webview/lib/message_pump_xwalk.cc
81 index 0000000..dd17582
83 +++ b/efl_webview/lib/message_pump_xwalk.cc
85 +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
86 +// Use of this source code is governed by a BSD-style license that can be
87 +// found in the LICENSE file.
89 +#include "efl_webview/lib/message_pump_xwalk.h"
94 +#include "base/debug/trace_event.h"
95 +#include "base/logging.h"
96 +#include "base/posix/eintr_wrapper.h"
97 +#include "base/threading/platform_thread.h"
103 +const int ecorePipeMessageSize = 1;
104 +const char wakupEcorePipeMessage[] = "W";
106 +void WakeUpEvent(void* data, void*, unsigned int)
108 + static_cast<MessagePumpXWalk*>(data)->HandleDispatch();
113 +struct MessagePumpXWalk::Private {
114 + MessagePump::Delegate* delegate;
118 + // This is the time when we need to do delayed work.
119 + base::TimeTicks delayed_work_time;
121 + // List of observers.
122 + ObserverList<base::MessagePumpObserver> observers;
124 + Ecore_Pipe* wakeup_pipe;
127 +MessagePumpXWalk::MessagePumpXWalk()
128 + : private_(new Private) {
129 + private_->wakeup_pipe = ecore_pipe_add(WakeUpEvent, this);
130 + private_->delegate = base::MessageLoopForUI::current();
131 + private_->should_quit = false;
134 +MessagePumpXWalk::~MessagePumpXWalk() {
135 + ecore_pipe_del(private_->wakeup_pipe);
138 +void MessagePumpXWalk::RunWithDispatcher(Delegate* delegate,
139 + base::MessagePumpDispatcher* dispatcher) {
143 +void MessagePumpXWalk::HandleDispatch() {
144 + // FIXME: dshwang does not have confidence about this implementation.
145 + // Need to check by efl experts.
146 + ecore_main_loop_iterate();
148 + bool more_work_is_plausible = private_->delegate->DoWork();
149 + if (private_->should_quit)
152 + more_work_is_plausible |=
153 + private_->delegate->DoDelayedWork(&private_->delayed_work_time);
154 + if (private_->should_quit)
157 + if (!more_work_is_plausible)
158 + more_work_is_plausible |= private_->delegate->DoIdleWork();
160 + if (more_work_is_plausible)
164 +void MessagePumpXWalk::AddObserver(base::MessagePumpObserver* observer) {
165 + private_->observers.AddObserver(observer);
168 +void MessagePumpXWalk::RemoveObserver(base::MessagePumpObserver* observer) {
169 + private_->observers.RemoveObserver(observer);
172 +void MessagePumpXWalk::Run(Delegate* delegate) {
176 +void MessagePumpXWalk::Quit() {
177 + private_->should_quit = true;
180 +void MessagePumpXWalk::ScheduleWork() {
181 + // This can be called on any thread, so we don't want to touch any state
182 + // variables as we would then need locks all over. This ensures that if
183 + // we are sleeping in a poll that we will wake up.
184 + if (HANDLE_EINTR(ecore_pipe_write(private_->wakeup_pipe,
185 + wakupEcorePipeMessage,
186 + ecorePipeMessageSize)) != 1) {
187 + NOTREACHED() << "Could not write to the UI message loop wakeup pipe!";
191 +void MessagePumpXWalk::ScheduleDelayedWork(
192 + const base::TimeTicks& delayed_work_time) {
193 + // We need to wake up the loop in case the poll timeout needs to be
194 + // adjusted. This will cause us to try to do work, but that's ok.
195 + private_->delayed_work_time = delayed_work_time;
199 +ObserverList<base::MessagePumpObserver>& MessagePumpXWalk::observers() {
200 + return private_->observers;
203 +} // namespace xwalk
204 diff --git a/efl_webview/lib/message_pump_xwalk.h b/efl_webview/lib/message_pump_xwalk.h
206 index 0000000..b45c42f
208 +++ b/efl_webview/lib/message_pump_xwalk.h
210 +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
211 +// Use of this source code is governed by a BSD-style license that can be
212 +// found in the LICENSE file.
214 +#ifndef EFL_WEBVIEW_LIBMESSAGE_PUMP_XWALK_H_
215 +#define EFL_WEBVIEW_LIBMESSAGE_PUMP_XWALK_H_
217 +#include "base/base_export.h"
218 +#include "base/event_types.h"
219 +#include "base/memory/scoped_ptr.h"
220 +#include "base/message_pump.h"
221 +#include "base/message_pump_dispatcher.h"
222 +#include "base/message_pump_observer.h"
223 +#include "base/observer_list.h"
224 +#include "base/time.h"
228 +class MessagePumpXWalk : public base::MessagePump {
230 + MessagePumpXWalk();
232 + // Like MessagePump::Run, but events are routed through dispatcher.
233 + virtual void RunWithDispatcher(Delegate* delegate,
234 + base::MessagePumpDispatcher* dispatcher);
236 + void HandleDispatch();
238 + // Adds an Observer, which will start receiving notifications immediately.
239 + void AddObserver(base::MessagePumpObserver* observer);
241 + // Removes an Observer. It is safe to call this method while an Observer is
242 + // receiving a notification callback.
243 + void RemoveObserver(base::MessagePumpObserver* observer);
245 + // Overridden from MessagePump:
246 + virtual void Run(Delegate* delegate) OVERRIDE;
247 + virtual void Quit() OVERRIDE;
248 + virtual void ScheduleWork() OVERRIDE;
249 + virtual void ScheduleDelayedWork(
250 + const base::TimeTicks& delayed_work_time) OVERRIDE;
253 + virtual ~MessagePumpXWalk();
255 + ObserverList<base::MessagePumpObserver>& observers();
259 + scoped_ptr<Private> private_;
261 + DISALLOW_COPY_AND_ASSIGN(MessagePumpXWalk);
264 +} // namespace xwalk
266 +#endif // EFL_WEBVIEW_LIBMESSAGE_PUMP_XWALK_H_
267 diff --git a/efl_webview/lib/web_runtime_context.cc b/efl_webview/lib/web_runtime_context.cc
268 index b2ad541..84613a8 100644
269 --- a/efl_webview/lib/web_runtime_context.cc
270 +++ b/efl_webview/lib/web_runtime_context.cc
272 #include "content/public/common/main_function_params.h"
273 #include "efl_webview/lib/browser_context_xwalk.h"
274 #include "efl_webview/lib/content_browser_client_xwalk.h"
275 +#include "efl_webview/lib/message_pump_xwalk.h"
279 @@ -66,12 +67,20 @@ void SubprocessPathInit() {
280 AppendSwitchPath(switches::kBrowserSubprocessPath, subprocess_path);
283 +base::MessagePump* MessagePumpFactory()
285 + return new MessagePumpXWalk;
290 WebRuntimeContext::WebRuntimeContext() {
294 + // Inject MessagePumpFacotry for embedder.
295 + base::MessageLoop::InitMessagePumpForUIFactory(MessagePumpFactory);
297 static content::ContentMainRunner *runner = 0;
299 runner = content::ContentMainRunner::Create();