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/sessions/ios/ios_live_tab.h" |
| 6 #include "ios/web/public/navigation_manager.h" |
| 7 |
| 8 namespace { |
| 9 const char kIOSLiveTabWebStateUserDataKey[] = "ios_live_tab"; |
| 10 } |
| 11 |
| 12 namespace sessions { |
| 13 |
| 14 std::string IOSLiveTab::user_agent_override_; |
| 15 |
| 16 // static |
| 17 IOSLiveTab* IOSLiveTab::GetForWebState(web::WebState* web_state) { |
| 18 if (!web_state->GetUserData(kIOSLiveTabWebStateUserDataKey)) { |
| 19 web_state->SetUserData(kIOSLiveTabWebStateUserDataKey, |
| 20 new IOSLiveTab(web_state)); |
| 21 } |
| 22 |
| 23 return static_cast<IOSLiveTab*>( |
| 24 web_state->GetUserData(kIOSLiveTabWebStateUserDataKey)); |
| 25 } |
| 26 |
| 27 IOSLiveTab::IOSLiveTab(web::WebState* web_state) : web_state_(web_state) {} |
| 28 |
| 29 IOSLiveTab::~IOSLiveTab() {} |
| 30 |
| 31 int IOSLiveTab::GetCurrentEntryIndex() { |
| 32 return navigation_manager()->GetCurrentEntryIndex(); |
| 33 } |
| 34 |
| 35 int IOSLiveTab::GetPendingEntryIndex() { |
| 36 return navigation_manager()->GetPendingItemIndex(); |
| 37 } |
| 38 |
| 39 sessions::SerializedNavigationEntry IOSLiveTab::GetEntryAtIndex(int index) { |
| 40 return sessions::IOSSerializedNavigationBuilder::FromNavigationItem( |
| 41 index, *navigation_manager()->GetItemAtIndex(index)); |
| 42 } |
| 43 |
| 44 sessions::SerializedNavigationEntry IOSLiveTab::GetPendingEntry() { |
| 45 return sessions::IOSSerializedNavigationBuilder::FromNavigationItem( |
| 46 GetPendingEntryIndex(), *navigation_manager()->GetPendingItem()); |
| 47 } |
| 48 |
| 49 int IOSLiveTab::GetEntryCount() { |
| 50 return navigation_manager()->GetEntryCount(); |
| 51 } |
| 52 |
| 53 void IOSLiveTab::LoadIfNecessary() { |
| 54 navigation_manager()->LoadIfNecessary(); |
| 55 } |
| 56 |
| 57 const std::string& IOSLiveTab::GetUserAgentOverride() const { |
| 58 // Dynamic user agent overrides are not supported on iOS. |
| 59 return user_agent_override_; |
| 60 } |
| 61 |
| 62 } // namespace sessions |
OLD | NEW |