1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5
6goog.provide('cvox.SearchLoader');
7goog.require('cvox.SearchContextMenu');
8
9/**
10 * @fileoverview Inject the script into the page.
11 */
12
13/**
14 * @constructor
15 */
16cvox.SearchLoader = function() {
17};
18
19/**
20 * Called when document ready state changes.
21 */
22cvox.SearchLoader.onReadyStateChange = function() {
23  /* Make sure document is complete. Loading base.js when the document is
24   * loading will destroy the DOM. */
25  if (document.readyState !== 'complete') {
26    return;
27  }
28  var GOOGLE_HOST = 'www.google.com';
29  var SEARCH_PATH = '/search';
30
31  if (window.location.host !== GOOGLE_HOST ||
32      window.location.pathname !== SEARCH_PATH) {
33    return;
34  }
35
36  cvox.SearchContextMenu.init();
37};
38
39/**
40 * Inject Search into the page.
41 */
42cvox.SearchLoader.init = function() {
43  if (document.readyState !== 'complete') {
44    document.onreadystatechange = cvox.SearchLoader.onReadyStateChange;
45  } else {
46    cvox.SearchLoader.onReadyStateChange();
47  }
48};
49