Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1716)

Unified Diff: content/browser/web_contents/web_contents_impl.cc

Issue 921443003: Fix RenderFrameCreated and RenderFrameDeleted WebContentsObserver methods (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Geolocation unit tests to create TestWebContents instead of regular WebContents. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/web_contents/web_contents_impl.cc
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 84565a2f99f77119f61048fdf2fa74dd51a129b7..94fd4b63e979f1ab1b5ebd24a3dac7bfdc8e077d 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -408,14 +408,10 @@ WebContentsImpl::~WebContentsImpl() {
// Manually call the observer methods for the root frame tree node.
RenderFrameHostManager* root = GetRenderManager();
- if (root->pending_frame_host()) {
- FOR_EACH_OBSERVER(WebContentsObserver,
- observers_,
- RenderFrameDeleted(root->pending_frame_host()));
- }
- FOR_EACH_OBSERVER(WebContentsObserver,
- observers_,
- RenderFrameDeleted(root->current_frame_host()));
+
+ if (root->pending_frame_host())
+ root->pending_frame_host()->SetRenderFrameCreated(false);
+ root->current_frame_host()->SetRenderFrameCreated(false);
if (root->pending_render_view_host()) {
FOR_EACH_OBSERVER(WebContentsObserver,
@@ -505,9 +501,12 @@ bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
ObserverListBase<WebContentsObserver>::Iterator it(observers_);
WebContentsObserver* observer;
if (render_frame_host) {
- while ((observer = it.GetNext()) != NULL)
- if (observer->OnMessageReceived(message, render_frame_host))
- return true;
+ if (!static_cast<RenderFrameHostImpl*>(render_frame_host)
+ ->is_swapped_out()) {
Charlie Reis 2015/02/12 00:29:31 I'm worried about regressions from this change. T
nasko 2015/02/12 17:52:26 Hmm, don't quite recall, but after all the followu
+ while ((observer = it.GetNext()) != NULL)
+ if (observer->OnMessageReceived(message, render_frame_host))
+ return true;
+ }
} else {
while ((observer = it.GetNext()) != NULL)
if (observer->OnMessageReceived(message))
@@ -1266,6 +1265,14 @@ void WebContentsImpl::Init(const WebContents::CreateParams& params) {
for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
g_created_callbacks.Get().at(i).Run(this);
+
+ // If the WebContents creation was renderer-initiated, it means that the
+ // corresponding RenderView and main RenderFrame have already been created.
Charlie Reis 2015/02/12 00:29:31 Wow. There are so many ways to create RenderFrame
nasko 2015/02/12 17:52:26 Acknowledged.
+ // Ensure observers are notified about this.
+ if (params.renderer_created) {
Charlie Reis 2015/02/12 00:29:31 Maybe params.renderer_initiated_creation?
nasko 2015/02/12 17:52:26 Done.
+ RenderViewCreated(GetRenderViewHost());
+ GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
+ }
}
void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
@@ -1584,6 +1591,7 @@ void WebContentsImpl::CreateNewWindow(
create_params.opener_suppressed = params.opener_suppressed;
if (params.disposition == NEW_BACKGROUND_TAB)
create_params.initially_hidden = true;
+ create_params.renderer_created = true;
WebContentsImpl* new_contents = NULL;
if (!is_guest) {
@@ -1597,7 +1605,6 @@ void WebContentsImpl::CreateNewWindow(
new_contents->GetController().SetSessionStorageNamespace(
partition_id,
session_storage_namespace);
- new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
// Save the window for later if we're not suppressing the opener (since it
// will be shown immediately).
@@ -3649,14 +3656,6 @@ void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
FOR_EACH_OBSERVER(
WebContentsObserver, observers_, RenderViewCreated(render_view_host));
- // We tell the observers now instead of when the main RenderFrameHostImpl is
- // constructed because otherwise it would be too early (i.e. IPCs sent to the
- // frame would be dropped because it's not created yet).
- RenderFrameHost* main_frame = render_view_host->GetMainFrame();
- FOR_EACH_OBSERVER(
- WebContentsObserver, observers_, RenderFrameCreated(main_frame));
- SetAccessibilityModeOnFrame(accessibility_mode_, main_frame);
Charlie Reis 2015/02/12 00:29:31 Where does SetAccessibilityModeOnFrame get called
nasko 2015/02/12 17:52:26 WebContentsImpl::RenderFrameCreated has pretty muc
-
DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host);
}
@@ -3690,10 +3689,6 @@ void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
base::TerminationStatus status,
int error_code) {
- // TODO(nasko): This isn't ideal; the termination process should be handled by
- // RenderFrameDeleted(). See http://crbug.com/455943.
- ClearPowerSaveBlockers(rvh->GetMainFrame());
Charlie Reis 2015/02/12 00:29:31 Just to confirm, we now get RenderFrameDeleted in
nasko 2015/02/12 17:52:26 Correct.
-
if (rvh != GetRenderViewHost()) {
// The pending page's RenderViewHost is gone.
return;

Powered by Google App Engine
This is Rietveld 408576698