Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: ios/web/web_state/js/resources/core.js

Issue 1541023002: Keep original pushState() method for use in JS overwrite (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This file adheres to closure-compiler conventions in order to enable 5 // This file adheres to closure-compiler conventions in order to enable
6 // compilation with ADVANCED_OPTIMIZATIONS. In particular, members that are to 6 // compilation with ADVANCED_OPTIMIZATIONS. In particular, members that are to
7 // be accessed externally should be specified in this['style'] as opposed to 7 // be accessed externally should be specified in this['style'] as opposed to
8 // this.style because member identifiers are minified by default. 8 // this.style because member identifiers are minified by default.
9 // See http://goo.gl/FwOgy 9 // See http://goo.gl/FwOgy
10 10
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 popstateEvent.state = JSON.parse(stateObject); 368 popstateEvent.state = JSON.parse(stateObject);
369 369
370 // setTimeout() is used in order to return immediately. Otherwise the 370 // setTimeout() is used in order to return immediately. Otherwise the
371 // dispatchEvent call waits for all event handlers to return, which could 371 // dispatchEvent call waits for all event handlers to return, which could
372 // cause a ReentryGuard failure. 372 // cause a ReentryGuard failure.
373 window.setTimeout(function() { 373 window.setTimeout(function() {
374 window.dispatchEvent(popstateEvent); 374 window.dispatchEvent(popstateEvent);
375 }, 0); 375 }, 0);
376 }; 376 };
377 377
378 // Keep the original replaceState() method. It's needed to update UIWebView's 378 // Keep the original pushState() and replaceState() methods. It's needed to
379 // URL and window.history.state property during history navigations that don't 379 // update the web view's URL and window.history.state property during history
380 // cause a page load. 380 // navigations that don't cause a page load.
381 var originalWindowHistoryPushState = window.history.pushState;
381 var originalWindowHistoryReplaceState = window.history.replaceState; 382 var originalWindowHistoryReplaceState = window.history.replaceState;
382 __gCrWeb['replaceWebViewURL'] = function(url, stateObject) { 383 __gCrWeb['replaceWebViewURL'] = function(url, stateObject) {
383 originalWindowHistoryReplaceState.call(history, stateObject, '', url); 384 originalWindowHistoryReplaceState.call(history, stateObject, '', url);
384 }; 385 };
385 386
386 // Intercept window.history methods to call back/forward natively. 387 // Intercept window.history methods to call back/forward natively.
387 window.history.back = function() { 388 window.history.back = function() {
388 invokeOnHost_({'command': 'window.history.back'}); 389 invokeOnHost_({'command': 'window.history.back'});
389 }; 390 };
390 window.history.forward = function() { 391 window.history.forward = function() {
391 invokeOnHost_({'command': 'window.history.forward'}); 392 invokeOnHost_({'command': 'window.history.forward'});
392 }; 393 };
393 window.history.go = function(delta) { 394 window.history.go = function(delta) {
394 invokeOnHost_({'command': 'window.history.go', 'value': delta}); 395 invokeOnHost_({'command': 'window.history.go', 'value': delta});
395 }; 396 };
396 window.history.pushState = function(stateObject, pageTitle, pageUrl) { 397 window.history.pushState = function(stateObject, pageTitle, pageUrl) {
397 __gCrWeb.message.invokeOnHost( 398 __gCrWeb.message.invokeOnHost(
398 {'command': 'window.history.willChangeState'}); 399 {'command': 'window.history.willChangeState'});
399 // Calling stringify() on undefined causes a JSON parse error. 400 // Calling stringify() on undefined causes a JSON parse error.
400 var serializedState = 401 var serializedState =
401 typeof(stateObject) == 'undefined' ? '' : 402 typeof(stateObject) == 'undefined' ? '' :
402 __gCrWeb.common.JSONStringify(stateObject); 403 __gCrWeb.common.JSONStringify(stateObject);
403 pageUrl = pageUrl || window.location.href; 404 pageUrl = pageUrl || window.location.href;
404 originalWindowHistoryReplaceState.call(history, stateObject, '', pageUrl); 405 originalWindowHistoryPushState.call(history, stateObject, '', pageUrl);
Eugene But (OOO till 7-30) 2016/01/04 20:52:30 I think you want to pass pageTitle as well, otherw
Jackie Quinn 2016/01/04 21:16:58 Done.
405 invokeOnHost_({'command': 'window.history.didPushState', 406 invokeOnHost_({'command': 'window.history.didPushState',
406 'stateObject': serializedState, 407 'stateObject': serializedState,
407 'baseUrl': document.baseURI, 408 'baseUrl': document.baseURI,
408 'pageUrl': pageUrl.toString()}); 409 'pageUrl': pageUrl.toString()});
409 }; 410 };
410 window.history.replaceState = function(stateObject, pageTitle, pageUrl) { 411 window.history.replaceState = function(stateObject, pageTitle, pageUrl) {
411 __gCrWeb.message.invokeOnHost( 412 __gCrWeb.message.invokeOnHost(
412 {'command': 'window.history.willChangeState'}); 413 {'command': 'window.history.willChangeState'});
413 414
414 // Calling stringify() on undefined causes a JSON parse error. 415 // Calling stringify() on undefined causes a JSON parse error.
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 653
653 // Handle or wait for and handle document load completion, if applicable. 654 // Handle or wait for and handle document load completion, if applicable.
654 if (__gCrWeb.core_dynamic.handleDocumentLoaded) 655 if (__gCrWeb.core_dynamic.handleDocumentLoaded)
655 __gCrWeb.core_dynamic.handleDocumentLoaded(); 656 __gCrWeb.core_dynamic.handleDocumentLoaded();
656 657
657 return true; 658 return true;
658 }; 659 };
659 660
660 __gCrWeb.core.documentInject(); 661 __gCrWeb.core.documentInject();
661 }()); // End of anonymous object 662 }()); // End of anonymous object
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698