1diff --git content/browser/web_contents/web_contents_impl.cc content/browser/web_contents/web_contents_impl.cc 2index 6b742d4635454..ddba5aadb21a1 100644 3--- content/browser/web_contents/web_contents_impl.cc 4+++ content/browser/web_contents/web_contents_impl.cc 5@@ -2983,6 +2983,12 @@ void WebContentsImpl::Init(const WebContents::CreateParams& params, 6 site_instance.get(), params.renderer_initiated_creation, 7 params.main_frame_name, GetOriginalOpener(), primary_main_frame_policy); 8 9+ if (params.view && params.delegate_view) { 10+ view_.reset(params.view); 11+ render_view_host_delegate_view_ = params.delegate_view; 12+ } 13+ 14+ if (!view_) { 15 WebContentsViewDelegate* delegate = 16 GetContentClient()->browser()->GetWebContentsViewDelegate(this); 17 18@@ -2993,6 +2999,7 @@ void WebContentsImpl::Init(const WebContents::CreateParams& params, 19 view_.reset(CreateWebContentsView(this, delegate, 20 &render_view_host_delegate_view_)); 21 } 22+ } 23 CHECK(render_view_host_delegate_view_); 24 CHECK(view_.get()); 25 26@@ -3857,6 +3864,15 @@ FrameTree* WebContentsImpl::CreateNewWindow( 27 // objects. 28 create_params.renderer_initiated_creation = !is_new_browsing_instance; 29 30+ if (delegate_) { 31+ delegate_->GetCustomWebContentsView(this, 32+ params.target_url, 33+ render_process_id, 34+ opener->GetRoutingID(), 35+ &create_params.view, 36+ &create_params.delegate_view); 37+ } 38+ 39 std::unique_ptr<WebContentsImpl> new_contents; 40 if (!is_guest) { 41 create_params.context = view_->GetNativeView(); 42@@ -7651,6 +7667,9 @@ void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, 43 // frames). 44 SetFocusedFrameTree(node->frame_tree()); 45 } 46+ 47+ observers_.NotifyObservers(&WebContentsObserver::OnFrameFocused, 48+ node->current_frame_host()); 49 } 50 51 void WebContentsImpl::DidCallFocus() { 52diff --git content/public/browser/web_contents.h content/public/browser/web_contents.h 53index b980a289bd530..3b33291faa4b9 100644 54--- content/public/browser/web_contents.h 55+++ content/public/browser/web_contents.h 56@@ -92,10 +92,12 @@ class BrowserContext; 57 class BrowserPluginGuestDelegate; 58 class RenderFrameHost; 59 class RenderViewHost; 60+class RenderViewHostDelegateView; 61 class RenderWidgetHostView; 62 class ScreenOrientationDelegate; 63 class SiteInstance; 64 class WebContentsDelegate; 65+class WebContentsView; 66 class WebUI; 67 struct DropData; 68 struct MHTMLGenerationParams; 69@@ -233,6 +235,10 @@ class WebContents : public PageNavigator, 70 network::mojom::WebSandboxFlags starting_sandbox_flags = 71 network::mojom::WebSandboxFlags::kNone; 72 73+ // Optionally specify the view and delegate view. 74+ content::WebContentsView* view = nullptr; 75+ content::RenderViewHostDelegateView* delegate_view = nullptr; 76+ 77 // Value used to set the last time the WebContents was made active, this is 78 // the value that'll be returned by GetLastActiveTime(). If this is left 79 // default initialized then the value is not passed on to the WebContents 80diff --git content/public/browser/web_contents_delegate.h content/public/browser/web_contents_delegate.h 81index 58e977220a5d9..17c8e137c4f61 100644 82--- content/public/browser/web_contents_delegate.h 83+++ content/public/browser/web_contents_delegate.h 84@@ -57,10 +57,12 @@ class EyeDropperListener; 85 class FileSelectListener; 86 class JavaScriptDialogManager; 87 class RenderFrameHost; 88+class RenderViewHostDelegateView; 89 class RenderWidgetHost; 90 class SessionStorageNamespace; 91 class SiteInstance; 92 class WebContentsImpl; 93+class WebContentsView; 94 struct ContextMenuParams; 95 struct DropData; 96 struct MediaPlayerWatchTime; 97@@ -343,6 +345,14 @@ class CONTENT_EXPORT WebContentsDelegate { 98 const StoragePartitionId& partition_id, 99 SessionStorageNamespace* session_storage_namespace); 100 101+ virtual void GetCustomWebContentsView( 102+ WebContents* web_contents, 103+ const GURL& target_url, 104+ int opener_render_process_id, 105+ int opener_render_frame_id, 106+ content::WebContentsView** view, 107+ content::RenderViewHostDelegateView** delegate_view) {} 108+ 109 // Notifies the delegate about the creation of a new WebContents. This 110 // typically happens when popups are created. 111 virtual void WebContentsCreated(WebContents* source_contents, 112diff --git content/public/browser/web_contents_observer.h content/public/browser/web_contents_observer.h 113index 469b98f8405d2..980fed8e97ea1 100644 114--- content/public/browser/web_contents_observer.h 115+++ content/public/browser/web_contents_observer.h 116@@ -778,6 +778,10 @@ class CONTENT_EXPORT WebContentsObserver { 117 // WebContents has gained/lost focus. 118 virtual void OnFocusChangedInPage(FocusedNodeDetails* details) {} 119 120+ // Notification that |render_frame_host| for this WebContents has gained 121+ // focus. 122+ virtual void OnFrameFocused(RenderFrameHost* render_frame_host) {} 123+ 124 // Notifies that the manifest URL for the main frame changed to 125 // |manifest_url|. This will be invoked when a document with a manifest loads 126 // or when the manifest URL changes (possibly to nothing). It is not invoked 127