Commit 7359e0be authored by Lukasz Anforowicz's avatar Lukasz Anforowicz Committed by Commit Bot

Call SetActiveURL while handling IPCs on the *browser* side.

Knowing the URL is very helpful not only for diagnosing renderer
crashes, but also for handling browser crashes, and DwoCs (e.g.
ones issued for renderer kills).  This CL introduces a call
to ContentClient::SetActiveURL in 4 places in the browser process:
- RenderViewHostImpl::OnMessageReceived
- RenderFrameProxyHost::OnMessageReceived
- RenderFrameHostImpl::OnMessageReceived
- RenderFrameHostImpl::DidCommitProvisionalLoad

Bug: 797968, 770239
Change-Id: I78481d0fcb40e7c0548eb5ee3bd1ff00c7703592
Reviewed-on: https://chromium-review.googlesource.com/846109
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#527031}
parent 0bee1776
......@@ -1448,6 +1448,8 @@ jumbo_source_set("browser") {
"sandbox_ipc_linux.h",
"sandbox_parameters_mac.h",
"sandbox_parameters_mac.mm",
"scoped_active_url.cc",
"scoped_active_url.h",
"screen_orientation/screen_orientation_provider.cc",
"screen_orientation/screen_orientation_provider.h",
"service_manager/common_browser_interfaces.cc",
......
......@@ -73,6 +73,7 @@
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/browser/renderer_host/render_widget_host_view_child_frame.h"
#include "content/browser/renderer_interface_binders.h"
#include "content/browser/scoped_active_url.h"
#include "content/browser/shared_worker/shared_worker_connector_impl.h"
#include "content/browser/shared_worker/shared_worker_service_impl.h"
#include "content/browser/storage_partition_impl.h"
......@@ -845,6 +846,12 @@ bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) {
if (!render_frame_created_)
return false;
// Crash reports trigerred by IPC messages for this frame should be associated
// with its URL.
// TODO(lukasza): Also call SetActiveURL for mojo messages dispatched to
// either the FrameHost interface or to interfaces bound by this frame.
ScopedActiveURL scoped_active_url(this);
// This message map is for handling internal IPC messages which should not
// be dispatched to other objects.
bool handled = true;
......@@ -1511,6 +1518,13 @@ void RenderFrameHostImpl::DidCommitProvisionalLoad(
validated_params,
service_manager::mojom::InterfaceProviderRequest
interface_provider_request) {
// DidCommitProvisionalLoad IPC should be associated with the URL being
// committed (not with the *last* committed URL that most other IPCs are
// associated with).
ScopedActiveURL scoped_active_url(
validated_params->url,
frame_tree_node()->frame_tree()->root()->current_origin());
ScopedCommitStateResetter commit_state_resetter(this);
RenderProcessHost* process = GetProcess();
......
......@@ -5,6 +5,7 @@
#include "content/browser/frame_host/render_frame_proxy_host.h"
#include <utility>
#include <vector>
#include "base/callback.h"
#include "base/lazy_instance.h"
......@@ -18,6 +19,7 @@
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/browser/renderer_host/render_widget_host_view_child_frame.h"
#include "content/browser/scoped_active_url.h"
#include "content/browser/site_instance_impl.h"
#include "content/common/frame_messages.h"
#include "content/common/frame_owner_properties.h"
......@@ -131,6 +133,10 @@ bool RenderFrameProxyHost::Send(IPC::Message *msg) {
}
bool RenderFrameProxyHost::OnMessageReceived(const IPC::Message& msg) {
// Crash reports trigerred by IPC messages for this proxy should be associated
// with the URL of the current RenderFrameHost that is being proxied.
ScopedActiveURL scoped_active_url(this);
if (cross_process_frame_connector_.get() &&
cross_process_frame_connector_->OnMessageReceived(msg))
return true;
......
......@@ -43,6 +43,7 @@
#include "content/browser/renderer_host/render_view_host_delegate_view.h"
#include "content/browser/renderer_host/render_widget_host_delegate.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/browser/scoped_active_url.h"
#include "content/common/browser_plugin/browser_plugin_messages.h"
#include "content/common/content_switches_internal.h"
#include "content/common/frame_messages.h"
......@@ -733,6 +734,10 @@ bool RenderViewHostImpl::OnMessageReceived(const IPC::Message& msg) {
}
}
// Crash reports trigerred by the IPC messages below should be associated
// with URL of the main frame.
ScopedActiveURL scoped_active_url(this);
if (delegate_->OnMessageReceived(this, msg))
return true;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/scoped_active_url.h"
#include "content/browser/frame_host/frame_tree.h"
#include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/frame_host/render_frame_proxy_host.h"
#include "content/browser/renderer_host/render_view_host_delegate.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/common/content_client.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace content {
ScopedActiveURL::ScopedActiveURL(const GURL& active_url,
const url::Origin& top_origin) {
GetContentClient()->SetActiveURL(active_url, top_origin.Serialize());
}
ScopedActiveURL::ScopedActiveURL(RenderFrameHost* frame)
: ScopedActiveURL(
static_cast<RenderFrameHostImpl*>(frame)->frame_tree_node()) {}
ScopedActiveURL::ScopedActiveURL(RenderFrameProxyHost* proxy)
: ScopedActiveURL(proxy->frame_tree_node()) {}
ScopedActiveURL::ScopedActiveURL(RenderViewHost* view)
: ScopedActiveURL(view->GetDelegate()->GetFrameTree()->root()) {}
ScopedActiveURL::ScopedActiveURL(FrameTreeNode* node)
: ScopedActiveURL(node->current_url(),
node->frame_tree()->root()->current_origin()) {}
ScopedActiveURL::~ScopedActiveURL() {
GetContentClient()->SetActiveURL(GURL(), "");
}
} // namespace content
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_SCOPED_ACTIVE_URL_H_
#define CONTENT_BROWSER_SCOPED_ACTIVE_URL_H_
#include "base/macros.h"
class GURL;
namespace url {
class Origin;
} // namespace url
namespace content {
class FrameTreeNode;
class RenderFrameHost;
class RenderFrameProxyHost;
class RenderViewHost;
// ScopedActiveURL calls ContentClient::SetActiveURL when constructed
// and calls it again with empty arguments when destructed.
class ScopedActiveURL {
public:
// Calls ContentClient::SetActiveURL with |active_url| and |top_origin| (to
// set the crash keys).
ScopedActiveURL(const GURL& active_url, const url::Origin& top_origin);
// Convenience constructor, calculating |active_url| and |top_origin| based on
// |frame|'s last committed origin and main frame.
explicit ScopedActiveURL(RenderFrameHost* frame);
// Convenience constructor, calculating |active_url| and |top_origin| based on
// |proxy|'s last committed origin and main frame.
explicit ScopedActiveURL(RenderFrameProxyHost* proxy);
// Convenience constructor, calculating |active_url| and |top_origin| based on
// the frame tree node of |view|'s main frame.
explicit ScopedActiveURL(RenderViewHost* view);
// Calls ContentClient::SetActiveURL with empty arguments (to reset the crash
// keys).
~ScopedActiveURL();
private:
explicit ScopedActiveURL(FrameTreeNode* node);
DISALLOW_COPY_AND_ASSIGN(ScopedActiveURL);
};
} // namespace content
#endif // CONTENT_BROWSER_SCOPED_ACTIVE_URL_H_
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