blob: 26f1cb41ea9101dad214490a2dea23cf655726fb [file] [log] [blame]
[email protected]92d457802013-04-01 19:18:491// Copyright (c) 2013 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 "content/renderer/internal_document_state_data.h"
6
avicb129c02017-05-03 06:49:297#include "base/memory/ptr_util.h"
[email protected]92d457802013-04-01 19:18:498#include "content/public/renderer/document_state.h"
Dmitry Gozman0a527132018-09-21 18:01:049#include "content/renderer/navigation_state.h"
Blink Reformata30d4232018-04-07 15:31:0610#include "third_party/blink/public/web/web_document_loader.h"
[email protected]92d457802013-04-01 19:18:4911
12namespace content {
13
14namespace {
15
16// Key InternalDocumentStateData is stored under in DocumentState.
17const char kUserDataKey[] = "InternalDocumentStateData";
18
19}
20
21InternalDocumentStateData::InternalDocumentStateData()
dglazkov821bc332015-08-23 02:15:3222 : http_status_code_(0),
[email protected]e20b88d2013-04-09 15:28:3723 is_overriding_user_agent_(false),
24 must_reset_scroll_and_scale_state_(false),
25 cache_policy_override_set_(false),
Yutaka Hirano458b9132017-10-24 15:17:2126 cache_policy_override_(blink::mojom::FetchCacheMode::kDefault) {}
[email protected]92d457802013-04-01 19:18:4927
28// static
Takeshi Yoshino41b671a2017-08-01 12:17:5129InternalDocumentStateData* InternalDocumentStateData::FromDocumentLoader(
30 blink::WebDocumentLoader* document_loader) {
31 return FromDocumentState(
32 static_cast<DocumentState*>(document_loader->GetExtraData()));
[email protected]e20b88d2013-04-09 15:28:3733}
34
35// static
36InternalDocumentStateData* InternalDocumentStateData::FromDocumentState(
37 DocumentState* ds) {
38 if (!ds)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:2839 return nullptr;
[email protected]92d457802013-04-01 19:18:4940 InternalDocumentStateData* data = static_cast<InternalDocumentStateData*>(
[email protected]e20b88d2013-04-09 15:28:3741 ds->GetUserData(&kUserDataKey));
[email protected]92d457802013-04-01 19:18:4942 if (!data) {
43 data = new InternalDocumentStateData;
avicb129c02017-05-03 06:49:2944 ds->SetUserData(&kUserDataKey, base::WrapUnique(data));
[email protected]92d457802013-04-01 19:18:4945 }
46 return data;
47}
48
49InternalDocumentStateData::~InternalDocumentStateData() {
50}
51
Dmitry Gozman0a527132018-09-21 18:01:0452void InternalDocumentStateData::CopyFrom(InternalDocumentStateData* other) {
53 http_status_code_ = other->http_status_code_;
54 is_overriding_user_agent_ = other->is_overriding_user_agent_;
55 must_reset_scroll_and_scale_state_ =
56 other->must_reset_scroll_and_scale_state_;
57 cache_policy_override_set_ = other->cache_policy_override_set_;
58 cache_policy_override_ = other->cache_policy_override_;
Dmitry Gozman1a2cb242018-12-15 02:51:2959 effective_connection_type_ = other->effective_connection_type_;
Dmitry Gozman2d871962019-01-08 00:05:0260 previews_state_ = other->previews_state_;
Dmitry Gozman00fd5bb2019-01-25 20:25:3361 request_id_ = other->request_id_;
Dmitry Gozman0a527132018-09-21 18:01:0462}
63
64void InternalDocumentStateData::set_navigation_state(
65 std::unique_ptr<NavigationState> navigation_state) {
66 navigation_state_ = std::move(navigation_state);
67}
68
[email protected]92d457802013-04-01 19:18:4969} // namespace content