1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_HISTORY_ITEM_H_
32 #define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_HISTORY_ITEM_H_
33 
34 #include "services/network/public/mojom/referrer_policy.mojom-shared.h"
35 #include "third_party/blink/public/platform/web_common.h"
36 #include "third_party/blink/public/platform/web_history_scroll_restoration_type.h"
37 #include "third_party/blink/public/platform/web_private_ptr.h"
38 #include "third_party/blink/public/platform/web_scroll_anchor_data.h"
39 #include "third_party/blink/public/platform/web_string.h"
40 
41 namespace gfx {
42 class PointF;
43 }  // namespace gfx
44 
45 namespace blink {
46 
47 class HistoryItem;
48 class WebHTTPBody;
49 class WebString;
50 class WebSerializedScriptValue;
51 template <typename T>
52 class WebVector;
53 
54 // Represents a frame-level navigation entry in session history.  A
55 // WebHistoryItem is a node in a tree.
56 //
57 // Copying a WebHistoryItem is cheap.
58 //
59 class WebHistoryItem {
60  public:
~WebHistoryItem()61   ~WebHistoryItem() { Reset(); }
62 
63   WebHistoryItem() = default;
WebHistoryItem(const WebHistoryItem & h)64   WebHistoryItem(const WebHistoryItem& h) { Assign(h); }
65   WebHistoryItem& operator=(const WebHistoryItem& h) {
66     Assign(h);
67     return *this;
68   }
69 
70   BLINK_EXPORT void Initialize();
71   BLINK_EXPORT void Reset();
72   BLINK_EXPORT void Assign(const WebHistoryItem&);
73 
IsNull()74   bool IsNull() const { return private_.IsNull(); }
75 
76   BLINK_EXPORT WebString UrlString() const;
77   BLINK_EXPORT void SetURLString(const WebString&);
78 
79   BLINK_EXPORT WebString GetReferrer() const;
80   BLINK_EXPORT network::mojom::ReferrerPolicy GetReferrerPolicy() const;
81   BLINK_EXPORT void SetReferrer(const WebString&,
82                                 network::mojom::ReferrerPolicy);
83 
84   BLINK_EXPORT const WebString& Target() const;
85   BLINK_EXPORT void SetTarget(const WebString&);
86 
87   BLINK_EXPORT gfx::PointF VisualViewportScrollOffset() const;
88   BLINK_EXPORT void SetVisualViewportScrollOffset(const gfx::PointF&);
89 
90   BLINK_EXPORT gfx::Point GetScrollOffset() const;
91   BLINK_EXPORT void SetScrollOffset(const gfx::Point&);
92 
93   BLINK_EXPORT float PageScaleFactor() const;
94   BLINK_EXPORT void SetPageScaleFactor(float);
95 
96   BLINK_EXPORT WebVector<WebString> GetDocumentState() const;
97   BLINK_EXPORT void SetDocumentState(const WebVector<WebString>&);
98 
99   BLINK_EXPORT int64_t ItemSequenceNumber() const;
100   BLINK_EXPORT void SetItemSequenceNumber(int64_t);
101 
102   BLINK_EXPORT int64_t DocumentSequenceNumber() const;
103   BLINK_EXPORT void SetDocumentSequenceNumber(int64_t);
104 
105   BLINK_EXPORT WebHistoryScrollRestorationType ScrollRestorationType() const;
106   BLINK_EXPORT void SetScrollRestorationType(WebHistoryScrollRestorationType);
107 
108   BLINK_EXPORT WebSerializedScriptValue StateObject() const;
109   BLINK_EXPORT void SetStateObject(const WebSerializedScriptValue&);
110 
111   BLINK_EXPORT WebString HttpContentType() const;
112   BLINK_EXPORT void SetHTTPContentType(const WebString&);
113 
114   BLINK_EXPORT WebHTTPBody HttpBody() const;
115   BLINK_EXPORT void SetHttpBody(const WebHTTPBody&);
116 
117   BLINK_EXPORT WebVector<WebString> GetReferencedFilePaths() const;
118 
119   BLINK_EXPORT bool DidSaveScrollOrScaleState() const;
120 
121   BLINK_EXPORT ScrollAnchorData GetScrollAnchorData() const;
122   BLINK_EXPORT void SetScrollAnchorData(const ScrollAnchorData&);
123 
124 #if INSIDE_BLINK
125   BLINK_EXPORT WebHistoryItem(HistoryItem*);
126   BLINK_EXPORT WebHistoryItem& operator=(HistoryItem*);
127   BLINK_EXPORT operator HistoryItem*() const;
128 #endif
129 
130  private:
131   WebPrivatePtr<HistoryItem> private_;
132   // TODO(dcheng): Remove this, since unique name is no longer a Blink concept.
133   WebString target_;
134 };
135 
136 }  // namespace blink
137 
138 #endif
139