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 "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
17 #include "components/html_viewer/blink_resource_constants.h" | 17 #include "components/html_viewer/blink_resource_constants.h" |
18 #include "components/html_viewer/web_clipboard_impl.h" | 18 #include "components/html_viewer/web_clipboard_impl.h" |
19 #include "components/html_viewer/web_cookie_jar_impl.h" | 19 #include "components/html_viewer/web_cookie_jar_impl.h" |
20 #include "components/html_viewer/web_graphics_context_3d_command_buffer_impl.h" | |
20 #include "components/html_viewer/web_socket_handle_impl.h" | 21 #include "components/html_viewer/web_socket_handle_impl.h" |
21 #include "components/html_viewer/web_url_loader_impl.h" | 22 #include "components/html_viewer/web_url_loader_impl.h" |
22 #include "components/message_port/web_message_port_channel_impl.h" | 23 #include "components/message_port/web_message_port_channel_impl.h" |
23 #include "components/mime_util/mime_util.h" | 24 #include "components/mime_util/mime_util.h" |
24 #include "components/scheduler/child/webthread_impl_for_worker_scheduler.h" | 25 #include "components/scheduler/child/webthread_impl_for_worker_scheduler.h" |
25 #include "components/scheduler/renderer/renderer_scheduler.h" | 26 #include "components/scheduler/renderer/renderer_scheduler.h" |
26 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h" | 27 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h" |
27 #include "mojo/application/public/cpp/application_impl.h" | 28 #include "mojo/application/public/cpp/application_impl.h" |
28 #include "mojo/application/public/cpp/connect.h" | 29 #include "mojo/application/public/cpp/connect.h" |
29 #include "mojo/common/user_agent.h" | 30 #include "mojo/common/user_agent.h" |
30 #include "net/base/data_url.h" | 31 #include "net/base/data_url.h" |
31 #include "net/base/ip_address_number.h" | 32 #include "net/base/ip_address_number.h" |
32 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
33 #include "net/base/net_util.h" | 34 #include "net/base/net_util.h" |
34 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" | 35 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" |
35 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
36 #include "ui/events/gestures/blink/web_gesture_curve_impl.h" | 37 #include "ui/events/gestures/blink/web_gesture_curve_impl.h" |
38 #include "url/gurl.h" | |
37 | 39 |
38 namespace html_viewer { | 40 namespace html_viewer { |
39 namespace { | 41 namespace { |
40 | 42 |
41 // Allows overriding user agent scring. | 43 // Allows overriding user agent scring. |
42 const char kUserAgentSwitch[] = "user-agent"; | 44 const char kUserAgentSwitch[] = "user-agent"; |
45 const char kEnableWebGLSwitch[] = "enable-webgl"; | |
43 | 46 |
44 class WebWaitableEventImpl : public blink::WebWaitableEvent { | 47 class WebWaitableEventImpl : public blink::WebWaitableEvent { |
45 public: | 48 public: |
46 WebWaitableEventImpl(ResetPolicy policy, InitialState state) { | 49 WebWaitableEventImpl(ResetPolicy policy, InitialState state) { |
47 bool manual_reset = policy == ResetPolicy::Manual; | 50 bool manual_reset = policy == ResetPolicy::Manual; |
48 bool initially_signaled = state == InitialState::Signaled; | 51 bool initially_signaled = state == InitialState::Signaled; |
49 impl_.reset(new base::WaitableEvent(manual_reset, initially_signaled)); | 52 impl_.reset(new base::WaitableEvent(manual_reset, initially_signaled)); |
50 } | 53 } |
51 virtual ~WebWaitableEventImpl() {} | 54 virtual ~WebWaitableEventImpl() {} |
52 | 55 |
53 virtual void reset() { impl_->Reset(); } | 56 virtual void reset() { impl_->Reset(); } |
54 virtual void wait() { impl_->Wait(); } | 57 virtual void wait() { impl_->Wait(); } |
55 virtual void signal() { impl_->Signal(); } | 58 virtual void signal() { impl_->Signal(); } |
56 | 59 |
57 base::WaitableEvent* impl() { | 60 base::WaitableEvent* impl() { |
58 return impl_.get(); | 61 return impl_.get(); |
59 } | 62 } |
60 | 63 |
61 private: | 64 private: |
62 scoped_ptr<base::WaitableEvent> impl_; | 65 scoped_ptr<base::WaitableEvent> impl_; |
63 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); | 66 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); |
64 }; | 67 }; |
65 | 68 |
66 } // namespace | 69 } // namespace |
67 | 70 |
68 BlinkPlatformImpl::BlinkPlatformImpl( | 71 BlinkPlatformImpl::BlinkPlatformImpl( |
69 mojo::ApplicationImpl* app, | 72 mojo::ApplicationImpl* app, |
70 scheduler::RendererScheduler* renderer_scheduler) | 73 scheduler::RendererScheduler* renderer_scheduler) |
71 : main_thread_task_runner_(renderer_scheduler->DefaultTaskRunner()), | 74 : app_(app), |
75 main_thread_task_runner_(renderer_scheduler->DefaultTaskRunner()), | |
72 main_thread_(new scheduler::WebThreadImplForRendererScheduler( | 76 main_thread_(new scheduler::WebThreadImplForRendererScheduler( |
73 renderer_scheduler)) { | 77 renderer_scheduler)) { |
74 if (app) { | 78 if (app) { |
75 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 79 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
76 request->url = mojo::String::From("mojo:network_service"); | 80 request->url = mojo::String::From("mojo:network_service"); |
77 scoped_ptr<mojo::ApplicationConnection> connection = | 81 scoped_ptr<mojo::ApplicationConnection> connection = |
78 app->ConnectToApplication(request.Pass()); | 82 app->ConnectToApplication(request.Pass()); |
79 connection->ConnectToService(&web_socket_factory_); | 83 connection->ConnectToService(&web_socket_factory_); |
80 connection->ConnectToService(&url_loader_factory_); | 84 connection->ConnectToService(&url_loader_factory_); |
81 | 85 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 blink::WebScrollbarBehavior* BlinkPlatformImpl::scrollbarBehavior() { | 159 blink::WebScrollbarBehavior* BlinkPlatformImpl::scrollbarBehavior() { |
156 return &scrollbar_behavior_; | 160 return &scrollbar_behavior_; |
157 } | 161 } |
158 | 162 |
159 const unsigned char* BlinkPlatformImpl::getTraceCategoryEnabledFlag( | 163 const unsigned char* BlinkPlatformImpl::getTraceCategoryEnabledFlag( |
160 const char* category_name) { | 164 const char* category_name) { |
161 static const unsigned char buf[] = "*"; | 165 static const unsigned char buf[] = "*"; |
162 return buf; | 166 return buf; |
163 } | 167 } |
164 | 168 |
169 blink::WebGraphicsContext3D* | |
170 BlinkPlatformImpl::createOffscreenGraphicsContext3D( | |
171 const blink::WebGraphicsContext3D::Attributes& attributes, | |
172 blink::WebGraphicsContext3D* shareContext) { | |
173 return createOffscreenGraphicsContext3D(attributes, shareContext, nullptr); | |
174 } | |
175 | |
176 blink::WebGraphicsContext3D* | |
177 BlinkPlatformImpl::createOffscreenGraphicsContext3D( | |
178 const blink::WebGraphicsContext3D::Attributes& attributes, | |
179 blink::WebGraphicsContext3D* shareContext, | |
180 blink::WebGLInfo* glInfo) { | |
181 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
182 if (command_line->HasSwitch(kEnableWebGLSwitch)) { | |
Fady Samuel
2015/09/14 19:21:43
Why make this a switch?
Peng
2015/09/14 19:28:46
I tested it with some simple webgl pages, it works
| |
183 return WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( | |
184 app_, GURL(attributes.topDocumentURL), attributes, shareContext, | |
185 glInfo); | |
186 } | |
187 return nullptr; | |
188 } | |
189 | |
190 blink::WebGraphicsContext3D* | |
191 BlinkPlatformImpl::createOffscreenGraphicsContext3D( | |
192 const blink::WebGraphicsContext3D::Attributes& attributes) { | |
193 return createOffscreenGraphicsContext3D(attributes, nullptr, nullptr); | |
194 } | |
195 | |
196 blink::WebGraphicsContext3DProvider* | |
197 BlinkPlatformImpl::createSharedOffscreenGraphicsContext3DProvider() { | |
198 return nullptr; | |
199 } | |
200 | |
165 blink::WebData BlinkPlatformImpl::loadResource(const char* resource) { | 201 blink::WebData BlinkPlatformImpl::loadResource(const char* resource) { |
166 for (size_t i = 0; i < arraysize(kDataResources); ++i) { | 202 for (size_t i = 0; i < arraysize(kDataResources); ++i) { |
167 if (!strcmp(resource, kDataResources[i].name)) { | 203 if (!strcmp(resource, kDataResources[i].name)) { |
168 base::StringPiece data = | 204 base::StringPiece data = |
169 ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( | 205 ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( |
170 kDataResources[i].id, ui::SCALE_FACTOR_100P); | 206 kDataResources[i].id, ui::SCALE_FACTOR_100P); |
171 return blink::WebData(data.data(), data.size()); | 207 return blink::WebData(data.data(), data.size()); |
172 } | 208 } |
173 } | 209 } |
174 NOTREACHED() << "Requested resource is unavailable: " << resource; | 210 NOTREACHED() << "Requested resource is unavailable: " << resource; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 BlinkPlatformImpl::notificationManager() { | 316 BlinkPlatformImpl::notificationManager() { |
281 return &web_notification_manager_; | 317 return &web_notification_manager_; |
282 } | 318 } |
283 | 319 |
284 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread) { | 320 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread) { |
285 DCHECK(!current_thread_slot_.Get()); | 321 DCHECK(!current_thread_slot_.Get()); |
286 current_thread_slot_.Set(thread); | 322 current_thread_slot_.Set(thread); |
287 } | 323 } |
288 | 324 |
289 } // namespace html_viewer | 325 } // namespace html_viewer |
OLD | NEW |