Commit 8576c403 authored by Kevin McNee's avatar Kevin McNee Committed by Commit Bot

Call WebContentsObserver::InnerWebContentsCreated for portals

InnerWebContentsCreated was only being called for GuestViews. We now
call it for portal inner contents creation.

This allows for test code, namely Safe Browsing tests, to be notified
of the creation of the inner contents, so that test classes are created
in time to observe the necessary events in the newly created contents.

Bug: 1096115
Change-Id: I6cc7e3cabb72523a8c116988194db2cbd42036cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2385775Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Commit-Queue: Kevin McNee <mcnee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805921}
parent 253d5ad0
...@@ -148,6 +148,26 @@ class DownloadItemCreatedObserver : public DownloadManager::Observer { ...@@ -148,6 +148,26 @@ class DownloadItemCreatedObserver : public DownloadManager::Observer {
DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver);
}; };
class InnerContentsCreationObserver : public content::WebContentsObserver {
public:
InnerContentsCreationObserver(
content::WebContents* web_contents,
base::RepeatingCallback<void(content::WebContents*)>
on_inner_contents_created)
: content::WebContentsObserver(web_contents),
on_inner_contents_created_(on_inner_contents_created) {}
// WebContentsObserver:
void InnerWebContentsCreated(
content::WebContents* inner_web_contents) override {
on_inner_contents_created_.Run(inner_web_contents);
}
private:
base::RepeatingCallback<void(content::WebContents*)>
on_inner_contents_created_;
};
// Test class to help create SafeBrowsingNavigationObservers for each // Test class to help create SafeBrowsingNavigationObservers for each
// WebContents before they are actually installed through AttachTabHelper. // WebContents before they are actually installed through AttachTabHelper.
class TestNavigationObserverManager class TestNavigationObserverManager
...@@ -162,6 +182,11 @@ class TestNavigationObserverManager ...@@ -162,6 +182,11 @@ class TestNavigationObserverManager
ASSERT_TRUE(contents); ASSERT_TRUE(contents);
observer_list_.push_back( observer_list_.push_back(
std::make_unique<SafeBrowsingNavigationObserver>(contents, this)); std::make_unique<SafeBrowsingNavigationObserver>(contents, this));
inner_contents_creation_observers_.push_back(
std::make_unique<InnerContentsCreationObserver>(
contents,
base::BindRepeating(&TestNavigationObserverManager::ObserveContents,
this)));
} }
// TabStripModelObserver: // TabStripModelObserver:
...@@ -183,6 +208,8 @@ class TestNavigationObserverManager ...@@ -183,6 +208,8 @@ class TestNavigationObserverManager
private: private:
std::vector<std::unique_ptr<SafeBrowsingNavigationObserver>> observer_list_; std::vector<std::unique_ptr<SafeBrowsingNavigationObserver>> observer_list_;
std::vector<std::unique_ptr<InnerContentsCreationObserver>>
inner_contents_creation_observers_;
DISALLOW_COPY_AND_ASSIGN(TestNavigationObserverManager); DISALLOW_COPY_AND_ASSIGN(TestNavigationObserverManager);
}; };
...@@ -2678,7 +2705,7 @@ class SBNavigationObserverPortalBrowserTest ...@@ -2678,7 +2705,7 @@ class SBNavigationObserverPortalBrowserTest
}; };
// Click a link which activates a portal to the landing page, and then click on // Click a link which activates a portal to the landing page, and then click on
// the landing page to trigger download. // the landing page to trigger the download.
IN_PROC_BROWSER_TEST_F(SBNavigationObserverPortalBrowserTest, IN_PROC_BROWSER_TEST_F(SBNavigationObserverPortalBrowserTest,
PortalActivation) { PortalActivation) {
GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL);
...@@ -2697,15 +2724,6 @@ IN_PROC_BROWSER_TEST_F(SBNavigationObserverPortalBrowserTest, ...@@ -2697,15 +2724,6 @@ IN_PROC_BROWSER_TEST_F(SBNavigationObserverPortalBrowserTest,
"});", "});",
landing_url))); landing_url)));
std::vector<content::WebContents*> inner_web_contents =
browser()
->tab_strip_model()
->GetActiveWebContents()
->GetInnerWebContents();
ASSERT_EQ(1u, inner_web_contents.size());
content::WebContents* portal_contents = inner_web_contents[0];
observer_manager_->ObserveContents(portal_contents);
// Note that this runs with a user gesture. // Note that this runs with a user gesture.
ASSERT_EQ(true, content::EvalJs( ASSERT_EQ(true, content::EvalJs(
browser()->tab_strip_model()->GetActiveWebContents(), browser()->tab_strip_model()->GetActiveWebContents(),
...@@ -2717,7 +2735,7 @@ IN_PROC_BROWSER_TEST_F(SBNavigationObserverPortalBrowserTest, ...@@ -2717,7 +2735,7 @@ IN_PROC_BROWSER_TEST_F(SBNavigationObserverPortalBrowserTest,
std::string test_server_ip(embedded_test_server()->host_port_pair().host()); std::string test_server_ip(embedded_test_server()->host_port_pair().host());
auto* nav_list = navigation_event_list(); auto* nav_list = navigation_event_list();
ASSERT_TRUE(nav_list); ASSERT_TRUE(nav_list);
ASSERT_EQ(3U, nav_list->Size()); ASSERT_EQ(4U, nav_list->Size());
VerifyNavigationEvent(GURL(), // source_url VerifyNavigationEvent(GURL(), // source_url
GURL(), // source_main_frame_url GURL(), // source_main_frame_url
initial_url, // original_request_url initial_url, // original_request_url
...@@ -2726,6 +2744,14 @@ IN_PROC_BROWSER_TEST_F(SBNavigationObserverPortalBrowserTest, ...@@ -2726,6 +2744,14 @@ IN_PROC_BROWSER_TEST_F(SBNavigationObserverPortalBrowserTest,
true, // has_committed true, // has_committed
false, // has_server_redirect false, // has_server_redirect
nav_list->Get(0)); nav_list->Get(0));
VerifyNavigationEvent(GURL(), // source_url
GURL(), // source_main_frame_url
landing_url, // original_request_url
landing_url, // destination_url
false, // is_user_initiated,
true, // has_committed
false, // has_server_redirect
nav_list->Get(1));
VerifyNavigationEvent(initial_url, // source_url VerifyNavigationEvent(initial_url, // source_url
initial_url, // source_main_frame_url initial_url, // source_main_frame_url
landing_url, // original_request_url landing_url, // original_request_url
...@@ -2733,7 +2759,7 @@ IN_PROC_BROWSER_TEST_F(SBNavigationObserverPortalBrowserTest, ...@@ -2733,7 +2759,7 @@ IN_PROC_BROWSER_TEST_F(SBNavigationObserverPortalBrowserTest,
true, // is_user_initiated, true, // is_user_initiated,
true, // has_committed true, // has_committed
false, // has_server_redirect false, // has_server_redirect
nav_list->Get(1)); nav_list->Get(2));
VerifyNavigationEvent(landing_url, // source_url VerifyNavigationEvent(landing_url, // source_url
landing_url, // source_main_frame_url landing_url, // source_main_frame_url
download_url, // original_request_url download_url, // original_request_url
...@@ -2741,7 +2767,7 @@ IN_PROC_BROWSER_TEST_F(SBNavigationObserverPortalBrowserTest, ...@@ -2741,7 +2767,7 @@ IN_PROC_BROWSER_TEST_F(SBNavigationObserverPortalBrowserTest,
true, // is_user_initiated, true, // is_user_initiated,
false, // has_committed false, // has_committed
false, // has_server_redirect false, // has_server_redirect
nav_list->Get(2)); nav_list->Get(3));
VerifyHostToIpMap(); VerifyHostToIpMap();
ReferrerChain referrer_chain; ReferrerChain referrer_chain;
......
...@@ -152,6 +152,7 @@ RenderFrameProxyHost* Portal::CreateProxyAndAttachPortal() { ...@@ -152,6 +152,7 @@ RenderFrameProxyHost* Portal::CreateProxyAndAttachPortal() {
WebContents::CreateParams params(outer_contents_impl->GetBrowserContext()); WebContents::CreateParams params(outer_contents_impl->GetBrowserContext());
portal_contents_.SetOwned(base::WrapUnique( portal_contents_.SetOwned(base::WrapUnique(
static_cast<WebContentsImpl*>(WebContents::Create(params).release()))); static_cast<WebContentsImpl*>(WebContents::Create(params).release())));
outer_contents_impl->InnerWebContentsCreated(portal_contents_.get());
web_contents_created = true; web_contents_created = true;
} }
......
...@@ -1182,6 +1182,11 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, ...@@ -1182,6 +1182,11 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
// this won't create one if none exists. // this won't create one if none exists.
FindRequestManager* GetFindRequestManagerForTesting(); FindRequestManager* GetFindRequestManagerForTesting();
// Convenience method to notify observers that an inner WebContents was
// created with |this| WebContents as its owner. This does *not* immediately
// guarantee that |inner_web_contents| has been added to the WebContents tree.
void InnerWebContentsCreated(WebContents* inner_web_contents);
// Detaches this WebContents from its outer WebContents. // Detaches this WebContents from its outer WebContents.
std::unique_ptr<WebContents> DetachFromOuterWebContents(); std::unique_ptr<WebContents> DetachFromOuterWebContents();
...@@ -1556,11 +1561,6 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, ...@@ -1556,11 +1561,6 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
// each inner WebContents is attached. // each inner WebContents is attached.
void FocusOuterAttachmentFrameChain(); void FocusOuterAttachmentFrameChain();
// Convenience method to notify observers that an inner WebContents was
// created with |this| WebContents as its owner. This does *not* immediately
// guarantee that |inner_web_contents| has been added to the WebContents tree.
void InnerWebContentsCreated(WebContents* inner_web_contents);
// Called just after an inner web contents is attached. // Called just after an inner web contents is attached.
void InnerWebContentsAttached(WebContents* inner_web_contents); void InnerWebContentsAttached(WebContents* inner_web_contents);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment