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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 default: | 65 default: |
66 return mojo::TARGET_DEFAULT; | 66 return mojo::TARGET_DEFAULT; |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 } // namespace | 70 } // namespace |
71 | 71 |
72 static int s_next_debugger_id = 1; | 72 static int s_next_debugger_id = 1; |
73 | 73 |
74 DocumentView::DocumentView( | 74 DocumentView::DocumentView( |
| 75 const base::Closure& destruction_callback, |
| 76 mojo::ServiceProviderPtr provider, |
75 mojo::URLResponsePtr response, | 77 mojo::URLResponsePtr response, |
76 mojo::ShellPtr shell, | 78 mojo::Shell* shell, |
77 scoped_refptr<base::MessageLoopProxy> compositor_thread) | 79 scoped_refptr<base::MessageLoopProxy> compositor_thread) |
78 : response_(response.Pass()), | 80 : destruction_callback_(destruction_callback), |
79 shell_(shell.Pass()), | 81 response_(response.Pass()), |
| 82 shell_(shell), |
80 web_view_(NULL), | 83 web_view_(NULL), |
81 root_(NULL), | 84 root_(NULL), |
82 view_manager_client_factory_(shell_.get(), this), | 85 view_manager_client_factory_(shell_, this), |
83 inspector_service_factory_(this), | 86 inspector_service_factory_(this), |
84 compositor_thread_(compositor_thread), | 87 compositor_thread_(compositor_thread), |
85 debugger_id_(s_next_debugger_id++), | 88 debugger_id_(s_next_debugger_id++), |
86 weak_factory_(this) { | 89 weak_factory_(this) { |
87 shell_.set_client(this); | 90 exported_services_.AddService(&view_manager_client_factory_); |
| 91 mojo::WeakBindToPipe(&exported_services_, provider.PassMessagePipe()); |
88 } | 92 } |
89 | 93 |
90 DocumentView::~DocumentView() { | 94 DocumentView::~DocumentView() { |
91 if (web_view_) | 95 if (web_view_) |
92 web_view_->close(); | 96 web_view_->close(); |
93 if (root_) | 97 if (root_) |
94 root_->RemoveObserver(this); | 98 root_->RemoveObserver(this); |
| 99 destruction_callback_.Run(); |
95 } | 100 } |
96 | 101 |
97 base::WeakPtr<DocumentView> DocumentView::GetWeakPtr() { | 102 base::WeakPtr<DocumentView> DocumentView::GetWeakPtr() { |
98 return weak_factory_.GetWeakPtr(); | 103 return weak_factory_.GetWeakPtr(); |
99 } | 104 } |
100 | 105 |
101 void DocumentView::AcceptConnection(const mojo::String& requestor_url, | |
102 mojo::ServiceProviderPtr provider) { | |
103 exported_services_.AddService(&view_manager_client_factory_); | |
104 mojo::WeakBindToPipe(&exported_services_, provider.PassMessagePipe()); | |
105 } | |
106 | |
107 void DocumentView::Initialize(mojo::Array<mojo::String> args) { | |
108 } | |
109 | |
110 void DocumentView::OnEmbed( | 106 void DocumentView::OnEmbed( |
111 mojo::ViewManager* view_manager, | 107 mojo::ViewManager* view_manager, |
112 mojo::View* root, | 108 mojo::View* root, |
113 mojo::ServiceProviderImpl* exported_services, | 109 mojo::ServiceProviderImpl* exported_services, |
114 scoped_ptr<mojo::ServiceProvider> imported_services) { | 110 scoped_ptr<mojo::ServiceProvider> imported_services) { |
115 | 111 |
116 root_ = root; | 112 root_ = root; |
117 imported_services_ = imported_services.Pass(); | 113 imported_services_ = imported_services.Pass(); |
118 navigator_host_.set_service_provider(imported_services_.get()); | 114 navigator_host_.set_service_provider(imported_services_.get()); |
119 exported_services->AddService(&inspector_service_factory_); | 115 exported_services->AddService(&inspector_service_factory_); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 256 |
261 blink::ServiceProvider& DocumentView::services() { | 257 blink::ServiceProvider& DocumentView::services() { |
262 return *this; | 258 return *this; |
263 } | 259 } |
264 | 260 |
265 mojo::NavigatorHost* DocumentView::NavigatorHost() { | 261 mojo::NavigatorHost* DocumentView::NavigatorHost() { |
266 return navigator_host_.get(); | 262 return navigator_host_.get(); |
267 } | 263 } |
268 | 264 |
269 mojo::Shell* DocumentView::Shell() { | 265 mojo::Shell* DocumentView::Shell() { |
270 return shell_.get(); | 266 return shell_; |
271 } | 267 } |
272 | 268 |
273 void DocumentView::OnViewBoundsChanged(mojo::View* view, | 269 void DocumentView::OnViewBoundsChanged(mojo::View* view, |
274 const mojo::Rect& old_bounds, | 270 const mojo::Rect& old_bounds, |
275 const mojo::Rect& new_bounds) { | 271 const mojo::Rect& new_bounds) { |
276 DCHECK_EQ(view, root_); | 272 DCHECK_EQ(view, root_); |
277 gfx::Size size = new_bounds.To<gfx::Rect>().size(); | 273 gfx::Size size = new_bounds.To<gfx::Rect>().size(); |
278 web_view_->resize(size); | 274 web_view_->resize(size); |
279 #if !ENABLE_SKY_COMPOSITOR | 275 #if !ENABLE_SKY_COMPOSITOR |
280 web_layer_tree_view_impl_->setViewportSize(size); | 276 web_layer_tree_view_impl_->setViewportSize(size); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 return web_view_->mainFrame()->mainWorldScriptContext(); | 313 return web_view_->mainFrame()->mainWorldScriptContext(); |
318 } | 314 } |
319 | 315 |
320 private: | 316 private: |
321 blink::WebView* web_view_; | 317 blink::WebView* web_view_; |
322 mojo::Shell* shell_; | 318 mojo::Shell* shell_; |
323 }; | 319 }; |
324 | 320 |
325 void DocumentView::StartDebuggerInspectorBackend() { | 321 void DocumentView::StartDebuggerInspectorBackend() { |
326 if (!inspector_backend_) { | 322 if (!inspector_backend_) { |
327 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_.get())); | 323 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_)); |
328 inspector_backend_.reset( | 324 inspector_backend_.reset( |
329 new inspector::InspectorBackendMojo(inspector_host_.get())); | 325 new inspector::InspectorBackendMojo(inspector_host_.get())); |
330 } | 326 } |
331 inspector_backend_->Connect(); | 327 inspector_backend_->Connect(); |
332 } | 328 } |
333 | 329 |
334 } // namespace sky | 330 } // namespace sky |
OLD | NEW |