| 1 | /* |
| 2 | * Copyright (C) 2015-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 "APIFrameInfo.h" |
| 29 | #include "APINavigation.h" |
| 30 | #include "APIObject.h" |
| 31 | #include "APIUserInitiatedAction.h" |
| 32 | #include "NavigationActionData.h" |
| 33 | #include <WebCore/ResourceRequest.h> |
| 34 | #include <wtf/URL.h> |
| 35 | |
| 36 | #if USE(APPLE_INTERNAL_SDK) |
| 37 | #include <WebKitAdditions/APINavigationActionAdditions.h> |
| 38 | #endif |
| 39 | |
| 40 | namespace API { |
| 41 | |
| 42 | class NavigationAction final : public ObjectImpl<Object::Type::NavigationAction> { |
| 43 | public: |
| 44 | template<typename... Args> static Ref<NavigationAction> create(Args&&... args) |
| 45 | { |
| 46 | return adoptRef(*new NavigationAction(std::forward<Args>(args)...)); |
| 47 | } |
| 48 | |
| 49 | FrameInfo* sourceFrame() const { return m_sourceFrame.get(); } |
| 50 | FrameInfo* targetFrame() const { return m_targetFrame.get(); } |
| 51 | Optional<WTF::String> targetFrameName() const { return m_targetFrameName; } |
| 52 | |
| 53 | const WebCore::ResourceRequest& request() const { return m_request; } |
| 54 | const WTF::URL& originalURL() const { return !m_originalURL.isNull() ? m_originalURL : m_request.url(); } |
| 55 | |
| 56 | WebCore::NavigationType navigationType() const { return m_navigationActionData.navigationType; } |
| 57 | OptionSet<WebKit::WebEvent::Modifier> modifiers() const { return m_navigationActionData.modifiers; } |
| 58 | WebKit::WebMouseEvent::Button mouseButton() const { return m_navigationActionData.mouseButton; } |
| 59 | WebKit::WebMouseEvent::SyntheticClickType syntheticClickType() const { return m_navigationActionData.syntheticClickType; } |
| 60 | WebCore::FloatPoint clickLocationInRootViewCoordinates() const { return m_navigationActionData.clickLocationInRootViewCoordinates; } |
| 61 | bool canHandleRequest() const { return m_navigationActionData.canHandleRequest; } |
| 62 | bool shouldOpenExternalSchemes() const { return m_navigationActionData.shouldOpenExternalURLsPolicy == WebCore::ShouldOpenExternalURLsPolicy::ShouldAllow || m_navigationActionData.shouldOpenExternalURLsPolicy == WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes; } |
| 63 | bool shouldOpenAppLinks() const { return m_shouldOpenAppLinks && m_navigationActionData.shouldOpenExternalURLsPolicy == WebCore::ShouldOpenExternalURLsPolicy::ShouldAllow; } |
| 64 | bool shouldPerformDownload() const { return !m_navigationActionData.downloadAttribute.isNull(); } |
| 65 | bool isRedirect() const { return m_navigationActionData.isRedirect; } |
| 66 | |
| 67 | bool isProcessingUserGesture() const { return m_userInitiatedAction; } |
| 68 | UserInitiatedAction* userInitiatedAction() const { return m_userInitiatedAction.get(); } |
| 69 | |
| 70 | Navigation* mainFrameNavigation() const { return m_mainFrameNavigation.get(); } |
| 71 | |
| 72 | #if HAVE(LOAD_OPTIMIZER) |
| 73 | APINAVIGATIONACTION_LOADOPTIMIZER_ADDITIONS_1 |
| 74 | #endif |
| 75 | |
| 76 | private: |
| 77 | NavigationAction(WebKit::NavigationActionData&& navigationActionData, API::FrameInfo* sourceFrame, API::FrameInfo* targetFrame, Optional<WTF::String> targetFrameName, WebCore::ResourceRequest&& request, const WTF::URL& originalURL, bool shouldOpenAppLinks, RefPtr<UserInitiatedAction>&& userInitiatedAction, API::Navigation* mainFrameNavigation) |
| 78 | : m_sourceFrame(sourceFrame) |
| 79 | , m_targetFrame(targetFrame) |
| 80 | , m_targetFrameName(targetFrameName) |
| 81 | , m_request(WTFMove(request)) |
| 82 | , m_originalURL(originalURL) |
| 83 | , m_shouldOpenAppLinks(shouldOpenAppLinks) |
| 84 | , m_userInitiatedAction(WTFMove(userInitiatedAction)) |
| 85 | , m_navigationActionData(WTFMove(navigationActionData)) |
| 86 | , m_mainFrameNavigation(mainFrameNavigation) |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | NavigationAction(WebKit::NavigationActionData&& navigationActionData, API::FrameInfo* sourceFrame, API::FrameInfo* targetFrame, Optional<WTF::String> targetFrameName, WebCore::ResourceRequest&& request, const WTF::URL& originalURL, bool shouldOpenAppLinks, RefPtr<UserInitiatedAction>&& userInitiatedAction) |
| 91 | : NavigationAction(WTFMove(navigationActionData), sourceFrame, targetFrame, targetFrameName, WTFMove(request), originalURL, shouldOpenAppLinks, WTFMove(userInitiatedAction), nullptr) |
| 92 | { |
| 93 | } |
| 94 | |
| 95 | RefPtr<FrameInfo> m_sourceFrame; |
| 96 | RefPtr<FrameInfo> m_targetFrame; |
| 97 | Optional<WTF::String> m_targetFrameName; |
| 98 | |
| 99 | WebCore::ResourceRequest m_request; |
| 100 | WTF::URL m_originalURL; |
| 101 | |
| 102 | bool m_shouldOpenAppLinks; |
| 103 | #if HAVE(LOAD_OPTIMIZER) |
| 104 | APINAVIGATIONACTION_LOADOPTIMIZER_ADDITIONS_2 |
| 105 | #endif |
| 106 | |
| 107 | RefPtr<UserInitiatedAction> m_userInitiatedAction; |
| 108 | |
| 109 | WebKit::NavigationActionData m_navigationActionData; |
| 110 | RefPtr<Navigation> m_mainFrameNavigation; |
| 111 | }; |
| 112 | |
| 113 | } // namespace API |
| 114 | |