OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/web/web_state/ui/crw_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_web_controller.h" |
6 | 6 |
7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
8 | 8 |
9 #import <objc/runtime.h> | 9 #import <objc/runtime.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 1725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1736 [self javascriptToReplaceWebViewURL:URL stateObjectJSON:stateObject]; | 1736 [self javascriptToReplaceWebViewURL:URL stateObjectJSON:stateObject]; |
1737 std::string outState; | 1737 std::string outState; |
1738 base::EscapeJSONString(base::SysNSStringToUTF8(stateObject), true, &outState); | 1738 base::EscapeJSONString(base::SysNSStringToUTF8(stateObject), true, &outState); |
1739 NSString* popstateJS = | 1739 NSString* popstateJS = |
1740 [NSString stringWithFormat:@"__gCrWeb.dispatchPopstateEvent(%@);", | 1740 [NSString stringWithFormat:@"__gCrWeb.dispatchPopstateEvent(%@);", |
1741 base::SysUTF8ToNSString(outState)]; | 1741 base::SysUTF8ToNSString(outState)]; |
1742 NSString* combinedJS = | 1742 NSString* combinedJS = |
1743 [NSString stringWithFormat:@"%@%@", replaceWebViewUrlJS, popstateJS]; | 1743 [NSString stringWithFormat:@"%@%@", replaceWebViewUrlJS, popstateJS]; |
1744 GURL blockURL(URL); | 1744 GURL blockURL(URL); |
1745 base::WeakNSObject<CRWWebController> weakSelf(self); | 1745 base::WeakNSObject<CRWWebController> weakSelf(self); |
1746 [self executeJavaScript:combinedJS completionHandler:^(id, NSError*) { | 1746 [self executeJavaScript:combinedJS |
1747 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) | 1747 completionHandler:^(id, NSError*) { |
1748 return; | 1748 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) |
1749 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); | 1749 return; |
1750 strongSelf.get()->_URLOnStartLoading = blockURL; | 1750 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); |
1751 strongSelf.get()->_lastRegisteredRequestURL = blockURL; | 1751 strongSelf.get()->_URLOnStartLoading = blockURL; |
1752 }]; | 1752 strongSelf.get()->_lastRegisteredRequestURL = blockURL; |
1753 }]; | |
droger
2016/09/05 09:21:31
If this is just a formatting change, I would not i
maksims (do not use this acc)
2016/09/05 10:39:13
Ok, thanks! I'll revert.
| |
1753 } | 1754 } |
1754 | 1755 |
1755 // Load the current URL in a web view, first ensuring the web view is visible. | 1756 // Load the current URL in a web view, first ensuring the web view is visible. |
1756 - (void)loadCurrentURLInWebView { | 1757 - (void)loadCurrentURLInWebView { |
1757 // Clear the set of URLs opened in external applications. | 1758 // Clear the set of URLs opened in external applications. |
1758 _openedApplicationURL.reset([[NSMutableSet alloc] init]); | 1759 _openedApplicationURL.reset([[NSMutableSet alloc] init]); |
1759 | 1760 |
1760 // Load the url. The UIWebView delegate callbacks take care of updating the | 1761 // Load the url. The UIWebView delegate callbacks take care of updating the |
1761 // session history and UI. | 1762 // session history and UI. |
1762 const GURL targetURL([self currentNavigationURL]); | 1763 const GURL targetURL([self currentNavigationURL]); |
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3050 ui::PageTransition transition = self.userInteractionRegistered | 3051 ui::PageTransition transition = self.userInteractionRegistered |
3051 ? ui::PAGE_TRANSITION_LINK | 3052 ? ui::PAGE_TRANSITION_LINK |
3052 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; | 3053 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
3053 [self pushStateWithPageURL:pushURL | 3054 [self pushStateWithPageURL:pushURL |
3054 stateObject:stateObject | 3055 stateObject:stateObject |
3055 transition:transition]; | 3056 transition:transition]; |
3056 | 3057 |
3057 NSString* replaceWebViewJS = | 3058 NSString* replaceWebViewJS = |
3058 [self javascriptToReplaceWebViewURL:pushURL stateObjectJSON:stateObject]; | 3059 [self javascriptToReplaceWebViewURL:pushURL stateObjectJSON:stateObject]; |
3059 base::WeakNSObject<CRWWebController> weakSelf(self); | 3060 base::WeakNSObject<CRWWebController> weakSelf(self); |
3060 [self executeJavaScript:replaceWebViewJS completionHandler:^(id, NSError*) { | 3061 [self executeJavaScript:replaceWebViewJS |
3061 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) | 3062 completionHandler:^(id, NSError*) { |
3062 return; | 3063 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) |
3063 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); | 3064 return; |
3064 [strongSelf optOutScrollsToTopForSubviews]; | 3065 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); |
3065 // Notify the observers. | 3066 [strongSelf optOutScrollsToTopForSubviews]; |
3066 strongSelf.get()->_webStateImpl->OnHistoryStateChanged(); | 3067 // Notify the observers. |
3067 [strongSelf didFinishNavigation]; | 3068 strongSelf.get()->_webStateImpl->OnHistoryStateChanged(); |
3068 }]; | 3069 [strongSelf didFinishNavigation]; |
3070 }]; | |
3069 return YES; | 3071 return YES; |
3070 } | 3072 } |
3071 | 3073 |
3072 - (BOOL)handleWindowHistoryDidReplaceStateMessage: | 3074 - (BOOL)handleWindowHistoryDidReplaceStateMessage: |
3073 (base::DictionaryValue*)message | 3075 (base::DictionaryValue*)message |
3074 context:(NSDictionary*)context { | 3076 context:(NSDictionary*)context { |
3075 DCHECK(_changingHistoryState); | 3077 DCHECK(_changingHistoryState); |
3076 _changingHistoryState = NO; | 3078 _changingHistoryState = NO; |
3077 | 3079 |
3078 std::string pageURL; | 3080 std::string pageURL; |
(...skipping 30 matching lines...) Expand all Loading... | |
3109 DLOG(WARNING) << "JS message parameter not found: stateObject"; | 3111 DLOG(WARNING) << "JS message parameter not found: stateObject"; |
3110 return NO; | 3112 return NO; |
3111 } | 3113 } |
3112 NSString* stateObject = base::SysUTF8ToNSString(stateObjectJSON); | 3114 NSString* stateObject = base::SysUTF8ToNSString(stateObjectJSON); |
3113 _URLOnStartLoading = replaceURL; | 3115 _URLOnStartLoading = replaceURL; |
3114 _lastRegisteredRequestURL = replaceURL; | 3116 _lastRegisteredRequestURL = replaceURL; |
3115 [self replaceStateWithPageURL:replaceURL stateObject:stateObject]; | 3117 [self replaceStateWithPageURL:replaceURL stateObject:stateObject]; |
3116 NSString* replaceStateJS = [self javascriptToReplaceWebViewURL:replaceURL | 3118 NSString* replaceStateJS = [self javascriptToReplaceWebViewURL:replaceURL |
3117 stateObjectJSON:stateObject]; | 3119 stateObjectJSON:stateObject]; |
3118 base::WeakNSObject<CRWWebController> weakSelf(self); | 3120 base::WeakNSObject<CRWWebController> weakSelf(self); |
3119 [self executeJavaScript:replaceStateJS completionHandler:^(id, NSError*) { | 3121 [self executeJavaScript:replaceStateJS |
3120 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) | 3122 completionHandler:^(id, NSError*) { |
3121 return; | 3123 if (!weakSelf || weakSelf.get()->_isBeingDestroyed) |
3122 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); | 3124 return; |
3123 [strongSelf didFinishNavigation]; | 3125 base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]); |
3124 }]; | 3126 [strongSelf didFinishNavigation]; |
3127 }]; | |
3125 return YES; | 3128 return YES; |
3126 } | 3129 } |
3127 | 3130 |
3128 #pragma mark - | 3131 #pragma mark - |
3129 | 3132 |
3130 - (BOOL)wantsKeyboardShield { | 3133 - (BOOL)wantsKeyboardShield { |
3131 if ([self.nativeController | 3134 if ([self.nativeController |
3132 respondsToSelector:@selector(wantsKeyboardShield)]) { | 3135 respondsToSelector:@selector(wantsKeyboardShield)]) { |
3133 return [self.nativeController wantsKeyboardShield]; | 3136 return [self.nativeController wantsKeyboardShield]; |
3134 } | 3137 } |
(...skipping 2494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5629 } | 5632 } |
5630 | 5633 |
5631 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 5634 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
5632 } | 5635 } |
5633 | 5636 |
5634 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5637 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
5635 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5638 return [action.request valueForHTTPHeaderField:@"Referer"]; |
5636 } | 5639 } |
5637 | 5640 |
5638 @end | 5641 @end |
OLD | NEW |