Clear webapp storage when site data is cleared
[chromium-blink-merge.git] / components / web_view / frame_tree.cc
blobdcaf159423e29b81d00c29ca66dbb727453461c0
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"
12 namespace web_view {
14 FrameTree::FrameTree(uint32_t root_app_id,
15 mojo::View* view,
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)
21 : view_(view),
22 delegate_(delegate),
23 root_(new Frame(this,
24 view,
25 view->id(),
26 root_app_id,
27 ViewOwnership::DOESNT_OWN_VIEW,
28 root_client,
29 user_data.Pass(),
30 client_properties)),
31 progress_(0.f),
32 change_id_(1u) {
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).
39 delete root_;
40 root_ = nullptr;
43 // static
44 bool FrameTree::AlwaysCreateNewFrameTree() {
45 return base::CommandLine::ForCurrentProcess()->HasSwitch(
46 web_view::switches::kOOPIFAlwaysCreateNewFrameTree);
49 Frame* FrameTree::CreateSharedFrame(
50 Frame* parent,
51 uint32_t frame_id,
52 uint32_t app_id,
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.
57 Frame* frame =
58 new Frame(this, frame_view, frame_id, app_id, ViewOwnership::OWNS_VIEW,
59 nullptr, nullptr, client_properties);
60 frame->Init(parent, nullptr);
61 return frame;
64 uint32_t FrameTree::AdvanceChangeID() {
65 return ++change_id_;
68 void FrameTree::LoadingStateChanged() {
69 bool loading = root_->IsLoading();
70 if (delegate_)
71 delegate_->LoadingStateChanged(loading);
74 void FrameTree::ProgressChanged() {
75 int frame_count = 0;
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);
80 if (delegate_)
81 delegate_->ProgressChanged(progress_);
84 void FrameTree::TitleChanged(const mojo::String& title) {
85 if (delegate_)
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