| 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 URLResponsePtr 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 : imported_services_(imported_services.Pass()), |
| 89 navigator_host_(application_connection->ConnectToApplication( |
| 90 "mojo://mojo_window_manager/")->GetServiceProvider()), |
| 85 web_view_(NULL), | 91 web_view_(NULL), |
| 86 root_(NULL), | 92 root_(NULL), |
| 93 view_manager_client_factory_(this), |
| 87 repaint_pending_(false), | 94 repaint_pending_(false), |
| 88 weak_factory_(this) { | 95 weak_factory_(this) { |
| 96 exported_services->AddService(&view_manager_client_factory_); |
| 97 Load(response.Pass()); |
| 89 } | 98 } |
| 90 | 99 |
| 91 HTMLDocumentView::~HTMLDocumentView() { | 100 HTMLDocumentView::~HTMLDocumentView() { |
| 92 if (web_view_) | 101 if (web_view_) |
| 93 web_view_->close(); | 102 web_view_->close(); |
| 94 if (root_) | 103 if (root_) |
| 95 root_->RemoveObserver(this); | 104 root_->RemoveObserver(this); |
| 96 } | 105 } |
| 97 | 106 |
| 98 void HTMLDocumentView::AttachToView(View* view) { | 107 void HTMLDocumentView::OnEmbed(ViewManager* view_manager, |
| 99 root_ = view; | 108 View* root, |
| 109 ServiceProviderImpl* exported_services, |
| 110 scoped_ptr<ServiceProvider> imported_services) { |
| 111 root_ = root; |
| 100 root_->SetColor(SK_ColorCYAN); // Dummy background color. | 112 root_->SetColor(SK_ColorCYAN); // Dummy background color. |
| 113 web_view_->resize(root_->bounds().size()); |
| 114 root_->AddObserver(this); |
| 115 } |
| 101 | 116 |
| 117 void HTMLDocumentView::OnViewManagerDisconnected(ViewManager* view_manager) { |
| 118 // TODO(aa): Need to figure out how shutdown works. |
| 119 } |
| 120 |
| 121 void HTMLDocumentView::Load(URLResponsePtr response) { |
| 102 web_view_ = blink::WebView::create(this); | 122 web_view_ = blink::WebView::create(this); |
| 103 ConfigureSettings(web_view_->settings()); | 123 ConfigureSettings(web_view_->settings()); |
| 104 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | 124 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 | 125 |
| 113 GURL url(response->url); | 126 GURL url(response->url); |
| 114 | 127 |
| 115 WebURLRequestExtraData* extra_data = new WebURLRequestExtraData; | 128 WebURLRequestExtraData* extra_data = new WebURLRequestExtraData; |
| 116 extra_data->synthetic_response = response.Pass(); | 129 extra_data->synthetic_response = response.Pass(); |
| 117 | 130 |
| 118 blink::WebURLRequest web_request; | 131 blink::WebURLRequest web_request; |
| 119 web_request.initialize(); | 132 web_request.initialize(); |
| 120 web_request.setURL(url); | 133 web_request.setURL(url); |
| 121 web_request.setExtraData(extra_data); | 134 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 = | 229 scoped_ptr<blink::WebInputEvent> web_event = |
| 217 TypeConverter<EventPtr, scoped_ptr<blink::WebInputEvent> >::ConvertTo( | 230 TypeConverter<EventPtr, scoped_ptr<blink::WebInputEvent> >::ConvertTo( |
| 218 event); | 231 event); |
| 219 if (web_event) | 232 if (web_event) |
| 220 web_view_->handleInputEvent(*web_event); | 233 web_view_->handleInputEvent(*web_event); |
| 221 } | 234 } |
| 222 | 235 |
| 223 void HTMLDocumentView::Repaint() { | 236 void HTMLDocumentView::Repaint() { |
| 224 repaint_pending_ = false; | 237 repaint_pending_ = false; |
| 225 | 238 |
| 239 if (!root_) |
| 240 return; |
| 241 |
| 226 web_view_->animate(0.0); | 242 web_view_->animate(0.0); |
| 227 web_view_->layout(); | 243 web_view_->layout(); |
| 228 | 244 |
| 229 int width = web_view_->size().width; | 245 int width = web_view_->size().width; |
| 230 int height = web_view_->size().height; | 246 int height = web_view_->size().height; |
| 231 | 247 |
| 232 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( | 248 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( |
| 233 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); | 249 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); |
| 234 | 250 |
| 235 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); | 251 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); |
| 236 | 252 |
| 237 root_->SetContents(canvas->getDevice()->accessBitmap(false)); | 253 root_->SetContents(canvas->getDevice()->accessBitmap(false)); |
| 238 } | 254 } |
| 239 | 255 |
| 240 } // namespace mojo | 256 } // namespace mojo |
| OLD | NEW |