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

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: Use pageTitle Created 4 years, 11 months 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,
406 pageTitle, pageUrl);
405 invokeOnHost_({'command': 'window.history.didPushState', 407 invokeOnHost_({'command': 'window.history.didPushState',
406 'stateObject': serializedState, 408 'stateObject': serializedState,
407 'baseUrl': document.baseURI, 409 'baseUrl': document.baseURI,
408 'pageUrl': pageUrl.toString()}); 410 'pageUrl': pageUrl.toString()});
409 }; 411 };
410 window.history.replaceState = function(stateObject, pageTitle, pageUrl) { 412 window.history.replaceState = function(stateObject, pageTitle, pageUrl) {
411 __gCrWeb.message.invokeOnHost( 413 __gCrWeb.message.invokeOnHost(
412 {'command': 'window.history.willChangeState'}); 414 {'command': 'window.history.willChangeState'});
413 415
414 // Calling stringify() on undefined causes a JSON parse error. 416 // Calling stringify() on undefined causes a JSON parse error.
415 var serializedState = 417 var serializedState =
416 typeof(stateObject) == 'undefined' ? '' : 418 typeof(stateObject) == 'undefined' ? '' :
417 __gCrWeb.common.JSONStringify(stateObject); 419 __gCrWeb.common.JSONStringify(stateObject);
418 pageUrl = pageUrl || window.location.href; 420 pageUrl = pageUrl || window.location.href;
419 originalWindowHistoryReplaceState.call(history, stateObject, '', pageUrl); 421 originalWindowHistoryReplaceState.call(history, stateObject,
422 pageTitle, pageUrl);
420 invokeOnHost_({'command': 'window.history.didReplaceState', 423 invokeOnHost_({'command': 'window.history.didReplaceState',
421 'stateObject': serializedState, 424 'stateObject': serializedState,
422 'baseUrl': document.baseURI, 425 'baseUrl': document.baseURI,
423 'pageUrl': pageUrl.toString()}); 426 'pageUrl': pageUrl.toString()});
424 }; 427 };
425 428
426 __gCrWeb['getFullyQualifiedURL'] = function(originalURL) { 429 __gCrWeb['getFullyQualifiedURL'] = function(originalURL) {
427 // A dummy anchor (never added to the document) is used to obtain the 430 // A dummy anchor (never added to the document) is used to obtain the
428 // fully-qualified URL of |originalURL|. 431 // fully-qualified URL of |originalURL|.
429 var anchor = document.createElement('a'); 432 var anchor = document.createElement('a');
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 655
653 // Handle or wait for and handle document load completion, if applicable. 656 // Handle or wait for and handle document load completion, if applicable.
654 if (__gCrWeb.core_dynamic.handleDocumentLoaded) 657 if (__gCrWeb.core_dynamic.handleDocumentLoaded)
655 __gCrWeb.core_dynamic.handleDocumentLoaded(); 658 __gCrWeb.core_dynamic.handleDocumentLoaded();
656 659
657 return true; 660 return true;
658 }; 661 };
659 662
660 __gCrWeb.core.documentInject(); 663 __gCrWeb.core.documentInject();
661 }()); // End of anonymous object 664 }()); // 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