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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 default: | 64 default: |
65 return mojo::TARGET_DEFAULT; | 65 return mojo::TARGET_DEFAULT; |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 } // namespace | 69 } // namespace |
70 | 70 |
71 static int s_next_debugger_id = 1; | 71 static int s_next_debugger_id = 1; |
72 | 72 |
73 DocumentView::DocumentView( | 73 DocumentView::DocumentView( |
74 const base::Closure& destruction_callback, | |
75 mojo::ServiceProviderPtr provider, | 74 mojo::ServiceProviderPtr provider, |
76 mojo::URLResponsePtr response, | 75 mojo::URLResponsePtr response, |
77 mojo::Shell* shell) | 76 mojo::Shell* shell) |
78 : destruction_callback_(destruction_callback), | 77 : response_(response.Pass()), |
79 response_(response.Pass()), | |
80 shell_(shell), | 78 shell_(shell), |
81 web_view_(NULL), | 79 web_view_(NULL), |
82 root_(NULL), | 80 root_(NULL), |
83 view_manager_client_factory_(shell_, this), | 81 view_manager_client_factory_(shell_, this), |
84 inspector_service_factory_(this), | 82 inspector_service_factory_(this), |
85 debugger_id_(s_next_debugger_id++), | 83 debugger_id_(s_next_debugger_id++), |
86 weak_factory_(this) { | 84 weak_factory_(this) { |
87 exported_services_.AddService(&view_manager_client_factory_); | 85 exported_services_.AddService(&view_manager_client_factory_); |
88 mojo::WeakBindToPipe(&exported_services_, provider.PassMessagePipe()); | 86 mojo::WeakBindToPipe(&exported_services_, provider.PassMessagePipe()); |
89 } | 87 } |
90 | 88 |
91 DocumentView::~DocumentView() { | 89 DocumentView::~DocumentView() { |
92 if (web_view_) | 90 if (web_view_) |
93 web_view_->close(); | 91 web_view_->close(); |
94 if (root_) | 92 if (root_) |
95 root_->RemoveObserver(this); | 93 root_->RemoveObserver(this); |
96 destruction_callback_.Run(); | |
97 } | 94 } |
98 | 95 |
99 base::WeakPtr<DocumentView> DocumentView::GetWeakPtr() { | 96 base::WeakPtr<DocumentView> DocumentView::GetWeakPtr() { |
100 return weak_factory_.GetWeakPtr(); | 97 return weak_factory_.GetWeakPtr(); |
101 } | 98 } |
102 | 99 |
103 void DocumentView::OnEmbed( | 100 void DocumentView::OnEmbed( |
104 mojo::ViewManager* view_manager, | 101 mojo::ViewManager* view_manager, |
105 mojo::View* root, | 102 mojo::View* root, |
106 mojo::ServiceProviderImpl* exported_services, | 103 mojo::ServiceProviderImpl* exported_services, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 if (root_ == lost_focus) { | 234 if (root_ == lost_focus) { |
238 web_view_->setFocus(false); | 235 web_view_->setFocus(false); |
239 } else if (root_ == gained_focus) { | 236 } else if (root_ == gained_focus) { |
240 web_view_->setFocus(true); | 237 web_view_->setFocus(true); |
241 } | 238 } |
242 } | 239 } |
243 | 240 |
244 void DocumentView::OnViewDestroyed(mojo::View* view) { | 241 void DocumentView::OnViewDestroyed(mojo::View* view) { |
245 DCHECK_EQ(view, root_); | 242 DCHECK_EQ(view, root_); |
246 | 243 |
247 delete this; | 244 root_ = nullptr; |
248 } | 245 } |
249 | 246 |
250 void DocumentView::OnViewInputEvent( | 247 void DocumentView::OnViewInputEvent( |
251 mojo::View* view, const mojo::EventPtr& event) { | 248 mojo::View* view, const mojo::EventPtr& event) { |
252 scoped_ptr<blink::WebInputEvent> web_event = | 249 scoped_ptr<blink::WebInputEvent> web_event = |
253 event.To<scoped_ptr<blink::WebInputEvent> >(); | 250 event.To<scoped_ptr<blink::WebInputEvent> >(); |
254 if (web_event) | 251 if (web_event) |
255 web_view_->handleInputEvent(*web_event); | 252 web_view_->handleInputEvent(*web_event); |
256 } | 253 } |
257 | 254 |
(...skipping 18 matching lines...) Expand all Loading... |
276 void DocumentView::StartDebuggerInspectorBackend() { | 273 void DocumentView::StartDebuggerInspectorBackend() { |
277 if (!inspector_backend_) { | 274 if (!inspector_backend_) { |
278 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_)); | 275 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_)); |
279 inspector_backend_.reset( | 276 inspector_backend_.reset( |
280 new inspector::InspectorBackendMojo(inspector_host_.get())); | 277 new inspector::InspectorBackendMojo(inspector_host_.get())); |
281 } | 278 } |
282 inspector_backend_->Connect(); | 279 inspector_backend_->Connect(); |
283 } | 280 } |
284 | 281 |
285 } // namespace sky | 282 } // namespace sky |
OLD | NEW |