function buildPreview(doc) {
  // Get the link to the feed source.
  var link = doc.querySelector('link');
  var parentTag = link.parentNode.tagName;
  if (parentTag != 'item' && parentTag != 'entry') {
    moreStoriesUrl = link.textContent;
  }

  // Setup the title image.
  var image = doc.querySelector('image');
  var titleImg;

  // Stores whether language script is Right to Left or not for setting style
  // of share buttons(Facebook, Twitter and Google Buzz) in iframe.
  var isRtl = 'lTR';

  if (image) {
    var url = image.querySelector('url');
    if (url) {
      titleImg = url.textContent;

      // Stores URL of title image to be shown on pop-up page.
      var titleImgUrl = titleImg;
      var pattern = /ar_/gi;
      var result = titleImgUrl.match(pattern);
      if (result != null || titleImgUrl == ISRAEL_IMAGE_URL) {
        isRtl = 'rTL';
      }
    }
  }

  var img = $('title');
  if (titleImg) {
    img.src = titleImg;
    if (moreStoriesUrl) {
      $('title_a').addEventListener('click', moreStories);
    }
  } else {
    img.style.display = 'none';
  }

  // Construct the iframe's HTML.
  var iframe_src = '<!doctype html><html><head><script>' +
                   $('iframe_script').textContent + '<' +
                   '/script><style> ' +
                   '.rTL {margin-right: 102px; text-align: right;} ' +
                   '.lTR {margin-left: 102px; text-align: left;} ' +
                   '</style></head><body onload="frameLoaded();" ' +
                   'style="padding:0px;margin:0px;">';

  var feed = $('feed');
  feed.className = '';
  var entries = doc.getElementsByTagName('entry');
  if (entries.length == 0) {
    entries = doc.getElementsByTagName('item');
  }
  var count = Math.min(entries.length, maxFeedItems);

  // Stores required height by pop-up page.
  var minHeight = 19;
  minHeight = (minHeight * (count - 1)) + 100;
  document.querySelector('body').style.minHeight = minHeight + 'px';
  $('feed').innerHTML = '';

  for (var i = 0; i < count; i++) {
    item = entries.item(i);

    // Grab the title for the feed item.
    var itemTitle = item.querySelector('title');
    if (itemTitle) {
      itemTitle = itemTitle.textContent;
    } else {
      itemTitle = 'Unknown title';
    }

    // Grab the description.
    var itemDesc = item.querySelector('description');
    if (!itemDesc) {
      itemDesc = item.querySelector('summary');
      if (!itemDesc) {
        itemDesc = item.querySelector('content');
      }
    }
    if (itemDesc) {
      itemDesc = itemDesc.childNodes[0].nodeValue;

    } else {
      itemDesc = '';
    }
    var itemLink = item.querySelector('link');
    if (itemLink) {
      itemLink = itemLink.textContent;
    } else {
      itemLink = 'Unknown itemLink';
    }
    var item = document.createElement('div');
    item.className = 'item';
    var box = document.createElement('div');
    box.className = 'open_box';
    box.addEventListener('click', showDesc);
    item.appendChild(box);

    var title = document.createElement('a');
    title.className = 'item_title';
    title.innerText = itemTitle;
    title.addEventListener('click', showDesc);
    item.appendChild(title);

    var desc = document.createElement('iframe');
    desc.scrolling = 'no';
    desc.className = 'item_desc';
    item.appendChild(desc);
    feed.appendChild(item);

    // Adds share buttons images(Facebook, Twitter and Google Buzz).
    itemDesc += "<div class = '" + isRtl + "'>";
    itemDesc += "<a style='cursor: pointer' id='fb' " +
      "onclick='openNewsShareWindow(this.id,\"" + itemLink + "\")'>" +
      "<img src='" + chrome.extension.getURL('/images/fb.png') + "'/></a>";
    itemDesc += " <a style='cursor: pointer' id='twitter' " +
      "onclick='openNewsShareWindow(this.id,\"" + itemLink + "\")'>" +
      "<img src='" + chrome.extension.getURL('/images/twitter.png') + "'/></a>";
    itemDesc += " <a style='cursor: pointer' id='buzz' " +
      "onclick='openNewsShareWindow(this.id,\"" + itemLink + "\")'>" +
      "<img src='" + chrome.extension.getURL('/images/buzz.png') + "'/></a>";
    itemDesc += '</div>';

    // The story body is created as an iframe with a data: URL in order to
    // isolate it from this page and protect against XSS.  As a data URL, it
    // has limited privileges and must communicate back using postMessage().
    desc.src = 'data:text/html;charset=utf-8,' + btoa(unescape(encodeURIComponent(iframe_src + itemDesc + '</body></html>')));
  }
  if (moreStoriesUrl && entries.length != 0) {
    var more = document.createElement('a');
    more.className = 'more';
    more.innerText = moreStoriesLocale;
    more.addEventListener('click', moreStories);
    feed.appendChild(more);
  }
  setStyleByLang(titleImgUrl);

  // Checks whether feed retrieved has news story or not. If not, then shows
  // error message accordingly.
  if (entries.length == 0) {
    $('noStories').innerText = chrome.i18n.getMessage('noStory');
    $('noStories').style.display = 'block';
  } else {
    $('noStories').style.display = 'none';
  }
}
Generates news iframe in pop-up page by parsing retrieved feed.
@param {HTMLDocument} doc HTML Document received in feed.