1 From ea4d75808eb04875c233f6a2acda23a98f09ad76 Mon Sep 17 00:00:00 2001
2 From: Dongseong Hwang <dongseong.hwang@intel.com>
3 Date: Fri, 5 Jul 2013 14:32:19 +0300
4 Subject: [PATCH 07/33] XWalk must set ContentClient for user agent.
6 This patch is base on Alex's finding.
7 content_client_xwalk is copied for xwalk project.
8 Render process must know user agent.
9 The solution is easy. ProcessMain uses ContentMainDelegateXWalk.
11 efl_webview/DEPS | 2 +
12 efl_webview/efl_webview.gyp | 4 ++
13 efl_webview/lib/content_client_xwalk.cc | 52 ++++++++++++++++++++++++++
14 efl_webview/lib/content_client_xwalk.h | 36 ++++++++++++++++++
15 efl_webview/lib/content_main_delegate_xwalk.cc | 29 ++++++++++++++
16 efl_webview/lib/content_main_delegate_xwalk.h | 33 ++++++++++++++++
17 efl_webview/lib/process_main.cc | 4 +-
18 efl_webview/lib/web_runtime_context.cc | 18 +--------
19 8 files changed, 160 insertions(+), 18 deletions(-)
20 create mode 100644 efl_webview/lib/content_client_xwalk.cc
21 create mode 100644 efl_webview/lib/content_client_xwalk.h
22 create mode 100644 efl_webview/lib/content_main_delegate_xwalk.cc
23 create mode 100644 efl_webview/lib/content_main_delegate_xwalk.h
25 diff --git a/efl_webview/DEPS b/efl_webview/DEPS
26 index dd8d329..1b41ffd 100644
27 --- a/efl_webview/DEPS
28 +++ b/efl_webview/DEPS
36 diff --git a/efl_webview/efl_webview.gyp b/efl_webview/efl_webview.gyp
37 index 3037aa2..f6b959f 100644
38 --- a/efl_webview/efl_webview.gyp
39 +++ b/efl_webview/efl_webview.gyp
42 'lib/content_browser_client_xwalk.cc',
43 'lib/content_browser_client_xwalk.h',
44 + 'lib/content_client_xwalk.cc',
45 + 'lib/content_client_xwalk.h',
46 + 'lib/content_main_delegate_xwalk.cc',
47 + 'lib/content_main_delegate_xwalk.h',
48 'lib/browser_context_xwalk.h',
49 'lib/message_pump_xwalk.cc',
50 'lib/message_pump_xwalk.h',
51 diff --git a/efl_webview/lib/content_client_xwalk.cc b/efl_webview/lib/content_client_xwalk.cc
53 index 0000000..0549d6b
55 +++ b/efl_webview/lib/content_client_xwalk.cc
57 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
58 +// Use of this source code is governed by a BSD-style license that can be
59 +// found in the LICENSE file.
61 +#include "efl_webview/lib/content_client_xwalk.h"
63 +#include "base/command_line.h"
64 +#include "base/string_piece.h"
65 +#include "base/utf_string_conversions.h"
66 +#include "content/public/common/content_switches.h"
67 +#include "ui/base/l10n/l10n_util.h"
68 +#include "ui/base/resource/resource_bundle.h"
69 +#include "webkit/user_agent/user_agent_util.h"
73 +ContentClientXWalk::ContentClientXWalk() {
76 +ContentClientXWalk::~ContentClientXWalk() {
79 +std::string ContentClientXWalk::GetUserAgent() const {
80 + // TODO(hmin): Define user agent for xwalk.
81 + std::string product = "Chrome/0.0.1";
82 + CommandLine* command_line = CommandLine::ForCurrentProcess();
83 + if (command_line->HasSwitch(switches::kUseMobileUserAgent))
84 + product += " Mobile";
85 + return webkit_glue::BuildUserAgentFromProduct(product);
88 +string16 ContentClientXWalk::GetLocalizedString(int message_id) const {
89 + return l10n_util::GetStringUTF16(message_id);
92 +base::StringPiece ContentClientXWalk::GetDataResource(
94 + ui::ScaleFactor scale_factor) const {
95 + return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
96 + resource_id, scale_factor);
99 +base::RefCountedStaticMemory* ContentClientXWalk::GetDataResourceBytes(
100 + int resource_id) const {
101 + return ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id);
104 +gfx::Image& ContentClientXWalk::GetNativeImageNamed(int resource_id) const {
105 + return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
108 +} // namespace xwalk
109 diff --git a/efl_webview/lib/content_client_xwalk.h b/efl_webview/lib/content_client_xwalk.h
111 index 0000000..0d88260
113 +++ b/efl_webview/lib/content_client_xwalk.h
115 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
116 +// Use of this source code is governed by a BSD-style license that can be
117 +// found in the LICENSE file.
119 +#ifndef EFL_WEBVIEW_LIB_CONTENT_CLIENT_XWALK_H_
120 +#define EFL_WEBVIEW_LIB_CONTENT_CLIENT_XWALK_H_
125 +#include "base/compiler_specific.h"
126 +#include "content/public/common/content_client.h"
130 +class ContentClientXWalk : public content::ContentClient {
132 + ContentClientXWalk();
133 + virtual ~ContentClientXWalk();
135 + virtual std::string GetUserAgent() const OVERRIDE;
136 + virtual string16 GetLocalizedString(int message_id) const OVERRIDE;
137 + virtual base::StringPiece GetDataResource(
139 + ui::ScaleFactor scale_factor) const OVERRIDE;
140 + virtual base::RefCountedStaticMemory* GetDataResourceBytes(
141 + int resource_id) const OVERRIDE;
142 + virtual gfx::Image& GetNativeImageNamed(int resource_id) const OVERRIDE;
145 + DISALLOW_COPY_AND_ASSIGN(ContentClientXWalk);
148 +} // namespace xwalk
150 +#endif // EFL_WEBVIEW_LIB_CONTENT_CLIENT_XWALK_H_
151 diff --git a/efl_webview/lib/content_main_delegate_xwalk.cc b/efl_webview/lib/content_main_delegate_xwalk.cc
153 index 0000000..526dd8a
155 +++ b/efl_webview/lib/content_main_delegate_xwalk.cc
157 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
158 +// Use of this source code is governed by a BSD-style license that can be
159 +// found in the LICENSE file.
161 +#include "efl_webview/lib/content_main_delegate_xwalk.h"
163 +#include "efl_webview/lib/content_browser_client_xwalk.h"
164 +#include "ui/base/resource/resource_bundle.h"
168 +ContentMainDelegateXWalk::ContentMainDelegateXWalk() { }
170 +void ContentMainDelegateXWalk::PreSandboxStartup() {
171 + ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL);
174 +bool ContentMainDelegateXWalk::BasicStartupComplete(int* exit_code) {
175 + content::SetContentClient(&content_client_);
179 +content::ContentBrowserClient*
180 + ContentMainDelegateXWalk::CreateContentBrowserClient() {
181 + browser_client_.reset(new ContentBrowserClientXWalk);
182 + return browser_client_.get();
185 +} // namespace xwalk
186 diff --git a/efl_webview/lib/content_main_delegate_xwalk.h b/efl_webview/lib/content_main_delegate_xwalk.h
188 index 0000000..850ee61
190 +++ b/efl_webview/lib/content_main_delegate_xwalk.h
192 +// Copyright (c) 2013 Intel Corporation. All rights reserved.
193 +// Use of this source code is governed by a BSD-style license that can be
194 +// found in the LICENSE file.
196 +#ifndef EFL_WEBVIEW_LIB_CONTENT_MAIN_DELEGATE_XWALK_H_
197 +#define EFL_WEBVIEW_LIB_CONTENT_MAIN_DELEGATE_XWALK_H_
199 +#include "base/compiler_specific.h"
200 +#include "base/memory/scoped_ptr.h"
201 +#include "content/public/app/content_main_delegate.h"
202 +#include "efl_webview/lib/content_browser_client_xwalk.h"
203 +#include "efl_webview/lib/content_client_xwalk.h"
207 +class ContentMainDelegateXWalk : public content::ContentMainDelegate {
209 + ContentMainDelegateXWalk();
211 + virtual void PreSandboxStartup() OVERRIDE;
212 + virtual bool BasicStartupComplete(int* exit_code) OVERRIDE;
213 + virtual content::ContentBrowserClient* CreateContentBrowserClient() OVERRIDE;
216 + scoped_ptr<ContentBrowserClientXWalk> browser_client_;
217 + ContentClientXWalk content_client_;
219 + DISALLOW_COPY_AND_ASSIGN(ContentMainDelegateXWalk);
222 +} // namespace xwalk
224 +#endif // EFL_WEBVIEW_LIB_CONTENT_MAIN_DELEGATE_XWALK_H_
225 diff --git a/efl_webview/lib/process_main.cc b/efl_webview/lib/process_main.cc
226 index 132b35c..5f1e4e44 100644
227 --- a/efl_webview/lib/process_main.cc
228 +++ b/efl_webview/lib/process_main.cc
230 #include "base/logging.h"
231 #include "content/public/app/content_main.h"
232 #include "content/public/common/content_switches.h"
233 +#include "efl_webview/lib/content_main_delegate_xwalk.h"
237 @@ -18,7 +19,8 @@ int ProcessMain(int argc, char** argv) {
238 command_line.GetSwitchValueASCII(switches::kProcessType);
239 CHECK(process_type != "");
241 - return content::ContentMain(argc, const_cast<const char**>(argv), 0);
242 + ContentMainDelegateXWalk delegate;
243 + return content::ContentMain(argc, const_cast<const char**>(argv), &delegate);
247 diff --git a/efl_webview/lib/web_runtime_context.cc b/efl_webview/lib/web_runtime_context.cc
248 index 84613a8..005a6d2 100644
249 --- a/efl_webview/lib/web_runtime_context.cc
250 +++ b/efl_webview/lib/web_runtime_context.cc
252 #include "base/base_paths.h"
253 #include "base/command_line.h"
254 #include "base/path_service.h"
255 -#include "content/public/app/content_main_delegate.h"
256 #include "content/public/app/content_main_runner.h"
257 #include "content/public/browser/browser_main_runner.h"
258 #include "content/public/common/content_switches.h"
259 #include "content/public/common/main_function_params.h"
260 #include "efl_webview/lib/browser_context_xwalk.h"
261 -#include "efl_webview/lib/content_browser_client_xwalk.h"
262 +#include "efl_webview/lib/content_main_delegate_xwalk.h"
263 #include "efl_webview/lib/message_pump_xwalk.h"
269 -class ContentMainDelegateXWalk : public content::ContentMainDelegate {
271 - ContentMainDelegateXWalk() { }
273 - content::ContentBrowserClient* CreateContentBrowserClient() {
274 - browser_client_.reset(new ContentBrowserClientXWalk);
275 - return browser_client_.get();
279 - scoped_ptr<ContentBrowserClientXWalk> browser_client_;
281 - DISALLOW_COPY_AND_ASSIGN(ContentMainDelegateXWalk);
284 WebRuntimeContext* g_context = 0;
285 // TODO: it should be passed via build system.
286 const char g_sub_process_name[] = "efl_process";