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/web_view/frame_tree.h"
7 #include "components/web_view/frame_tree_delegate.h"
8 #include "components/web_view/frame_user_data.h"
12 FrameTree::FrameTree(uint32_t root_app_id
,
14 mojo::ViewTreeClientPtr view_tree_client
,
15 FrameTreeDelegate
* delegate
,
16 mojom::FrameClient
* root_client
,
17 scoped_ptr
<FrameUserData
> user_data
,
18 const Frame::ClientPropertyMap
& client_properties
)
25 ViewOwnership::DOESNT_OWN_VIEW
,
31 root_
->Init(nullptr, view_tree_client
.Pass(), nullptr);
34 FrameTree::~FrameTree() {
35 // Destroy the root explicitly in case it calls back to us for state (such
36 // as to see if it is the root).
41 Frame
* FrameTree::CreateChildFrame(
43 mojo::InterfaceRequest
<mojom::Frame
> frame_request
,
44 mojom::FrameClientPtr client
,
47 const Frame::ClientPropertyMap
& client_properties
) {
48 mojom::FrameClient
* raw_client
= client
.get();
49 scoped_ptr
<FrameUserData
> user_data
=
50 delegate_
->CreateUserDataForNewFrame(client
.Pass());
51 mus::View
* frame_view
= root_
->view()->GetChildById(frame_id
);
52 // |frame_view| may be null if the View hasn't been created yet. If this is
53 // the case the View will be connected to the Frame in Frame::OnTreeChanged.
55 new Frame(this, frame_view
, frame_id
, app_id
, ViewOwnership::OWNS_VIEW
,
56 raw_client
, user_data
.Pass(), client_properties
);
57 frame
->Init(parent
, nullptr, frame_request
.Pass());
61 uint32_t FrameTree::AdvanceChangeID() {
65 void FrameTree::LoadingStateChanged() {
66 const bool loading
= root_
->IsLoading();
69 const double total_progress
= root_
->GatherProgress(&frame_count
);
70 // Make sure the progress bar never runs backwards, even if that means
71 // accuracy takes a hit.
72 progress_
= std::max(progress_
, total_progress
/ frame_count
);
74 delegate_
->LoadingStateChanged(loading
, progress_
);
77 void FrameTree::TitleChanged(const mojo::String
& title
) {
78 delegate_
->TitleChanged(title
);
81 void FrameTree::DidCommitProvisionalLoad(Frame
* source
) {
82 delegate_
->DidCommitProvisionalLoad(source
);
85 void FrameTree::ClientPropertyChanged(const Frame
* source
,
86 const mojo::String
& name
,
87 const mojo::Array
<uint8_t>& value
) {
88 root_
->NotifyClientPropertyChanged(source
, name
, value
);
91 } // namespace web_view