| 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.h" | 5 #include "mojo/services/html_viewer/html_document.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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 return true; | 92 return true; |
| 93 | 93 |
| 94 // Otherwise we don't know if we're the right app to handle this request. Ask | 94 // Otherwise we don't know if we're the right app to handle this request. Ask |
| 95 // host to do the navigation for us. | 95 // host to do the navigation for us. |
| 96 return false; | 96 return false; |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace | 99 } // namespace |
| 100 | 100 |
| 101 HTMLDocument::HTMLDocument( | 101 HTMLDocument::HTMLDocument( |
| 102 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 102 mojo::ServiceProviderImpl* service_provider, |
| 103 URLResponsePtr response, | 103 URLResponsePtr response, |
| 104 mojo::Shell* shell, | 104 mojo::Shell* shell, |
| 105 scoped_refptr<base::MessageLoopProxy> compositor_thread, | 105 scoped_refptr<base::MessageLoopProxy> compositor_thread, |
| 106 WebMediaPlayerFactory* web_media_player_factory, | 106 WebMediaPlayerFactory* web_media_player_factory, |
| 107 bool is_headless) | 107 bool is_headless) |
| 108 : response_(response.Pass()), | 108 : response_(response.Pass()), |
| 109 shell_(shell), | 109 shell_(shell), |
| 110 web_view_(nullptr), | 110 web_view_(nullptr), |
| 111 root_(nullptr), | 111 root_(nullptr), |
| 112 view_manager_client_factory_(shell_, this), | 112 view_manager_client_factory_(shell_, this), |
| 113 compositor_thread_(compositor_thread), | 113 compositor_thread_(compositor_thread), |
| 114 web_media_player_factory_(web_media_player_factory), | 114 web_media_player_factory_(web_media_player_factory), |
| 115 is_headless_(is_headless) { | 115 is_headless_(is_headless) { |
| 116 exported_services_.AddService(this); | 116 printf("MSW HTMLDocument::HTMLDocument\n"); |
| 117 exported_services_.AddService(&view_manager_client_factory_); | 117 service_provider->AddService(this); |
| 118 exported_services_.Bind(services.Pass()); | 118 service_provider->AddService(&view_manager_client_factory_); |
| 119 Load(response_.Pass()); | 119 Load(response_.Pass()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 HTMLDocument::~HTMLDocument() { | 122 HTMLDocument::~HTMLDocument() { |
| 123 STLDeleteElements(&ax_provider_impls_); | 123 STLDeleteElements(&ax_providers_); |
| 124 | 124 |
| 125 if (web_view_) | 125 if (web_view_) |
| 126 web_view_->close(); | 126 web_view_->close(); |
| 127 if (root_) | 127 if (root_) |
| 128 root_->RemoveObserver(this); | 128 root_->RemoveObserver(this); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void HTMLDocument::OnEmbed( | 131 void HTMLDocument::OnEmbed( |
| 132 View* root, | 132 View* root, |
| 133 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 133 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 134 mojo::ServiceProviderPtr exposed_services) { | 134 mojo::ServiceProviderPtr exposed_services) { |
| 135 printf("MSW HTMLDocument::OnEmbed\n"); |
| 135 DCHECK(!is_headless_); | 136 DCHECK(!is_headless_); |
| 136 root_ = root; | 137 root_ = root; |
| 137 embedder_service_provider_ = exposed_services.Pass(); | 138 embedder_service_provider_ = exposed_services.Pass(); |
| 138 navigator_host_.set_service_provider(embedder_service_provider_.get()); | 139 navigator_host_.set_service_provider(embedder_service_provider_.get()); |
| 139 UpdateWebviewSizeFromViewSize(); | 140 UpdateWebviewSizeFromViewSize(); |
| 140 web_layer_tree_view_impl_->set_view(root_); | 141 web_layer_tree_view_impl_->set_view(root_); |
| 141 root_->AddObserver(this); | 142 root_->AddObserver(this); |
| 142 } | 143 } |
| 143 | 144 |
| 144 void HTMLDocument::Create(mojo::ApplicationConnection* connection, | |
| 145 mojo::InterfaceRequest<AxProvider> request) { | |
| 146 if (!web_view_) | |
| 147 return; | |
| 148 ax_provider_impls_.insert( | |
| 149 WeakBindToRequest(new AxProviderImpl(web_view_), &request)); | |
| 150 } | |
| 151 | |
| 152 void HTMLDocument::OnViewManagerDisconnected(ViewManager* view_manager) { | 145 void HTMLDocument::OnViewManagerDisconnected(ViewManager* view_manager) { |
| 153 // TODO(aa): Need to figure out how shutdown works. | 146 // TODO(aa): Need to figure out how shutdown works. |
| 154 } | 147 } |
| 155 | 148 |
| 149 void HTMLDocument::Create(mojo::ApplicationConnection* connection, |
| 150 mojo::InterfaceRequest<AxProvider> request) { |
| 151 printf("MSW HTMLDocument::Create (AxProvider) web_view=%p\n", web_view_); |
| 152 if (!did_finish_load_) { |
| 153 // Cache AxProvider interface requests until the document finishes loading. |
| 154 mojo::InterfaceRequest<AxProvider>* cached_request = |
| 155 new mojo::InterfaceRequest<AxProvider>(); |
| 156 *cached_request = request.Pass(); |
| 157 ax_provider_requests_.insert(cached_request); |
| 158 } else { |
| 159 ax_providers_.insert( |
| 160 WeakBindToRequest(new AxProviderImpl(web_view_), &request)); |
| 161 } |
| 162 } |
| 163 |
| 164 // void HTMLDocument::GetLayoutTreeAsText( |
| 165 // const GetLayoutTreeAsTextCallback& callback) { |
| 166 // //callback.Run("foo"); |
| 167 // callback.Run(web_view_->mainFrame()->layoutTreeAsText()->utf8()); |
| 168 // } |
| 169 |
| 170 // void HTMLDocument::Create( |
| 171 // mojo::ApplicationConnection* connection, |
| 172 // mojo::InterfaceRequest<mojo::HTMLDocumentTestAPI> request) { |
| 173 // WeakBindToRequest(this, &request); |
| 174 // //BindToRequest(this, &request); |
| 175 // } |
| 176 |
| 156 void HTMLDocument::Load(URLResponsePtr response) { | 177 void HTMLDocument::Load(URLResponsePtr response) { |
| 178 printf("MSW HTMLDocument::Load\n"); |
| 157 web_view_ = blink::WebView::create(this); | 179 web_view_ = blink::WebView::create(this); |
| 158 web_layer_tree_view_impl_->set_widget(web_view_); | 180 web_layer_tree_view_impl_->set_widget(web_view_); |
| 159 ConfigureSettings(web_view_->settings()); | 181 ConfigureSettings(web_view_->settings()); |
| 160 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | 182 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); |
| 161 | 183 |
| 162 GURL url(response->url); | 184 GURL url(response->url); |
| 163 | 185 |
| 164 WebURLRequestExtraData* extra_data = new WebURLRequestExtraData; | 186 WebURLRequestExtraData* extra_data = new WebURLRequestExtraData; |
| 165 extra_data->synthetic_response = response.Pass(); | 187 extra_data->synthetic_response = response.Pass(); |
| 166 | 188 |
| 167 blink::WebURLRequest web_request; | 189 blink::WebURLRequest web_request; |
| 168 web_request.initialize(); | 190 web_request.initialize(); |
| 169 web_request.setURL(url); | 191 web_request.setURL(url); |
| 170 web_request.setExtraData(extra_data); | 192 web_request.setExtraData(extra_data); |
| 171 | 193 |
| 172 web_view_->mainFrame()->loadRequest(web_request); | 194 web_view_->mainFrame()->loadRequest(web_request); |
| 195 web_view_->layout(); |
| 173 } | 196 } |
| 174 | 197 |
| 175 void HTMLDocument::UpdateWebviewSizeFromViewSize() { | 198 void HTMLDocument::UpdateWebviewSizeFromViewSize() { |
| 199 printf("MSW HTMLDocument::UpdateWebviewSizeFromViewSize\n"); |
| 176 web_view_->setDeviceScaleFactor(root_->viewport_metrics().device_pixel_ratio); | 200 web_view_->setDeviceScaleFactor(root_->viewport_metrics().device_pixel_ratio); |
| 177 const gfx::Size size_in_pixels(root_->bounds().width, root_->bounds().height); | 201 const gfx::Size size_in_pixels(root_->bounds().width, root_->bounds().height); |
| 178 const gfx::Size size_in_dips = gfx::ConvertSizeToDIP( | 202 const gfx::Size size_in_dips = gfx::ConvertSizeToDIP( |
| 179 root_->viewport_metrics().device_pixel_ratio, size_in_pixels); | 203 root_->viewport_metrics().device_pixel_ratio, size_in_pixels); |
| 180 web_view_->resize( | 204 web_view_->resize( |
| 181 blink::WebSize(size_in_dips.width(), size_in_dips.height())); | 205 blink::WebSize(size_in_dips.width(), size_in_dips.height())); |
| 182 web_layer_tree_view_impl_->setViewportSize(size_in_pixels); | 206 web_layer_tree_view_impl_->setViewportSize(size_in_pixels); |
| 183 } | 207 } |
| 184 | 208 |
| 185 blink::WebStorageNamespace* HTMLDocument::createSessionStorageNamespace() { | 209 blink::WebStorageNamespace* HTMLDocument::createSessionStorageNamespace() { |
| 186 return new WebStorageNamespaceImpl(); | 210 return new WebStorageNamespaceImpl(); |
| 187 } | 211 } |
| 188 | 212 |
| 189 void HTMLDocument::initializeLayerTreeView() { | 213 void HTMLDocument::initializeLayerTreeView() { |
| 214 printf("MSW HTMLDocument::initializeLayerTreeView\n"); |
| 190 if (is_headless_) { | 215 if (is_headless_) { |
| 191 web_layer_tree_view_impl_.reset( | 216 web_layer_tree_view_impl_.reset( |
| 192 new WebLayerTreeViewImpl(compositor_thread_, nullptr, nullptr)); | 217 new WebLayerTreeViewImpl(compositor_thread_, nullptr, nullptr)); |
| 193 return; | 218 return; |
| 194 } | 219 } |
| 195 | 220 |
| 196 ServiceProviderPtr surfaces_service_provider; | 221 ServiceProviderPtr surfaces_service_provider; |
| 197 shell_->ConnectToApplication("mojo:surfaces_service", | 222 shell_->ConnectToApplication("mojo:surfaces_service", |
| 198 GetProxy(&surfaces_service_provider), nullptr); | 223 GetProxy(&surfaces_service_provider), nullptr); |
| 199 mojo::SurfacePtr surface; | 224 mojo::SurfacePtr surface; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 306 |
| 282 void HTMLDocument::didAddMessageToConsole( | 307 void HTMLDocument::didAddMessageToConsole( |
| 283 const blink::WebConsoleMessage& message, | 308 const blink::WebConsoleMessage& message, |
| 284 const blink::WebString& source_name, | 309 const blink::WebString& source_name, |
| 285 unsigned source_line, | 310 unsigned source_line, |
| 286 const blink::WebString& stack_trace) { | 311 const blink::WebString& stack_trace) { |
| 287 VLOG(1) << "[" << source_name.utf8() << "(" << source_line << ")] " | 312 VLOG(1) << "[" << source_name.utf8() << "(" << source_line << ")] " |
| 288 << message.text.utf8(); | 313 << message.text.utf8(); |
| 289 } | 314 } |
| 290 | 315 |
| 316 void HTMLDocument::didFinishLoad(blink::WebLocalFrame* frame) { |
| 317 did_finish_load_ = true; |
| 318 printf("MSW HTMLDocument::didFinishLoad\n"); |
| 319 // Bind any pending AxProviderImpl interface requests... |
| 320 for (auto it : ax_provider_requests_) |
| 321 ax_providers_.insert(WeakBindToRequest(new AxProviderImpl(web_view_), it)); |
| 322 STLDeleteElements(&ax_provider_requests_); |
| 323 } |
| 324 |
| 291 void HTMLDocument::didNavigateWithinPage( | 325 void HTMLDocument::didNavigateWithinPage( |
| 292 blink::WebLocalFrame* frame, | 326 blink::WebLocalFrame* frame, |
| 293 const blink::WebHistoryItem& history_item, | 327 const blink::WebHistoryItem& history_item, |
| 294 blink::WebHistoryCommitType commit_type) { | 328 blink::WebHistoryCommitType commit_type) { |
| 329 printf("MSW HTMLDocument::didNavigateWithinPage\n"); |
| 295 if (navigator_host_.get()) | 330 if (navigator_host_.get()) |
| 296 navigator_host_->DidNavigateLocally(history_item.urlString().utf8()); | 331 navigator_host_->DidNavigateLocally(history_item.urlString().utf8()); |
| 297 } | 332 } |
| 298 | 333 |
| 299 blink::WebEncryptedMediaClient* HTMLDocument::encryptedMediaClient() { | 334 blink::WebEncryptedMediaClient* HTMLDocument::encryptedMediaClient() { |
| 300 if (!web_encrypted_media_client_) { | 335 if (!web_encrypted_media_client_) { |
| 301 if (!media_permission_) | 336 if (!media_permission_) |
| 302 media_permission_.reset(new media::DefaultMediaPermission(true)); | 337 media_permission_.reset(new media::DefaultMediaPermission(true)); |
| 303 web_encrypted_media_client_.reset(new media::WebEncryptedMediaClientImpl( | 338 web_encrypted_media_client_.reset(new media::WebEncryptedMediaClientImpl( |
| 304 make_scoped_ptr(new media::DefaultCdmFactory()), | 339 make_scoped_ptr(new media::DefaultCdmFactory()), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 320 } | 355 } |
| 321 | 356 |
| 322 void HTMLDocument::OnViewInputEvent(View* view, const mojo::EventPtr& event) { | 357 void HTMLDocument::OnViewInputEvent(View* view, const mojo::EventPtr& event) { |
| 323 scoped_ptr<blink::WebInputEvent> web_event = | 358 scoped_ptr<blink::WebInputEvent> web_event = |
| 324 event.To<scoped_ptr<blink::WebInputEvent>>(); | 359 event.To<scoped_ptr<blink::WebInputEvent>>(); |
| 325 if (web_event) | 360 if (web_event) |
| 326 web_view_->handleInputEvent(*web_event); | 361 web_view_->handleInputEvent(*web_event); |
| 327 } | 362 } |
| 328 | 363 |
| 329 } // namespace html_viewer | 364 } // namespace html_viewer |
| OLD | NEW |