OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 | 5 |
6 // NOTE: If you modify this file, you also have to change its hash in | 6 // NOTE: If you modify this file, you also have to change its hash in |
7 // local_ntp.html and in LocalNtpSource::GetContentSecurityPolicyScriptSrc. | 7 // local_ntp.html and in LocalNtpSource::GetContentSecurityPolicyScriptSrc. |
8 | 8 |
9 | 9 |
10 /** | 10 /** |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 iframe.tabIndex = 1; | 656 iframe.tabIndex = 1; |
657 iframe.src = 'chrome-search://most-visited/single.html?' + args.join('&'); | 657 iframe.src = 'chrome-search://most-visited/single.html?' + args.join('&'); |
658 $(IDS.TILES).appendChild(iframe); | 658 $(IDS.TILES).appendChild(iframe); |
659 | 659 |
660 iframe.onload = function() { | 660 iframe.onload = function() { |
661 reloadTiles(); | 661 reloadTiles(); |
662 renderTheme(); | 662 renderTheme(); |
663 }; | 663 }; |
664 | 664 |
665 window.addEventListener('message', handlePostMessage); | 665 window.addEventListener('message', handlePostMessage); |
666 | |
667 // Inject the OneGoogleBar loader script. It'll create a global variable | |
668 // named "og" which injectOneGoogleBar expects. | |
669 var ogScript = document.createElement('script'); | |
670 ogScript.src = 'chrome-search://local-ntp/one-google.js'; | |
671 document.body.appendChild(ogScript); | |
672 ogScript.onload = function() { | |
673 injectOneGoogleBar(); | |
674 } | |
666 } | 675 } |
667 | 676 |
668 | 677 |
669 /** | 678 /** |
670 * Binds event listeners. | 679 * Binds event listeners. |
671 */ | 680 */ |
672 function listen() { | 681 function listen() { |
673 document.addEventListener('DOMContentLoaded', init); | 682 document.addEventListener('DOMContentLoaded', init); |
674 } | 683 } |
675 | 684 |
685 | |
686 /** | |
687 * Injects the One Google Bar into the page. Called asynchronously, so that it | |
688 * doesn't block the main page load. It expects a global variable named "og" | |
sfiera
2017/04/27 12:16:07
Can you pass og.html and og.end_of_body_html inste
Marc Treib
2017/04/27 14:00:56
Good idea, done.
sfiera
2017/04/28 11:17:56
Doesn't feel more or less magical to me, it's just
| |
689 * with the following fields: | |
690 * .html - the main bar HTML. | |
691 * .end_of_body_html - HTML to be inserted at the end of the body. | |
692 */ | |
693 function injectOneGoogleBar() { | |
694 var inHeadStyle = document.createElement('link'); | |
695 inHeadStyle.rel = "stylesheet"; | |
696 inHeadStyle.href = 'chrome-search://local-ntp/one-google-in-head.css'; | |
sfiera
2017/04/27 12:16:07
Can you use a "directory" for the one-google files
Marc Treib
2017/04/27 14:00:56
Sure, done.
| |
697 document.head.appendChild(inHeadStyle); | |
698 | |
699 inHeadStyle.onload = function() { | |
sfiera
2017/04/27 12:16:07
Is the injection order a restriction of the API? H
Marc Treib
2017/04/27 14:00:56
Most of this is mandated by the API, yes. The two
| |
700 var inHeadScript = document.createElement('script'); | |
701 inHeadScript.src = 'chrome-search://local-ntp/one-google-in-head.js'; | |
702 document.head.appendChild(inHeadScript); | |
703 | |
704 inHeadScript.onload = function() { | |
705 var ogElem = $('one-google'); | |
706 ogElem.innerHTML = og.html; | |
707 | |
708 var afterBarScript = document.createElement('script'); | |
709 afterBarScript.src = | |
710 'chrome-search://local-ntp/one-google-after-bar.js'; | |
711 ogElem.parentNode.insertBefore(afterBarScript, ogElem.nextSibling); | |
712 | |
713 afterBarScript.onload = function() { | |
714 $('one-google-end-of-body').innerHTML = og.end_of_body_html; | |
715 | |
716 var endOfBodyScript = document.createElement('script'); | |
717 endOfBodyScript.src = | |
718 'chrome-search://local-ntp/one-google-end-of-body.js'; | |
719 document.body.appendChild(endOfBodyScript); | |
720 } | |
721 } | |
722 } | |
723 } | |
724 | |
725 | |
676 return { | 726 return { |
677 init: init, // Exposed for testing. | 727 init: init, // Exposed for testing. |
678 listen: listen | 728 listen: listen |
679 }; | 729 }; |
680 | 730 |
681 } | 731 } |
682 | 732 |
683 if (!window.localNTPUnitTest) { | 733 if (!window.localNTPUnitTest) { |
684 LocalNTP().listen(); | 734 LocalNTP().listen(); |
685 } | 735 } |
OLD | NEW |