OLD | NEW |
---|---|
(Empty) | |
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/public/common/page_state.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "third_party/WebKit/Source/Platform/chromium/public/WebHTTPBody.h" | |
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" | |
11 #include "webkit/base/file_path_string_conversions.h" | |
12 #include "webkit/glue/glue_serialize_deprecated.h" | |
13 | |
14 namespace content { | |
15 | |
16 // static | |
17 PageState PageState::CreateFromEncodedData(const std::string& data) { | |
18 return PageState(data); | |
19 } | |
20 | |
21 // static | |
22 PageState PageState::CreateFromURL(const GURL& url) { | |
23 return PageState(webkit_glue::CreateHistoryStateForURL(url)); | |
24 } | |
25 | |
26 // static | |
27 PageState PageState::CreateForTesting( | |
Tom Sepez
2013/05/24 17:46:49
Can this move to the _unittest file? Maybe as a te
| |
28 const GURL& url, | |
29 bool body_contains_password_data, | |
30 const char* optional_body_data, | |
31 const base::FilePath* optional_body_file_path) { | |
32 WebKit::WebHistoryItem history_item; | |
33 history_item.initialize(); | |
34 history_item.setURLString( | |
35 WebKit::WebString::fromUTF8(url.possibly_invalid_spec())); | |
36 if (optional_body_data || optional_body_file_path) { | |
37 WebKit::WebHTTPBody http_body; | |
38 http_body.initialize(); | |
39 http_body.setContainsPasswordData(body_contains_password_data); | |
40 if (optional_body_data) { | |
41 http_body.appendData( | |
42 WebKit::WebData(optional_body_data, strlen(optional_body_data))); | |
43 } | |
44 if (optional_body_file_path) { | |
45 http_body.appendFile( | |
46 webkit_base::FilePathToWebString(*optional_body_file_path)); | |
47 } | |
48 history_item.setHTTPBody(http_body); | |
49 } | |
50 return PageState(webkit_glue::HistoryItemToString(history_item)); | |
51 } | |
52 | |
53 PageState::PageState() { | |
54 } | |
55 | |
56 bool PageState::IsValid() const { | |
57 return !data_.empty(); | |
58 } | |
59 | |
60 bool PageState::Equals(const PageState& other) const { | |
61 return data_ == other.data_; | |
62 } | |
63 | |
64 const std::string& PageState::ToEncodedData() const { | |
65 return data_; | |
66 } | |
67 | |
68 std::vector<base::FilePath> PageState::GetReferencedFiles() const { | |
69 return webkit_glue::FilePathsFromHistoryState(data_); | |
70 } | |
71 | |
72 PageState PageState::RemovePasswordData() const { | |
73 return PageState(webkit_glue::RemovePasswordDataFromHistoryState(data_)); | |
74 } | |
75 | |
76 PageState PageState::RemoveScrollOffset() const { | |
77 return PageState(webkit_glue::RemoveScrollOffsetFromHistoryState(data_)); | |
78 } | |
79 | |
80 PageState::PageState(const std::string& data) | |
81 : data_(data) { | |
82 // TODO(darin): Enable this DCHECK once tests have been fixed up to not pass | |
83 // bogus encoded data to CreateFromEncodedData. | |
84 //DCHECK(IsValid()); | |
85 } | |
86 | |
87 } // namespace content | |
OLD | NEW |