1/*
2 * Copyright (C) 2010 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 "FrameLoadState.h"
30#include "GenericCallback.h"
31#include "WebFramePolicyListenerProxy.h"
32#include <WebCore/FrameLoaderTypes.h>
33#include <wtf/Forward.h>
34#include <wtf/Function.h>
35#include <wtf/text/WTFString.h>
36
37#if ENABLE(CONTENT_FILTERING)
38#include <WebCore/ContentFilterUnblockHandler.h>
39#endif
40
41namespace API {
42class Navigation;
43}
44
45namespace IPC {
46class Connection;
47class Decoder;
48}
49
50namespace WebKit {
51class SafeBrowsingWarning;
52class WebCertificateInfo;
53class WebFramePolicyListenerProxy;
54class WebPageProxy;
55class WebsiteDataStore;
56enum class ShouldExpectSafeBrowsingResult;
57enum class ProcessSwapRequestedByClient;
58struct WebsitePoliciesData;
59
60typedef GenericCallback<API::Data*> DataCallback;
61
62class WebFrameProxy : public API::ObjectImpl<API::Object::Type::Frame> {
63public:
64 static Ref<WebFrameProxy> create(WebPageProxy& page, uint64_t frameID)
65 {
66 return adoptRef(*new WebFrameProxy(page, frameID));
67 }
68
69 virtual ~WebFrameProxy();
70
71 uint64_t frameID() const { return m_frameID; }
72 WebPageProxy* page() const;
73
74 void webProcessWillShutDown();
75
76 bool isMainFrame() const;
77
78 void setIsFrameSet(bool value) { m_isFrameSet = value; }
79 bool isFrameSet() const { return m_isFrameSet; }
80
81 FrameLoadState& frameLoadState() { return m_frameLoadState; }
82
83 void loadURL(const URL&);
84 // Sub frames only. For main frames, use WebPageProxy::loadData.
85 void loadData(const IPC::DataReference&, const String& MIMEType, const String& encodingName, const URL& baseURL);
86 void stopLoading() const;
87
88 const URL& url() const { return m_frameLoadState.url(); }
89 const URL& provisionalURL() const { return m_frameLoadState.provisionalURL(); }
90
91 void setUnreachableURL(const URL&);
92 const URL& unreachableURL() const { return m_frameLoadState.unreachableURL(); }
93
94 const String& mimeType() const { return m_MIMEType; }
95 bool containsPluginDocument() const { return m_containsPluginDocument; }
96
97 const String& title() const { return m_title; }
98
99 WebCertificateInfo* certificateInfo() const { return m_certificateInfo.get(); }
100
101 bool canProvideSource() const;
102 bool canShowMIMEType(const String& mimeType) const;
103
104 bool isDisplayingStandaloneImageDocument() const;
105 bool isDisplayingStandaloneMediaDocument() const;
106 bool isDisplayingMarkupDocument() const;
107 bool isDisplayingPDFDocument() const;
108
109 void getWebArchive(Function<void (API::Data*, CallbackBase::Error)>&&);
110 void getMainResourceData(Function<void (API::Data*, CallbackBase::Error)>&&);
111 void getResourceData(API::URL*, Function<void (API::Data*, CallbackBase::Error)>&&);
112
113 void didStartProvisionalLoad(const URL&);
114 void didExplicitOpen(const URL&);
115 void didReceiveServerRedirectForProvisionalLoad(const URL&);
116 void didFailProvisionalLoad();
117 void didCommitLoad(const String& contentType, WebCertificateInfo&, bool containsPluginDocument);
118 void didFinishLoad();
119 void didFailLoad();
120 void didSameDocumentNavigation(const URL&); // eg. anchor navigation, session state change.
121 void didChangeTitle(const String&);
122
123 WebFramePolicyListenerProxy& setUpPolicyListenerProxy(CompletionHandler<void(WebCore::PolicyAction, API::WebsitePolicies*, ProcessSwapRequestedByClient, RefPtr<SafeBrowsingWarning>&&)>&&, ShouldExpectSafeBrowsingResult);
124
125#if ENABLE(CONTENT_FILTERING)
126 void contentFilterDidBlockLoad(WebCore::ContentFilterUnblockHandler contentFilterUnblockHandler) { m_contentFilterUnblockHandler = WTFMove(contentFilterUnblockHandler); }
127 bool didHandleContentFilterUnblockNavigation(const WebCore::ResourceRequest&);
128#endif
129
130#if PLATFORM(GTK)
131 void collapseSelection();
132#endif
133
134private:
135 WebFrameProxy(WebPageProxy&, uint64_t frameID);
136
137 WeakPtr<WebPageProxy> m_page;
138
139 FrameLoadState m_frameLoadState;
140
141 String m_MIMEType;
142 String m_title;
143 bool m_isFrameSet;
144 bool m_containsPluginDocument { false };
145 RefPtr<WebCertificateInfo> m_certificateInfo;
146 RefPtr<WebFramePolicyListenerProxy> m_activeListener;
147 uint64_t m_frameID;
148#if ENABLE(CONTENT_FILTERING)
149 WebCore::ContentFilterUnblockHandler m_contentFilterUnblockHandler;
150#endif
151};
152
153} // namespace WebKit
154