| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/public/common/page_state.h" | 5 #include "content/public/common/page_state.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/common/page_state_serialization.h" | 9 #include "content/common/page_state_serialization.h" |
| 10 #include "content/public/common/referrer.h" | |
| 11 | 10 |
| 12 namespace content { | 11 namespace content { |
| 13 namespace { | 12 namespace { |
| 14 | 13 |
| 15 base::NullableString16 ToNullableString16(const std::string& utf8) { | 14 base::NullableString16 ToNullableString16(const std::string& utf8) { |
| 16 return base::NullableString16(base::UTF8ToUTF16(utf8), false); | 15 return base::NullableString16(base::UTF8ToUTF16(utf8), false); |
| 17 } | 16 } |
| 18 | 17 |
| 19 base::FilePath ToFilePath(const base::NullableString16& s) { | 18 base::FilePath ToFilePath(const base::NullableString16& s) { |
| 20 return base::FilePath::FromUTF16Unsafe(s.string()); | 19 return base::FilePath::FromUTF16Unsafe(s.string()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 49 void RecursivelyRemoveReferrer(ExplodedFrameState* state) { | 48 void RecursivelyRemoveReferrer(ExplodedFrameState* state) { |
| 50 state->referrer = base::NullableString16(); | 49 state->referrer = base::NullableString16(); |
| 51 state->referrer_policy = blink::WebReferrerPolicyDefault; | 50 state->referrer_policy = blink::WebReferrerPolicyDefault; |
| 52 for (std::vector<ExplodedFrameState>::iterator it = state->children.begin(); | 51 for (std::vector<ExplodedFrameState>::iterator it = state->children.begin(); |
| 53 it != state->children.end(); | 52 it != state->children.end(); |
| 54 ++it) { | 53 ++it) { |
| 55 RecursivelyRemoveReferrer(&*it); | 54 RecursivelyRemoveReferrer(&*it); |
| 56 } | 55 } |
| 57 } | 56 } |
| 58 | 57 |
| 59 bool RecursivelyCheckReferrer(ExplodedFrameState* state) { | |
| 60 Referrer referrer(GURL(state->referrer.string()), state->referrer_policy); | |
| 61 GURL url(state->url_string.string()); | |
| 62 if (url.SchemeIsHTTPOrHTTPS() && | |
| 63 Referrer::SanitizeForRequest(url, referrer).url != referrer.url) { | |
| 64 LOG(ERROR) << "Referrer for request to " << url << " is " << referrer.url | |
| 65 << " but should be " | |
| 66 << Referrer::SanitizeForRequest(url, referrer).url; | |
| 67 return false; | |
| 68 } | |
| 69 for (std::vector<ExplodedFrameState>::iterator it = state->children.begin(); | |
| 70 it != state->children.end(); | |
| 71 ++it) { | |
| 72 if (!RecursivelyCheckReferrer(&*it)) | |
| 73 return false; | |
| 74 } | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 } // namespace | 58 } // namespace |
| 79 | 59 |
| 80 // static | 60 // static |
| 81 PageState PageState::CreateFromEncodedData(const std::string& data) { | 61 PageState PageState::CreateFromEncodedData(const std::string& data) { |
| 82 return PageState(data); | 62 return PageState(data); |
| 83 } | 63 } |
| 84 | 64 |
| 85 // static | 65 // static |
| 86 PageState PageState::CreateFromURL(const GURL& url) { | 66 PageState PageState::CreateFromURL(const GURL& url) { |
| 87 ExplodedPageState state; | 67 ExplodedPageState state; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 body_contains_password_data; | 101 body_contains_password_data; |
| 122 } | 102 } |
| 123 | 103 |
| 124 return ToPageState(state); | 104 return ToPageState(state); |
| 125 } | 105 } |
| 126 | 106 |
| 127 PageState::PageState() { | 107 PageState::PageState() { |
| 128 } | 108 } |
| 129 | 109 |
| 130 bool PageState::IsValid() const { | 110 bool PageState::IsValid() const { |
| 131 if (data_.empty()) | 111 return !data_.empty(); |
| 132 return false; | |
| 133 | |
| 134 ExplodedPageState state; | |
| 135 // This should return false, but tests create invalid page state. | |
| 136 if (!DecodePageState(data_, &state)) | |
| 137 return true; | |
| 138 | |
| 139 // TODO(jochen): Remove referrer check once http://crbug.com/450589 is fixed. | |
| 140 return RecursivelyCheckReferrer(&state.top); | |
| 141 } | 112 } |
| 142 | 113 |
| 143 bool PageState::Equals(const PageState& other) const { | 114 bool PageState::Equals(const PageState& other) const { |
| 144 return data_ == other.data_; | 115 return data_ == other.data_; |
| 145 } | 116 } |
| 146 | 117 |
| 147 const std::string& PageState::ToEncodedData() const { | 118 const std::string& PageState::ToEncodedData() const { |
| 148 return data_; | 119 return data_; |
| 149 } | 120 } |
| 150 | 121 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 163 } |
| 193 | 164 |
| 194 PageState::PageState(const std::string& data) | 165 PageState::PageState(const std::string& data) |
| 195 : data_(data) { | 166 : data_(data) { |
| 196 // TODO(darin): Enable this DCHECK once tests have been fixed up to not pass | 167 // TODO(darin): Enable this DCHECK once tests have been fixed up to not pass |
| 197 // bogus encoded data to CreateFromEncodedData. | 168 // bogus encoded data to CreateFromEncodedData. |
| 198 //DCHECK(IsValid()); | 169 //DCHECK(IsValid()); |
| 199 } | 170 } |
| 200 | 171 |
| 201 } // namespace content | 172 } // namespace content |
| OLD | NEW |