blob: f8b5f9794ace8fab6bcbfe0820d6ef5d36556589 (
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
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
|
// 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 "ios/chrome/browser/sync/ios_chrome_synced_tab_delegate.h"
#include "base/memory/ref_counted.h"
#include "components/sessions/ios/ios_serialized_navigation_builder.h"
#include "components/sync_sessions/sync_sessions_client.h"
#include "components/sync_sessions/synced_window_delegate.h"
#include "components/sync_sessions/synced_window_delegates_getter.h"
#include "ios/chrome/browser/sessions/ios_chrome_session_tab_helper.h"
#include "ios/web/public/favicon_status.h"
#include "ios/web/public/navigation_item.h"
#include "ios/web/public/navigation_manager.h"
#include "ios/web/public/web_state/web_state.h"
using web::NavigationItem;
DEFINE_WEB_STATE_USER_DATA_KEY(IOSChromeSyncedTabDelegate);
namespace {
// Helper to access the correct NavigationItem, accounting for pending entries.
NavigationItem* GetPossiblyPendingItemAtIndex(web::WebState* web_state, int i) {
int pending_index = web_state->GetNavigationManager()->GetPendingItemIndex();
return (pending_index == i)
? web_state->GetNavigationManager()->GetPendingItem()
: web_state->GetNavigationManager()->GetItemAtIndex(i);
}
} // namespace
IOSChromeSyncedTabDelegate::IOSChromeSyncedTabDelegate(web::WebState* web_state)
: web_state_(web_state), sync_session_id_(0) {}
IOSChromeSyncedTabDelegate::~IOSChromeSyncedTabDelegate() {}
SessionID::id_type IOSChromeSyncedTabDelegate::GetWindowId() const {
return IOSChromeSessionTabHelper::FromWebState(web_state_)->window_id().id();
}
SessionID::id_type IOSChromeSyncedTabDelegate::GetSessionId() const {
return IOSChromeSessionTabHelper::FromWebState(web_state_)->session_id().id();
}
bool IOSChromeSyncedTabDelegate::IsBeingDestroyed() const {
return web_state_->IsBeingDestroyed();
}
std::string IOSChromeSyncedTabDelegate::GetExtensionAppId() const {
return std::string();
}
bool IOSChromeSyncedTabDelegate::IsInitialBlankNavigation() const {
return web_state_->GetNavigationManager()->GetItemCount() == 0;
}
int IOSChromeSyncedTabDelegate::GetCurrentEntryIndex() const {
return web_state_->GetNavigationManager()->GetCurrentItemIndex();
}
int IOSChromeSyncedTabDelegate::GetEntryCount() const {
return web_state_->GetNavigationManager()->GetItemCount();
}
GURL IOSChromeSyncedTabDelegate::GetVirtualURLAtIndex(int i) const {
NavigationItem* item = GetPossiblyPendingItemAtIndex(web_state_, i);
return item ? item->GetVirtualURL() : GURL();
}
GURL IOSChromeSyncedTabDelegate::GetFaviconURLAtIndex(int i) const {
NavigationItem* item = GetPossiblyPendingItemAtIndex(web_state_, i);
return (item->GetFavicon().valid ? item->GetFavicon().url : GURL());
}
ui::PageTransition IOSChromeSyncedTabDelegate::GetTransitionAtIndex(
int i) const {
NavigationItem* item = GetPossiblyPendingItemAtIndex(web_state_, i);
return item->GetTransitionType();
}
void IOSChromeSyncedTabDelegate::GetSerializedNavigationAtIndex(
int i,
sessions::SerializedNavigationEntry* serialized_entry) const {
NavigationItem* item = GetPossiblyPendingItemAtIndex(web_state_, i);
*serialized_entry =
sessions::IOSSerializedNavigationBuilder::FromNavigationItem(i, *item);
}
bool IOSChromeSyncedTabDelegate::ProfileIsSupervised() const {
return false;
}
const std::vector<const sessions::SerializedNavigationEntry*>*
IOSChromeSyncedTabDelegate::GetBlockedNavigations() const {
NOTREACHED();
return nullptr;
}
bool IOSChromeSyncedTabDelegate::IsPlaceholderTab() const {
return false;
}
int IOSChromeSyncedTabDelegate::GetSyncId() const {
return sync_session_id_;
}
void IOSChromeSyncedTabDelegate::SetSyncId(int sync_id) {
sync_session_id_ = sync_id;
}
bool IOSChromeSyncedTabDelegate::ShouldSync(
sync_sessions::SyncSessionsClient* sessions_client) {
if (sessions_client->GetSyncedWindowDelegatesGetter()->FindById(
GetWindowId()) == nullptr)
return false;
if (IsInitialBlankNavigation())
return false; // This deliberately ignores a new pending entry.
int entry_count = GetEntryCount();
for (int i = 0; i < entry_count; ++i) {
const GURL& virtual_url = GetVirtualURLAtIndex(i);
if (!virtual_url.is_valid())
continue;
if (sessions_client->ShouldSyncURL(virtual_url))
return true;
}
return false;
}
|