#include "chrome/browser/history/history_tab_helper.h"
#include <optional>
#include <string>
#include "build/build_config.h"
#include "chrome/browser/complex_tasks/task_tab_helper.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history_clusters/history_clusters_tab_helper.h"
#include "chrome/browser/history_embeddings/history_embeddings_tab_helper.h"
#include "chrome/browser/preloading/prefetch/no_state_prefetch/no_state_prefetch_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "components/history/content/browser/history_context_helper.h"
#include "components/history/core/browser/history_constants.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/history_types.h"
#include "components/history/core/browser/url_row.h"
#include "components/no_state_prefetch/browser/no_state_prefetch_manager.h"
#include "components/sessions/content/navigation_task_id.h"
#include "components/sessions/content/session_tab_helper.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "net/http/http_response_headers.h"
#include "ui/base/page_transition_types.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/jni_string.h"
#include "chrome/browser/android/background_tab_manager.h"
#include "chrome/browser/feed/feed_service_factory.h"
#include "chrome/browser/flags/android/chrome_session_state.h"
#include "chrome/browser/history/jni_headers/HistoryTabHelper_jni.h"
#include "chrome/browser/ui/android/tab_model/tab_model.h"
#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
#include "components/feed/core/v2/public/feed_api.h"
#include "components/feed/core/v2/public/feed_service.h"
#include "content/public/browser/web_contents.h"
#else
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#endif
namespace {
NavigationEntry;
WebContents;
#if BUILDFLAG(IS_ANDROID)
using chrome::android::BackgroundTabManager;
#endif
#if BUILDFLAG(IS_ANDROID)
bool IsNavigationFromFeed(content::WebContents& web_contents, const GURL& url) {
feed::FeedService* feed_service =
feed::FeedServiceFactory::GetForBrowserContext(
web_contents.GetBrowserContext());
if (!feed_service)
return false;
return feed_service->GetStream()->WasUrlRecentlyNavigatedFromFeed(url);
}
#endif
bool ShouldConsiderForNtpMostVisited(
content::WebContents& web_contents,
content::NavigationHandle* navigation_handle) { … }
std::optional<history::Opener> GetHistoryOpenerFromOpenerWebContents(
base::WeakPtr<content::WebContents> opener_web_contents) { … }
history::VisitContextAnnotations::BrowserType GetBrowserType(
WebContents* web_contents) { … }
history::VisitContentAnnotations::PasswordState
ConvertSessionsPasswordStateToHistory(
sessions::SerializedNavigationEntry::PasswordState password_state) { … }
}
HistoryTabHelper::HistoryTabHelper(WebContents* web_contents)
: … { … }
HistoryTabHelper::~HistoryTabHelper() = default;
void HistoryTabHelper::UpdateHistoryForNavigation(
const history::HistoryAddPageArgs& add_page_args) { … }
history::HistoryAddPageArgs HistoryTabHelper::CreateHistoryAddPageArgs(
const GURL& virtual_url,
base::Time timestamp,
int nav_entry_id,
content::NavigationHandle* navigation_handle) { … }
void HistoryTabHelper::OnPasswordStateUpdated(
sessions::SerializedNavigationEntry::PasswordState password_state) { … }
void HistoryTabHelper::DidFinishNavigation(
content::NavigationHandle* navigation_handle) { … }
void HistoryTabHelper::DidFinishLoad(
content::RenderFrameHost* render_frame_host,
const GURL& validated_url) { … }
void HistoryTabHelper::DidOpenRequestedURL(
content::WebContents* new_contents,
content::RenderFrameHost* source_render_frame_host,
const GURL& url,
const content::Referrer& referrer,
WindowOpenDisposition disposition,
ui::PageTransition transition,
bool started_from_context_menu,
bool renderer_initiated) { … }
void HistoryTabHelper::OnLanguageDetermined(
const translate::LanguageDetectionDetails& details) { … }
void HistoryTabHelper::TitleWasSet(NavigationEntry* entry) { … }
history::HistoryService* HistoryTabHelper::GetHistoryService() { … }
void HistoryTabHelper::WebContentsDestroyed() { … }
bool HistoryTabHelper::IsEligibleTab(
const history::HistoryAddPageArgs& add_page_args) const { … }
#if BUILDFLAG(IS_ANDROID)
static void JNI_HistoryTabHelper_SetAppIdNative(
JNIEnv* env,
const base::android::JavaParamRef<jstring>& japp_id,
const base::android::JavaParamRef<jobject>& jweb_contents) {
auto* web_contents = content::WebContents::FromJavaWebContents(jweb_contents);
auto* history_tab_helper = HistoryTabHelper::FromWebContents(web_contents);
history_tab_helper->SetAppId(base::android::ConvertJavaStringToUTF8(japp_id));
}
#endif
WEB_CONTENTS_USER_DATA_KEY_IMPL(HistoryTabHelper);