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 <WebCore/PageIdentifier.h>
31#include <wtf/Ref.h>
32#include <wtf/WeakPtr.h>
33#include <wtf/text/WTFString.h>
34
35namespace API {
36class Data;
37}
38
39namespace IPC {
40class Decoder;
41class Encoder;
42}
43
44namespace WebKit {
45
46class SuspendedPageProxy;
47
48class WebBackForwardListItem : public API::ObjectImpl<API::Object::Type::BackForwardListItem> {
49public:
50 static Ref<WebBackForwardListItem> create(BackForwardListItemState&&, WebCore::PageIdentifier);
51 virtual ~WebBackForwardListItem();
52
53 static WebBackForwardListItem* itemForID(const WebCore::BackForwardItemIdentifier&);
54 static HashMap<WebCore::BackForwardItemIdentifier, WebBackForwardListItem*>& allItems();
55
56 const WebCore::BackForwardItemIdentifier& itemID() const { return m_itemState.identifier; }
57 const BackForwardListItemState& itemState() { return m_itemState; }
58 WebCore::PageIdentifier pageID() const { return m_pageID; }
59
60 WebCore::ProcessIdentifier lastProcessIdentifier() const { return m_lastProcessIdentifier; }
61 void setLastProcessIdentifier(const WebCore::ProcessIdentifier& identifier) { m_lastProcessIdentifier = identifier; }
62
63 void setPageState(PageState pageState) { m_itemState.pageState = WTFMove(pageState); }
64 const PageState& pageState() const { return m_itemState.pageState; }
65
66 const String& originalURL() const { return m_itemState.pageState.mainFrameState.originalURLString; }
67 const String& url() const { return m_itemState.pageState.mainFrameState.urlString; }
68 const String& title() const { return m_itemState.pageState.title; }
69
70 bool itemIsInSameDocument(const WebBackForwardListItem&) const;
71 bool itemIsClone(const WebBackForwardListItem&);
72
73#if PLATFORM(COCOA) || PLATFORM(GTK)
74 ViewSnapshot* snapshot() const { return m_itemState.snapshot.get(); }
75 void setSnapshot(RefPtr<ViewSnapshot>&& snapshot) { m_itemState.snapshot = WTFMove(snapshot); }
76#endif
77 void setSuspendedPage(SuspendedPageProxy*);
78 SuspendedPageProxy* suspendedPage() const;
79
80#if !LOG_DISABLED
81 const char* loggingString();
82#endif
83
84private:
85 WebBackForwardListItem(BackForwardListItemState&&, WebCore::PageIdentifier);
86
87 void removeSuspendedPageFromProcessPool();
88
89 BackForwardListItemState m_itemState;
90 WebCore::PageIdentifier m_pageID;
91 WebCore::ProcessIdentifier m_lastProcessIdentifier;
92 WeakPtr<SuspendedPageProxy> m_suspendedPage;
93};
94
95typedef Vector<Ref<WebBackForwardListItem>> BackForwardListItemVector;
96
97} // namespace WebKit
98