OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/services/html_viewer/blink_platform_impl.h" | 5 #include "mojo/services/html_viewer/blink_platform_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
| 9 #include "base/command_line.h" |
9 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
11 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
12 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "mojo/services/html_viewer/blink_resource_constants.h" | 15 #include "mojo/services/html_viewer/blink_resource_constants.h" |
15 #include "mojo/services/html_viewer/webthread_impl.h" | 16 #include "mojo/services/html_viewer/webthread_impl.h" |
16 #include "net/base/data_url.h" | 17 #include "net/base/data_url.h" |
17 #include "net/base/mime_util.h" | 18 #include "net/base/mime_util.h" |
18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
19 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" | 20 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" |
20 | 21 |
21 namespace html_viewer { | 22 namespace html_viewer { |
22 namespace { | 23 namespace { |
23 | 24 |
| 25 // Allows overriding user agent scring. |
| 26 const char kUserAgentSwitch[] = "user-agent"; |
| 27 |
24 // TODO(darin): Figure out what our UA should really be. | 28 // TODO(darin): Figure out what our UA should really be. |
25 const char kUserAgentString[] = | 29 const char kDefaultUserAgentString[] = |
26 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " | 30 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " |
27 "Chrome/35.0.1916.153 Safari/537.36"; | 31 "Chrome/35.0.1916.153 Safari/537.36"; |
28 | 32 |
29 class WebWaitableEventImpl : public blink::WebWaitableEvent { | 33 class WebWaitableEventImpl : public blink::WebWaitableEvent { |
30 public: | 34 public: |
31 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {} | 35 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {} |
32 virtual ~WebWaitableEventImpl() {} | 36 virtual ~WebWaitableEventImpl() {} |
33 | 37 |
34 virtual void wait() { impl_->Wait(); } | 38 virtual void wait() { impl_->Wait(); } |
35 virtual void signal() { impl_->Signal(); } | 39 virtual void signal() { impl_->Signal(); } |
36 | 40 |
37 base::WaitableEvent* impl() { | 41 base::WaitableEvent* impl() { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 169 |
166 blink::WebURLLoader* BlinkPlatformImpl::createURLLoader() { | 170 blink::WebURLLoader* BlinkPlatformImpl::createURLLoader() { |
167 return NULL; | 171 return NULL; |
168 } | 172 } |
169 | 173 |
170 blink::WebSocketHandle* BlinkPlatformImpl::createWebSocketHandle() { | 174 blink::WebSocketHandle* BlinkPlatformImpl::createWebSocketHandle() { |
171 return NULL; | 175 return NULL; |
172 } | 176 } |
173 | 177 |
174 blink::WebString BlinkPlatformImpl::userAgent() { | 178 blink::WebString BlinkPlatformImpl::userAgent() { |
175 return blink::WebString::fromUTF8(kUserAgentString); | 179 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 180 if (command_line->HasSwitch(kUserAgentSwitch)) { |
| 181 return blink::WebString::fromUTF8( |
| 182 command_line->GetSwitchValueASCII(kUserAgentSwitch)); |
| 183 } |
| 184 return blink::WebString::fromUTF8(kDefaultUserAgentString); |
176 } | 185 } |
177 | 186 |
178 blink::WebData BlinkPlatformImpl::parseDataURL( | 187 blink::WebData BlinkPlatformImpl::parseDataURL( |
179 const blink::WebURL& url, | 188 const blink::WebURL& url, |
180 blink::WebString& mimetype_out, | 189 blink::WebString& mimetype_out, |
181 blink::WebString& charset_out) { | 190 blink::WebString& charset_out) { |
182 std::string mimetype, charset, data; | 191 std::string mimetype, charset, data; |
183 if (net::DataURL::Parse(url, &mimetype, &charset, &data) | 192 if (net::DataURL::Parse(url, &mimetype, &charset, &data) |
184 && net::IsSupportedMimeType(mimetype)) { | 193 && net::IsSupportedMimeType(mimetype)) { |
185 mimetype_out = blink::WebString::fromUTF8(mimetype); | 194 mimetype_out = blink::WebString::fromUTF8(mimetype); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 249 } |
241 | 250 |
242 // static | 251 // static |
243 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { | 252 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { |
244 WebThreadImplForMessageLoop* impl = | 253 WebThreadImplForMessageLoop* impl = |
245 static_cast<WebThreadImplForMessageLoop*>(thread); | 254 static_cast<WebThreadImplForMessageLoop*>(thread); |
246 delete impl; | 255 delete impl; |
247 } | 256 } |
248 | 257 |
249 } // namespace html_viewer | 258 } // namespace html_viewer |
OLD | NEW |