| 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" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "mojo/public/cpp/application/application_connection.h" |
| 13 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 12 #include "mojo/public/cpp/system/data_pipe.h" | 14 #include "mojo/public/cpp/system/data_pipe.h" |
| 13 #include "mojo/services/html_viewer/blink_input_events_type_converters.h" | 15 #include "mojo/services/html_viewer/blink_input_events_type_converters.h" |
| 14 #include "mojo/services/html_viewer/blink_url_request_type_converters.h" | 16 #include "mojo/services/html_viewer/blink_url_request_type_converters.h" |
| 15 #include "mojo/services/html_viewer/webstoragenamespace_impl.h" | 17 #include "mojo/services/html_viewer/webstoragenamespace_impl.h" |
| 16 #include "mojo/services/html_viewer/weburlloader_impl.h" | 18 #include "mojo/services/html_viewer/weburlloader_impl.h" |
| 17 #include "mojo/services/public/cpp/view_manager/view.h" | 19 #include "mojo/services/public/cpp/view_manager/view.h" |
| 18 #include "skia/ext/refptr.h" | 20 #include "skia/ext/refptr.h" |
| 19 #include "third_party/WebKit/public/platform/Platform.h" | 21 #include "third_party/WebKit/public/platform/Platform.h" |
| 20 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" | 22 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" |
| 21 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 23 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 if (request.extraData()) | 73 if (request.extraData()) |
| 72 return true; | 74 return true; |
| 73 | 75 |
| 74 // Otherwise we don't know if we're the right app to handle this request. Ask | 76 // Otherwise we don't know if we're the right app to handle this request. Ask |
| 75 // host to do the navigation for us. | 77 // host to do the navigation for us. |
| 76 return false; | 78 return false; |
| 77 } | 79 } |
| 78 | 80 |
| 79 } // namespace | 81 } // namespace |
| 80 | 82 |
| 81 HTMLDocumentView::HTMLDocumentView(ServiceProvider* service_provider, | 83 HTMLDocumentView::HTMLDocumentView( |
| 82 ViewManager* view_manager) | 84 ContentHandlerResponsePtr response, |
| 83 : view_manager_(view_manager), | 85 scoped_ptr<ServiceProvider> imported_services, |
| 84 navigator_host_(service_provider), | 86 ServiceProviderImpl* exported_services, |
| 87 ApplicationConnection* application_connection) |
| 88 : response_(response.Pass()), |
| 89 imported_services_(imported_services.Pass()), |
| 90 navigator_host_(application_connection->ConnectToApplication( |
| 91 "mojo://mojo_window_manager/")->GetServiceProvider()), |
| 85 web_view_(NULL), | 92 web_view_(NULL), |
| 86 root_(NULL), | 93 root_(NULL), |
| 94 view_manager_client_factory_(this), |
| 87 repaint_pending_(false), | 95 repaint_pending_(false), |
| 88 weak_factory_(this) { | 96 weak_factory_(this) { |
| 97 exported_services->AddService(&view_manager_client_factory_); |
| 98 Load(response_->response.Pass()); |
| 89 } | 99 } |
| 90 | 100 |
| 91 HTMLDocumentView::~HTMLDocumentView() { | 101 HTMLDocumentView::~HTMLDocumentView() { |
| 92 if (web_view_) | 102 if (web_view_) |
| 93 web_view_->close(); | 103 web_view_->close(); |
| 94 if (root_) | 104 if (root_) |
| 95 root_->RemoveObserver(this); | 105 root_->RemoveObserver(this); |
| 96 } | 106 } |
| 97 | 107 |
| 98 void HTMLDocumentView::AttachToView(View* view) { | 108 void HTMLDocumentView::OnEmbed(ViewManager* view_manager, |
| 99 root_ = view; | 109 View* root, |
| 110 ServiceProviderImpl* exported_services, |
| 111 scoped_ptr<ServiceProvider> imported_services) { |
| 112 root_ = root; |
| 100 root_->SetColor(SK_ColorCYAN); // Dummy background color. | 113 root_->SetColor(SK_ColorCYAN); // Dummy background color. |
| 114 web_view_->resize(root_->bounds().size()); |
| 115 root_->AddObserver(this); |
| 116 } |
| 101 | 117 |
| 118 void HTMLDocumentView::OnViewManagerDisconnected(ViewManager* view_manager) { |
| 119 // TODO(aa) |
| 120 } |
| 121 |
| 122 void HTMLDocumentView::Load(URLResponsePtr response) { |
| 102 web_view_ = blink::WebView::create(this); | 123 web_view_ = blink::WebView::create(this); |
| 103 ConfigureSettings(web_view_->settings()); | 124 ConfigureSettings(web_view_->settings()); |
| 104 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | 125 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); |
| 105 web_view_->resize(root_->bounds().size()); | |
| 106 | |
| 107 root_->AddObserver(this); | |
| 108 } | |
| 109 | |
| 110 void HTMLDocumentView::Load(URLResponsePtr response) { | |
| 111 DCHECK(web_view_); | |
| 112 | 126 |
| 113 GURL url(response->url); | 127 GURL url(response->url); |
| 114 | 128 |
| 115 WebURLRequestExtraData* extra_data = new WebURLRequestExtraData; | 129 WebURLRequestExtraData* extra_data = new WebURLRequestExtraData; |
| 116 extra_data->synthetic_response = response.Pass(); | 130 extra_data->synthetic_response = response.Pass(); |
| 117 | 131 |
| 118 blink::WebURLRequest web_request; | 132 blink::WebURLRequest web_request; |
| 119 web_request.initialize(); | 133 web_request.initialize(); |
| 120 web_request.setURL(url); | 134 web_request.setURL(url); |
| 121 web_request.setExtraData(extra_data); | 135 web_request.setExtraData(extra_data); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 scoped_ptr<blink::WebInputEvent> web_event = | 230 scoped_ptr<blink::WebInputEvent> web_event = |
| 217 TypeConverter<EventPtr, scoped_ptr<blink::WebInputEvent> >::ConvertTo( | 231 TypeConverter<EventPtr, scoped_ptr<blink::WebInputEvent> >::ConvertTo( |
| 218 event); | 232 event); |
| 219 if (web_event) | 233 if (web_event) |
| 220 web_view_->handleInputEvent(*web_event); | 234 web_view_->handleInputEvent(*web_event); |
| 221 } | 235 } |
| 222 | 236 |
| 223 void HTMLDocumentView::Repaint() { | 237 void HTMLDocumentView::Repaint() { |
| 224 repaint_pending_ = false; | 238 repaint_pending_ = false; |
| 225 | 239 |
| 240 if (!root_) |
| 241 return; |
| 242 |
| 226 web_view_->animate(0.0); | 243 web_view_->animate(0.0); |
| 227 web_view_->layout(); | 244 web_view_->layout(); |
| 228 | 245 |
| 229 int width = web_view_->size().width; | 246 int width = web_view_->size().width; |
| 230 int height = web_view_->size().height; | 247 int height = web_view_->size().height; |
| 231 | 248 |
| 232 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( | 249 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( |
| 233 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); | 250 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); |
| 234 | 251 |
| 235 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); | 252 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); |
| 236 | 253 |
| 237 root_->SetContents(canvas->getDevice()->accessBitmap(false)); | 254 root_->SetContents(canvas->getDevice()->accessBitmap(false)); |
| 238 } | 255 } |
| 239 | 256 |
| 240 } // namespace mojo | 257 } // namespace mojo |
| OLD | NEW |