diff --git a/ios/web/web_state/js/resources/core.js b/ios/web/web_state/js/resources/core.js index 510c504343492..376d8d48e74b9 100644 --- a/ios/web/web_state/js/resources/core.js +++ b/ios/web/web_state/js/resources/core.js @@ -434,6 +434,11 @@ goog.require('__crWeb.message'); return anchor.href; }; + __gCrWeb['sendFaviconsToHost'] = function() { + __gCrWeb.message.invokeOnHost({'command': 'document.favicons', + 'favicons': __gCrWeb.common.getFavicons()}); + } + // Tracks whether user is in the middle of scrolling/dragging. If user is // scrolling, ignore window.scrollTo() until user stops scrolling. var webViewScrollViewIsDragging_ = false; diff --git a/ios/web/web_state/js/resources/core_dynamic_ui.js b/ios/web/web_state/js/resources/core_dynamic_ui.js index 1d2f4c2939ede..dc65cad20fb43 100644 --- a/ios/web/web_state/js/resources/core_dynamic_ui.js +++ b/ios/web/web_state/js/resources/core_dynamic_ui.js @@ -116,8 +116,7 @@ __gCrWeb.core_dynamic = {}; var loaded_ = function() { invokeOnHost_({'command': 'document.loaded'}); // Send the favicons to the browser. - invokeOnHost_({'command': 'document.favicons', - 'favicons': __gCrWeb.common.getFavicons()}); + __gCrWeb.sendFaviconsToHost(); // Add placeholders for plugin content. if (__gCrWeb.common.updatePluginPlaceholders()) __gCrWeb.message.invokeOnHost({'command': 'addPluginPlaceholders'}); diff --git a/ios/web/web_state/js/resources/core_dynamic_wk.js b/ios/web/web_state/js/resources/core_dynamic_wk.js index 47ded420a1fe0..9694da0506d17 100644 --- a/ios/web/web_state/js/resources/core_dynamic_wk.js +++ b/ios/web/web_state/js/resources/core_dynamic_wk.js @@ -41,8 +41,7 @@ __gCrWeb.core_dynamic = {}; */ __gCrWeb.didFinishNavigation = function() { // Send the favicons to the browser. - __gCrWeb.message.invokeOnHost({'command': 'document.favicons', - 'favicons': __gCrWeb.common.getFavicons()}); + __gCrWeb.sendFaviconsToHost(); // Add placeholders for plugin content. if (__gCrWeb.common.updatePluginPlaceholders()) __gCrWeb.message.invokeOnHost({'command': 'addPluginPlaceholders'}); diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm index 01d6a55bab99f..45614483df75b 100644 --- a/ios/web/web_state/ui/crw_web_controller.mm +++ b/ios/web/web_state/ui/crw_web_controller.mm @@ -2426,6 +2426,11 @@ - (BOOL)handleWindowHashChangeMessage:(base::DictionaryValue*)message context:(NSDictionary*)context { [self checkForUnexpectedURLChange]; + // Because hash changes don't trigger |-didFinishNavigation|, fetch favicons + // for the new page manually. + [self evaluateJavaScript:@"__gCrWeb.sendFaviconsToHost();" + stringResultHandler:nil]; + // Notify the observers. _webStateImpl->OnUrlHashChanged(); return YES;