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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
// Copyright 2016 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 "services/navigation/public/cpp/view.h"
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#include "services/navigation/public/cpp/view_delegate.h"
#include "services/navigation/public/cpp/view_observer.h"
#include "ui/aura/mus/window_port_mus.h"
#include "ui/aura/window.h"
namespace navigation {
namespace {
// Callback with result of Embed().
void EmbedCallback(bool result) {}
} // namespace
////////////////////////////////////////////////////////////////////////////////
// View, public:
View::View(mojom::ViewFactoryPtr factory) : binding_(this) {
mojom::ViewClientPtr client;
binding_.Bind(MakeRequest(&client));
factory->CreateView(std::move(client), MakeRequest(&view_));
}
View::View(mojom::ViewPtr view, mojom::ViewClientRequest request)
: view_(std::move(view)), binding_(this, std::move(request)) {}
View::~View() {}
void View::AddObserver(ViewObserver* observer) {
observers_.AddObserver(observer);
}
void View::RemoveObserver(ViewObserver* observer) {
observers_.RemoveObserver(observer);
}
void View::NavigateToURL(const GURL& url) {
view_->NavigateTo(url);
}
void View::NavigateToOffset(int offset) {
view_->NavigateToOffset(offset);
}
void View::GoBack() {
if (can_go_back_)
view_->GoBack();
}
void View::GoForward() {
if (can_go_forward_)
view_->GoForward();
}
void View::GetBackMenuItems(std::vector<NavigationListItem>* items) {
DCHECK(items);
for (int i = navigation_list_cursor_ - 1, offset = -1; i >= 0;
--i, --offset) {
items->push_back(NavigationListItem(
base::UTF8ToUTF16(navigation_list_[i]->title), offset));
}
}
void View::GetForwardMenuItems(std::vector<NavigationListItem>* items) {
DCHECK(items);
for (int i = navigation_list_cursor_ + 1, offset = 1;
i < static_cast<int>(navigation_list_.size()); ++i, ++offset) {
items->push_back(NavigationListItem(
base::UTF8ToUTF16(navigation_list_[i]->title), offset));
}
}
void View::Reload(bool bypass_cache) {
view_->Reload(bypass_cache);
}
void View::Stop() {
view_->Stop();
}
void View::ShowInterstitial(const std::string& html) {
view_->ShowInterstitial(html);
}
void View::HideInterstitial() {
view_->HideInterstitial();
}
void View::EmbedInWindow(aura::Window* parent) {
ui::mojom::WindowTreeClientPtr client;
view_->GetWindowTreeClient(MakeRequest(&client));
const uint32_t embed_flags = 0u; // Nothing special.
aura::WindowPortMus::Get(parent)->Embed(std::move(client), embed_flags,
base::Bind(&EmbedCallback));
}
////////////////////////////////////////////////////////////////////////////////
// View, mojom::ViewClient implementation:
void View::OpenURL(mojom::OpenURLParamsPtr params) {
if (delegate_)
delegate_->OpenURL(this, std::move(params));
}
void View::LoadingStateChanged(bool is_loading) {
is_loading_ = is_loading;
for (auto& observer : observers_)
observer.LoadingStateChanged(this);
}
void View::NavigationStateChanged(const GURL& url,
const std::string& title,
bool can_go_back,
bool can_go_forward) {
url_ = url;
title_ = base::UTF8ToUTF16(title);
can_go_back_ = can_go_back;
can_go_forward_ = can_go_forward;
for (auto& observer : observers_)
observer.NavigationStateChanged(this);
}
void View::LoadProgressChanged(double progress) {
for (auto& observer : observers_)
observer.LoadProgressChanged(this, progress);
}
void View::UpdateHoverURL(const GURL& url) {
for (auto& observer : observers_)
observer.HoverTargetURLChanged(this, url);
}
void View::ViewCreated(mojom::ViewPtr view,
mojom::ViewClientRequest request,
bool is_popup,
const gfx::Rect& initial_bounds,
bool user_gesture) {
if (delegate_) {
delegate_->ViewCreated(
this, base::WrapUnique(new View(std::move(view), std::move(request))),
is_popup, initial_bounds, user_gesture);
}
}
void View::Close() {
if (delegate_)
delegate_->Close(this);
}
void View::NavigationPending(mojom::NavigationEntryPtr entry) {
pending_navigation_ = std::move(entry);
}
void View::NavigationCommitted(mojom::NavigationCommittedDetailsPtr details,
int current_index) {
switch (details->type) {
case mojom::NavigationType::NEW_PAGE:
navigation_list_.push_back(std::move(pending_navigation_));
navigation_list_cursor_ = current_index;
break;
case mojom::NavigationType::EXISTING_PAGE:
navigation_list_cursor_ = current_index;
break;
default:
break;
}
}
void View::NavigationEntryChanged(mojom::NavigationEntryPtr entry,
int entry_index) {
navigation_list_[entry_index] = std::move(entry);
}
void View::NavigationListPruned(bool from_front, int count) {
DCHECK(count < static_cast<int>(navigation_list_.size()));
if (from_front) {
auto it = navigation_list_.begin() + count;
navigation_list_.erase(navigation_list_.begin(), it);
} else {
auto it = navigation_list_.end() - count;
navigation_list_.erase(it, navigation_list_.end());
}
}
} // namespace navigation
|