Make to call WebContentsImpl::RenderViewCreated() when we create child window.

Actually we do not call WebContentsImpl::RenderViewCreated() when we care child window.
It makes many issues such as addJavascriptInterface() is not working well in child window.

BUG=361418
TEST=WebContentsImplBrowserTest.RenderViewCreatedForChildWindow

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271240 0039d316-1c4b-4281-b951-d872f2087c98
parent ffebd7dd
...@@ -1418,6 +1418,7 @@ void WebContentsImpl::CreateNewWindow( ...@@ -1418,6 +1418,7 @@ void WebContentsImpl::CreateNewWindow(
if (params.disposition == NEW_BACKGROUND_TAB) if (params.disposition == NEW_BACKGROUND_TAB)
create_params.initially_hidden = true; create_params.initially_hidden = true;
new_contents->Init(create_params); new_contents->Init(create_params);
new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
// Save the window for later if we're not suppressing the opener (since it // Save the window for later if we're not suppressing the opener (since it
// will be shown immediately). // will be shown immediately).
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "content/browser/renderer_host/render_view_host_delegate.h" #include "content/browser/renderer_host/render_view_host_delegate.h"
#include "content/browser/renderer_host/render_widget_host_delegate.h" #include "content/browser/renderer_host/render_widget_host_delegate.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/browser/ax_event_notification_details.h"
#include "content/public/browser/color_chooser.h" #include "content/public/browser/color_chooser.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
...@@ -630,6 +629,7 @@ class CONTENT_EXPORT WebContentsImpl ...@@ -630,6 +629,7 @@ class CONTENT_EXPORT WebContentsImpl
private: private:
friend class TestNavigationObserver; friend class TestNavigationObserver;
friend class WebContentsAddedObserver;
friend class WebContentsObserver; friend class WebContentsObserver;
friend class WebContents; // To implement factory methods. friend class WebContents; // To implement factory methods.
......
...@@ -437,5 +437,24 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ...@@ -437,5 +437,24 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
EXPECT_EQ(3, delegate->loadingStateToDifferentDocumentCount()); EXPECT_EQ(3, delegate->loadingStateToDifferentDocumentCount());
} }
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
RenderViewCreatedForChildWindow) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
NavigateToURL(shell(),
embedded_test_server()->GetURL("/title1.html"));
WebContentsAddedObserver new_web_contents_observer;
ASSERT_TRUE(ExecuteScript(shell()->web_contents(),
"var a = document.createElement('a');"
"a.href='./title2.html';"
"a.target = '_blank';"
"document.body.appendChild(a);"
"a.click();"));
WebContents* new_web_contents = new_web_contents_observer.GetWebContents();
WaitForLoadStop(new_web_contents);
EXPECT_TRUE(new_web_contents_observer.RenderViewCreatedCalled());
}
} // namespace content } // namespace content
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -91,4 +92,57 @@ void ShellAddedObserver::ShellCreated(Shell* shell) { ...@@ -91,4 +92,57 @@ void ShellAddedObserver::ShellCreated(Shell* shell) {
runner_->QuitClosure().Run(); runner_->QuitClosure().Run();
} }
class RenderViewCreatedObserver : public WebContentsObserver {
public:
RenderViewCreatedObserver(WebContents* web_contents)
: WebContentsObserver(web_contents),
render_view_created_called_(false) {
}
// WebContentsObserver:
virtual void RenderViewCreated(RenderViewHost* rvh) OVERRIDE {
render_view_created_called_ = true;
}
bool render_view_created_called_;
};
WebContentsAddedObserver::WebContentsAddedObserver()
: web_contents_created_callback_(
base::Bind(
&WebContentsAddedObserver::WebContentsCreated,
base::Unretained(this))),
web_contents_(NULL) {
WebContentsImpl::AddCreatedCallback(web_contents_created_callback_);
}
WebContentsAddedObserver::~WebContentsAddedObserver() {
WebContentsImpl::RemoveCreatedCallback(web_contents_created_callback_);
}
void WebContentsAddedObserver::WebContentsCreated(WebContents* web_contents) {
DCHECK(!web_contents_);
web_contents_ = web_contents;
child_observer_.reset(new RenderViewCreatedObserver(web_contents));
if (runner_.get())
runner_->QuitClosure().Run();
}
WebContents* WebContentsAddedObserver::GetWebContents() {
if (web_contents_)
return web_contents_;
runner_ = new MessageLoopRunner();
runner_->Run();
return web_contents_;
}
bool WebContentsAddedObserver::RenderViewCreatedCalled() {
if (child_observer_)
return child_observer_->render_view_created_called_;
return false;
}
} // namespace content } // namespace content
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ #ifndef CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_
#define CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ #define CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_
#include "base/callback.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -25,7 +26,9 @@ class Rect; ...@@ -25,7 +26,9 @@ class Rect;
namespace content { namespace content {
class MessageLoopRunner; class MessageLoopRunner;
class RenderViewCreatedObserver;
class Shell; class Shell;
class WebContents;
// Generate the file path for testing a particular test. // Generate the file path for testing a particular test.
// The file for the tests is all located in // The file for the tests is all located in
...@@ -76,6 +79,33 @@ class ShellAddedObserver { ...@@ -76,6 +79,33 @@ class ShellAddedObserver {
DISALLOW_COPY_AND_ASSIGN(ShellAddedObserver); DISALLOW_COPY_AND_ASSIGN(ShellAddedObserver);
}; };
// Used to wait for a new WebContents to be created. Instantiate this object
// before the operation that will create the window.
class WebContentsAddedObserver {
public:
WebContentsAddedObserver();
~WebContentsAddedObserver();
// Will run a message loop to wait for the new window if it hasn't been
// created since the constructor
WebContents* GetWebContents();
// Will tell whether RenderViewCreated Callback has invoked
bool RenderViewCreatedCalled();
base::Callback<void(WebContents*)> web_contents_created_callback_;
private:
void WebContentsCreated(WebContents* web_contents);
// Callback invoked on WebContents creation.
WebContents* web_contents_;
scoped_ptr<RenderViewCreatedObserver> child_observer_;
scoped_refptr<MessageLoopRunner> runner_;
DISALLOW_COPY_AND_ASSIGN(WebContentsAddedObserver);
};
#if defined OS_MACOSX #if defined OS_MACOSX
void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds); void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds);
#endif #endif
......
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