blob: c908555bc889a1a19247db0106c549cd676f30f8 [file] [log] [blame]
clamy1e5574e2016-09-29 16:48:441// Copyright 2016 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 "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
6
7#include "base/memory/ptr_util.h"
John Abd-El-Malekd2377982018-01-08 22:23:128#include "chrome/browser/prerender/prerender_contents.h"
9#include "chrome/browser/prerender/prerender_histograms.h"
clamy1e5574e2016-09-29 16:48:4410#include "chrome/browser/sessions/session_tab_helper.h"
11#include "content/public/browser/navigation_handle.h"
brettw00899e62016-11-12 02:10:1712#include "extensions/features/features.h"
clamy1e5574e2016-09-29 16:48:4413
14ChromeNavigationUIData::ChromeNavigationUIData() {}
15
16ChromeNavigationUIData::ChromeNavigationUIData(
17 content::NavigationHandle* navigation_handle) {
John Abd-El-Malekd2377982018-01-08 22:23:1218 auto* web_contents = navigation_handle->GetWebContents();
brettw00899e62016-11-12 02:10:1719#if BUILDFLAG(ENABLE_EXTENSIONS)
clamy1e5574e2016-09-29 16:48:4420 SessionTabHelper* session_tab_helper =
John Abd-El-Malekd2377982018-01-08 22:23:1221 SessionTabHelper::FromWebContents(web_contents);
clamy1e5574e2016-09-29 16:48:4422 int tab_id = session_tab_helper ? session_tab_helper->session_id().id() : -1;
23 int window_id =
24 session_tab_helper ? session_tab_helper->window_id().id() : -1;
25 extension_data_ = base::MakeUnique<extensions::ExtensionNavigationUIData>(
26 navigation_handle, tab_id, window_id);
27#endif
John Abd-El-Malekd2377982018-01-08 22:23:1228
29 auto* prerender_contents =
30 prerender::PrerenderContents::FromWebContents(web_contents);
31 if (prerender_contents) {
32 prerender_mode_ = prerender_contents->prerender_mode();
33 prerender_histogram_prefix_ =
34 prerender::PrerenderHistograms::GetHistogramPrefix(
35 prerender_contents->origin());
36 }
clamy1e5574e2016-09-29 16:48:4437}
38
39ChromeNavigationUIData::~ChromeNavigationUIData() {}
40
41std::unique_ptr<content::NavigationUIData> ChromeNavigationUIData::Clone()
42 const {
43 std::unique_ptr<ChromeNavigationUIData> copy =
44 base::MakeUnique<ChromeNavigationUIData>();
45
brettw00899e62016-11-12 02:10:1746#if BUILDFLAG(ENABLE_EXTENSIONS)
clamy1e5574e2016-09-29 16:48:4447 if (extension_data_)
48 copy->SetExtensionNavigationUIData(extension_data_->DeepCopy());
49#endif
50
Jian Li18173422017-11-08 03:00:0251#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
52 if (offline_page_data_)
53 copy->SetOfflinePageNavigationUIData(offline_page_data_->DeepCopy());
54#endif
55
John Abd-El-Malekd2377982018-01-08 22:23:1256 copy->prerender_mode_ = prerender_mode_;
57 copy->prerender_histogram_prefix_ = prerender_histogram_prefix_;
58
clamy1e5574e2016-09-29 16:48:4459 return std::move(copy);
60}
61
brettw00899e62016-11-12 02:10:1762#if BUILDFLAG(ENABLE_EXTENSIONS)
clamy1e5574e2016-09-29 16:48:4463void ChromeNavigationUIData::SetExtensionNavigationUIData(
64 std::unique_ptr<extensions::ExtensionNavigationUIData> extension_data) {
65 extension_data_ = std::move(extension_data);
66}
67#endif
Jian Li18173422017-11-08 03:00:0268
69#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
70void ChromeNavigationUIData::SetOfflinePageNavigationUIData(
71 std::unique_ptr<offline_pages::OfflinePageNavigationUIData>
72 offline_page_data) {
73 offline_page_data_ = std::move(offline_page_data);
74}
75#endif