1/*
2 * Copyright (C) 2010-2011, 2016 Apple 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
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "APIObject.h"
29#include "SessionState.h"
30#include <wtf/Ref.h>
31#include <wtf/WeakPtr.h>
32#include <wtf/text/WTFString.h>
33
34namespace API {
35class Data;
36}
37
38namespace IPC {
39class Decoder;
40class Encoder;
41}
42
43namespace WebKit {
44
45class SuspendedPageProxy;
46
47class WebBackForwardListItem : public API::ObjectImpl<API::Object::Type::BackForwardListItem> {
48public:
49 static Ref<WebBackForwardListItem> create(BackForwardListItemState&&, uint64_t pageID);
50 virtual ~WebBackForwardListItem();
51
52 static WebBackForwardListItem* itemForID(const WebCore::BackForwardItemIdentifier&);
53 static HashMap<WebCore::BackForwardItemIdentifier, WebBackForwardListItem*>& allItems();
54
55 const WebCore::BackForwardItemIdentifier& itemID() const { return m_itemState.identifier; }
56 const BackForwardListItemState& itemState() { return m_itemState; }
57 uint64_t pageID() const { return m_pageID; }
58
59 WebCore::ProcessIdentifier lastProcessIdentifier() const { return m_lastProcessIdentifier; }
60 void setLastProcessIdentifier(const WebCore::ProcessIdentifier& identifier) { m_lastProcessIdentifier = identifier; }
61
62 void setPageState(PageState pageState) { m_itemState.pageState = WTFMove(pageState); }
63 const PageState& pageState() const { return m_itemState.pageState; }
64
65 const String& originalURL() const { return m_itemState.pageState.mainFrameState.originalURLString; }
66 const String& url() const { return m_itemState.pageState.mainFrameState.urlString; }
67 const String& title() const { return m_itemState.pageState.title; }
68
69 bool itemIsInSameDocument(const WebBackForwardListItem&) const;
70 bool itemIsClone(const WebBackForwardListItem&);
71
72#if PLATFORM(COCOA) || PLATFORM(GTK)
73 ViewSnapshot* snapshot() const { return m_itemState.snapshot.get(); }
74 void setSnapshot(RefPtr<ViewSnapshot>&& snapshot) { m_itemState.snapshot = WTFMove(snapshot); }
75#endif
76 void setSuspendedPage(SuspendedPageProxy*);
77 SuspendedPageProxy* suspendedPage() const { return m_suspendedPage.get(); }
78
79#if !LOG_DISABLED
80 const char* loggingString();
81#endif
82
83private:
84 explicit WebBackForwardListItem(BackForwardListItemState&&, uint64_t pageID);
85
86 void removeSuspendedPageFromProcessPool();
87
88 BackForwardListItemState m_itemState;
89 uint64_t m_pageID;
90 WebCore::ProcessIdentifier m_lastProcessIdentifier;
91 WeakPtr<SuspendedPageProxy> m_suspendedPage;
92};
93
94typedef Vector<Ref<WebBackForwardListItem>> BackForwardListItemVector;
95
96} // namespace WebKit
97