Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: mojo/services/html_viewer/blink_platform_impl.cc

Issue 1008543005: Add HTMLViewer command line arg to set user agent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: formatting Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698