summaryrefslogtreecommitdiffstats
path: root/components/web_view/frame_tree.cc
blob: eee41c18a2f848ac179f90a19a80be901751cae7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/web_view/frame_tree.h"

#include "components/web_view/frame_tree_delegate.h"
#include "components/web_view/frame_user_data.h"

namespace web_view {

FrameTree::FrameTree(uint32_t root_app_id,
                     mojo::View* view,
                     mojo::ViewTreeClientPtr view_tree_client,
                     FrameTreeDelegate* delegate,
                     FrameTreeClient* root_client,
                     scoped_ptr<FrameUserData> user_data,
                     const Frame::ClientPropertyMap& client_properties)
    : view_(view),
      delegate_(delegate),
      root_(new Frame(this,
                      view,
                      view->id(),
                      root_app_id,
                      ViewOwnership::DOESNT_OWN_VIEW,
                      root_client,
                      user_data.Pass(),
                      client_properties)),
      progress_(0.f),
      change_id_(1u) {
  root_->Init(nullptr, view_tree_client.Pass());
}

FrameTree::~FrameTree() {
  // Destroy the root explicitly in case it calls back to us for state (such
  // as to see if it is the root).
  delete root_;
  root_ = nullptr;
}

Frame* FrameTree::CreateSharedFrame(
    Frame* parent,
    uint32_t frame_id,
    uint32_t app_id,
    const Frame::ClientPropertyMap& client_properties) {
  mojo::View* frame_view = root_->view()->GetChildById(frame_id);
  // |frame_view| may be null if the View hasn't been created yet. If this is
  // the case the View will be connected to the Frame in Frame::OnTreeChanged.
  Frame* frame =
      new Frame(this, frame_view, frame_id, app_id, ViewOwnership::OWNS_VIEW,
                nullptr, nullptr, client_properties);
  frame->Init(parent, nullptr);
  return frame;
}

uint32_t FrameTree::AdvanceChangeID() {
  return ++change_id_;
}

void FrameTree::LoadingStateChanged() {
  bool loading = root_->IsLoading();
  if (delegate_)
    delegate_->LoadingStateChanged(loading);
}

void FrameTree::ProgressChanged() {
  int frame_count = 0;
  double total_progress = root_->GatherProgress(&frame_count);
  // Make sure the progress bar never runs backwards, even if that means
  // accuracy takes a hit.
  progress_ = std::max(progress_, total_progress / frame_count);
  if (delegate_)
    delegate_->ProgressChanged(progress_);
}

void FrameTree::TitleChanged(const mojo::String& title) {
  if (delegate_)
    delegate_->TitleChanged(title);
}

void FrameTree::ClientPropertyChanged(const Frame* source,
                                      const mojo::String& name,
                                      const mojo::Array<uint8_t>& value) {
  root_->NotifyClientPropertyChanged(source, name, value);
}

}  // namespace web_view