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 "mojo/services/html_viewer/html_document_view.h" | 5 #include "mojo/services/html_viewer/html_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/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 // Otherwise we don't know if we're the right app to handle this request. Ask | 77 // Otherwise we don't know if we're the right app to handle this request. Ask |
78 // host to do the navigation for us. | 78 // host to do the navigation for us. |
79 return false; | 79 return false; |
80 } | 80 } |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 HTMLDocumentView::HTMLDocumentView( | 84 HTMLDocumentView::HTMLDocumentView( |
85 URLResponsePtr response, | 85 URLResponsePtr response, |
86 scoped_ptr<ServiceProvider> imported_services, | 86 InterfaceRequest<ServiceProvider> service_provider_request, |
87 ServiceProviderImpl* exported_services, | |
88 Shell* shell) | 87 Shell* shell) |
89 : imported_services_(imported_services.Pass()), | 88 : shell_(shell), |
90 shell_(shell), | |
91 web_view_(NULL), | 89 web_view_(NULL), |
92 root_(NULL), | 90 root_(NULL), |
93 view_manager_client_factory_(shell, this), | 91 view_manager_client_factory_(shell, this), |
94 repaint_pending_(false), | 92 repaint_pending_(false), |
95 weak_factory_(this) { | 93 weak_factory_(this) { |
| 94 ServiceProviderImpl* exported_services = new ServiceProviderImpl(); |
96 exported_services->AddService(&view_manager_client_factory_); | 95 exported_services->AddService(&view_manager_client_factory_); |
| 96 BindToRequest(exported_services, &service_provider_request); |
97 Load(response.Pass()); | 97 Load(response.Pass()); |
98 } | 98 } |
99 | 99 |
100 HTMLDocumentView::~HTMLDocumentView() { | 100 HTMLDocumentView::~HTMLDocumentView() { |
101 if (web_view_) | 101 if (web_view_) |
102 web_view_->close(); | 102 web_view_->close(); |
103 if (root_) | 103 if (root_) |
104 root_->RemoveObserver(this); | 104 root_->RemoveObserver(this); |
105 } | 105 } |
106 | 106 |
107 void HTMLDocumentView::OnEmbed(ViewManager* view_manager, | 107 void HTMLDocumentView::OnEmbed( |
108 View* root, | 108 ViewManager* view_manager, |
109 ServiceProviderImpl* exported_services, | 109 View* root, |
110 scoped_ptr<ServiceProvider> imported_services) { | 110 ServiceProviderImpl* embedee_service_provider_impl, |
| 111 scoped_ptr<ServiceProvider> embedder_service_provider) { |
111 root_ = root; | 112 root_ = root; |
| 113 embedder_service_provider_ = embedder_service_provider.Pass(); |
| 114 navigator_host_.set_service_provider(embedder_service_provider_.get()); |
| 115 |
112 root_->SetColor(SK_ColorCYAN); // Dummy background color. | 116 root_->SetColor(SK_ColorCYAN); // Dummy background color. |
113 web_view_->resize(root_->bounds().size()); | 117 web_view_->resize(root_->bounds().size()); |
114 root_->AddObserver(this); | 118 root_->AddObserver(this); |
115 } | 119 } |
116 | 120 |
117 void HTMLDocumentView::OnViewManagerDisconnected(ViewManager* view_manager) { | 121 void HTMLDocumentView::OnViewManagerDisconnected(ViewManager* view_manager) { |
118 // TODO(aa): Need to figure out how shutdown works. | 122 // TODO(aa): Need to figure out how shutdown works. |
119 } | 123 } |
120 | 124 |
121 void HTMLDocumentView::Load(URLResponsePtr response) { | 125 void HTMLDocumentView::Load(URLResponsePtr response) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 blink::WebNavigationPolicy HTMLDocumentView::decidePolicyForNavigation( | 187 blink::WebNavigationPolicy HTMLDocumentView::decidePolicyForNavigation( |
184 blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* data, | 188 blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* data, |
185 const blink::WebURLRequest& request, blink::WebNavigationType nav_type, | 189 const blink::WebURLRequest& request, blink::WebNavigationType nav_type, |
186 blink::WebNavigationPolicy default_policy, bool is_redirect) { | 190 blink::WebNavigationPolicy default_policy, bool is_redirect) { |
187 if (CanNavigateLocally(frame, request)) | 191 if (CanNavigateLocally(frame, request)) |
188 return default_policy; | 192 return default_policy; |
189 | 193 |
190 NavigationDetailsPtr nav_details(NavigationDetails::New()); | 194 NavigationDetailsPtr nav_details(NavigationDetails::New()); |
191 nav_details->request = URLRequest::From(request); | 195 nav_details->request = URLRequest::From(request); |
192 | 196 |
193 GetNavigatorHost()->RequestNavigate( | 197 navigator_host_->RequestNavigate( |
194 root_->id(), | |
195 WebNavigationPolicyToNavigationTarget(default_policy), | 198 WebNavigationPolicyToNavigationTarget(default_policy), |
196 nav_details.Pass()); | 199 nav_details.Pass()); |
197 | 200 |
198 return blink::WebNavigationPolicyIgnore; | 201 return blink::WebNavigationPolicyIgnore; |
199 } | 202 } |
200 | 203 |
201 void HTMLDocumentView::didAddMessageToConsole( | 204 void HTMLDocumentView::didAddMessageToConsole( |
202 const blink::WebConsoleMessage& message, | 205 const blink::WebConsoleMessage& message, |
203 const blink::WebString& source_name, | 206 const blink::WebString& source_name, |
204 unsigned source_line, | 207 unsigned source_line, |
205 const blink::WebString& stack_trace) { | 208 const blink::WebString& stack_trace) { |
206 } | 209 } |
207 | 210 |
208 void HTMLDocumentView::didNavigateWithinPage( | 211 void HTMLDocumentView::didNavigateWithinPage( |
209 blink::WebLocalFrame* frame, const blink::WebHistoryItem& history_item, | 212 blink::WebLocalFrame* frame, const blink::WebHistoryItem& history_item, |
210 blink::WebHistoryCommitType commit_type) { | 213 blink::WebHistoryCommitType commit_type) { |
211 GetNavigatorHost()->DidNavigateLocally(root_->id(), | 214 navigator_host_->DidNavigateLocally(history_item.urlString().utf8()); |
212 history_item.urlString().utf8()); | |
213 } | 215 } |
214 | 216 |
215 void HTMLDocumentView::OnViewBoundsChanged(View* view, | 217 void HTMLDocumentView::OnViewBoundsChanged(View* view, |
216 const gfx::Rect& old_bounds, | 218 const gfx::Rect& old_bounds, |
217 const gfx::Rect& new_bounds) { | 219 const gfx::Rect& new_bounds) { |
218 DCHECK_EQ(view, root_); | 220 DCHECK_EQ(view, root_); |
219 web_view_->resize(view->bounds().size()); | 221 web_view_->resize(view->bounds().size()); |
220 } | 222 } |
221 | 223 |
222 void HTMLDocumentView::OnViewDestroyed(View* view) { | 224 void HTMLDocumentView::OnViewDestroyed(View* view) { |
(...skipping 22 matching lines...) Expand all Loading... |
245 int height = web_view_->size().height; | 247 int height = web_view_->size().height; |
246 | 248 |
247 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( | 249 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( |
248 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); | 250 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); |
249 | 251 |
250 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); | 252 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); |
251 | 253 |
252 root_->SetContents(canvas->getDevice()->accessBitmap(false)); | 254 root_->SetContents(canvas->getDevice()->accessBitmap(false)); |
253 } | 255 } |
254 | 256 |
255 NavigatorHost* HTMLDocumentView::GetNavigatorHost() { | |
256 if (!navigator_host_.get()) { | |
257 // TODO(aa): This should come via |imported_services| in OnEmbed(). | |
258 InterfacePtr<ServiceProvider> sp; | |
259 shell_->ConnectToApplication("mojo:mojo_window_manager", Get(&sp)); | |
260 ConnectToService(sp.get(), &navigator_host_); | |
261 } | |
262 return navigator_host_.get(); | |
263 } | |
264 | |
265 } // namespace mojo | 257 } // namespace mojo |
OLD | NEW |