Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: mojo/services/html_viewer/html_document_view.cc

Issue 514063003: Update view_manager and window_manager to make use of content handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@viewman2
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/connect.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"
15 #include "mojo/public/interfaces/application/shell.mojom.h"
13 #include "mojo/services/html_viewer/blink_input_events_type_converters.h" 16 #include "mojo/services/html_viewer/blink_input_events_type_converters.h"
14 #include "mojo/services/html_viewer/blink_url_request_type_converters.h" 17 #include "mojo/services/html_viewer/blink_url_request_type_converters.h"
15 #include "mojo/services/html_viewer/webstoragenamespace_impl.h" 18 #include "mojo/services/html_viewer/webstoragenamespace_impl.h"
16 #include "mojo/services/html_viewer/weburlloader_impl.h" 19 #include "mojo/services/html_viewer/weburlloader_impl.h"
17 #include "mojo/services/public/cpp/view_manager/view.h" 20 #include "mojo/services/public/cpp/view_manager/view.h"
18 #include "skia/ext/refptr.h" 21 #include "skia/ext/refptr.h"
19 #include "third_party/WebKit/public/platform/Platform.h" 22 #include "third_party/WebKit/public/platform/Platform.h"
20 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" 23 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h"
21 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 24 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
22 #include "third_party/WebKit/public/web/WebDocument.h" 25 #include "third_party/WebKit/public/web/WebDocument.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if (request.extraData()) 74 if (request.extraData())
72 return true; 75 return true;
73 76
74 // 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
75 // host to do the navigation for us. 78 // host to do the navigation for us.
76 return false; 79 return false;
77 } 80 }
78 81
79 } // namespace 82 } // namespace
80 83
81 HTMLDocumentView::HTMLDocumentView(ServiceProvider* service_provider, 84 HTMLDocumentView::HTMLDocumentView(
82 ViewManager* view_manager) 85 URLResponsePtr response,
83 : view_manager_(view_manager), 86 scoped_ptr<ServiceProvider> imported_services,
84 navigator_host_(service_provider), 87 ServiceProviderImpl* exported_services,
88 Shell* shell)
89 : imported_services_(imported_services.Pass()),
90 shell_(shell),
85 web_view_(NULL), 91 web_view_(NULL),
86 root_(NULL), 92 root_(NULL),
93 view_manager_client_factory_(shell, this),
87 repaint_pending_(false), 94 repaint_pending_(false),
88 weak_factory_(this) { 95 weak_factory_(this) {
96
97 exported_services->AddService(&view_manager_client_factory_);
98 Load(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): Need to figure out how shutdown works.
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 blink::WebNavigationPolicy HTMLDocumentView::decidePolicyForNavigation( 184 blink::WebNavigationPolicy HTMLDocumentView::decidePolicyForNavigation(
171 blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* data, 185 blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* data,
172 const blink::WebURLRequest& request, blink::WebNavigationType nav_type, 186 const blink::WebURLRequest& request, blink::WebNavigationType nav_type,
173 blink::WebNavigationPolicy default_policy, bool is_redirect) { 187 blink::WebNavigationPolicy default_policy, bool is_redirect) {
174 if (CanNavigateLocally(frame, request)) 188 if (CanNavigateLocally(frame, request))
175 return default_policy; 189 return default_policy;
176 190
177 NavigationDetailsPtr nav_details(NavigationDetails::New()); 191 NavigationDetailsPtr nav_details(NavigationDetails::New());
178 nav_details->request = URLRequest::From(request); 192 nav_details->request = URLRequest::From(request);
179 193
180 navigator_host_->RequestNavigate( 194 GetNavigatorHost()->RequestNavigate(
181 root_->id(), 195 root_->id(),
182 WebNavigationPolicyToNavigationTarget(default_policy), 196 WebNavigationPolicyToNavigationTarget(default_policy),
183 nav_details.Pass()); 197 nav_details.Pass());
184 198
185 return blink::WebNavigationPolicyIgnore; 199 return blink::WebNavigationPolicyIgnore;
186 } 200 }
187 201
188 void HTMLDocumentView::didAddMessageToConsole( 202 void HTMLDocumentView::didAddMessageToConsole(
189 const blink::WebConsoleMessage& message, 203 const blink::WebConsoleMessage& message,
190 const blink::WebString& source_name, 204 const blink::WebString& source_name,
191 unsigned source_line, 205 unsigned source_line,
192 const blink::WebString& stack_trace) { 206 const blink::WebString& stack_trace) {
193 } 207 }
194 208
195 void HTMLDocumentView::didNavigateWithinPage( 209 void HTMLDocumentView::didNavigateWithinPage(
196 blink::WebLocalFrame* frame, const blink::WebHistoryItem& history_item, 210 blink::WebLocalFrame* frame, const blink::WebHistoryItem& history_item,
197 blink::WebHistoryCommitType commit_type) { 211 blink::WebHistoryCommitType commit_type) {
198 navigator_host_->DidNavigateLocally(root_->id(), 212 GetNavigatorHost()->DidNavigateLocally(root_->id(),
199 history_item.urlString().utf8()); 213 history_item.urlString().utf8());
200 } 214 }
201 215
202 void HTMLDocumentView::OnViewBoundsChanged(View* view, 216 void HTMLDocumentView::OnViewBoundsChanged(View* view,
203 const gfx::Rect& old_bounds, 217 const gfx::Rect& old_bounds,
204 const gfx::Rect& new_bounds) { 218 const gfx::Rect& new_bounds) {
205 DCHECK_EQ(view, root_); 219 DCHECK_EQ(view, root_);
206 web_view_->resize(view->bounds().size()); 220 web_view_->resize(view->bounds().size());
207 } 221 }
208 222
209 void HTMLDocumentView::OnViewDestroyed(View* view) { 223 void HTMLDocumentView::OnViewDestroyed(View* view) {
210 DCHECK_EQ(view, root_); 224 DCHECK_EQ(view, root_);
211 view->RemoveObserver(this); 225 view->RemoveObserver(this);
212 root_ = NULL; 226 root_ = NULL;
213 } 227 }
214 228
215 void HTMLDocumentView::OnViewInputEvent(View* view, const EventPtr& event) { 229 void HTMLDocumentView::OnViewInputEvent(View* view, const EventPtr& event) {
216 scoped_ptr<blink::WebInputEvent> web_event = 230 scoped_ptr<blink::WebInputEvent> web_event =
217 event.To<scoped_ptr<blink::WebInputEvent> >(); 231 event.To<scoped_ptr<blink::WebInputEvent> >();
218 if (web_event) 232 if (web_event)
219 web_view_->handleInputEvent(*web_event); 233 web_view_->handleInputEvent(*web_event);
220 } 234 }
221 235
222 void HTMLDocumentView::Repaint() { 236 void HTMLDocumentView::Repaint() {
223 repaint_pending_ = false; 237 repaint_pending_ = false;
224 238
239 if (!root_)
240 return;
241
225 web_view_->animate(0.0); 242 web_view_->animate(0.0);
226 web_view_->layout(); 243 web_view_->layout();
227 244
228 int width = web_view_->size().width; 245 int width = web_view_->size().width;
229 int height = web_view_->size().height; 246 int height = web_view_->size().height;
230 247
231 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( 248 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster(
232 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); 249 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType)));
233 250
234 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); 251 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height));
235 252
236 root_->SetContents(canvas->getDevice()->accessBitmap(false)); 253 root_->SetContents(canvas->getDevice()->accessBitmap(false));
237 } 254 }
238 255
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
239 } // namespace mojo 266 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698