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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 }; | 620 }; |
621 inputbox.ondragenter = function() { | 621 inputbox.ondragenter = function() { |
622 setFakeboxDragFocus(true); | 622 setFakeboxDragFocus(true); |
623 }; | 623 }; |
624 inputbox.ondragleave = function() { | 624 inputbox.ondragleave = function() { |
625 setFakeboxDragFocus(false); | 625 setFakeboxDragFocus(false); |
626 }; | 626 }; |
627 | 627 |
628 // Update the fakebox style to match the current key capturing state. | 628 // Update the fakebox style to match the current key capturing state. |
629 setFakeboxFocus(searchboxApiHandle.isKeyCaptureEnabled); | 629 setFakeboxFocus(searchboxApiHandle.isKeyCaptureEnabled); |
| 630 |
| 631 // Inject the OneGoogleBar loader script. It'll create a global variable |
| 632 // named "og" with the following fields: |
| 633 // .html - the main bar HTML. |
| 634 // .end_of_body_html - HTML to be inserted at the end of the body. |
| 635 var ogScript = document.createElement('script'); |
| 636 ogScript.src = 'chrome-search://local-ntp/one-google.js'; |
| 637 document.body.appendChild(ogScript); |
| 638 ogScript.onload = function() { |
| 639 injectOneGoogleBar(og.html, og.end_of_body_html); |
| 640 } |
630 } else { | 641 } else { |
631 document.body.classList.add(CLASSES.NON_GOOGLE_PAGE); | 642 document.body.classList.add(CLASSES.NON_GOOGLE_PAGE); |
632 } | 643 } |
633 | 644 |
634 if (searchboxApiHandle.rtl) { | 645 if (searchboxApiHandle.rtl) { |
635 $(IDS.NOTIFICATION).dir = 'rtl'; | 646 $(IDS.NOTIFICATION).dir = 'rtl'; |
636 // Grabbing the root HTML element. | 647 // Grabbing the root HTML element. |
637 document.documentElement.setAttribute('dir', 'rtl'); | 648 document.documentElement.setAttribute('dir', 'rtl'); |
638 // Add class for setting alignments based on language directionality. | 649 // Add class for setting alignments based on language directionality. |
639 document.documentElement.classList.add(CLASSES.RTL); | 650 document.documentElement.classList.add(CLASSES.RTL); |
(...skipping 26 matching lines...) Expand all Loading... |
666 } | 677 } |
667 | 678 |
668 | 679 |
669 /** | 680 /** |
670 * Binds event listeners. | 681 * Binds event listeners. |
671 */ | 682 */ |
672 function listen() { | 683 function listen() { |
673 document.addEventListener('DOMContentLoaded', init); | 684 document.addEventListener('DOMContentLoaded', init); |
674 } | 685 } |
675 | 686 |
| 687 |
| 688 /** |
| 689 * Injects the One Google Bar into the page. Called asynchronously, so that it |
| 690 * doesn't block the main page load. |
| 691 */ |
| 692 function injectOneGoogleBar(barHtml, endOfBodyHtml) { |
| 693 var inHeadStyle = document.createElement('link'); |
| 694 inHeadStyle.rel = "stylesheet"; |
| 695 inHeadStyle.href = 'chrome-search://local-ntp/one-google/in-head.css'; |
| 696 document.head.appendChild(inHeadStyle); |
| 697 |
| 698 inHeadStyle.onload = function() { |
| 699 var inHeadScript = document.createElement('script'); |
| 700 inHeadScript.src = 'chrome-search://local-ntp/one-google/in-head.js'; |
| 701 document.head.appendChild(inHeadScript); |
| 702 |
| 703 inHeadScript.onload = function() { |
| 704 var ogElem = $('one-google'); |
| 705 ogElem.innerHTML = barHtml; |
| 706 |
| 707 var afterBarScript = document.createElement('script'); |
| 708 afterBarScript.src = |
| 709 'chrome-search://local-ntp/one-google/after-bar.js'; |
| 710 ogElem.parentNode.insertBefore(afterBarScript, ogElem.nextSibling); |
| 711 |
| 712 afterBarScript.onload = function() { |
| 713 $('one-google-end-of-body').innerHTML = endOfBodyHtml; |
| 714 |
| 715 var endOfBodyScript = document.createElement('script'); |
| 716 endOfBodyScript.src = |
| 717 'chrome-search://local-ntp/one-google/end-of-body.js'; |
| 718 document.body.appendChild(endOfBodyScript); |
| 719 } |
| 720 } |
| 721 } |
| 722 } |
| 723 |
| 724 |
676 return { | 725 return { |
677 init: init, // Exposed for testing. | 726 init: init, // Exposed for testing. |
678 listen: listen | 727 listen: listen |
679 }; | 728 }; |
680 | 729 |
681 } | 730 } |
682 | 731 |
683 if (!window.localNTPUnitTest) { | 732 if (!window.localNTPUnitTest) { |
684 LocalNTP().listen(); | 733 LocalNTP().listen(); |
685 } | 734 } |
OLD | NEW |