Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / web_view / frame_tree.cc
blobfc0cb3a5b01958af0444e270b768517a6ef2216f
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"
10 namespace web_view {
12 FrameTree::FrameTree(uint32_t root_app_id,
13 mus::View* view,
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)
19 : view_(view),
20 delegate_(delegate),
21 root_(new Frame(this,
22 view,
23 view->id(),
24 root_app_id,
25 ViewOwnership::DOESNT_OWN_VIEW,
26 root_client,
27 user_data.Pass(),
28 client_properties)),
29 progress_(0.f),
30 change_id_(1u) {
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).
37 delete root_;
38 root_ = nullptr;
41 Frame* FrameTree::CreateChildFrame(
42 Frame* parent,
43 mojo::InterfaceRequest<mojom::Frame> frame_request,
44 mojom::FrameClientPtr client,
45 uint32_t frame_id,
46 uint32_t app_id,
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.
54 Frame* frame =
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());
58 return frame;
61 uint32_t FrameTree::AdvanceChangeID() {
62 return ++change_id_;
65 void FrameTree::LoadingStateChanged() {
66 const bool loading = root_->IsLoading();
67 if (loading) {
68 int frame_count = 0;
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