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 "base/command_line.h"
8 #include "components/web_view/frame_tree_delegate.h"
9 #include "components/web_view/frame_user_data.h"
10 #include "components/web_view/web_view_switches.h"
14 FrameTree::FrameTree(uint32_t root_app_id
,
16 mojo::ViewTreeClientPtr view_tree_client
,
17 FrameTreeDelegate
* delegate
,
18 FrameTreeClient
* root_client
,
19 scoped_ptr
<FrameUserData
> user_data
,
20 const Frame::ClientPropertyMap
& client_properties
)
27 ViewOwnership::DOESNT_OWN_VIEW
,
33 root_
->Init(nullptr, view_tree_client
.Pass());
36 FrameTree::~FrameTree() {
37 // Destroy the root explicitly in case it calls back to us for state (such
38 // as to see if it is the root).
44 bool FrameTree::AlwaysCreateNewFrameTree() {
45 return base::CommandLine::ForCurrentProcess()->HasSwitch(
46 web_view::switches::kOOPIFAlwaysCreateNewFrameTree
);
49 Frame
* FrameTree::CreateSharedFrame(
53 const Frame::ClientPropertyMap
& client_properties
) {
54 mojo::View
* frame_view
= root_
->view()->GetChildById(frame_id
);
55 // |frame_view| may be null if the View hasn't been created yet. If this is
56 // the case the View will be connected to the Frame in Frame::OnTreeChanged.
58 new Frame(this, frame_view
, frame_id
, app_id
, ViewOwnership::OWNS_VIEW
,
59 nullptr, nullptr, client_properties
);
60 frame
->Init(parent
, nullptr);
64 uint32_t FrameTree::AdvanceChangeID() {
68 void FrameTree::LoadingStateChanged() {
69 bool loading
= root_
->IsLoading();
71 delegate_
->LoadingStateChanged(loading
);
74 void FrameTree::ProgressChanged() {
76 double total_progress
= root_
->GatherProgress(&frame_count
);
77 // Make sure the progress bar never runs backwards, even if that means
78 // accuracy takes a hit.
79 progress_
= std::max(progress_
, total_progress
/ frame_count
);
81 delegate_
->ProgressChanged(progress_
);
84 void FrameTree::TitleChanged(const mojo::String
& title
) {
86 delegate_
->TitleChanged(title
);
89 void FrameTree::ClientPropertyChanged(const Frame
* source
,
90 const mojo::String
& name
,
91 const mojo::Array
<uint8_t>& value
) {
92 root_
->NotifyClientPropertyChanged(source
, name
, value
);
95 } // namespace web_view