| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "components/web_view/frame_tree.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "components/web_view/frame_tree_delegate.h" | |
| 10 #include "components/web_view/frame_user_data.h" | |
| 11 | |
| 12 namespace web_view { | |
| 13 | |
| 14 FrameTree::FrameTree(uint32_t root_app_id, | |
| 15 mus::Window* window, | |
| 16 mus::mojom::WindowTreeClientPtr window_tree_client, | |
| 17 FrameTreeDelegate* delegate, | |
| 18 mojom::FrameClient* root_client, | |
| 19 scoped_ptr<FrameUserData> user_data, | |
| 20 const Frame::ClientPropertyMap& client_properties, | |
| 21 base::TimeTicks navigation_start_time) | |
| 22 : window_(window), | |
| 23 delegate_(delegate), | |
| 24 root_(new Frame(this, | |
| 25 window, | |
| 26 window->id(), | |
| 27 root_app_id, | |
| 28 WindowOwnership::DOESNT_OWN_WINDOW, | |
| 29 root_client, | |
| 30 std::move(user_data), | |
| 31 client_properties)), | |
| 32 progress_(0.f), | |
| 33 change_id_(1u) { | |
| 34 root_->Init(nullptr, std::move(window_tree_client), nullptr, | |
| 35 navigation_start_time); | |
| 36 } | |
| 37 | |
| 38 FrameTree::~FrameTree() { | |
| 39 // Destroy the root explicitly in case it calls back to us for state (such | |
| 40 // as to see if it is the root). | |
| 41 delete root_; | |
| 42 root_ = nullptr; | |
| 43 } | |
| 44 | |
| 45 Frame* FrameTree::CreateChildFrame( | |
| 46 Frame* parent, | |
| 47 mojo::InterfaceRequest<mojom::Frame> frame_request, | |
| 48 mojom::FrameClientPtr client, | |
| 49 uint32_t frame_id, | |
| 50 uint32_t app_id, | |
| 51 const Frame::ClientPropertyMap& client_properties) { | |
| 52 mojom::FrameClient* raw_client = client.get(); | |
| 53 scoped_ptr<FrameUserData> user_data = | |
| 54 delegate_->CreateUserDataForNewFrame(std::move(client)); | |
| 55 mus::Window* frame_window = root_->window()->GetChildById(frame_id); | |
| 56 // |frame_window| may be null if the Window hasn't been created yet. If this | |
| 57 // is the case the Window will be connected to the Frame in | |
| 58 // Frame::OnTreeChanged. | |
| 59 Frame* frame = new Frame(this, frame_window, frame_id, app_id, | |
| 60 WindowOwnership::OWNS_WINDOW, raw_client, | |
| 61 std::move(user_data), client_properties); | |
| 62 frame->Init(parent, nullptr, std::move(frame_request), base::TimeTicks()); | |
| 63 return frame; | |
| 64 } | |
| 65 | |
| 66 uint32_t FrameTree::AdvanceChangeID() { | |
| 67 return ++change_id_; | |
| 68 } | |
| 69 | |
| 70 void FrameTree::LoadingStateChanged() { | |
| 71 const bool loading = root_->IsLoading(); | |
| 72 if (loading) { | |
| 73 int frame_count = 0; | |
| 74 const double total_progress = root_->GatherProgress(&frame_count); | |
| 75 // Make sure the progress bar never runs backwards, even if that means | |
| 76 // accuracy takes a hit. | |
| 77 progress_ = std::max(progress_, total_progress / frame_count); | |
| 78 } | |
| 79 delegate_->LoadingStateChanged(loading, progress_); | |
| 80 } | |
| 81 | |
| 82 void FrameTree::TitleChanged(const mojo::String& title) { | |
| 83 delegate_->TitleChanged(title); | |
| 84 } | |
| 85 | |
| 86 void FrameTree::DidCommitProvisionalLoad(Frame* source) { | |
| 87 delegate_->DidCommitProvisionalLoad(source); | |
| 88 } | |
| 89 | |
| 90 void FrameTree::DidNavigateLocally(Frame* source, const GURL& url) { | |
| 91 delegate_->DidNavigateLocally(source, url); | |
| 92 } | |
| 93 | |
| 94 void FrameTree::ClientPropertyChanged(const Frame* source, | |
| 95 const mojo::String& name, | |
| 96 const mojo::Array<uint8_t>& value) { | |
| 97 root_->NotifyClientPropertyChanged(source, name, value); | |
| 98 } | |
| 99 | |
| 100 } // namespace web_view | |
| OLD | NEW |