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

Unified Diff: chrome/browser/resources/local_ntp/local_ntp.js

Issue 2819553003: Hook up LocalNtpSource to OneGoogleBarService (Closed)
Patch Set: Tests! Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/local_ntp/local_ntp.html ('k') | chrome/browser/search/local_ntp_source.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/local_ntp/local_ntp.js
diff --git a/chrome/browser/resources/local_ntp/local_ntp.js b/chrome/browser/resources/local_ntp/local_ntp.js
index 8ba21d32b5aa53b73d264073f5ff1db0fe49d19c..637b99d7ff92a247c79fbd70d93f94f3f689dbe8 100644
--- a/chrome/browser/resources/local_ntp/local_ntp.js
+++ b/chrome/browser/resources/local_ntp/local_ntp.js
@@ -627,6 +627,17 @@ function init() {
// Update the fakebox style to match the current key capturing state.
setFakeboxFocus(searchboxApiHandle.isKeyCaptureEnabled);
+
+ // Inject the OneGoogleBar loader script. It'll create a global variable
+ // named "og" with the following fields:
+ // .html - the main bar HTML.
+ // .end_of_body_html - HTML to be inserted at the end of the body.
+ var ogScript = document.createElement('script');
+ ogScript.src = 'chrome-search://local-ntp/one-google.js';
+ document.body.appendChild(ogScript);
+ ogScript.onload = function() {
+ injectOneGoogleBar(og.html, og.end_of_body_html);
+ }
} else {
document.body.classList.add(CLASSES.NON_GOOGLE_PAGE);
}
@@ -673,6 +684,44 @@ function listen() {
document.addEventListener('DOMContentLoaded', init);
}
+
+/**
+ * Injects the One Google Bar into the page. Called asynchronously, so that it
+ * doesn't block the main page load.
+ */
+function injectOneGoogleBar(barHtml, endOfBodyHtml) {
+ var inHeadStyle = document.createElement('link');
+ inHeadStyle.rel = "stylesheet";
+ inHeadStyle.href = 'chrome-search://local-ntp/one-google/in-head.css';
+ document.head.appendChild(inHeadStyle);
+
+ inHeadStyle.onload = function() {
+ var inHeadScript = document.createElement('script');
+ inHeadScript.src = 'chrome-search://local-ntp/one-google/in-head.js';
+ document.head.appendChild(inHeadScript);
+
+ inHeadScript.onload = function() {
+ var ogElem = $('one-google');
+ ogElem.innerHTML = barHtml;
+
+ var afterBarScript = document.createElement('script');
+ afterBarScript.src =
+ 'chrome-search://local-ntp/one-google/after-bar.js';
+ ogElem.parentNode.insertBefore(afterBarScript, ogElem.nextSibling);
+
+ afterBarScript.onload = function() {
+ $('one-google-end-of-body').innerHTML = endOfBodyHtml;
+
+ var endOfBodyScript = document.createElement('script');
+ endOfBodyScript.src =
+ 'chrome-search://local-ntp/one-google/end-of-body.js';
+ document.body.appendChild(endOfBodyScript);
+ }
+ }
+ }
+}
+
+
return {
init: init, // Exposed for testing.
listen: listen
« no previous file with comments | « chrome/browser/resources/local_ntp/local_ntp.html ('k') | chrome/browser/search/local_ntp_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698