Unreviewed, fix iOS build with recent SDKs.
[WebKit-https.git] / Source / WebKit / UIProcess / API / Cocoa / WKNavigationAction.mm
1 /*
2  * Copyright (C) 2014 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 #import "config.h"
27 #import "WKNavigationActionInternal.h"
28
29 #import "NavigationActionData.h"
30 #import "WKFrameInfoInternal.h"
31 #import "WKNavigationInternal.h"
32 #import "WebEventFactory.h"
33 #import "_WKUserInitiatedActionInternal.h"
34 #import <WebCore/FloatPoint.h>
35 #import <wtf/RetainPtr.h>
36
37 #if PLATFORM(IOS_FAMILY)
38 #import "WebIOSEventFactory.h"
39 #endif
40
41 @implementation WKNavigationAction
42
43 static WKNavigationType toWKNavigationType(WebCore::NavigationType navigationType)
44 {
45     switch (navigationType) {
46     case WebCore::NavigationType::LinkClicked:
47         return WKNavigationTypeLinkActivated;
48     case WebCore::NavigationType::FormSubmitted:
49         return WKNavigationTypeFormSubmitted;
50     case WebCore::NavigationType::BackForward:
51         return WKNavigationTypeBackForward;
52     case WebCore::NavigationType::Reload:
53         return WKNavigationTypeReload;
54     case WebCore::NavigationType::FormResubmitted:
55         return WKNavigationTypeFormResubmitted;
56     case WebCore::NavigationType::Other:
57         return WKNavigationTypeOther;
58     }
59
60     ASSERT_NOT_REACHED();
61     return WKNavigationTypeOther;
62 }
63
64 #if PLATFORM(IOS_FAMILY)
65 static WKSyntheticClickType toWKSyntheticClickType(WebKit::WebMouseEvent::SyntheticClickType syntheticClickType)
66 {
67     switch (syntheticClickType) {
68     case WebKit::WebMouseEvent::NoTap:
69         return WKSyntheticClickTypeNoTap;
70     case WebKit::WebMouseEvent::OneFingerTap:
71         return WKSyntheticClickTypeOneFingerTap;
72     case WebKit::WebMouseEvent::TwoFingerTap:
73         return WKSyntheticClickTypeTwoFingerTap;
74     }
75     ASSERT_NOT_REACHED();
76     return WKSyntheticClickTypeNoTap;
77 }
78 #endif
79
80 - (void)dealloc
81 {
82     _navigationAction->~NavigationAction();
83
84     [super dealloc];
85 }
86
87 - (NSString *)description
88 {
89     return [NSString stringWithFormat:@"<%@: %p; navigationType = %ld; syntheticClickType = %ld; position x = %.2f y = %.2f request = %@; sourceFrame = %@; targetFrame = %@>", NSStringFromClass(self.class), self,
90         (long)self.navigationType,
91 #if PLATFORM(IOS_FAMILY)
92         (long)self._syntheticClickType, self._clickLocationInRootViewCoordinates.x, self._clickLocationInRootViewCoordinates.y,
93 #else
94         0L, 0.0, 0.0,
95 #endif
96         self.request, self.sourceFrame, self.targetFrame];
97 }
98
99 - (WKFrameInfo *)sourceFrame
100 {
101     return wrapper(_navigationAction->sourceFrame());
102 }
103
104 - (WKFrameInfo *)targetFrame
105 {
106     return wrapper(_navigationAction->targetFrame());
107 }
108
109 - (WKNavigationType)navigationType
110 {
111     return toWKNavigationType(_navigationAction->navigationType());
112 }
113
114 - (NSURLRequest *)request
115 {
116     return _navigationAction->request().nsURLRequest(WebCore::HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody);
117 }
118
119 #if PLATFORM(IOS_FAMILY)
120 - (WKSyntheticClickType)_syntheticClickType
121 {
122     return toWKSyntheticClickType(_navigationAction->syntheticClickType());
123 }
124
125 - (CGPoint)_clickLocationInRootViewCoordinates
126 {
127     return _navigationAction->clickLocationInRootViewCoordinates();
128 }
129 #endif
130
131 #if PLATFORM(MAC)
132
133 - (NSEventModifierFlags)modifierFlags
134 {
135     return WebKit::WebEventFactory::toNSEventModifierFlags(_navigationAction->modifiers());
136 }
137
138 - (NSInteger)buttonNumber
139 {
140     return WebKit::WebEventFactory::toNSButtonNumber(_navigationAction->mouseButton());
141 }
142
143 #else
144
145 - (UIKeyModifierFlags)modifierFlags
146 {
147     return WebIOSEventFactory::toUIKeyModifierFlags(_navigationAction->modifiers());
148 }
149
150 #endif
151
152 #pragma mark WKObject protocol implementation
153
154 - (API::Object&)_apiObject
155 {
156     return *_navigationAction;
157 }
158
159 @end
160
161 @implementation WKNavigationAction (WKPrivate)
162
163 - (NSURL *)_originalURL
164 {
165     return _navigationAction->originalURL();
166 }
167
168 - (BOOL)_isUserInitiated
169 {
170     return _navigationAction->isProcessingUserGesture();
171 }
172
173 - (BOOL)_canHandleRequest
174 {
175     return _navigationAction->canHandleRequest();
176 }
177
178 - (BOOL)_shouldOpenExternalSchemes
179 {
180     return _navigationAction->shouldOpenExternalSchemes();
181 }
182
183 - (BOOL)_shouldOpenAppLinks
184 {
185     return _navigationAction->shouldOpenAppLinks();
186 }
187
188 - (BOOL)_shouldPerformDownload
189 {
190     return _navigationAction->shouldPerformDownload();
191 }
192
193 - (BOOL)_shouldOpenExternalURLs
194 {
195     return [self _shouldOpenExternalSchemes];
196 }
197
198 - (_WKUserInitiatedAction *)_userInitiatedAction
199 {
200     return wrapper(_navigationAction->userInitiatedAction());
201 }
202
203 - (BOOL)_isRedirect
204 {
205     return _navigationAction->isRedirect();
206 }
207
208 - (WKNavigation *)_mainFrameNavigation
209 {
210     return wrapper(_navigationAction->mainFrameNavigation());
211 }
212
213 @end