| 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/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "components/html_viewer/blink_resource_constants.h" | 15 #include "components/html_viewer/blink_resource_constants.h" |
| 16 #include "components/html_viewer/web_clipboard_impl.h" | 16 #include "components/html_viewer/web_clipboard_impl.h" |
| 17 #include "components/html_viewer/web_cookie_jar_impl.h" | 17 #include "components/html_viewer/web_cookie_jar_impl.h" |
| 18 #include "components/html_viewer/web_message_port_channel_impl.h" | 18 #include "components/html_viewer/web_message_port_channel_impl.h" |
| 19 #include "components/html_viewer/web_socket_handle_impl.h" | 19 #include "components/html_viewer/web_socket_handle_impl.h" |
| 20 #include "components/html_viewer/web_thread_impl.h" | |
| 21 #include "components/html_viewer/web_url_loader_impl.h" | 20 #include "components/html_viewer/web_url_loader_impl.h" |
| 21 #include "components/scheduler/child/webthread_impl_for_worker_scheduler.h" |
| 22 #include "components/scheduler/renderer/renderer_scheduler.h" |
| 23 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h" |
| 22 #include "net/base/data_url.h" | 24 #include "net/base/data_url.h" |
| 23 #include "net/base/mime_util.h" | 25 #include "net/base/mime_util.h" |
| 24 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
| 25 #include "net/base/net_util.h" | 27 #include "net/base/net_util.h" |
| 26 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" | 28 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" |
| 27 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" | 29 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" |
| 28 #include "third_party/mojo/src/mojo/public/cpp/application/connect.h" | 30 #include "third_party/mojo/src/mojo/public/cpp/application/connect.h" |
| 29 #include "ui/events/gestures/blink/web_gesture_curve_impl.h" | 31 #include "ui/events/gestures/blink/web_gesture_curve_impl.h" |
| 30 | 32 |
| 31 namespace html_viewer { | 33 namespace html_viewer { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 51 return impl_.get(); | 53 return impl_.get(); |
| 52 } | 54 } |
| 53 | 55 |
| 54 private: | 56 private: |
| 55 scoped_ptr<base::WaitableEvent> impl_; | 57 scoped_ptr<base::WaitableEvent> impl_; |
| 56 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); | 58 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); |
| 57 }; | 59 }; |
| 58 | 60 |
| 59 } // namespace | 61 } // namespace |
| 60 | 62 |
| 61 BlinkPlatformImpl::BlinkPlatformImpl(mojo::ApplicationImpl* app) | 63 BlinkPlatformImpl::BlinkPlatformImpl( |
| 62 : shared_timer_func_(NULL), | 64 mojo::ApplicationImpl* app, |
| 65 scheduler::RendererScheduler* renderer_scheduler) |
| 66 : main_thread_task_runner_(renderer_scheduler->DefaultTaskRunner()), |
| 67 main_thread_( |
| 68 new scheduler::WebThreadImplForRendererScheduler(renderer_scheduler)), |
| 69 shared_timer_func_(NULL), |
| 63 shared_timer_fire_time_(0.0), | 70 shared_timer_fire_time_(0.0), |
| 64 shared_timer_fire_time_was_set_while_suspended_(false), | 71 shared_timer_fire_time_was_set_while_suspended_(false), |
| 65 shared_timer_suspended_(0), | 72 shared_timer_suspended_(0) { |
| 66 current_thread_slot_(&DestroyCurrentThread), | |
| 67 scheduler_(base::ThreadTaskRunnerHandle::Get()) { | |
| 68 if (app) { | 73 if (app) { |
| 69 app->ConnectToService("mojo:network_service", &network_service_); | 74 app->ConnectToService("mojo:network_service", &network_service_); |
| 70 | 75 |
| 71 mojo::CookieStorePtr cookie_store; | 76 mojo::CookieStorePtr cookie_store; |
| 72 network_service_->GetCookieStore(GetProxy(&cookie_store)); | 77 network_service_->GetCookieStore(GetProxy(&cookie_store)); |
| 73 cookie_jar_.reset(new WebCookieJarImpl(cookie_store.Pass())); | 78 cookie_jar_.reset(new WebCookieJarImpl(cookie_store.Pass())); |
| 74 | 79 |
| 75 mojo::ServiceProviderPtr service_provider; | 80 mojo::ServiceProviderPtr service_provider; |
| 76 app->ConnectToService("mojo:core_services", &service_provider); | 81 app->ConnectToService("mojo:core_services", &service_provider); |
| 77 mojo::ClipboardPtr clipboard; | 82 mojo::ClipboardPtr clipboard; |
| 78 mojo::ConnectToService(service_provider.get(), &clipboard); | 83 mojo::ConnectToService(service_provider.get(), &clipboard); |
| 79 clipboard_.reset(new WebClipboardImpl(clipboard.Pass())); | 84 clipboard_.reset(new WebClipboardImpl(clipboard.Pass())); |
| 80 } | 85 } |
| 86 shared_timer_.SetTaskRunner(main_thread_task_runner_); |
| 81 } | 87 } |
| 82 | 88 |
| 83 BlinkPlatformImpl::~BlinkPlatformImpl() { | 89 BlinkPlatformImpl::~BlinkPlatformImpl() { |
| 84 } | 90 } |
| 85 | 91 |
| 86 blink::WebCookieJar* BlinkPlatformImpl::cookieJar() { | 92 blink::WebCookieJar* BlinkPlatformImpl::cookieJar() { |
| 87 return cookie_jar_.get(); | 93 return cookie_jar_.get(); |
| 88 } | 94 } |
| 89 | 95 |
| 90 blink::WebClipboard* BlinkPlatformImpl::clipboard() { | 96 blink::WebClipboard* BlinkPlatformImpl::clipboard() { |
| 91 return clipboard_.get(); | 97 return clipboard_.get(); |
| 92 } | 98 } |
| 93 | 99 |
| 94 blink::WebMimeRegistry* BlinkPlatformImpl::mimeRegistry() { | 100 blink::WebMimeRegistry* BlinkPlatformImpl::mimeRegistry() { |
| 95 return &mime_registry_; | 101 return &mime_registry_; |
| 96 } | 102 } |
| 97 | 103 |
| 98 blink::WebThemeEngine* BlinkPlatformImpl::themeEngine() { | 104 blink::WebThemeEngine* BlinkPlatformImpl::themeEngine() { |
| 99 return &theme_engine_; | 105 return &theme_engine_; |
| 100 } | 106 } |
| 101 | 107 |
| 102 blink::WebScheduler* BlinkPlatformImpl::scheduler() { | |
| 103 return &scheduler_; | |
| 104 } | |
| 105 | |
| 106 blink::WebString BlinkPlatformImpl::defaultLocale() { | 108 blink::WebString BlinkPlatformImpl::defaultLocale() { |
| 107 return blink::WebString::fromUTF8("en-US"); | 109 return blink::WebString::fromUTF8("en-US"); |
| 108 } | 110 } |
| 109 | 111 |
| 110 blink::WebBlobRegistry* BlinkPlatformImpl::blobRegistry() { | 112 blink::WebBlobRegistry* BlinkPlatformImpl::blobRegistry() { |
| 111 return &blob_registry_; | 113 return &blob_registry_; |
| 112 } | 114 } |
| 113 | 115 |
| 114 double BlinkPlatformImpl::currentTime() { | 116 double BlinkPlatformImpl::currentTime() { |
| 115 return base::Time::Now().ToDoubleT(); | 117 return base::Time::Now().ToDoubleT(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 247 |
| 246 bool BlinkPlatformImpl::isReservedIPAddress( | 248 bool BlinkPlatformImpl::isReservedIPAddress( |
| 247 const blink::WebString& host) const { | 249 const blink::WebString& host) const { |
| 248 net::IPAddressNumber address; | 250 net::IPAddressNumber address; |
| 249 if (!net::ParseURLHostnameToNumber(host.utf8(), &address)) | 251 if (!net::ParseURLHostnameToNumber(host.utf8(), &address)) |
| 250 return false; | 252 return false; |
| 251 return net::IsIPAddressReserved(address); | 253 return net::IsIPAddressReserved(address); |
| 252 } | 254 } |
| 253 | 255 |
| 254 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) { | 256 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) { |
| 255 return new WebThreadImpl(name); | 257 scheduler::WebThreadImplForWorkerScheduler* thread = |
| 258 new scheduler::WebThreadImplForWorkerScheduler(name); |
| 259 thread->TaskRunner()->PostTask( |
| 260 FROM_HERE, base::Bind(&BlinkPlatformImpl::UpdateWebThreadTLS, |
| 261 base::Unretained(this), thread)); |
| 262 return thread; |
| 256 } | 263 } |
| 257 | 264 |
| 258 blink::WebThread* BlinkPlatformImpl::currentThread() { | 265 blink::WebThread* BlinkPlatformImpl::currentThread() { |
| 259 WebThreadImplForMessageLoop* thread = | 266 if (main_thread_->isCurrentThread()) |
| 260 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get()); | 267 return main_thread_.get(); |
| 261 if (thread) | 268 return static_cast<blink::WebThread*>(current_thread_slot_.Get()); |
| 262 return (thread); | |
| 263 | |
| 264 scoped_refptr<base::MessageLoopProxy> message_loop = | |
| 265 base::MessageLoopProxy::current(); | |
| 266 if (!message_loop.get()) | |
| 267 return NULL; | |
| 268 | |
| 269 thread = new WebThreadImplForMessageLoop(message_loop.get()); | |
| 270 current_thread_slot_.Set(thread); | |
| 271 return thread; | |
| 272 } | 269 } |
| 273 | 270 |
| 274 void BlinkPlatformImpl::yieldCurrentThread() { | 271 void BlinkPlatformImpl::yieldCurrentThread() { |
| 275 base::PlatformThread::YieldCurrentThread(); | 272 base::PlatformThread::YieldCurrentThread(); |
| 276 } | 273 } |
| 277 | 274 |
| 278 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent() { | 275 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent() { |
| 279 return new WebWaitableEventImpl(); | 276 return new WebWaitableEventImpl(); |
| 280 } | 277 } |
| 281 | 278 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 303 | 300 |
| 304 blink::WebCrypto* BlinkPlatformImpl::crypto() { | 301 blink::WebCrypto* BlinkPlatformImpl::crypto() { |
| 305 return &web_crypto_; | 302 return &web_crypto_; |
| 306 } | 303 } |
| 307 | 304 |
| 308 blink::WebNotificationManager* | 305 blink::WebNotificationManager* |
| 309 BlinkPlatformImpl::notificationManager() { | 306 BlinkPlatformImpl::notificationManager() { |
| 310 return &web_notification_manager_; | 307 return &web_notification_manager_; |
| 311 } | 308 } |
| 312 | 309 |
| 313 // static | 310 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread) { |
| 314 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { | 311 DCHECK(!current_thread_slot_.Get()); |
| 315 WebThreadImplForMessageLoop* impl = | 312 current_thread_slot_.Set(thread); |
| 316 static_cast<WebThreadImplForMessageLoop*>(thread); | |
| 317 delete impl; | |
| 318 } | 313 } |
| 319 | 314 |
| 320 } // namespace html_viewer | 315 } // namespace html_viewer |
| OLD | NEW |