Chromium Code Reviews| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 | 73 |
| 74 // Otherwise we don't know if we're the right app to handle this request. Ask | 74 // Otherwise we don't know if we're the right app to handle this request. Ask |
| 75 // host to do the navigation for us. | 75 // host to do the navigation for us. |
| 76 return false; | 76 return false; |
| 77 } | 77 } |
| 78 | 78 |
| 79 } // namespace | 79 } // namespace |
| 80 | 80 |
| 81 HTMLDocumentView::HTMLDocumentView(ServiceProvider* service_provider, | 81 HTMLDocumentView::HTMLDocumentView(ServiceProvider* service_provider, |
| 82 ViewManager* view_manager) | 82 ViewManager* view_manager) |
| 83 : view_manager_(view_manager), | 83 : SimpleFrameClient(service_provider, 0), |
| 84 view_manager_(view_manager), | |
| 84 web_view_(NULL), | 85 web_view_(NULL), |
| 85 root_(NULL), | 86 root_(NULL), |
| 86 repaint_pending_(false), | 87 repaint_pending_(false), |
| 87 navigator_host_(service_provider), | |
| 88 weak_factory_(this) { | 88 weak_factory_(this) { |
| 89 } | 89 } |
| 90 | 90 |
| 91 HTMLDocumentView::~HTMLDocumentView() { | 91 HTMLDocumentView::~HTMLDocumentView() { |
| 92 if (web_view_) | 92 if (web_view_) |
| 93 web_view_->close(); | 93 web_view_->close(); |
| 94 if (root_) | 94 if (root_) |
| 95 root_->RemoveObserver(this); | 95 root_->RemoveObserver(this); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void HTMLDocumentView::AttachToView(View* view) { | 98 void HTMLDocumentView::AttachToView(View* view) { |
| 99 root_ = view; | 99 root_ = view; |
| 100 root_id_ = root_->id(); | |
| 100 root_->SetColor(SK_ColorCYAN); // Dummy background color. | 101 root_->SetColor(SK_ColorCYAN); // Dummy background color. |
| 101 | 102 |
| 102 web_view_ = blink::WebView::create(this); | 103 web_view_ = blink::WebView::create(this); |
| 103 ConfigureSettings(web_view_->settings()); | 104 ConfigureSettings(web_view_->settings()); |
| 104 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | 105 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); |
| 105 web_view_->resize(root_->bounds().size()); | 106 web_view_->resize(root_->bounds().size()); |
| 106 | 107 |
| 107 root_->AddObserver(this); | 108 root_->AddObserver(this); |
| 108 } | 109 } |
| 109 | 110 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 138 | 139 |
| 139 bool HTMLDocumentView::allowsBrokenNullLayerTreeView() const { | 140 bool HTMLDocumentView::allowsBrokenNullLayerTreeView() const { |
| 140 // TODO(darin): Switch to using compositor bindings. | 141 // TODO(darin): Switch to using compositor bindings. |
| 141 // | 142 // |
| 142 // NOTE: Note to Blink maintainers, feel free to break this code if it is the | 143 // NOTE: Note to Blink maintainers, feel free to break this code if it is the |
| 143 // last NOT using compositor bindings and you want to delete this code path. | 144 // last NOT using compositor bindings and you want to delete this code path. |
| 144 // | 145 // |
| 145 return true; | 146 return true; |
| 146 } | 147 } |
| 147 | 148 |
| 148 blink::WebCookieJar* HTMLDocumentView::cookieJar(blink::WebLocalFrame* frame) { | 149 SimpleFrameClient::SimpleFrameClient(ServiceProvider* service_provider, |
| 150 Id root_id) | |
| 151 : service_provider_(service_provider), | |
| 152 navigator_host_(service_provider), | |
| 153 root_id_(root_id) { | |
| 154 } | |
| 155 | |
| 156 SimpleFrameClient::~SimpleFrameClient() { | |
| 157 } | |
| 158 | |
| 159 blink::WebFrame* SimpleFrameClient::createChildFrame( | |
| 160 blink::WebLocalFrame* parent, | |
| 161 const blink::WebString& frameName) { | |
| 162 // TODO(mpcomplete): What happens if root_ is destroyed and the child frames | |
| 163 // live on? Can that happen? | |
| 164 blink::WebLocalFrame* web_frame = | |
| 165 blink::WebLocalFrame::create(new SimpleFrameClient(service_provider_, | |
|
darin (slow to review)
2014/08/14 23:45:52
why do you need a new WebFrameClient instance per
Matt Perry
2014/08/15 00:40:04
Doh. I guess you don't. I assumed WebLocalFrame ex
| |
| 166 root_id_)); | |
| 167 parent->appendChild(web_frame); | |
| 168 | |
| 169 return web_frame; | |
| 170 } | |
| 171 | |
| 172 void SimpleFrameClient::didDisownOpener(blink::WebLocalFrame* frame) { | |
| 173 } | |
| 174 | |
| 175 void SimpleFrameClient::frameDetached(blink::WebFrame* frame) { | |
| 176 bool is_subframe = !!frame->parent(); | |
| 177 | |
| 178 if (is_subframe) | |
| 179 frame->parent()->removeChild(frame); | |
| 180 | |
| 181 // |frame| is invalid after here. | |
| 182 frame->close(); | |
| 183 | |
| 184 if (is_subframe) { | |
| 185 delete this; | |
| 186 // Object is invalid after this point. | |
| 187 } | |
| 188 } | |
| 189 | |
| 190 void SimpleFrameClient::frameFocused() { | |
| 191 } | |
| 192 | |
| 193 void SimpleFrameClient::willClose(blink::WebFrame* frame) { | |
| 194 } | |
| 195 | |
| 196 blink::WebCookieJar* SimpleFrameClient::cookieJar(blink::WebLocalFrame* frame) { | |
| 149 // TODO(darin): Blink does not fallback to the Platform provided WebCookieJar. | 197 // TODO(darin): Blink does not fallback to the Platform provided WebCookieJar. |
| 150 // Either it should, as it once did, or we should find another solution here. | 198 // Either it should, as it once did, or we should find another solution here. |
| 151 return blink::Platform::current()->cookieJar(); | 199 return blink::Platform::current()->cookieJar(); |
| 152 } | 200 } |
| 153 | 201 |
| 154 blink::WebNavigationPolicy HTMLDocumentView::decidePolicyForNavigation( | 202 blink::WebNavigationPolicy SimpleFrameClient::decidePolicyForNavigation( |
| 155 blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* data, | 203 blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* data, |
| 156 const blink::WebURLRequest& request, blink::WebNavigationType nav_type, | 204 const blink::WebURLRequest& request, blink::WebNavigationType nav_type, |
| 157 blink::WebNavigationPolicy default_policy, bool is_redirect) { | 205 blink::WebNavigationPolicy default_policy, bool is_redirect) { |
| 158 if (CanNavigateLocally(frame, request)) | 206 if (CanNavigateLocally(frame, request)) |
| 159 return default_policy; | 207 return default_policy; |
| 160 | 208 |
| 161 NavigationDetailsPtr nav_details(NavigationDetails::New()); | 209 NavigationDetailsPtr nav_details(NavigationDetails::New()); |
| 162 nav_details->request = URLRequest::From(request); | 210 nav_details->request = URLRequest::From(request); |
| 163 | 211 |
| 164 navigator_host_->RequestNavigate( | 212 navigator_host_->RequestNavigate( |
| 165 root_->id(), | 213 root_id_, |
| 166 WebNavigationPolicyToNavigationTarget(default_policy), | 214 WebNavigationPolicyToNavigationTarget(default_policy), |
| 167 nav_details.Pass()); | 215 nav_details.Pass()); |
| 168 | 216 |
| 169 return blink::WebNavigationPolicyIgnore; | 217 return blink::WebNavigationPolicyIgnore; |
| 170 } | 218 } |
| 171 | 219 |
| 172 void HTMLDocumentView::didAddMessageToConsole( | 220 void SimpleFrameClient::didAddMessageToConsole( |
| 173 const blink::WebConsoleMessage& message, | 221 const blink::WebConsoleMessage& message, |
| 174 const blink::WebString& source_name, | 222 const blink::WebString& source_name, |
| 175 unsigned source_line, | 223 unsigned source_line, |
| 176 const blink::WebString& stack_trace) { | 224 const blink::WebString& stack_trace) { |
| 177 } | 225 } |
| 178 | 226 |
| 179 void HTMLDocumentView::didNavigateWithinPage( | 227 void SimpleFrameClient::didNavigateWithinPage( |
| 180 blink::WebLocalFrame* frame, const blink::WebHistoryItem& history_item, | 228 blink::WebLocalFrame* frame, const blink::WebHistoryItem& history_item, |
| 181 blink::WebHistoryCommitType commit_type) { | 229 blink::WebHistoryCommitType commit_type) { |
| 182 navigator_host_->DidNavigateLocally(root_->id(), | 230 navigator_host_->DidNavigateLocally(root_id_, |
| 183 history_item.urlString().utf8()); | 231 history_item.urlString().utf8()); |
| 184 } | 232 } |
| 185 | 233 |
| 186 void HTMLDocumentView::OnViewBoundsChanged(View* view, | 234 void HTMLDocumentView::OnViewBoundsChanged(View* view, |
| 187 const gfx::Rect& old_bounds, | 235 const gfx::Rect& old_bounds, |
| 188 const gfx::Rect& new_bounds) { | 236 const gfx::Rect& new_bounds) { |
| 189 DCHECK_EQ(view, root_); | 237 DCHECK_EQ(view, root_); |
| 190 web_view_->resize(view->bounds().size()); | 238 web_view_->resize(view->bounds().size()); |
| 191 } | 239 } |
| 192 | 240 |
| 193 void HTMLDocumentView::OnViewDestroyed(View* view) { | 241 void HTMLDocumentView::OnViewDestroyed(View* view) { |
| 194 DCHECK_EQ(view, root_); | 242 DCHECK_EQ(view, root_); |
| 195 view->RemoveObserver(this); | 243 view->RemoveObserver(this); |
| 196 root_ = NULL; | 244 root_ = NULL; |
| 245 root_id_ = 0; | |
| 197 } | 246 } |
| 198 | 247 |
| 199 void HTMLDocumentView::OnViewInputEvent(View* view, const EventPtr& event) { | 248 void HTMLDocumentView::OnViewInputEvent(View* view, const EventPtr& event) { |
| 200 scoped_ptr<blink::WebInputEvent> web_event = | 249 scoped_ptr<blink::WebInputEvent> web_event = |
| 201 TypeConverter<EventPtr, scoped_ptr<blink::WebInputEvent> >::ConvertTo( | 250 TypeConverter<EventPtr, scoped_ptr<blink::WebInputEvent> >::ConvertTo( |
| 202 event); | 251 event); |
| 203 if (web_event) | 252 if (web_event) |
| 204 web_view_->handleInputEvent(*web_event); | 253 web_view_->handleInputEvent(*web_event); |
| 205 } | 254 } |
| 206 | 255 |
| 207 void HTMLDocumentView::Repaint() { | 256 void HTMLDocumentView::Repaint() { |
| 208 repaint_pending_ = false; | 257 repaint_pending_ = false; |
| 209 | 258 |
| 210 web_view_->animate(0.0); | 259 web_view_->animate(0.0); |
| 211 web_view_->layout(); | 260 web_view_->layout(); |
| 212 | 261 |
| 213 int width = web_view_->size().width; | 262 int width = web_view_->size().width; |
| 214 int height = web_view_->size().height; | 263 int height = web_view_->size().height; |
| 215 | 264 |
| 216 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( | 265 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( |
| 217 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); | 266 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); |
| 218 | 267 |
| 219 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); | 268 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); |
| 220 | 269 |
| 221 root_->SetContents(canvas->getDevice()->accessBitmap(false)); | 270 root_->SetContents(canvas->getDevice()->accessBitmap(false)); |
| 222 } | 271 } |
| 223 | 272 |
| 224 } // namespace mojo | 273 } // namespace mojo |
| OLD | NEW |