[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 1 | // 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 | |
avi | cb129c0 | 2017-05-03 06:49:29 | [diff] [blame] | 7 | #include "base/memory/ptr_util.h" |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 8 | #include "content/public/renderer/document_state.h" |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 9 | #include "content/renderer/navigation_state.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 10 | #include "third_party/blink/public/web/web_document_loader.h" |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 11 | |
| 12 | namespace content { |
| 13 | |
| 14 | namespace { |
| 15 | |
| 16 | // Key InternalDocumentStateData is stored under in DocumentState. |
| 17 | const char kUserDataKey[] = "InternalDocumentStateData"; |
| 18 | |
| 19 | } |
| 20 | |
| 21 | InternalDocumentStateData::InternalDocumentStateData() |
dglazkov | 821bc33 | 2015-08-23 02:15:32 | [diff] [blame] | 22 | : http_status_code_(0), |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 23 | is_overriding_user_agent_(false), |
| 24 | must_reset_scroll_and_scale_state_(false), |
| 25 | cache_policy_override_set_(false), |
Yutaka Hirano | 458b913 | 2017-10-24 15:17:21 | [diff] [blame] | 26 | cache_policy_override_(blink::mojom::FetchCacheMode::kDefault) {} |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 27 | |
| 28 | // static |
Takeshi Yoshino | 41b671a | 2017-08-01 12:17:51 | [diff] [blame] | 29 | InternalDocumentStateData* InternalDocumentStateData::FromDocumentLoader( |
| 30 | blink::WebDocumentLoader* document_loader) { |
| 31 | return FromDocumentState( |
| 32 | static_cast<DocumentState*>(document_loader->GetExtraData())); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | // static |
| 36 | InternalDocumentStateData* InternalDocumentStateData::FromDocumentState( |
| 37 | DocumentState* ds) { |
| 38 | if (!ds) |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 39 | return nullptr; |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 40 | InternalDocumentStateData* data = static_cast<InternalDocumentStateData*>( |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 41 | ds->GetUserData(&kUserDataKey)); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 42 | if (!data) { |
| 43 | data = new InternalDocumentStateData; |
avi | cb129c0 | 2017-05-03 06:49:29 | [diff] [blame] | 44 | ds->SetUserData(&kUserDataKey, base::WrapUnique(data)); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 45 | } |
| 46 | return data; |
| 47 | } |
| 48 | |
| 49 | InternalDocumentStateData::~InternalDocumentStateData() { |
| 50 | } |
| 51 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 52 | void 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 Gozman | 1a2cb24 | 2018-12-15 02:51:29 | [diff] [blame] | 59 | effective_connection_type_ = other->effective_connection_type_; |
Dmitry Gozman | 2d87196 | 2019-01-08 00:05:02 | [diff] [blame] | 60 | previews_state_ = other->previews_state_; |
Dmitry Gozman | 00fd5bb | 2019-01-25 20:25:33 | [diff] [blame] | 61 | request_id_ = other->request_id_; |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void InternalDocumentStateData::set_navigation_state( |
| 65 | std::unique_ptr<NavigationState> navigation_state) { |
| 66 | navigation_state_ = std::move(navigation_state); |
| 67 | } |
| 68 | |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 69 | } // namespace content |