Refactor WebContentsDelegate::AddNewContents to take target_url

CL 2 of 3 to use target_url in Navigate to allow tabbed
PWAs to always open URLs outside of the app scope
in a NORMAL browser, rather than in an APP tab.

crrev.com/c/2172258 : Save target_url from CreateNewWindow
crrev.com/c/2167732 : Populate AddNewContents with target_url
crrev.com/c/2167649 : Use target_url in Navigate

AddNewContents is called after a renderer calls both CreateNewWindow
and ShowCreatedWindow.  The target_url from CreateNewWindow is
saved in WebContentsImpl::pending_contents_ and is now populated
into AddNewContents.

This is a refactor only change to add a new parameter
which is not yet used.

Bug: 1065915, 1063717
Change-Id: I8733014b1cf36bf73431b883b4825bce168e709c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2167732
Commit-Queue: Joel Hockey <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Cr-Commit-Position: refs/heads/master@{#764143}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 485287c9..e4319c21 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -3014,8 +3014,8 @@
 
       gfx::Rect initial_rect;  // Report an empty initial rect.
       delegate_->AddNewContents(this, std::move(new_contents),
-                                params.disposition, initial_rect,
-                                has_user_gesture, &was_blocked);
+                                params.target_url, params.disposition,
+                                initial_rect, has_user_gesture, &was_blocked);
       // The delegate may delete |new_contents_impl| during AddNewContents().
       if (!weak_new_contents)
         return nullptr;
@@ -3143,7 +3143,8 @@
     base::WeakPtr<WebContentsImpl> weak_created =
         created->weak_factory_.GetWeakPtr();
     delegate->AddNewContents(this, std::move(owned_created->contents),
-                             disposition, initial_rect, user_gesture, nullptr);
+                             std::move(owned_created->target_url), disposition,
+                             initial_rect, user_gesture, nullptr);
     // The delegate may delete |created| during AddNewContents().
     if (!weak_created)
       return;
@@ -4866,10 +4867,9 @@
       title_for_view_source, ui::PAGE_TRANSITION_LINK,
       /* is_renderer_initiated = */ false,
       /* blob_url_loader_factory = */ nullptr);
-  navigation_entry->SetVirtualURL(GURL(content::kViewSourceScheme +
-                                       std::string(":") +
-                                       frame_entry->url().spec()));
-
+  const GURL url(content::kViewSourceScheme + std::string(":") +
+                 frame_entry->url().spec());
+  navigation_entry->SetVirtualURL(url);
   navigation_entry->set_isolation_info(
       frame->GetIsolationInfoForSubresources());
 
@@ -4898,7 +4898,7 @@
   gfx::Rect initial_rect;
   constexpr bool kUserGesture = true;
   bool ignored_was_blocked;
-  delegate_->AddNewContents(this, std::move(view_source_contents),
+  delegate_->AddNewContents(this, std::move(view_source_contents), url,
                             WindowOpenDisposition::NEW_FOREGROUND_TAB,
                             initial_rect, kUserGesture, &ignored_was_blocked);
   // Note that the |delegate_| could have deleted |view_source_contents| during