// The port for communicating back to the extension.
var benchmarkExtensionPort = chrome.extension.connect();

// The url is what this page is known to the benchmark as.
// The benchmark uses this id to differentiate the benchmark's
// results from random pages being browsed.

// TODO(mbelshe): If the page redirects, the location changed and the
// benchmark stalls.
var benchmarkExtensionUrl = window.location.toString();

function sendTimesToExtension() {
  var times = window.chrome.loadTimes();

  if (times.finishLoadTime != 0) {
    benchmarkExtensionPort.postMessage({message: "load", url: benchmarkExtensionUrl, values: times});
  } else {
    window.setTimeout(sendTimesToExtension, 100);
  }
}

function loadComplete() {
  // Only trigger for top-level frames (e.g. the one we benchmarked)
  if (window.parent == window) {
    sendTimesToExtension();
  }
}

window.addEventListener("load", loadComplete);

// The port for communicating back to the extension.
var benchmarkExtensionPort = chrome.extension.connect();

// The url is what this page is known to the benchmark as.
// The benchmark uses this id to differentiate the benchmark's
// results from random pages being browsed.

// TODO(mbelshe): If the page redirects, the location changed and the
// benchmark stalls.
var benchmarkExtensionUrl = window.location.toString();

function sendTimesToExtension() {
  if (window.parent != window) {
    return;
  }

  var times = window.chrome.loadTimes();

  // If the load is not finished yet, schedule a timer to check again in a
  // little bit.
  if (times.finishLoadTime != 0) {
    benchmarkExtensionPort.postMessage({message: "load", url: benchmarkExtensionUrl, values: times});
  } else {
    window.setTimeout(sendTimesToExtension, 100);
  }
}

// We can't use the onload event because this script runs at document idle,
// which may run after the onload has completed.
sendTimesToExtension();

Update the benchmark to use the document.readyState to measure page-completedness rather than the onload event. Extensions were moved from the pre-onload state to running at document idle some time ago.
Update the benchmark to use the document.readyState to measure page-completedness
rather than the onload event.  Extensions were moved from the pre-onload state
to running at document idle some time ago.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/397013

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@32076 0039d316-1c4b-4281-b951-d872f2087c98
