You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/12/23 17:53:16 UTC
ios commit: CB-5697 Fix location.reload() not firing deviceready.
Updated Branches:
refs/heads/master a61b2891c -> ced5b8f9f
CB-5697 Fix location.reload() not firing deviceready.
It was being detected as a hash change event.
This commit also fixes isFragmentIdentifierToRequest ignoring query parameters.
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/ced5b8f9
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/ced5b8f9
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/ced5b8f9
Branch: refs/heads/master
Commit: ced5b8f9f563a739b23c5f6f6e7504ac9cb819eb
Parents: a61b289
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Dec 23 11:51:43 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Dec 23 11:52:29 2013 -0500
----------------------------------------------------------------------
CordovaLib/Classes/CDVWebViewDelegate.m | 62 +++++++++++++---------------
1 file changed, 29 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/ced5b8f9/CordovaLib/Classes/CDVWebViewDelegate.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVWebViewDelegate.m b/CordovaLib/Classes/CDVWebViewDelegate.m
index 581089c..416abfd 100644
--- a/CordovaLib/Classes/CDVWebViewDelegate.m
+++ b/CordovaLib/Classes/CDVWebViewDelegate.m
@@ -91,6 +91,16 @@ typedef enum {
STATE_CANCELLED = 5
} State;
+static NSString *stripFragment(NSString* url)
+{
+ NSRange r = [url rangeOfString:@"#"];
+
+ if (r.location == NSNotFound) {
+ return url;
+ }
+ return [url substringToIndex:r.location];
+}
+
@implementation CDVWebViewDelegate
- (id)initWithDelegate:(NSObject <UIWebViewDelegate>*)delegate
@@ -110,33 +120,8 @@ typedef enum {
NSString* originalRequestUrl = [originalRequest.URL absoluteString];
NSString* newRequestUrl = [newRequest.URL absoluteString];
- // no fragment, easy
- if (newRequest.URL.fragment == nil) {
- return NO;
- }
-
- // if the urls have fragments and they are equal
- if ((originalRequest.URL.fragment && newRequest.URL.fragment) && [originalRequestUrl isEqualToString:newRequestUrl]) {
- return YES;
- }
-
- NSString* urlFormat = @"%@://%@:%d/%@#%@";
- // reconstruct the URLs (ignoring basic auth credentials, query string)
- NSString* baseOriginalRequestUrl = [NSString stringWithFormat:urlFormat,
- [originalRequest.URL scheme],
- [originalRequest.URL host],
- [[originalRequest.URL port] intValue],
- [originalRequest.URL path],
- [newRequest.URL fragment] // add the new request's fragment
- ];
- NSString* baseNewRequestUrl = [NSString stringWithFormat:urlFormat,
- [newRequest.URL scheme],
- [newRequest.URL host],
- [[newRequest.URL port] intValue],
- [newRequest.URL path],
- [newRequest.URL fragment]
- ];
-
+ NSString* baseOriginalRequestUrl = stripFragment(originalRequestUrl);
+ NSString* baseNewRequestUrl = stripFragment(newRequestUrl);
return [baseOriginalRequestUrl isEqualToString:baseNewRequestUrl];
}
@@ -163,6 +148,11 @@ typedef enum {
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.__cordovaLoadToken=%d", _curLoadToken]];
}
+- (NSString*)evalForCurrentURL:(UIWebView*)webView
+{
+ return [webView stringByEvaluatingJavaScriptFromString:@"location.href"];
+}
+
- (void)pollForPageLoadStart:(UIWebView*)webView
{
if (_state != STATE_IOS5_POLLING_FOR_LOAD_START) {
@@ -211,17 +201,23 @@ typedef enum {
shouldLoad = [_delegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
}
- // Ignore hash changes that don't navigate to a different page.
- if ([self request:request isFragmentIdentifierToRequest:webView.request]) {
- VerboseLog(@"Detected hash change shouldLoad");
- return shouldLoad;
- }
-
VerboseLog(@"webView shouldLoad=%d (before) state=%d loadCount=%d URL=%@", shouldLoad, _state, _loadCount, request.URL);
if (shouldLoad) {
BOOL isTopLevelNavigation = [request.URL isEqual:[request mainDocumentURL]];
if (isTopLevelNavigation) {
+ // Ignore hash changes that don't navigate to a different page.
+ // webView.request does actually update when history.replaceState() gets called.
+ if ([self request:request isFragmentIdentifierToRequest:webView.request]) {
+ NSString* prevURL = [self evalForCurrentURL:webView];
+ if ([prevURL isEqualToString:[request.URL absoluteString]]) {
+ VerboseLog(@"Page reload detected.");
+ } else {
+ VerboseLog(@"Detected hash change shouldLoad");
+ return shouldLoad;
+ }
+ }
+
switch (_state) {
case STATE_WAITING_FOR_LOAD_FINISH:
// Redirect case.