Changeset 164258 in webkit
- Timestamp:
- Feb 17, 2014 4:44:31 PM (10 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 1 added
- 7 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r164256 r164258 1 2014-02-17 Anders Carlsson <andersca@apple.com> 2 3 Add history delegate to WKWebView 4 https://bugs.webkit.org/show_bug.cgi?id=128930 5 6 Reviewed by Dan Bernstein. 7 8 * UIProcess/API/Cocoa/WKHistoryDelegatePrivate.h: Copied from Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h. 9 * UIProcess/API/Cocoa/WKProcessClass.mm: 10 (-[WKProcessClass initWithConfiguration:]): 11 * UIProcess/API/Cocoa/WKWebView.mm: 12 (-[WKWebView _historyDelegate]): 13 (-[WKWebView _setHistoryDelegate:]): 14 * UIProcess/API/Cocoa/WKWebViewPrivate.h: 15 * UIProcess/Cocoa/HistoryClient.h: Copied from Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h. 16 * UIProcess/Cocoa/HistoryClient.mm: Added. 17 (WebKit::HistoryClient::HistoryClient): 18 (WebKit::HistoryClient::~HistoryClient): 19 (WebKit::HistoryClient::didNavigateWithNavigationData): 20 (WebKit::HistoryClient::didPerformClientRedirect): 21 (WebKit::HistoryClient::didPerformServerRedirect): 22 (WebKit::HistoryClient::didUpdateHistoryTitle): 23 (WebKit::HistoryClient::populateVisitedLinks): 24 (WebKit::HistoryClient::shouldTrackVisitedLinks): 25 * UIProcess/Cocoa/NavigationState.h: 26 * UIProcess/Cocoa/NavigationState.mm: 27 (WebKit::navigationStates): 28 (WebKit::NavigationState::NavigationState): 29 (WebKit::NavigationState::~NavigationState): 30 (WebKit::NavigationState::fromWebPage): 31 (WebKit::NavigationState::historyDelegate): 32 (WebKit::NavigationState::setHistoryDelegate): 33 (WebKit::NavigationState::didNavigateWithNavigationData): 34 (WebKit::NavigationState::didPerformClientRedirect): 35 (WebKit::NavigationState::didPerformServerRedirect): 36 (WebKit::NavigationState::didUpdateHistoryTitle): 37 * WebKit2.xcodeproj/project.pbxproj: 38 1 39 2014-02-17 Sam Weinig <sam@webkit.org> 2 40 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKHistoryDelegatePrivate.h
r164257 r164258 24 24 */ 25 25 26 #import <WebKit2/WK WebView.h>26 #import <WebKit2/WKFoundation.h> 27 27 28 28 #if WK_API_ENABLED 29 29 30 typedef NS_OPTIONS(NSUInteger, _WKRenderingProgressEvents) { 31 _WKRenderingProgressEventFirstLayout = 1 << 0, 32 _WKRenderingProgressEventFirstPaintWithSignificantArea = 1 << 2, 33 }; 30 #import <Foundation/Foundation.h> 34 31 35 @class WK BrowsingContextHandle;36 @class WK RemoteObjectRegistry;32 @class WKNavigationData; 33 @class WKWebView; 37 34 38 @ interface WKWebView (WKPrivate)35 @protocol WKHistoryDelegatePrivate <NSObject> 39 36 40 @property (nonatomic, readonly) WKRemoteObjectRegistry *_remoteObjectRegistry; 41 @property (nonatomic, readonly) WKBrowsingContextHandle *_handle; 42 43 @property (nonatomic, setter=_setObservedRenderingProgressEvents:) _WKRenderingProgressEvents _observedRenderingProgressEvents; 44 45 #if TARGET_OS_IPHONE 46 @property (nonatomic, setter=_setMinimumLayoutSizeOverride:) CGSize _minimumLayoutSizeOverride; 47 48 // Define the inset of the scrollview unusable by the web page. 49 @property (nonatomic, setter=_setObscuredInsets:) UIEdgeInsets _obscuredInsets; 50 51 - (void)_beginInteractiveObscuredInsetsChange; 52 - (void)_endInteractiveObscuredInsetsChange; 53 #endif 37 - (void)_webView:(WKWebView *)webView didNavigateWithNavigationData:(WKNavigationData *)navigationData; 38 - (void)_webView:(WKWebView *)webView didPerformClientRedirectFromURL:(NSURL *)sourceURL toURL:(NSURL *)destinationURL; 39 - (void)_webView:(WKWebView *)webView didPerformServerRedirectFromURL:(NSURL *)sourceURL toURL:(NSURL *)destinationURL; 40 - (void)_webView:(WKWebView *)webView didUpdateHistoryTitle:(NSString *)title forURL:(NSURL *)URL; 54 41 55 42 @end -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessClass.mm
r162876 r164258 29 29 #if WK_API_ENABLED 30 30 31 #import "HistoryClient.h" 31 32 #import "WKObject.h" 32 33 #import "WKProcessClassConfigurationPrivate.h" … … 66 67 67 68 API::Object::constructInWrapper<WebKit::WebContext>(self, bundlePath); 69 _context->setHistoryClient(std::make_unique<WebKit::HistoryClient>()); 68 70 69 71 return self; -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
r164120 r164258 36 36 #import "WKBackForwardListItemInternal.h" 37 37 #import "WKBrowsingContextHandleInternal.h" 38 #import "WKHistoryDelegatePrivate.h" 38 39 #import "WKNavigationDelegate.h" 39 40 #import "WKNavigationInternal.h" … … 462 463 } 463 464 465 - (id <WKHistoryDelegatePrivate>)_historyDelegate 466 { 467 return [_navigationState->historyDelegate().leakRef() autorelease]; 468 } 469 470 - (void)_setHistoryDelegate:(id <WKHistoryDelegatePrivate>)historyDelegate 471 { 472 _navigationState->setHistoryDelegate(historyDelegate); 473 } 474 464 475 static inline WebCore::LayoutMilestones layoutMilestones(_WKRenderingProgressEvents events) 465 476 { -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
r164109 r164258 35 35 @class WKBrowsingContextHandle; 36 36 @class WKRemoteObjectRegistry; 37 @protocol WKHistoryDelegatePrivate; 37 38 38 39 @interface WKWebView (WKPrivate) … … 42 43 43 44 @property (nonatomic, setter=_setObservedRenderingProgressEvents:) _WKRenderingProgressEvents _observedRenderingProgressEvents; 45 46 @property (nonatomic, weak, setter=_setHistoryDelegate:) id <WKHistoryDelegatePrivate> _historyDelegate; 44 47 45 48 #if TARGET_OS_IPHONE -
trunk/Source/WebKit2/UIProcess/Cocoa/HistoryClient.h
r164257 r164258 24 24 */ 25 25 26 #import <WebKit2/WKWebView.h> 26 #ifndef HistoryClient_h 27 #define HistoryClient_h 28 29 #import "WKFoundation.h" 27 30 28 31 #if WK_API_ENABLED 29 32 30 typedef NS_OPTIONS(NSUInteger, _WKRenderingProgressEvents) { 31 _WKRenderingProgressEventFirstLayout = 1 << 0, 32 _WKRenderingProgressEventFirstPaintWithSignificantArea = 1 << 2, 33 #import "APIHistoryClient.h" 34 35 namespace WebKit { 36 37 class HistoryClient : public API::HistoryClient { 38 public: 39 HistoryClient(); 40 ~HistoryClient(); 41 42 private: 43 // API::HistoryClient 44 virtual void didNavigateWithNavigationData(WebContext*, WebPageProxy*, const WebNavigationDataStore&, WebFrameProxy*) override; 45 virtual void didPerformClientRedirect(WebContext*, WebPageProxy*, const WTF::String& sourceURL, const WTF::String& destinationURL, WebFrameProxy*) override; 46 virtual void didPerformServerRedirect(WebContext*, WebPageProxy*, const WTF::String& sourceURL, const WTF::String& destinationURL, WebFrameProxy*) override; 47 virtual void didUpdateHistoryTitle(WebContext*, WebPageProxy*, const WTF::String& title, const WTF::String& url, WebFrameProxy*) override; 48 virtual void populateVisitedLinks(WebContext*) override; 49 virtual bool shouldTrackVisitedLinks() const override; 33 50 }; 34 51 35 @class WKBrowsingContextHandle; 36 @class WKRemoteObjectRegistry; 52 } // namespace WebKit 37 53 38 @interface WKWebView (WKPrivate) 54 #endif // WK_API_ENABLED 39 55 40 @property (nonatomic, readonly) WKRemoteObjectRegistry *_remoteObjectRegistry; 41 @property (nonatomic, readonly) WKBrowsingContextHandle *_handle; 42 43 @property (nonatomic, setter=_setObservedRenderingProgressEvents:) _WKRenderingProgressEvents _observedRenderingProgressEvents; 44 45 #if TARGET_OS_IPHONE 46 @property (nonatomic, setter=_setMinimumLayoutSizeOverride:) CGSize _minimumLayoutSizeOverride; 47 48 // Define the inset of the scrollview unusable by the web page. 49 @property (nonatomic, setter=_setObscuredInsets:) UIEdgeInsets _obscuredInsets; 50 51 - (void)_beginInteractiveObscuredInsetsChange; 52 - (void)_endInteractiveObscuredInsetsChange; 53 #endif 54 55 @end 56 57 #endif 56 #endif // HistoryClient_h -
trunk/Source/WebKit2/UIProcess/Cocoa/NavigationState.h
r164146 r164258 40 40 @class WKNavigation; 41 41 @class WKWebView; 42 @protocol WKHistoryDelegatePrivate; 42 43 @protocol WKNavigationDelegate; 43 44 44 45 namespace WebKit { 46 47 struct WebNavigationDataStore; 45 48 46 49 class NavigationState : private PageLoadState::Observer { … … 48 51 explicit NavigationState(WKWebView *); 49 52 ~NavigationState(); 53 54 static NavigationState& fromWebPage(WebPageProxy&); 50 55 51 56 std::unique_ptr<API::PolicyClient> createPolicyClient(); … … 55 60 void setNavigationDelegate(id <WKNavigationDelegate>); 56 61 62 RetainPtr<id <WKHistoryDelegatePrivate> > historyDelegate(); 63 void setHistoryDelegate(id <WKHistoryDelegatePrivate>); 64 57 65 RetainPtr<WKNavigation> createLoadRequestNavigation(uint64_t navigationID, NSURLRequest *); 66 67 // Called by the history client. 68 void didNavigateWithNavigationData(const WebKit::WebNavigationDataStore&); 69 void didPerformClientRedirect(const WTF::String& sourceURL, const WTF::String& destinationURL); 70 void didPerformServerRedirect(const WTF::String& sourceURL, const WTF::String& destinationURL); 71 void didUpdateHistoryTitle(const WTF::String& title, const WTF::String& url); 58 72 59 73 private: … … 126 140 127 141 HashMap<uint64_t, RetainPtr<WKNavigation>> m_navigations; 142 143 WeakObjCPtr<id <WKHistoryDelegatePrivate> > m_historyDelegate; 144 struct { 145 bool webViewDidNavigateWithNavigationData : 1; 146 bool webViewDidPerformClientRedirectFromURLToURL : 1; 147 bool webViewDidPerformServerRedirectFromURLToURL : 1; 148 bool webViewDidUpdateHistoryTitleForURL : 1; 149 } m_historyDelegateMethods; 128 150 }; 129 151 -
trunk/Source/WebKit2/UIProcess/Cocoa/NavigationState.mm
r164146 r164258 29 29 #if WK_API_ENABLED 30 30 31 #import "APINavigationData.h" 32 #import "APIURL.h" 33 #import "APIString.h" 31 34 #import "NavigationActionData.h" 32 35 #import "PageLoadState.h" … … 34 37 #import "WKBackForwardListItemInternal.h" 35 38 #import "WKFrameInfoInternal.h" 39 #import "WKHistoryDelegatePrivate.h" 36 40 #import "WKNSURLAuthenticationChallenge.h" 41 #import "WKNSURLExtras.h" 37 42 #import "WKNSURLProtectionSpace.h" 38 43 #import "WKNavigationActionInternal.h" 44 #import "WKNavigationDataInternal.h" 39 45 #import "WKNavigationDelegatePrivate.h" 40 46 #import "WKNavigationInternal.h" … … 43 49 #import "WebFrameProxy.h" 44 50 #import "WebPageProxy.h" 51 #import <wtf/NeverDestroyed.h> 45 52 46 53 namespace WebKit { 54 55 static HashMap<WebPageProxy*, NavigationState*>& navigationStates() 56 { 57 static NeverDestroyed<HashMap<WebPageProxy*, NavigationState*>> navigationStates; 58 59 return navigationStates; 60 } 47 61 48 62 NavigationState::NavigationState(WKWebView *webView) 49 63 : m_webView(webView) 50 64 , m_navigationDelegateMethods() 65 , m_historyDelegateMethods() 51 66 { 52 67 ASSERT(m_webView->_page); 53 68 ASSERT(!navigationStates().contains(m_webView->_page.get())); 69 70 navigationStates().add(m_webView->_page.get(), this); 54 71 m_webView->_page->pageLoadState().addObserver(*this); 55 72 } … … 57 74 NavigationState::~NavigationState() 58 75 { 76 ASSERT(navigationStates().get(m_webView->_page.get()) == this); 77 78 navigationStates().remove(m_webView->_page.get()); 59 79 m_webView->_page->pageLoadState().removeObserver(*this); 80 } 81 82 NavigationState& NavigationState::fromWebPage(WebPageProxy& webPageProxy) 83 { 84 ASSERT(navigationStates().contains(&webPageProxy)); 85 86 return *navigationStates().get(&webPageProxy); 60 87 } 61 88 … … 95 122 } 96 123 124 RetainPtr<id <WKHistoryDelegatePrivate> > NavigationState::historyDelegate() 125 { 126 return m_historyDelegate.get(); 127 } 128 129 void NavigationState::setHistoryDelegate(id <WKHistoryDelegatePrivate> historyDelegate) 130 { 131 m_historyDelegate = historyDelegate; 132 133 m_historyDelegateMethods.webViewDidNavigateWithNavigationData = [historyDelegate respondsToSelector:@selector(_webView:didNavigateWithNavigationData:)]; 134 m_historyDelegateMethods.webViewDidPerformClientRedirectFromURLToURL = [historyDelegate respondsToSelector:@selector(_webView:didPerformClientRedirectFromURL:toURL:)]; 135 m_historyDelegateMethods.webViewDidPerformServerRedirectFromURLToURL = [historyDelegate respondsToSelector:@selector(_webView:didPerformServerRedirectFromURL:toURL:)]; 136 m_historyDelegateMethods.webViewDidUpdateHistoryTitleForURL = [historyDelegate respondsToSelector:@selector(_webView:didUpdateHistoryTitle:forURL:)]; 137 } 138 97 139 RetainPtr<WKNavigation> NavigationState::createLoadRequestNavigation(uint64_t navigationID, NSURLRequest *request) 98 140 { … … 106 148 107 149 return navigation; 150 } 151 152 void NavigationState::didNavigateWithNavigationData(const WebKit::WebNavigationDataStore& navigationDataStore) 153 { 154 if (!m_historyDelegateMethods.webViewDidNavigateWithNavigationData) 155 return; 156 157 auto historyDelegate = m_historyDelegate.get(); 158 if (!historyDelegate) 159 return; 160 161 [historyDelegate _webView:m_webView didNavigateWithNavigationData:wrapper(*API::NavigationData::create(navigationDataStore))]; 162 } 163 164 void NavigationState::didPerformClientRedirect(const WTF::String& sourceURL, const WTF::String& destinationURL) 165 { 166 if (!m_historyDelegateMethods.webViewDidPerformClientRedirectFromURLToURL) 167 return; 168 169 auto historyDelegate = m_historyDelegate.get(); 170 if (!historyDelegate) 171 return; 172 173 [historyDelegate _webView:m_webView didPerformClientRedirectFromURL:[NSURL _web_URLWithWTFString:sourceURL] toURL:[NSURL _web_URLWithWTFString:destinationURL]]; 174 } 175 176 void NavigationState::didPerformServerRedirect(const WTF::String& sourceURL, const WTF::String& destinationURL) 177 { 178 if (!m_historyDelegateMethods.webViewDidPerformServerRedirectFromURLToURL) 179 return; 180 181 auto historyDelegate = m_historyDelegate.get(); 182 if (!historyDelegate) 183 return; 184 185 [historyDelegate _webView:m_webView didPerformServerRedirectFromURL:[NSURL _web_URLWithWTFString:sourceURL] toURL:[NSURL _web_URLWithWTFString:destinationURL]]; 186 } 187 188 void NavigationState::didUpdateHistoryTitle(const WTF::String& title, const WTF::String& url) 189 { 190 if (!m_historyDelegateMethods.webViewDidUpdateHistoryTitleForURL) 191 return; 192 193 auto historyDelegate = m_historyDelegate.get(); 194 if (!historyDelegate) 195 return; 196 197 [historyDelegate _webView:m_webView didUpdateHistoryTitle:title forURL:[NSURL _web_URLWithWTFString:url]]; 108 198 } 109 199 -
trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
r164256 r164258 165 165 1A3EED0F161A535400AEB4F5 /* MessageReceiverMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A3EED0D161A535300AEB4F5 /* MessageReceiverMap.h */; }; 166 166 1A3EED12161A53D600AEB4F5 /* MessageReceiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A3EED11161A53D600AEB4F5 /* MessageReceiver.h */; }; 167 1A422F8B18B29B5400D8CD96 /* WKHistoryDelegatePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A422F8A18B29B5400D8CD96 /* WKHistoryDelegatePrivate.h */; settings = {ATTRIBUTES = (Private, ); }; }; 168 1A422F8E18B29C6400D8CD96 /* HistoryClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A422F8C18B29C6400D8CD96 /* HistoryClient.mm */; }; 169 1A422F8F18B29C6400D8CD96 /* HistoryClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A422F8D18B29C6400D8CD96 /* HistoryClient.h */; }; 167 170 1A433F0D113C53DD00FACDE9 /* WebErrors.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A433F0C113C53DD00FACDE9 /* WebErrors.h */; }; 168 171 1A43E829188F3CDC009E4D30 /* WKProcessClassConfiguration.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A43E827188F3CDC009E4D30 /* WKProcessClassConfiguration.mm */; }; … … 1829 1832 1A3EED0D161A535300AEB4F5 /* MessageReceiverMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageReceiverMap.h; sourceTree = "<group>"; }; 1830 1833 1A3EED11161A53D600AEB4F5 /* MessageReceiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageReceiver.h; sourceTree = "<group>"; }; 1834 1A422F8A18B29B5400D8CD96 /* WKHistoryDelegatePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKHistoryDelegatePrivate.h; sourceTree = "<group>"; }; 1835 1A422F8C18B29C6400D8CD96 /* HistoryClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = HistoryClient.mm; sourceTree = "<group>"; }; 1836 1A422F8D18B29C6400D8CD96 /* HistoryClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HistoryClient.h; sourceTree = "<group>"; }; 1831 1837 1A433F0C113C53DD00FACDE9 /* WebErrors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebErrors.h; sourceTree = "<group>"; }; 1832 1838 1A43E827188F3CDC009E4D30 /* WKProcessClassConfiguration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKProcessClassConfiguration.mm; sourceTree = "<group>"; }; … … 4024 4030 isa = PBXGroup; 4025 4031 children = ( 4032 1A422F8D18B29C6400D8CD96 /* HistoryClient.h */, 4033 1A422F8C18B29C6400D8CD96 /* HistoryClient.mm */, 4026 4034 1ABC3DF41899E437004F0626 /* NavigationState.h */, 4027 4035 1ABC3DF31899E437004F0626 /* NavigationState.mm */, … … 4358 4366 1A4D664918A3030E00D82E21 /* WKFrameInfo.mm */, 4359 4367 1A4D664D18A3031B00D82E21 /* WKFrameInfoInternal.h */, 4368 1A422F8A18B29B5400D8CD96 /* WKHistoryDelegatePrivate.h */, 4360 4369 1A5B1C4F1898606F004FCF9B /* WKNavigation.h */, 4361 4370 1A5B1C4E1898606F004FCF9B /* WKNavigation.mm */, … … 6290 6299 1ABC3DF11899C6B6004F0626 /* WKNavigationInternal.h in Headers */, 6291 6300 1F604BA81889FA7400EE0395 /* WKRenderingProgressEvents.h in Headers */, 6301 1A422F8F18B29C6400D8CD96 /* HistoryClient.h in Headers */, 6292 6302 BCBAACEB145225E30053F82F /* WKProcessGroup.h in Headers */, 6293 6303 377EAD4817E2C77B002D193D /* WKUserContentInjectedFrames.h in Headers */, … … 6534 6544 1A5E4DA412D3BD3D0099A2BB /* TextCheckerState.h in Headers */, 6535 6545 1AAF263914687C39004A1E8A /* TiledCoreAnimationDrawingArea.h in Headers */, 6546 1A422F8B18B29B5400D8CD96 /* WKHistoryDelegatePrivate.h in Headers */, 6536 6547 370F34A71829CFF3009027C8 /* WKBrowsingContextHistoryDelegate.h in Headers */, 6537 6548 1AF05D8714688348008B1E81 /* TiledCoreAnimationDrawingAreaProxy.h in Headers */, … … 8033 8044 755422BD18062BB20046F6A8 /* WKOriginDataManager.cpp in Sources */, 8034 8045 CD73BA4E131ACDB700EEDED2 /* WebFullScreenManagerMessageReceiver.cpp in Sources */, 8046 1A422F8E18B29C6400D8CD96 /* HistoryClient.mm in Sources */, 8035 8047 1FB00AC8185F76460019142E /* WKWebProcessPlugInPageGroup.mm in Sources */, 8036 8048 CD6F75F4131B66D000D6B21E /* WebFullScreenManagerProxy.cpp in Sources */,
Note: See TracChangeset
for help on using the changeset viewer.