Set the original url correctly if the frame is loaded via loadData Base URL

Upstream fix: https://codereview.chromium.org/176883012
BUG: b/13206940
This is not a direct cherry pick because this code schange get refactored
into render_frame_impl in chromium trunk.

Change-Id: If807722dfee9b8570bb0b54e53c383f857a57fd1
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index 1342817..84f63fe 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -1981,10 +1981,7 @@
     // Track the URL of the original request.  We use the first entry of the
     // redirect chain if it exists because the chain may have started in another
     // process.
-    if (params.redirects.size() > 0)
-      params.original_request_url = params.redirects.at(0);
-    else
-      params.original_request_url = original_request.url();
+    params.original_request_url = GetOriginalRequestURL(ds);
 
     params.history_list_was_cleared =
         navigation_state->history_list_was_cleared();
@@ -6474,4 +6471,20 @@
   SendUpdateFaviconURL(urls);
 }
 
+GURL RenderViewImpl::GetOriginalRequestURL(WebDataSource* ds) {
+  // WebDataSource has unreachable URL means that the frame is loaded through
+  // blink::WebFrame::loadData(), and the base URL will be in the redirect
+  // chain. However, we never visited the baseURL. So in this case, we should
+  // use the unreachable URL as the original URL.
+  if (ds->hasUnreachableURL())
+    return ds->unreachableURL();
+
+  std::vector<GURL> redirects;
+  GetRedirectChain(ds, &redirects);
+  if (!redirects.empty())
+    return redirects.at(0);
+
+  return ds->originalRequest().url();
+}
+
 }  // namespace content
diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h
index f341ecc..3015086 100644
--- a/content/renderer/render_view_impl.h
+++ b/content/renderer/render_view_impl.h
@@ -1112,6 +1112,12 @@
       const gfx::Range& selection_range,
       const ContextMenuParams& params);
 
+
+  // Returns the original request url. If there is no redirect, the original
+  // url is the same as ds->request()->url(). If the WebDataSource belongs to a
+  // frame was loaded by loadData, the original url will be ds->unreachableURL()
+  static GURL GetOriginalRequestURL(blink::WebDataSource* ds);
+
   // Starts nav_state_sync_timer_ if it isn't already running.
   void StartNavStateSyncTimerIfNecessary();