| 1 | /* |
| 2 | * Copyright (C) 2006-2018 Apple Inc. All rights reserved. |
| 3 | * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
| 15 | * its contributors may be used to endorse or promote products derived |
| 16 | * from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #pragma once |
| 31 | |
| 32 | #include "FrameLoaderTypes.h" |
| 33 | #include "ResourceRequest.h" |
| 34 | #include <wtf/WeakPtr.h> |
| 35 | #include <wtf/text/WTFString.h> |
| 36 | |
| 37 | #if ENABLE(CONTENT_FILTERING) |
| 38 | #include "ContentFilterUnblockHandler.h" |
| 39 | #endif |
| 40 | |
| 41 | namespace WTF { |
| 42 | template<typename> class CompletionHandler; |
| 43 | class CompletionHandlerCallingScope; |
| 44 | } |
| 45 | |
| 46 | namespace WebCore { |
| 47 | |
| 48 | class DocumentLoader; |
| 49 | class FormState; |
| 50 | class Frame; |
| 51 | class NavigationAction; |
| 52 | class ResourceError; |
| 53 | class ResourceResponse; |
| 54 | |
| 55 | enum class ShouldContinue { |
| 56 | Yes, |
| 57 | No |
| 58 | }; |
| 59 | |
| 60 | enum class NavigationPolicyDecision : uint8_t { |
| 61 | ContinueLoad, |
| 62 | IgnoreLoad, |
| 63 | StopAllLoads, |
| 64 | }; |
| 65 | |
| 66 | enum class PolicyDecisionMode { Synchronous, Asynchronous }; |
| 67 | |
| 68 | using NewWindowPolicyDecisionFunction = CompletionHandler<void(const ResourceRequest&, WeakPtr<FormState>&&, const String& frameName, const NavigationAction&, ShouldContinue)>; |
| 69 | using NavigationPolicyDecisionFunction = CompletionHandler<void(ResourceRequest&&, WeakPtr<FormState>&&, NavigationPolicyDecision)>; |
| 70 | |
| 71 | class PolicyChecker { |
| 72 | WTF_MAKE_NONCOPYABLE(PolicyChecker); |
| 73 | WTF_MAKE_FAST_ALLOCATED; |
| 74 | public: |
| 75 | explicit PolicyChecker(Frame&); |
| 76 | |
| 77 | void checkNavigationPolicy(ResourceRequest&&, const ResourceResponse& redirectResponse, DocumentLoader*, RefPtr<FormState>&&, NavigationPolicyDecisionFunction&&, PolicyDecisionMode = PolicyDecisionMode::Asynchronous); |
| 78 | void checkNavigationPolicy(ResourceRequest&&, const ResourceResponse& redirectResponse, NavigationPolicyDecisionFunction&&); |
| 79 | void checkNewWindowPolicy(NavigationAction&&, ResourceRequest&&, RefPtr<FormState>&&, const String& frameName, NewWindowPolicyDecisionFunction&&); |
| 80 | |
| 81 | void stopCheck(); |
| 82 | |
| 83 | void cannotShowMIMEType(const ResourceResponse&); |
| 84 | |
| 85 | FrameLoadType loadType() const { return m_loadType; } |
| 86 | void setLoadType(FrameLoadType loadType) { m_loadType = loadType; } |
| 87 | |
| 88 | bool delegateIsDecidingNavigationPolicy() const { return m_delegateIsDecidingNavigationPolicy; } |
| 89 | bool delegateIsHandlingUnimplementablePolicy() const { return m_delegateIsHandlingUnimplementablePolicy; } |
| 90 | |
| 91 | #if ENABLE(CONTENT_FILTERING) |
| 92 | void setContentFilterUnblockHandler(ContentFilterUnblockHandler unblockHandler) { m_contentFilterUnblockHandler = WTFMove(unblockHandler); } |
| 93 | #endif |
| 94 | |
| 95 | private: |
| 96 | void handleUnimplementablePolicy(const ResourceError&); |
| 97 | WTF::CompletionHandlerCallingScope extendBlobURLLifetimeIfNecessary(ResourceRequest&) const; |
| 98 | |
| 99 | Frame& m_frame; |
| 100 | |
| 101 | bool m_delegateIsDecidingNavigationPolicy; |
| 102 | bool m_delegateIsHandlingUnimplementablePolicy; |
| 103 | |
| 104 | // This identifies the type of navigation action which prompted this load. Note |
| 105 | // that WebKit conveys this value as the WebActionNavigationTypeKey value |
| 106 | // on navigation action delegate callbacks. |
| 107 | FrameLoadType m_loadType; |
| 108 | |
| 109 | #if ENABLE(CONTENT_FILTERING) |
| 110 | ContentFilterUnblockHandler m_contentFilterUnblockHandler; |
| 111 | #endif |
| 112 | }; |
| 113 | |
| 114 | } // namespace WebCore |
| 115 | |