Don't preload rarely seen large images
[chromium-blink-merge.git] / components / html_viewer / document_resource_waiter.cc
blob9e082975d1088eb6dbb5041fce25759b717ad30e
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/html_viewer/document_resource_waiter.h"
7 #include "components/html_viewer/frame_tree_manager.h"
8 #include "components/html_viewer/global_state.h"
9 #include "components/html_viewer/html_document_oopif.h"
10 #include "components/view_manager/public/cpp/view.h"
12 namespace html_viewer {
14 DocumentResourceWaiter::DocumentResourceWaiter(GlobalState* global_state,
15 mojo::URLResponsePtr response,
16 HTMLDocumentOOPIF* document)
17 : global_state_(global_state),
18 document_(document),
19 response_(response.Pass()),
20 root_(nullptr),
21 frame_tree_client_binding_(this) {
24 DocumentResourceWaiter::~DocumentResourceWaiter() {
27 void DocumentResourceWaiter::Release(
28 mojo::InterfaceRequest<mandoline::FrameTreeClient>*
29 frame_tree_client_request,
30 mandoline::FrameTreeServerPtr* frame_tree_server,
31 mojo::Array<mandoline::FrameDataPtr>* frame_data,
32 mojo::URLResponsePtr* response) {
33 DCHECK(IsReady());
34 *frame_tree_client_request = frame_tree_client_request_.Pass();
35 *frame_tree_server = server_.Pass();
36 *frame_data = frame_data_.Pass();
37 *response = response_.Pass();
40 bool DocumentResourceWaiter::IsReady() const {
41 return root_ && root_->viewport_metrics().device_pixel_ratio != 0.0f &&
42 !frame_data_.is_null();
45 void DocumentResourceWaiter::Bind(
46 mojo::InterfaceRequest<mandoline::FrameTreeClient> request) {
47 if (frame_tree_client_binding_.is_bound() || !frame_data_.is_null()) {
48 DVLOG(1) << "Request for FrameTreeClient after already supplied one";
49 return;
51 frame_tree_client_binding_.Bind(request.Pass());
54 void DocumentResourceWaiter::OnConnect(
55 mandoline::FrameTreeServerPtr server,
56 mojo::Array<mandoline::FrameDataPtr> frame_data) {
57 DCHECK(frame_data_.is_null());
58 server_ = server.Pass();
59 frame_data_ = frame_data.Pass();
60 CHECK(frame_data_.size() > 0u);
61 frame_tree_client_request_ = frame_tree_client_binding_.Unbind();
62 if (IsReady())
63 document_->LoadIfNecessary();
66 void DocumentResourceWaiter::OnFrameAdded(mandoline::FrameDataPtr frame_data) {
67 // It is assumed we receive OnConnect() (which unbinds) before anything else.
68 NOTREACHED();
71 void DocumentResourceWaiter::OnFrameRemoved(uint32_t frame_id) {
72 // It is assumed we receive OnConnect() (which unbinds) before anything else.
73 NOTREACHED();
76 } // namespace html_viewer