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 "mandoline/tab/frame_tree.h"
7 #include "mandoline/tab/frame_tree_delegate.h"
8 #include "mandoline/tab/frame_user_data.h"
12 FrameTree::FrameTree(mojo::View
* view
,
13 FrameTreeDelegate
* delegate
,
14 FrameTreeClient
* root_client
,
15 scoped_ptr
<FrameUserData
> user_data
)
21 ViewOwnership::DOESNT_OWN_VIEW
,
24 Frame::ClientPropertyMap()),
29 FrameTree::~FrameTree() {
32 Frame
* FrameTree::CreateAndAddFrame(mojo::View
* view
,
34 FrameTreeClient
* client
,
35 scoped_ptr
<FrameUserData
> user_data
) {
36 return CreateAndAddFrameImpl(view
, view
->id(), parent
, client
,
37 user_data
.Pass(), Frame::ClientPropertyMap());
40 Frame
* FrameTree::CreateOrReplaceFrame(Frame
* frame
,
42 FrameTreeClient
* frame_tree_client
,
43 scoped_ptr
<FrameUserData
> user_data
) {
44 DCHECK(frame
&& frame
->HasAncestor(&root_
));
46 if (frame
->view() == view
) {
47 // It's important we Swap() here rather than destroy as otherwise the
48 // clients see a destroy followed by a new frame, which confuses html
50 DCHECK(frame
!= &root_
);
51 frame
->Swap(frame_tree_client
, user_data
.Pass());
55 return CreateAndAddFrame(view
, frame
, frame_tree_client
, user_data
.Pass());
58 void FrameTree::CreateSharedFrame(
61 const Frame::ClientPropertyMap
& client_properties
) {
62 mojo::View
* frame_view
= root_
.view()->GetChildById(frame_id
);
63 // |frame_view| may be null if the View hasn't been created yet. If this is
64 // the case the View will be connected to the Frame in Frame::OnTreeChanged.
65 CreateAndAddFrameImpl(frame_view
, frame_id
, parent
, nullptr, nullptr,
69 Frame
* FrameTree::CreateAndAddFrameImpl(
73 FrameTreeClient
* client
,
74 scoped_ptr
<FrameUserData
> user_data
,
75 const Frame::ClientPropertyMap
& client_properties
) {
76 Frame
* frame
= new Frame(this, view
, frame_id
, ViewOwnership::OWNS_VIEW
,
77 client
, user_data
.Pass(), client_properties
);
82 void FrameTree::LoadingStateChanged() {
83 bool loading
= root_
.IsLoading();
85 delegate_
->LoadingStateChanged(loading
);
88 void FrameTree::ProgressChanged() {
90 double total_progress
= root_
.GatherProgress(&frame_count
);
91 // Make sure the progress bar never runs backwards, even if that means
92 // accuracy takes a hit.
93 progress_
= std::max(progress_
, total_progress
/ frame_count
);
95 delegate_
->ProgressChanged(progress_
);
98 void FrameTree::ClientPropertyChanged(const Frame
* source
,
99 const mojo::String
& name
,
100 const mojo::Array
<uint8_t>& value
) {
101 root_
.NotifyClientPropertyChanged(source
, name
, value
);
104 } // namespace mandoline