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 <objc/runtime.h> | 7 #import <objc/runtime.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 // Show overlay view, don't reload web page. | 251 // Show overlay view, don't reload web page. |
252 BOOL _overlayPreviewMode; | 252 BOOL _overlayPreviewMode; |
253 // If |YES|, calls |setShouldSuppressDialogs:YES| when window id is injected | 253 // If |YES|, calls |setShouldSuppressDialogs:YES| when window id is injected |
254 // into the web view. | 254 // into the web view. |
255 BOOL _shouldSuppressDialogsOnWindowIDInjection; | 255 BOOL _shouldSuppressDialogsOnWindowIDInjection; |
256 // The URL of an expected future recreation of the |webView|. Valid | 256 // The URL of an expected future recreation of the |webView|. Valid |
257 // only if the web view was discarded for non-user-visible reasons, such that | 257 // only if the web view was discarded for non-user-visible reasons, such that |
258 // if the next load request is for that URL, it should be treated as a | 258 // if the next load request is for that URL, it should be treated as a |
259 // reconstruction that should use cache aggressively. | 259 // reconstruction that should use cache aggressively. |
260 GURL _expectedReconstructionURL; | 260 GURL _expectedReconstructionURL; |
| 261 // Whether the web page is currently performing window.history.pushState or |
| 262 // window.history.replaceState |
| 263 // Set to YES on window.history.willChangeState message. To NO on |
| 264 // window.history.didPushState or window.history.didReplaceState. |
| 265 BOOL _changingHistoryState; |
261 | 266 |
262 scoped_ptr<web::NewWindowInfo> _externalRequest; | 267 scoped_ptr<web::NewWindowInfo> _externalRequest; |
263 | 268 |
264 // The WebStateImpl instance associated with this CRWWebController. | 269 // The WebStateImpl instance associated with this CRWWebController. |
265 scoped_ptr<WebStateImpl> _webStateImpl; | 270 scoped_ptr<WebStateImpl> _webStateImpl; |
266 | 271 |
267 // A set of URLs opened in external applications; stored so that errors | 272 // A set of URLs opened in external applications; stored so that errors |
268 // from the web view can be identified as resulting from these events. | 273 // from the web view can be identified as resulting from these events. |
269 base::scoped_nsobject<NSMutableSet> _openedApplicationURL; | 274 base::scoped_nsobject<NSMutableSet> _openedApplicationURL; |
270 | 275 |
(...skipping 1621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1892 } | 1897 } |
1893 | 1898 |
1894 - (BOOL)isBeingDestroyed { | 1899 - (BOOL)isBeingDestroyed { |
1895 return _isBeingDestroyed; | 1900 return _isBeingDestroyed; |
1896 } | 1901 } |
1897 | 1902 |
1898 - (BOOL)isHalted { | 1903 - (BOOL)isHalted { |
1899 return _isHalted; | 1904 return _isHalted; |
1900 } | 1905 } |
1901 | 1906 |
| 1907 - (BOOL)changingHistoryState { |
| 1908 return _changingHistoryState; |
| 1909 } |
| 1910 |
1902 - (web::ReferrerPolicy)referrerPolicyFromString:(const std::string&)policy { | 1911 - (web::ReferrerPolicy)referrerPolicyFromString:(const std::string&)policy { |
1903 // TODO(stuartmorgan): Remove this temporary bridge to the helper function | 1912 // TODO(stuartmorgan): Remove this temporary bridge to the helper function |
1904 // once the referrer handling moves into the subclasses. | 1913 // once the referrer handling moves into the subclasses. |
1905 return web::ReferrerPolicyFromString(policy); | 1914 return web::ReferrerPolicyFromString(policy); |
1906 } | 1915 } |
1907 | 1916 |
1908 #pragma mark - | 1917 #pragma mark - |
1909 #pragma mark CRWWebControllerContainerViewDelegate | 1918 #pragma mark CRWWebControllerContainerViewDelegate |
1910 | 1919 |
1911 - (CRWWebViewProxyImpl*)contentViewProxyForContainerView: | 1920 - (CRWWebViewProxyImpl*)contentViewProxyForContainerView: |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2390 - (BOOL)handleWindowHistoryGoMessage:(base::DictionaryValue*)message | 2399 - (BOOL)handleWindowHistoryGoMessage:(base::DictionaryValue*)message |
2391 context:(NSDictionary*)context { | 2400 context:(NSDictionary*)context { |
2392 int delta; | 2401 int delta; |
2393 message->GetInteger("value", &delta); | 2402 message->GetInteger("value", &delta); |
2394 [self goDelta:delta]; | 2403 [self goDelta:delta]; |
2395 return YES; | 2404 return YES; |
2396 } | 2405 } |
2397 | 2406 |
2398 - (BOOL)handleWindowHistoryWillChangeStateMessage:(base::DictionaryValue*)unused | 2407 - (BOOL)handleWindowHistoryWillChangeStateMessage:(base::DictionaryValue*)unused |
2399 context:(NSDictionary*)unusedContext { | 2408 context:(NSDictionary*)unusedContext { |
2400 // This dummy handler is a workaround for crbug.com/490673. Issue was | 2409 _changingHistoryState = YES; |
2401 // happening when two sequential calls of window.history.pushState were | |
2402 // performed by the page. In that case state was changed twice before | |
2403 // first change was reported to embedder (and first URL change was reported | |
2404 // incorrectly). | |
2405 | |
2406 // Using dummy handler for window.history.willChangeState message holds | |
2407 // second state change until the first change is reported, because messages | |
2408 // are queued. This is essentially a sleep, and not the real fix of the | |
2409 // problem. TODO(eugenebut): refactor handleWindowHistoryDidPushStateMessage: | |
2410 // to avoid this "sleep". | |
2411 return YES; | 2410 return YES; |
2412 } | 2411 } |
2413 | 2412 |
2414 - (BOOL)handleWindowHistoryDidPushStateMessage:(base::DictionaryValue*)message | 2413 - (BOOL)handleWindowHistoryDidPushStateMessage:(base::DictionaryValue*)message |
2415 context:(NSDictionary*)context { | 2414 context:(NSDictionary*)context { |
| 2415 DCHECK(_changingHistoryState); |
| 2416 _changingHistoryState = NO; |
| 2417 |
2416 // If there is a pending entry, a new navigation has been registered but | 2418 // If there is a pending entry, a new navigation has been registered but |
2417 // hasn't begun loading. Since the pushState message is coming from the | 2419 // hasn't begun loading. Since the pushState message is coming from the |
2418 // previous page, ignore it and allow the previously registered navigation to | 2420 // previous page, ignore it and allow the previously registered navigation to |
2419 // continue. This can ocur if a pushState is issued from an anchor tag | 2421 // continue. This can ocur if a pushState is issued from an anchor tag |
2420 // onClick event, as the click would have already been registered. | 2422 // onClick event, as the click would have already been registered. |
2421 if ([self sessionController].pendingEntry) | 2423 if ([self sessionController].pendingEntry) |
2422 return NO; | 2424 return NO; |
2423 | 2425 |
2424 std::string pageURL; | 2426 std::string pageURL; |
2425 std::string baseURL; | 2427 std::string baseURL; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2487 // Notify the observers. | 2489 // Notify the observers. |
2488 strongSelf.get()->_webStateImpl->OnHistoryStateChanged(); | 2490 strongSelf.get()->_webStateImpl->OnHistoryStateChanged(); |
2489 [strongSelf didFinishNavigation]; | 2491 [strongSelf didFinishNavigation]; |
2490 }]; | 2492 }]; |
2491 return YES; | 2493 return YES; |
2492 } | 2494 } |
2493 | 2495 |
2494 - (BOOL)handleWindowHistoryDidReplaceStateMessage: | 2496 - (BOOL)handleWindowHistoryDidReplaceStateMessage: |
2495 (base::DictionaryValue*)message | 2497 (base::DictionaryValue*)message |
2496 context:(NSDictionary*)context { | 2498 context:(NSDictionary*)context { |
| 2499 DCHECK(_changingHistoryState); |
| 2500 _changingHistoryState = NO; |
| 2501 |
2497 std::string pageURL; | 2502 std::string pageURL; |
2498 std::string baseURL; | 2503 std::string baseURL; |
2499 if (!message->GetString("pageUrl", &pageURL) || | 2504 if (!message->GetString("pageUrl", &pageURL) || |
2500 !message->GetString("baseUrl", &baseURL)) { | 2505 !message->GetString("baseUrl", &baseURL)) { |
2501 DLOG(WARNING) << "JS message parameter not found: pageUrl or baseUrl"; | 2506 DLOG(WARNING) << "JS message parameter not found: pageUrl or baseUrl"; |
2502 return NO; | 2507 return NO; |
2503 } | 2508 } |
2504 GURL replaceURL = web::history_state_util::GetHistoryStateChangeUrl( | 2509 GURL replaceURL = web::history_state_util::GetHistoryStateChangeUrl( |
2505 [self currentURL], GURL(baseURL), pageURL); | 2510 [self currentURL], GURL(baseURL), pageURL); |
2506 // UIWebView seems to choke on unicode characters that haven't been | 2511 // UIWebView seems to choke on unicode characters that haven't been |
(...skipping 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3816 if ([MIMEType isEqualToString:@"text/html"] || | 3821 if ([MIMEType isEqualToString:@"text/html"] || |
3817 [MIMEType isEqualToString:@"application/xhtml+xml"] || | 3822 [MIMEType isEqualToString:@"application/xhtml+xml"] || |
3818 [MIMEType isEqualToString:@"application/xml"]) { | 3823 [MIMEType isEqualToString:@"application/xml"]) { |
3819 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; | 3824 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; |
3820 } | 3825 } |
3821 | 3826 |
3822 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 3827 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
3823 } | 3828 } |
3824 | 3829 |
3825 @end | 3830 @end |
OLD | NEW |