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/content/content_live_tab.h" 6 7 #include <memory> 8 9 #include "base/memory/ptr_util.h" 10 #include "components/sessions/content/content_platform_specific_tab_data.h" 11 #include "third_party/blink/public/common/user_agent/user_agent_metadata.h" 12 13 namespace { 14 const char kContentLiveTabWebContentsUserDataKey[] = "content_live_tab"; 15 } 16 17 namespace sessions { 18 19 // static GetForWebContents(content::WebContents * contents)20ContentLiveTab* ContentLiveTab::GetForWebContents( 21 content::WebContents* contents) { 22 if (!contents->GetUserData(kContentLiveTabWebContentsUserDataKey)) { 23 contents->SetUserData(kContentLiveTabWebContentsUserDataKey, 24 base::WrapUnique(new ContentLiveTab(contents))); 25 } 26 27 return static_cast<ContentLiveTab*>(contents->GetUserData( 28 kContentLiveTabWebContentsUserDataKey)); 29 } 30 ContentLiveTab(content::WebContents * contents)31ContentLiveTab::ContentLiveTab(content::WebContents* contents) 32 : web_contents_(contents) {} 33 ~ContentLiveTab()34ContentLiveTab::~ContentLiveTab() {} 35 IsInitialBlankNavigation()36bool ContentLiveTab::IsInitialBlankNavigation() { 37 return navigation_controller().IsInitialBlankNavigation(); 38 } 39 GetCurrentEntryIndex()40int ContentLiveTab::GetCurrentEntryIndex() { 41 return navigation_controller().GetCurrentEntryIndex(); 42 } 43 GetPendingEntryIndex()44int ContentLiveTab::GetPendingEntryIndex() { 45 return navigation_controller().GetPendingEntryIndex(); 46 } 47 GetEntryAtIndex(int index)48sessions::SerializedNavigationEntry ContentLiveTab::GetEntryAtIndex(int index) { 49 return sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( 50 index, navigation_controller().GetEntryAtIndex(index)); 51 } 52 GetPendingEntry()53sessions::SerializedNavigationEntry ContentLiveTab::GetPendingEntry() { 54 return sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( 55 GetPendingEntryIndex(), navigation_controller().GetPendingEntry()); 56 } 57 GetEntryCount()58int ContentLiveTab::GetEntryCount() { 59 return navigation_controller().GetEntryCount(); 60 } 61 62 std::unique_ptr<sessions::PlatformSpecificTabData> GetPlatformSpecificTabData()63ContentLiveTab::GetPlatformSpecificTabData() { 64 return std::make_unique<sessions::ContentPlatformSpecificTabData>( 65 web_contents()); 66 } 67 GetUserAgentOverride()68const std::string& ContentLiveTab::GetUserAgentOverride() { 69 return web_contents()->GetUserAgentOverride().ua_string_override; 70 } 71 72 } // namespace sessions 73