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 "sky/viewer/document_view.h" | 5 #include "sky/viewer/document_view.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "sky/engine/public/platform/WebInputEvent.h" | 27 #include "sky/engine/public/platform/WebInputEvent.h" |
28 #include "sky/engine/public/platform/WebScreenInfo.h" | 28 #include "sky/engine/public/platform/WebScreenInfo.h" |
29 #include "sky/engine/public/web/Sky.h" | 29 #include "sky/engine/public/web/Sky.h" |
30 #include "sky/engine/public/web/WebConsoleMessage.h" | 30 #include "sky/engine/public/web/WebConsoleMessage.h" |
31 #include "sky/engine/public/web/WebDocument.h" | 31 #include "sky/engine/public/web/WebDocument.h" |
32 #include "sky/engine/public/web/WebElement.h" | 32 #include "sky/engine/public/web/WebElement.h" |
33 #include "sky/engine/public/web/WebLocalFrame.h" | 33 #include "sky/engine/public/web/WebLocalFrame.h" |
34 #include "sky/engine/public/web/WebScriptSource.h" | 34 #include "sky/engine/public/web/WebScriptSource.h" |
35 #include "sky/engine/public/web/WebSettings.h" | 35 #include "sky/engine/public/web/WebSettings.h" |
36 #include "sky/engine/public/web/WebView.h" | 36 #include "sky/engine/public/web/WebView.h" |
37 #include "sky/engine/v8_inspector/inspector_backend_mojo.h" | |
38 #include "sky/engine/v8_inspector/inspector_host.h" | |
39 #include "sky/viewer/converters/input_event_types.h" | 37 #include "sky/viewer/converters/input_event_types.h" |
40 #include "sky/viewer/converters/url_request_types.h" | 38 #include "sky/viewer/converters/url_request_types.h" |
41 #include "sky/viewer/internals.h" | 39 #include "sky/viewer/internals.h" |
42 #include "sky/viewer/platform/weburlloader_impl.h" | 40 #include "sky/viewer/platform/weburlloader_impl.h" |
43 #include "sky/viewer/runtime_flags.h" | 41 #include "sky/viewer/runtime_flags.h" |
44 #include "sky/viewer/script/script_runner.h" | |
45 #include "third_party/skia/include/core/SkCanvas.h" | 42 #include "third_party/skia/include/core/SkCanvas.h" |
46 #include "third_party/skia/include/core/SkColor.h" | 43 #include "third_party/skia/include/core/SkColor.h" |
47 #include "third_party/skia/include/core/SkDevice.h" | 44 #include "third_party/skia/include/core/SkDevice.h" |
48 #include "ui/events/gestures/gesture_recognizer.h" | 45 #include "ui/events/gestures/gesture_recognizer.h" |
49 #include "v8/include/v8.h" | 46 #include "v8/include/v8.h" |
50 | 47 |
51 namespace sky { | 48 namespace sky { |
52 namespace { | 49 namespace { |
53 | 50 |
54 void ConfigureSettings(blink::WebSettings* settings) { | 51 void ConfigureSettings(blink::WebSettings* settings) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 return make_scoped_ptr(new ui::TouchEvent( | 90 return make_scoped_ptr(new ui::TouchEvent( |
94 ConvertEventTypeToUIEventType(event.type), | 91 ConvertEventTypeToUIEventType(event.type), |
95 gfx::PointF(pointer_event.x * device_pixel_ratio, | 92 gfx::PointF(pointer_event.x * device_pixel_ratio, |
96 pointer_event.y * device_pixel_ratio), | 93 pointer_event.y * device_pixel_ratio), |
97 pointer_event.pointer, | 94 pointer_event.pointer, |
98 base::TimeDelta::FromMillisecondsD(pointer_event.timeStampMS))); | 95 base::TimeDelta::FromMillisecondsD(pointer_event.timeStampMS))); |
99 } | 96 } |
100 | 97 |
101 } // namespace | 98 } // namespace |
102 | 99 |
103 static int s_next_debugger_id = 1; | |
104 | |
105 DocumentView::DocumentView( | 100 DocumentView::DocumentView( |
106 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 101 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
107 mojo::ServiceProviderPtr exported_services, | 102 mojo::ServiceProviderPtr exported_services, |
108 mojo::URLResponsePtr response, | 103 mojo::URLResponsePtr response, |
109 mojo::Shell* shell) | 104 mojo::Shell* shell) |
110 : response_(response.Pass()), | 105 : response_(response.Pass()), |
111 exported_services_(services.Pass()), | 106 exported_services_(services.Pass()), |
112 shell_(shell), | 107 shell_(shell), |
113 web_view_(nullptr), | 108 web_view_(nullptr), |
114 root_(nullptr), | 109 root_(nullptr), |
115 view_manager_client_factory_(shell_, this), | 110 view_manager_client_factory_(shell_, this), |
116 inspector_service_factory_(this), | |
117 bitmap_rasterizer_(nullptr), | 111 bitmap_rasterizer_(nullptr), |
118 debugger_id_(s_next_debugger_id++), | |
119 weak_factory_(this) { | 112 weak_factory_(this) { |
120 exported_services_.AddService(&view_manager_client_factory_); | 113 exported_services_.AddService(&view_manager_client_factory_); |
121 inspector_service_provider_impl_.AddService(&inspector_service_factory_); | |
122 } | 114 } |
123 | 115 |
124 DocumentView::~DocumentView() { | 116 DocumentView::~DocumentView() { |
125 if (web_view_) | 117 if (web_view_) |
126 web_view_->close(); | 118 web_view_->close(); |
127 if (root_) | 119 if (root_) |
128 root_->RemoveObserver(this); | 120 root_->RemoveObserver(this); |
129 ui::GestureRecognizer::Get()->CleanupStateForConsumer(this); | 121 ui::GestureRecognizer::Get()->CleanupStateForConsumer(this); |
130 } | 122 } |
131 | 123 |
132 base::WeakPtr<DocumentView> DocumentView::GetWeakPtr() { | 124 base::WeakPtr<DocumentView> DocumentView::GetWeakPtr() { |
133 return weak_factory_.GetWeakPtr(); | 125 return weak_factory_.GetWeakPtr(); |
134 } | 126 } |
135 | 127 |
136 void DocumentView::OnEmbed( | 128 void DocumentView::OnEmbed( |
137 mojo::View* root, | 129 mojo::View* root, |
138 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 130 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
139 mojo::ServiceProviderPtr exposed_services) { | 131 mojo::ServiceProviderPtr exposed_services) { |
140 root_ = root; | 132 root_ = root; |
141 imported_services_ = exposed_services.Pass(); | 133 imported_services_ = exposed_services.Pass(); |
142 navigator_host_.set_service_provider(imported_services_.get()); | 134 navigator_host_.set_service_provider(imported_services_.get()); |
143 | 135 |
144 if (services.is_pending()) | |
145 inspector_service_provider_impl_.Bind(services.Pass()); | |
146 | |
147 Load(response_.Pass()); | 136 Load(response_.Pass()); |
148 | 137 |
149 UpdateRootSizeAndViewportMetrics(root_->bounds()); | 138 UpdateRootSizeAndViewportMetrics(root_->bounds()); |
150 | 139 |
151 // TODO(abarth): We should ask the view whether it is focused instead of | 140 // TODO(abarth): We should ask the view whether it is focused instead of |
152 // assuming that we're focused. | 141 // assuming that we're focused. |
153 web_view_->setFocus(true); | 142 web_view_->setFocus(true); |
154 root_->AddObserver(this); | 143 root_->AddObserver(this); |
155 } | 144 } |
156 | 145 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 return blink::WebNavigationPolicyIgnore; | 251 return blink::WebNavigationPolicyIgnore; |
263 } | 252 } |
264 | 253 |
265 void DocumentView::didAddMessageToConsole( | 254 void DocumentView::didAddMessageToConsole( |
266 const blink::WebConsoleMessage& message, | 255 const blink::WebConsoleMessage& message, |
267 const blink::WebString& source_name, | 256 const blink::WebString& source_name, |
268 unsigned source_line, | 257 unsigned source_line, |
269 const blink::WebString& stack_trace) { | 258 const blink::WebString& stack_trace) { |
270 } | 259 } |
271 | 260 |
272 void DocumentView::didCreateScriptContext(blink::WebLocalFrame* frame, | 261 void DocumentView::didCreateIsolate(blink::WebLocalFrame* frame, |
273 v8::Handle<v8::Context> context) { | 262 Dart_Isolate isolate) { |
274 script_runner_.reset(new ScriptRunner(frame, context)); | 263 Internals::Create(isolate, this); |
275 | |
276 v8::Isolate* isolate = context->GetIsolate(); | |
277 gin::Handle<Internals> internals = Internals::Create(isolate, this); | |
278 context->Global()->Set(gin::StringToV8(isolate, "internals"), | |
279 gin::ConvertToV8(isolate, internals)); | |
280 } | 264 } |
281 | 265 |
282 blink::ServiceProvider* DocumentView::services() { | 266 blink::ServiceProvider* DocumentView::services() { |
283 return this; | 267 return this; |
284 } | 268 } |
285 | 269 |
286 mojo::NavigatorHost* DocumentView::NavigatorHost() { | 270 mojo::NavigatorHost* DocumentView::NavigatorHost() { |
287 return navigator_host_.get(); | 271 return navigator_host_.get(); |
288 } | 272 } |
289 | 273 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 for (auto& gesture : *gestures) { | 332 for (auto& gesture : *gestures) { |
349 scoped_ptr<blink::WebInputEvent> gesture_event = | 333 scoped_ptr<blink::WebInputEvent> gesture_event = |
350 ConvertEvent(mojo::Event::From(*gesture), device_pixel_ratio); | 334 ConvertEvent(mojo::Event::From(*gesture), device_pixel_ratio); |
351 if (gesture_event) | 335 if (gesture_event) |
352 web_view_->handleInputEvent(*gesture_event); | 336 web_view_->handleInputEvent(*gesture_event); |
353 } | 337 } |
354 } | 338 } |
355 } | 339 } |
356 } | 340 } |
357 | 341 |
358 class InspectorHostImpl : public inspector::InspectorHost { | |
359 public: | |
360 InspectorHostImpl(blink::WebView* web_view, mojo::Shell* shell) | |
361 : web_view_(web_view), shell_(shell) {} | |
362 | |
363 virtual ~InspectorHostImpl() {} | |
364 | |
365 mojo::Shell* GetShell() override { return shell_; } | |
366 v8::Isolate* GetIsolate() override { return blink::mainThreadIsolate(); } | |
367 v8::Local<v8::Context> GetContext() override { | |
368 return web_view_->mainFrame()->mainWorldScriptContext(); | |
369 } | |
370 | |
371 private: | |
372 blink::WebView* web_view_; | |
373 mojo::Shell* shell_; | |
374 }; | |
375 | |
376 void DocumentView::StartDebuggerInspectorBackend() { | 342 void DocumentView::StartDebuggerInspectorBackend() { |
377 if (!inspector_backend_) { | 343 // FIXME: Do we need this for dart? |
378 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_)); | |
379 inspector_backend_.reset( | |
380 new inspector::InspectorBackendMojo(inspector_host_.get())); | |
381 } | |
382 inspector_backend_->Connect(); | |
383 } | 344 } |
384 | 345 |
385 } // namespace sky | 346 } // namespace sky |
OLD | NEW |