Navigation transitions (web to native app): Get names and rects of transition elements (Chrome side)

Web to native app navigation transition uses Activity Transitions APIs in Android L. It requires the names and rects of transition elements. This CL gets the names and rects and pass them to TransitionRequestManager.

This is the Chrome side of the CL. Blink side will be done after this CL is landed. https://codereview.chromium.org/654953002/

Design doc: https://docs.google.com/a/chromium.org/document/d/17jg1RRL3RI969cLwbKBIcoGDsPwqaEdBxafGNYGwiY4/edit#
Demo video: https://drive.google.com/a/google.com/file/d/0B3hetueIc91Gd01DU25uT2hWU2M/view?usp=sharing
Activity Transitions in Android L: https://developer.android.com/preview/material/animations.html#transitions

BUG=370696

Review URL: https://codereview.chromium.org/652283002

Cr-Commit-Position: refs/heads/master@{#300304}
diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc
index 546a95e..4146c91d 100644
--- a/content/browser/renderer_host/render_message_filter.cc
+++ b/content/browser/renderer_host/render_message_filter.cc
@@ -1227,13 +1227,15 @@
 #endif
 
 void RenderMessageFilter::OnAddNavigationTransitionData(
-    int render_frame_id,
-    const std::string& allowed_destination_host_pattern,
-    const std::string& selector,
-    const std::string& markup) {
+    FrameHostMsg_AddNavigationTransitionData_Params params) {
   TransitionRequestManager::GetInstance()->AddPendingTransitionRequestData(
-      render_process_id_, render_frame_id, allowed_destination_host_pattern,
-      selector, markup);
+      render_process_id_,
+      params.render_frame_id,
+      params.allowed_destination_host_pattern,
+      params.selector,
+      params.markup,
+      params.names,
+      params.rects);
 }
 
 void RenderMessageFilter::OnAllocateGpuMemoryBuffer(
diff --git a/content/browser/renderer_host/render_message_filter.h b/content/browser/renderer_host/render_message_filter.h
index e8add98..5aa9054 100644
--- a/content/browser/renderer_host/render_message_filter.h
+++ b/content/browser/renderer_host/render_message_filter.h
@@ -27,6 +27,7 @@
 #include "media/base/channel_layout.h"
 #include "net/cookies/canonical_cookie.h"
 #include "third_party/WebKit/public/web/WebPopupType.h"
+#include "ui/gfx/geometry/rect.h"
 #include "ui/gfx/gpu_memory_buffer.h"
 #include "ui/gfx/native_widget_types.h"
 #include "ui/surface/transport_dib.h"
@@ -46,6 +47,7 @@
 #endif
 
 struct FontDescriptor;
+struct FrameHostMsg_AddNavigationTransitionData_Params;
 struct ViewHostMsg_CreateWindow_Params;
 
 namespace blink {
@@ -288,10 +290,7 @@
 #endif
 
   void OnAddNavigationTransitionData(
-    int render_frame_id,
-    const std::string& allowed_destination_host_pattern,
-    const std::string& selector,
-    const std::string& markup);
+      FrameHostMsg_AddNavigationTransitionData_Params params);
 
   void OnAllocateGpuMemoryBuffer(uint32 width,
                                  uint32 height,
diff --git a/content/browser/transition_browsertest.cc b/content/browser/transition_browsertest.cc
index 2452dd6c..6d199a8 100644
--- a/content/browser/transition_browsertest.cc
+++ b/content/browser/transition_browsertest.cc
@@ -64,8 +64,9 @@
         ResourceRequestInfoImpl::ForRequest(request_);
 
     if (is_transition_request_) {
-      TransitionRequestManager::GetInstance()->AddPendingTransitionRequestData(
-          info->GetChildID(), info->GetRenderFrameID(), "*", "", "");
+      TransitionRequestManager::GetInstance(
+          )->AddPendingTransitionRequestDataForTesting(
+              info->GetChildID(), info->GetRenderFrameID());
     }
   }
 
diff --git a/content/browser/transition_request_manager.cc b/content/browser/transition_request_manager.cc
index e2c83ea..b863991 100644
--- a/content/browser/transition_request_manager.cc
+++ b/content/browser/transition_request_manager.cc
@@ -82,6 +82,22 @@
 TransitionLayerData::~TransitionLayerData() {
 }
 
+TransitionRequestManager::TransitionRequestData::AllowedEntry::AllowedEntry(
+    const std::string& allowed_destination_host_pattern,
+    const std::string& css_selector,
+    const std::string& markup,
+    const std::vector<std::string>& names,
+    const std::vector<gfx::Rect>& rects)
+    : allowed_destination_host_pattern(allowed_destination_host_pattern),
+      css_selector(css_selector),
+      markup(markup),
+      names(names),
+      rects(rects) {
+}
+
+TransitionRequestManager::TransitionRequestData::AllowedEntry::~AllowedEntry() {
+}
+
 void TransitionRequestManager::ParseTransitionStylesheetsFromHeaders(
     const scoped_refptr<net::HttpResponseHeaders>& headers,
     std::vector<GURL>& entering_stylesheets,
@@ -112,10 +128,14 @@
 void TransitionRequestManager::TransitionRequestData::AddEntry(
     const std::string& allowed_destination_host_pattern,
     const std::string& css_selector,
-    const std::string& markup) {
+    const std::string& markup,
+    const std::vector<std::string>& names,
+    const std::vector<gfx::Rect>& rects) {
   allowed_entries_.push_back(AllowedEntry(allowed_destination_host_pattern,
                                           css_selector,
-                                          markup));
+                                          markup,
+                                          names,
+                                          rects));
 }
 
 bool TransitionRequestManager::TransitionRequestData::FindEntry(
@@ -133,6 +153,8 @@
   const AllowedEntry& allowed_entry = allowed_entries_[0];
   transition_data->markup = allowed_entry.markup;
   transition_data->css_selector = allowed_entry.css_selector;
+  transition_data->names = allowed_entry.names;
+  transition_data->rects = allowed_entry.rects;
   return true;
 }
 
@@ -155,13 +177,28 @@
     int render_frame_id,
     const std::string& allowed_destination_host_pattern,
     const std::string& css_selector,
-    const std::string& markup) {
+    const std::string& markup,
+    const std::vector<std::string>& names,
+    const std::vector<gfx::Rect>& rects) {
   DCHECK_CURRENTLY_ON(BrowserThread::IO);
 
   std::pair<int, int> key(render_process_id, render_frame_id);
-  pending_transition_frames_[key].AddEntry(allowed_destination_host_pattern,
-                                           css_selector,
-                                           markup);
+  pending_transition_frames_[key].AddEntry(
+      allowed_destination_host_pattern, css_selector, markup, names, rects);
+}
+
+void TransitionRequestManager::AddPendingTransitionRequestDataForTesting(
+    int render_process_id,
+    int render_frame_id) {
+  DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+  std::pair<int, int> key(render_process_id, render_frame_id);
+  pending_transition_frames_[key].AddEntry(
+      "*", /* allowed_destination_host_pattern */
+      "", /* css_selector */
+      "", /* markup */
+      std::vector<std::string>(), /* names */
+      std::vector<gfx::Rect>()); /* rects */
 }
 
 void TransitionRequestManager::ClearPendingTransitionRequestData(
diff --git a/content/browser/transition_request_manager.h b/content/browser/transition_request_manager.h
index 0a01878e..a610896 100644
--- a/content/browser/transition_request_manager.h
+++ b/content/browser/transition_request_manager.h
@@ -13,6 +13,7 @@
 #include "base/basictypes.h"
 #include "base/memory/ref_counted.h"
 #include "content/common/content_export.h"
+#include "ui/gfx/geometry/rect.h"
 #include "url/gurl.h"
 
 template <typename T>
@@ -32,6 +33,8 @@
 
   std::string markup;
   std::string css_selector;
+  std::vector<std::string> names;
+  std::vector<gfx::Rect> rects;
   scoped_refptr<net::HttpResponseHeaders> response_headers;
   GURL request_url;
 };
@@ -69,7 +72,12 @@
       int render_frame_id,
       const std::string& allowed_destination_host_pattern,
       const std::string& css_selector,
-      const std::string& markup);
+      const std::string& markup,
+      const std::vector<std::string>& names,
+      const std::vector<gfx::Rect>& rects);
+  CONTENT_EXPORT void AddPendingTransitionRequestDataForTesting(
+      int render_process_id,
+      int render_frame_id);
 
   void ClearPendingTransitionRequestData(int render_process_id,
                                          int render_frame_id);
@@ -81,7 +89,9 @@
     ~TransitionRequestData();
     void AddEntry(const std::string& allowed_destination_host_pattern,
                   const std::string& selector,
-                  const std::string& markup);
+                  const std::string& markup,
+                  const std::vector<std::string>& names,
+                  const std::vector<gfx::Rect>& rects);
     bool FindEntry(const GURL& request_url,
                     TransitionLayerData* transition_data);
 
@@ -93,13 +103,15 @@
       std::string allowed_destination_host_pattern;
       std::string css_selector;
       std::string markup;
+      std::vector<std::string> names;
+      std::vector<gfx::Rect> rects;
 
       AllowedEntry(const std::string& allowed_destination_host_pattern,
                    const std::string& css_selector,
-                   const std::string& markup) :
-        allowed_destination_host_pattern(allowed_destination_host_pattern),
-        css_selector(css_selector),
-        markup(markup) {}
+                   const std::string& markup,
+                   const std::vector<std::string>& names,
+                   const std::vector<gfx::Rect>& rects);
+      ~AllowedEntry();
     };
     std::vector<AllowedEntry> allowed_entries_;
   };
diff --git a/content/browser/web_contents/web_contents_android.cc b/content/browser/web_contents/web_contents_android.cc
index 52702a41..1bef8a3 100644
--- a/content/browser/web_contents/web_contents_android.cc
+++ b/content/browser/web_contents/web_contents_android.cc
@@ -151,13 +151,11 @@
   BrowserThread::PostTask(
       BrowserThread::IO,
       FROM_HERE,
-      base::Bind(&TransitionRequestManager::AddPendingTransitionRequestData,
-                 base::Unretained(TransitionRequestManager::GetInstance()),
-                 frame->GetProcess()->GetID(),
-                 frame->GetRoutingID(),
-                 "*",
-                 "",
-                 ""));
+      base::Bind(
+          &TransitionRequestManager::AddPendingTransitionRequestDataForTesting,
+          base::Unretained(TransitionRequestManager::GetInstance()),
+          frame->GetProcess()->GetID(),
+          frame->GetRoutingID()));
 }
 
 void WebContentsAndroid::SetupTransitionView(JNIEnv* env,
diff --git a/content/common/frame_messages.h b/content/common/frame_messages.h
index 70c479c..1773952 100644
--- a/content/common/frame_messages.h
+++ b/content/common/frame_messages.h
@@ -262,6 +262,15 @@
   IPC_STRUCT_MEMBER(std::string, frame_to_navigate)
 IPC_STRUCT_END()
 
+IPC_STRUCT_BEGIN(FrameHostMsg_AddNavigationTransitionData_Params)
+  IPC_STRUCT_MEMBER(int, render_frame_id)
+  IPC_STRUCT_MEMBER(std::string, allowed_destination_host_pattern)
+  IPC_STRUCT_MEMBER(std::string, selector)
+  IPC_STRUCT_MEMBER(std::string, markup)
+  IPC_STRUCT_MEMBER(std::vector<std::string>, names)
+  IPC_STRUCT_MEMBER(std::vector<gfx::Rect>, rects)
+IPC_STRUCT_END()
+
 IPC_STRUCT_BEGIN(FrameHostMsg_OpenURL_Params)
   IPC_STRUCT_MEMBER(GURL, url)
   IPC_STRUCT_MEMBER(content::Referrer, referrer)
@@ -738,11 +747,8 @@
 
 // Notifies the browser that the renderer has a pending navigation transition.
 // The string parameters are all UTF8.
-IPC_MESSAGE_CONTROL4(FrameHostMsg_AddNavigationTransitionData,
-                     int /* render_frame_id */,
-                     std::string  /* allowed_destination_host_pattern */,
-                     std::string  /* selector */,
-                     std::string  /* markup */)
+IPC_MESSAGE_CONTROL1(FrameHostMsg_AddNavigationTransitionData,
+                     FrameHostMsg_AddNavigationTransitionData_Params)
 
 // PlzNavigate
 // Tells the browser to perform a navigation.
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
index 5c37f722..0ead242 100644
--- a/content/renderer/render_frame_impl.cc
+++ b/content/renderer/render_frame_impl.cc
@@ -2499,13 +2499,41 @@
   render_view_->didUpdateCurrentHistoryItem(frame);
 }
 
+// TODO(zhenw): This will be removed once the blink side implementation is done.
 void RenderFrameImpl::addNavigationTransitionData(
     const blink::WebString& allowed_destination_host_pattern,
     const blink::WebString& selector,
     const blink::WebString& markup) {
-  Send(new FrameHostMsg_AddNavigationTransitionData(
-      routing_id_, allowed_destination_host_pattern.utf8(), selector.utf8(),
-      markup.utf8()));
+  FrameHostMsg_AddNavigationTransitionData_Params params;
+  params.render_frame_id = routing_id_;
+  params.allowed_destination_host_pattern =
+      allowed_destination_host_pattern.utf8();
+  params.selector = selector.utf8();
+  params.markup = markup.utf8();
+
+  Send(new FrameHostMsg_AddNavigationTransitionData(params));
+}
+
+void RenderFrameImpl::addNavigationTransitionData(
+    const blink::WebString& allowed_destination_host_pattern,
+    const blink::WebString& selector,
+    const blink::WebString& markup,
+    const blink::WebVector<blink::WebString>& web_names,
+    const blink::WebVector<blink::WebRect>& web_rects) {
+  FrameHostMsg_AddNavigationTransitionData_Params params;
+  params.render_frame_id = routing_id_;
+  params.allowed_destination_host_pattern =
+      allowed_destination_host_pattern.utf8();
+  params.selector = selector.utf8();
+  params.markup = markup.utf8();
+  for (size_t i = 0; i < web_names.size(); i++) {
+    params.names.push_back(web_names[i].utf8());
+  }
+  for (size_t i = 0; i < web_rects.size(); i++) {
+    params.rects.push_back(gfx::Rect(web_rects[i]));
+  }
+
+  Send(new FrameHostMsg_AddNavigationTransitionData(params));
 }
 
 void RenderFrameImpl::didChangeThemeColor() {
diff --git a/content/renderer/render_frame_impl.h b/content/renderer/render_frame_impl.h
index a5e394b..379ef9cb 100644
--- a/content/renderer/render_frame_impl.h
+++ b/content/renderer/render_frame_impl.h
@@ -36,6 +36,7 @@
 
 class GURL;
 class TransportDIB;
+struct FrameHostMsg_AddNavigationTransitionData_Params;
 struct FrameMsg_Navigate_Params;
 struct FrameMsg_RequestNavigation_Params;
 
@@ -372,9 +373,15 @@
                                      blink::WebHistoryCommitType commit_type);
   virtual void didUpdateCurrentHistoryItem(blink::WebLocalFrame* frame);
   virtual void addNavigationTransitionData(
+        const blink::WebString& allowedDestinationOrigin,
+        const blink::WebString& selector,
+        const blink::WebString& markup);
+  virtual void addNavigationTransitionData(
       const blink::WebString& allowedDestinationOrigin,
       const blink::WebString& selector,
-      const blink::WebString& markup);
+      const blink::WebString& markup,
+      const blink::WebVector<blink::WebString>& web_names,
+      const blink::WebVector<blink::WebRect>& web_rects);
   virtual void didChangeThemeColor();
   virtual void requestNotificationPermission(
       const blink::WebSecurityOrigin& origin,