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

Unified Diff: chrome/browser/media/router/presentation_service_delegate_impl.cc

Issue 2545523008: [Media Router] Crasher fix for PresentationServiceDelegateImpl. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media/router/presentation_service_delegate_impl.cc
diff --git a/chrome/browser/media/router/presentation_service_delegate_impl.cc b/chrome/browser/media/router/presentation_service_delegate_impl.cc
index 28b4ede4feca4489bddfa1b8b062527ed5a93980..d0d1a196c72cee8927de24a58b59776342306123 100644
--- a/chrome/browser/media/router/presentation_service_delegate_impl.cc
+++ b/chrome/browser/media/router/presentation_service_delegate_impl.cc
@@ -12,6 +12,7 @@
#include "base/containers/small_map.h"
#include "base/guid.h"
#include "base/memory/ptr_util.h"
+#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "chrome/browser/media/router/create_presentation_connection_request.h"
#include "chrome/browser/media/router/media_route.h"
@@ -51,13 +52,18 @@ RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) {
// Gets the last committed URL for the render frame specified by
// |render_frame_host_id|.
-GURL GetLastCommittedURLForFrame(RenderFrameHostId render_frame_host_id) {
+GURL GetLastCommittedURLForFrame(RenderFrameHostId render_frame_host_id,
+ content::WebContents* web_contents) {
RenderFrameHost* render_frame_host = RenderFrameHost::FromID(
render_frame_host_id.first, render_frame_host_id.second);
+ // crbug.com/663740: The RFH may not be associated with the frame tree; in
+ // that case, GetLastCommittedOrigin() may crash.
+ if (!render_frame_host ||
+ !base::ContainsValue(web_contents->GetAllFrames(), render_frame_host))
+ return GURL();
+
// TODO(crbug.com/632623): Use url::Origin in place of GURL for origins
- return render_frame_host
- ? render_frame_host->GetLastCommittedOrigin().GetURL()
- : GURL();
+ return render_frame_host->GetLastCommittedOrigin().GetURL();
}
// Observes messages originating from the MediaSink connected to a MediaRoute
@@ -170,7 +176,7 @@ class PresentationFrame {
RenderFrameHostId render_frame_host_id_;
// References to the owning WebContents, and the corresponding MediaRouter.
- const content::WebContents* web_contents_;
+ content::WebContents* web_contents_;
MediaRouter* router_;
DelegateObserver* delegate_observer_;
@@ -225,7 +231,8 @@ bool PresentationFrame::SetScreenAvailabilityListener(
sinks_observer.reset(new PresentationMediaSinksObserver(
router_, listener, source,
- GetLastCommittedURLForFrame(render_frame_host_id_).GetOrigin()));
+ GetLastCommittedURLForFrame(render_frame_host_id_, web_contents_)
+ .GetOrigin()));
if (!sinks_observer->Init()) {
url_to_sinks_observer_.erase(source.id());
@@ -549,7 +556,8 @@ void PresentationFrameManager::SetDefaultPresentationUrl(
ClearDefaultPresentationRequest();
} else {
DCHECK(!callback.is_null());
- GURL frame_url(GetLastCommittedURLForFrame(render_frame_host_id));
+ GURL frame_url(
+ GetLastCommittedURLForFrame(render_frame_host_id, web_contents_));
PresentationRequest request(render_frame_host_id,
std::vector<GURL>({default_presentation_url}),
frame_url);
@@ -795,7 +803,7 @@ void PresentationServiceDelegateImpl::StartSession(
std::unique_ptr<CreatePresentationConnectionRequest> request(
new CreatePresentationConnectionRequest(
render_frame_host_id, presentation_url,
- GetLastCommittedURLForFrame(render_frame_host_id),
+ GetLastCommittedURLForFrame(render_frame_host_id, web_contents_),
base::Bind(&PresentationServiceDelegateImpl::OnStartSessionSucceeded,
weak_factory_.GetWeakPtr(), render_process_id,
render_frame_id, success_cb),
@@ -834,7 +842,7 @@ void PresentationServiceDelegateImpl::JoinSession(
router_->JoinRoute(
MediaSourceForPresentationUrl(presentation_url).id(), presentation_id,
GetLastCommittedURLForFrame(
- RenderFrameHostId(render_process_id, render_frame_id))
+ RenderFrameHostId(render_process_id, render_frame_id), web_contents_)
.GetOrigin(),
web_contents_, route_response_callbacks, base::TimeDelta(), incognito);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698