Commit d0ec7fd4 authored by Yi Su's avatar Yi Su Committed by Commit Bot

Make sure search_engine.js find Open Search <link> when page is loaded.

Current implementation of search_engine.js finds Open Search <link> when
the Js file is injected without a check on page's loading status. This CL
adds a check for document.readyState, so that the finding process will
only be executed when the page is fully loaded.

Bug: 433824
Change-Id: I3384081dd3079f15dba6a727cf1373edc4b593ba
Reviewed-on: https://chromium-review.googlesource.com/c/1323716
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606406}
parent c593df03
...@@ -300,17 +300,28 @@ document.addEventListener('submit', function(event) { ...@@ -300,17 +300,28 @@ document.addEventListener('submit', function(event) {
* found, sends a message containing the page's URL and OSDD's URL to native * found, sends a message containing the page's URL and OSDD's URL to native
* side. If the page has multiple OSDD <links>s (which should never happen on a * side. If the page has multiple OSDD <links>s (which should never happen on a
* sane web site), only send the first <link>. * sane web site), only send the first <link>.
* @return {undefined}
*/ */
var links = document.getElementsByTagName('link'); function findOpenSearchLink() {
for (var i = 0; i < links.length; ++i) { var links = document.getElementsByTagName('link');
if (links[i].type == 'application/opensearchdescription+xml') { for (var i = 0; i < links.length; ++i) {
__gCrWeb.message.invokeOnHost({ if (links[i].type == 'application/opensearchdescription+xml') {
'command': 'searchEngine.openSearch', __gCrWeb.message.invokeOnHost({
'pageUrl': document.URL, 'command': 'searchEngine.openSearch',
'osddUrl': links[i].href 'pageUrl': document.URL,
}); 'osddUrl': links[i].href
break; });
} return;
}; }
};
}
// If document is loaded, finds the Open Search <link>, otherwise waits until
// it's loaded and then starts finding.
if (document.readyState == 'complete') {
findOpenSearchLink();
} else {
window.addEventListener('load', findOpenSearchLink);
}
}()); // End of anonymous object }()); // End of anonymous object
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment