XWalk WebView patchset, README and LICENSE files.
[platform/framework/web/xwalk_webview.git] / patchset / 0006-Add-message_pump_xwalk-for-embedder.patch
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.
5
6 This message pump does not have main loop. This message pump works with
7 elm_run().
8
9 After this patch, app can use content_api like common elm_object.
10
11 How to build and run.
12
13 make efl_webview_example
14 ./out/[Debug|Release]/efl_webview_example
15
16 There are only two api classes:
17 1. xwalk::WebView
18 2. xwalk::ProcessMain() <- function
19
20 TODO
21 1. make elm_websomething using xwalk::WebView
22 2. all xwalk changes get together into efl_webview/lib directory
23 3. more stablize
24 ---
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
34
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
39 @@ -53,6 +53,8 @@
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',
46          'lib/process_main.h',
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 {
53  
54    net::URLRequestContextGetter* CreateRequestContext(
55        content::ProtocolHandlerMap* protocol_handlers) {
56 -    return content::ShellBrowserContext::CreateRequestContext(protocol_handlers);
57 +    return content::ShellBrowserContext::CreateRequestContext(
58 +        protocol_handlers);
59    }
60  
61   private:
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);
76  }
77  
78  } // namespace xwalk
79 diff --git a/efl_webview/lib/message_pump_xwalk.cc b/efl_webview/lib/message_pump_xwalk.cc
80 new file mode 100644
81 index 0000000..dd17582
82 --- /dev/null
83 +++ b/efl_webview/lib/message_pump_xwalk.cc
84 @@ -0,0 +1,119 @@
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.
88 +
89 +#include "efl_webview/lib/message_pump_xwalk.h"
90 +
91 +#include <Ecore.h>
92 +#include <Ecore_X.h>
93 +
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"
98 +
99 +namespace xwalk {
100 +
101 +namespace {
102 +
103 +const int ecorePipeMessageSize = 1;
104 +const char wakupEcorePipeMessage[] = "W";
105 +
106 +void WakeUpEvent(void* data, void*, unsigned int)
107 +{
108 +  static_cast<MessagePumpXWalk*>(data)->HandleDispatch();
109 +}
110 +
111 +}  // namespace
112 +
113 +struct MessagePumpXWalk::Private {
114 +  MessagePump::Delegate* delegate;
115 +
116 +  bool should_quit;
117 +
118 +  // This is the time when we need to do delayed work.
119 +  base::TimeTicks delayed_work_time;
120 +
121 +  // List of observers.
122 +  ObserverList<base::MessagePumpObserver> observers;
123 +
124 +  Ecore_Pipe* wakeup_pipe;
125 +};
126 +
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;
132 +}
133 +
134 +MessagePumpXWalk::~MessagePumpXWalk() {
135 +  ecore_pipe_del(private_->wakeup_pipe);
136 +}
137 +
138 +void MessagePumpXWalk::RunWithDispatcher(Delegate* delegate,
139 +    base::MessagePumpDispatcher* dispatcher) {
140 +  NOTREACHED();
141 +}
142 +
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();
147 +
148 +  bool more_work_is_plausible = private_->delegate->DoWork();
149 +  if (private_->should_quit)
150 +    return;
151 +
152 +  more_work_is_plausible |=
153 +      private_->delegate->DoDelayedWork(&private_->delayed_work_time);
154 +  if (private_->should_quit)
155 +    return;
156 +
157 +  if (!more_work_is_plausible)
158 +    more_work_is_plausible |= private_->delegate->DoIdleWork();
159 +
160 +  if (more_work_is_plausible)
161 +    ScheduleWork();
162 +}
163 +
164 +void MessagePumpXWalk::AddObserver(base::MessagePumpObserver* observer) {
165 +  private_->observers.AddObserver(observer);
166 +}
167 +
168 +void MessagePumpXWalk::RemoveObserver(base::MessagePumpObserver* observer) {
169 +  private_->observers.RemoveObserver(observer);
170 +}
171 +
172 +void MessagePumpXWalk::Run(Delegate* delegate) {
173 +  NOTREACHED();
174 +}
175 +
176 +void MessagePumpXWalk::Quit() {
177 +  private_->should_quit = true;
178 +}
179 +
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!";
188 +  }
189 +}
190 +
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;
196 +  ScheduleWork();
197 +}
198 +
199 +ObserverList<base::MessagePumpObserver>& MessagePumpXWalk::observers() {
200 +  return private_->observers;
201 +}
202 +
203 +}  // namespace xwalk
204 diff --git a/efl_webview/lib/message_pump_xwalk.h b/efl_webview/lib/message_pump_xwalk.h
205 new file mode 100644
206 index 0000000..b45c42f
207 --- /dev/null
208 +++ b/efl_webview/lib/message_pump_xwalk.h
209 @@ -0,0 +1,57 @@
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.
213 +
214 +#ifndef EFL_WEBVIEW_LIBMESSAGE_PUMP_XWALK_H_
215 +#define EFL_WEBVIEW_LIBMESSAGE_PUMP_XWALK_H_
216 +
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"
225 +
226 +namespace xwalk {
227 +
228 +class MessagePumpXWalk : public base::MessagePump {
229 +public:
230 +  MessagePumpXWalk();
231 +
232 +  // Like MessagePump::Run, but events are routed through dispatcher.
233 +  virtual void RunWithDispatcher(Delegate* delegate,
234 +                                 base::MessagePumpDispatcher* dispatcher);
235 +
236 +  void HandleDispatch();
237 +
238 +  // Adds an Observer, which will start receiving notifications immediately.
239 +  void AddObserver(base::MessagePumpObserver* observer);
240 +
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);
244 +
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;
251 +
252 +protected:
253 +  virtual ~MessagePumpXWalk();
254 +
255 +  ObserverList<base::MessagePumpObserver>& observers();
256 +
257 +private:
258 +  struct Private;
259 +  scoped_ptr<Private> private_;
260 +
261 +  DISALLOW_COPY_AND_ASSIGN(MessagePumpXWalk);
262 +};
263 +
264 +}  // namespace xwalk
265 +
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
271 @@ -29,6 +29,7 @@
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"
276  
277  namespace xwalk {
278  
279 @@ -66,12 +67,20 @@ void SubprocessPathInit() {
280        AppendSwitchPath(switches::kBrowserSubprocessPath, subprocess_path);
281  }
282  
283 +base::MessagePump* MessagePumpFactory()
284 +{
285 +    return new MessagePumpXWalk;
286 +}
287 +
288  } // namespace
289  
290  WebRuntimeContext::WebRuntimeContext() {
291    DCHECK(!g_context);
292    g_context = this;
293  
294 +  // Inject MessagePumpFacotry for embedder.
295 +  base::MessageLoop::InitMessagePumpForUIFactory(MessagePumpFactory);
296 +
297    static content::ContentMainRunner *runner = 0;
298    if (!runner) {
299      runner = content::ContentMainRunner::Create();
300 -- 
301 1.8.1.2
302