Commit 1529bc84 authored by blundell's avatar blundell Committed by Commit bot

[sessions] Introduce iOS implementation of LiveTab interface

This CL introduces IOSLiveTab, an iOS-specific implementation of the LiveTab
interface that is backed by WebState (the iOS analogue of WebContents).

BUG=371476

Review URL: https://codereview.chromium.org/1372103002

Cr-Commit-Position: refs/heads/master@{#351100}
parent b076edb7
...@@ -147,6 +147,8 @@ ...@@ -147,6 +147,8 @@
'sources': [ 'sources': [
'<@(sessions_core_sources)', '<@(sessions_core_sources)',
'sessions/ios/ios_live_tab.cc',
'sessions/ios/ios_live_tab.h',
'sessions/ios/ios_serialized_navigation_builder.cc', 'sessions/ios/ios_serialized_navigation_builder.cc',
'sessions/ios/ios_serialized_navigation_builder.h', 'sessions/ios/ios_serialized_navigation_builder.h',
'sessions/ios/ios_serialized_navigation_driver.cc', 'sessions/ios/ios_serialized_navigation_driver.cc',
......
...@@ -41,6 +41,8 @@ if (!is_ios) { ...@@ -41,6 +41,8 @@ if (!is_ios) {
} else { } else {
source_set("sessions") { source_set("sessions") {
sources = [ sources = [
"ios/ios_live_tab.cc",
"ios/ios_live_tab.h",
"ios/ios_serialized_navigation_builder.cc", "ios/ios_serialized_navigation_builder.cc",
"ios/ios_serialized_navigation_builder.h", "ios/ios_serialized_navigation_builder.h",
"ios/ios_serialized_navigation_driver.cc", "ios/ios_serialized_navigation_driver.cc",
......
// 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/sessions/ios/ios_live_tab.h"
#include "ios/web/public/navigation_manager.h"
namespace {
const char kIOSLiveTabWebStateUserDataKey[] = "ios_live_tab";
}
namespace sessions {
std::string IOSLiveTab::user_agent_override_;
// static
IOSLiveTab* IOSLiveTab::GetForWebState(web::WebState* web_state) {
if (!web_state->GetUserData(kIOSLiveTabWebStateUserDataKey)) {
web_state->SetUserData(kIOSLiveTabWebStateUserDataKey,
new IOSLiveTab(web_state));
}
return static_cast<IOSLiveTab*>(
web_state->GetUserData(kIOSLiveTabWebStateUserDataKey));
}
IOSLiveTab::IOSLiveTab(web::WebState* web_state) : web_state_(web_state) {}
IOSLiveTab::~IOSLiveTab() {}
int IOSLiveTab::GetCurrentEntryIndex() {
return navigation_manager()->GetCurrentEntryIndex();
}
int IOSLiveTab::GetPendingEntryIndex() {
return navigation_manager()->GetPendingItemIndex();
}
sessions::SerializedNavigationEntry IOSLiveTab::GetEntryAtIndex(int index) {
return sessions::IOSSerializedNavigationBuilder::FromNavigationItem(
index, *navigation_manager()->GetItemAtIndex(index));
}
sessions::SerializedNavigationEntry IOSLiveTab::GetPendingEntry() {
return sessions::IOSSerializedNavigationBuilder::FromNavigationItem(
GetPendingEntryIndex(), *navigation_manager()->GetPendingItem());
}
int IOSLiveTab::GetEntryCount() {
return navigation_manager()->GetEntryCount();
}
void IOSLiveTab::LoadIfNecessary() {
navigation_manager()->LoadIfNecessary();
}
const std::string& IOSLiveTab::GetUserAgentOverride() const {
// Dynamic user agent overrides are not supported on iOS.
return user_agent_override_;
}
} // namespace sessions
// 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.
#ifndef COMPONENTS_SESSIONS_IOS_IOS_LIVE_TAB_H_
#define COMPONENTS_SESSIONS_IOS_IOS_LIVE_TAB_H_
#include "base/basictypes.h"
#include "base/supports_user_data.h"
#include "components/sessions/core/live_tab.h"
#include "components/sessions/ios/ios_serialized_navigation_builder.h"
#include "ios/web/public/web_state/web_state.h"
namespace content {
class NavigationManager;
class NavigationEntry;
}
namespace sessions {
// An implementation of LiveTab that is backed by web::WebState for use
// on //ios/web-based platforms.
class SESSIONS_EXPORT IOSLiveTab : public LiveTab,
public base::SupportsUserData::Data {
public:
~IOSLiveTab() override;
// Returns the IOSLiveTab associated with |web_state|, creating it if
// it has not already been created.
static IOSLiveTab* GetForWebState(web::WebState* web_state);
// LiveTab:
int GetCurrentEntryIndex() override;
int GetPendingEntryIndex() override;
sessions::SerializedNavigationEntry GetEntryAtIndex(int index) override;
sessions::SerializedNavigationEntry GetPendingEntry() override;
int GetEntryCount() override;
void LoadIfNecessary() override;
const std::string& GetUserAgentOverride() const override;
web::WebState* web_state() { return web_state_; }
const web::WebState* web_state() const { return web_state_; }
private:
friend class base::SupportsUserData;
explicit IOSLiveTab(web::WebState* web_state);
web::NavigationManager* navigation_manager() {
return web_state_->GetNavigationManager();
}
web::WebState* web_state_;
// Needed to return an empty string in GetUserAgentOverride().
static std::string user_agent_override_;
DISALLOW_COPY_AND_ASSIGN(IOSLiveTab);
};
} // namespace sessions
#endif // COMPONENTS_SESSIONS_IOS_IOS_LIVE_TAB_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment