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 "components/html_viewer/blink_platform_impl.h" | 5 #include "components/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/command_line.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "components/html_viewer/blink_resource_constants.h" | 16 #include "components/html_viewer/blink_resource_constants.h" |
17 #include "components/html_viewer/web_clipboard_impl.h" | 17 #include "components/html_viewer/web_clipboard_impl.h" |
18 #include "components/html_viewer/web_cookie_jar_impl.h" | 18 #include "components/html_viewer/web_cookie_jar_impl.h" |
19 #include "components/html_viewer/web_message_port_channel_impl.h" | 19 #include "components/html_viewer/web_message_port_channel_impl.h" |
20 #include "components/html_viewer/web_socket_handle_impl.h" | 20 #include "components/html_viewer/web_socket_handle_impl.h" |
21 #include "components/html_viewer/web_url_loader_impl.h" | 21 #include "components/html_viewer/web_url_loader_impl.h" |
22 #include "components/mime_util/mime_util.h" | 22 #include "components/mime_util/mime_util.h" |
23 #include "components/scheduler/child/webthread_impl_for_worker_scheduler.h" | 23 #include "components/scheduler/child/webthread_impl_for_worker_scheduler.h" |
24 #include "components/scheduler/renderer/renderer_scheduler.h" | 24 #include "components/scheduler/renderer/renderer_scheduler.h" |
25 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h" | 25 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h" |
26 #include "mojo/application/public/cpp/application_impl.h" | 26 #include "mojo/application/public/cpp/application_impl.h" |
27 #include "mojo/application/public/cpp/connect.h" | 27 #include "mojo/application/public/cpp/connect.h" |
| 28 #include "mojo/common/user_agent.h" |
28 #include "net/base/data_url.h" | 29 #include "net/base/data_url.h" |
29 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
30 #include "net/base/net_util.h" | 31 #include "net/base/net_util.h" |
31 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" | 32 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" |
32 #include "ui/events/gestures/blink/web_gesture_curve_impl.h" | 33 #include "ui/events/gestures/blink/web_gesture_curve_impl.h" |
33 | 34 |
34 namespace html_viewer { | 35 namespace html_viewer { |
35 namespace { | 36 namespace { |
36 | 37 |
37 // Allows overriding user agent scring. | 38 // Allows overriding user agent scring. |
38 const char kUserAgentSwitch[] = "user-agent"; | 39 const char kUserAgentSwitch[] = "user-agent"; |
39 | 40 |
40 // TODO(darin): Figure out what our UA should really be. | |
41 const char kDefaultUserAgentString[] = | |
42 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " | |
43 "Chrome/42.0.2311.68 Safari/537.36"; | |
44 | |
45 class WebWaitableEventImpl : public blink::WebWaitableEvent { | 41 class WebWaitableEventImpl : public blink::WebWaitableEvent { |
46 public: | 42 public: |
47 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {} | 43 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {} |
48 ~WebWaitableEventImpl() override {} | 44 ~WebWaitableEventImpl() override {} |
49 | 45 |
50 void wait() override { impl_->Wait(); } | 46 void wait() override { impl_->Wait(); } |
51 void signal() override { impl_->Signal(); } | 47 void signal() override { impl_->Signal(); } |
52 | 48 |
53 base::WaitableEvent* impl() { | 49 base::WaitableEvent* impl() { |
54 return impl_.get(); | 50 return impl_.get(); |
(...skipping 10 matching lines...) Expand all Loading... |
65 mojo::ApplicationImpl* app, | 61 mojo::ApplicationImpl* app, |
66 scheduler::RendererScheduler* renderer_scheduler) | 62 scheduler::RendererScheduler* renderer_scheduler) |
67 : main_thread_task_runner_(renderer_scheduler->DefaultTaskRunner()), | 63 : main_thread_task_runner_(renderer_scheduler->DefaultTaskRunner()), |
68 main_thread_( | 64 main_thread_( |
69 new scheduler::WebThreadImplForRendererScheduler(renderer_scheduler)), | 65 new scheduler::WebThreadImplForRendererScheduler(renderer_scheduler)), |
70 shared_timer_func_(NULL), | 66 shared_timer_func_(NULL), |
71 shared_timer_fire_time_(0.0), | 67 shared_timer_fire_time_(0.0), |
72 shared_timer_fire_time_was_set_while_suspended_(false), | 68 shared_timer_fire_time_was_set_while_suspended_(false), |
73 shared_timer_suspended_(0) { | 69 shared_timer_suspended_(0) { |
74 if (app) { | 70 if (app) { |
75 app->ConnectToService("mojo:network_service", &network_service_); | 71 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 72 request->url = mojo::String::From("mojo:network_service"); |
| 73 app->ConnectToService(request.Pass(), &network_service_); |
76 | 74 |
77 mojo::CookieStorePtr cookie_store; | 75 mojo::CookieStorePtr cookie_store; |
78 network_service_->GetCookieStore(GetProxy(&cookie_store)); | 76 network_service_->GetCookieStore(GetProxy(&cookie_store)); |
79 cookie_jar_.reset(new WebCookieJarImpl(cookie_store.Pass())); | 77 cookie_jar_.reset(new WebCookieJarImpl(cookie_store.Pass())); |
80 | 78 |
81 mojo::ClipboardPtr clipboard; | 79 mojo::ClipboardPtr clipboard; |
82 app->ConnectToService("mojo:clipboard", &clipboard); | 80 mojo::URLRequestPtr request2(mojo::URLRequest::New()); |
| 81 request2->url = mojo::String::From("mojo:clipboard"); |
| 82 app->ConnectToService(request2.Pass(), &clipboard); |
83 clipboard_.reset(new WebClipboardImpl(clipboard.Pass())); | 83 clipboard_.reset(new WebClipboardImpl(clipboard.Pass())); |
84 } | 84 } |
85 shared_timer_.SetTaskRunner(main_thread_task_runner_); | 85 shared_timer_.SetTaskRunner(main_thread_task_runner_); |
86 } | 86 } |
87 | 87 |
88 BlinkPlatformImpl::~BlinkPlatformImpl() { | 88 BlinkPlatformImpl::~BlinkPlatformImpl() { |
89 } | 89 } |
90 | 90 |
91 blink::WebCookieJar* BlinkPlatformImpl::cookieJar() { | 91 blink::WebCookieJar* BlinkPlatformImpl::cookieJar() { |
92 return cookie_jar_.get(); | 92 return cookie_jar_.get(); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 blink::WebSocketHandle* BlinkPlatformImpl::createWebSocketHandle() { | 209 blink::WebSocketHandle* BlinkPlatformImpl::createWebSocketHandle() { |
210 return new WebSocketHandleImpl(network_service_.get()); | 210 return new WebSocketHandleImpl(network_service_.get()); |
211 } | 211 } |
212 | 212 |
213 blink::WebString BlinkPlatformImpl::userAgent() { | 213 blink::WebString BlinkPlatformImpl::userAgent() { |
214 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 214 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
215 if (command_line->HasSwitch(kUserAgentSwitch)) { | 215 if (command_line->HasSwitch(kUserAgentSwitch)) { |
216 return blink::WebString::fromUTF8( | 216 return blink::WebString::fromUTF8( |
217 command_line->GetSwitchValueASCII(kUserAgentSwitch)); | 217 command_line->GetSwitchValueASCII(kUserAgentSwitch)); |
218 } | 218 } |
219 return blink::WebString::fromUTF8(kDefaultUserAgentString); | 219 return blink::WebString::fromUTF8(mojo::common::GetUserAgent()); |
220 } | 220 } |
221 | 221 |
222 blink::WebData BlinkPlatformImpl::parseDataURL( | 222 blink::WebData BlinkPlatformImpl::parseDataURL( |
223 const blink::WebURL& url, | 223 const blink::WebURL& url, |
224 blink::WebString& mimetype_out, | 224 blink::WebString& mimetype_out, |
225 blink::WebString& charset_out) { | 225 blink::WebString& charset_out) { |
226 std::string mimetype, charset, data; | 226 std::string mimetype, charset, data; |
227 if (net::DataURL::Parse(url, &mimetype, &charset, &data) && | 227 if (net::DataURL::Parse(url, &mimetype, &charset, &data) && |
228 mime_util::IsSupportedMimeType(mimetype)) { | 228 mime_util::IsSupportedMimeType(mimetype)) { |
229 mimetype_out = blink::WebString::fromUTF8(mimetype); | 229 mimetype_out = blink::WebString::fromUTF8(mimetype); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 BlinkPlatformImpl::notificationManager() { | 305 BlinkPlatformImpl::notificationManager() { |
306 return &web_notification_manager_; | 306 return &web_notification_manager_; |
307 } | 307 } |
308 | 308 |
309 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread) { | 309 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread) { |
310 DCHECK(!current_thread_slot_.Get()); | 310 DCHECK(!current_thread_slot_.Get()); |
311 current_thread_slot_.Set(thread); | 311 current_thread_slot_.Set(thread); |
312 } | 312 } |
313 | 313 |
314 } // namespace html_viewer | 314 } // namespace html_viewer |
OLD | NEW |