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