 Chromium Code Reviews
 Chromium Code Reviews Issue 2927983004:
  [DevTools] Rework RFDTAH navigation tracking with browser side navigation  (Closed)
    
  
    Issue 2927983004:
  [DevTools] Rework RFDTAH navigation tracking with browser side navigation  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 5 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 
| 6 | 6 | 
| 7 #include <tuple> | 7 #include <tuple> | 
| 8 #include <utility> | 8 #include <utility> | 
| 9 | 9 | 
| 10 #include "base/guid.h" | 10 #include "base/guid.h" | 
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 void SendMessageToClient(int session_id, const std::string& message); | 116 void SendMessageToClient(int session_id, const std::string& message); | 
| 117 | 117 | 
| 118 RenderFrameDevToolsAgentHost* agent_; | 118 RenderFrameDevToolsAgentHost* agent_; | 
| 119 RenderFrameHostImpl* host_; | 119 RenderFrameHostImpl* host_; | 
| 120 bool attached_; | 120 bool attached_; | 
| 121 bool suspended_; | 121 bool suspended_; | 
| 122 DevToolsMessageChunkProcessor chunk_processor_; | 122 DevToolsMessageChunkProcessor chunk_processor_; | 
| 123 // <session_id, message> | 123 // <session_id, message> | 
| 124 std::vector<std::pair<int, std::string>> pending_messages_; | 124 std::vector<std::pair<int, std::string>> pending_messages_; | 
| 125 // <call_id> -> PendingMessage | 125 // <call_id> -> PendingMessage | 
| 126 std::map<int, PendingMessage> sent_messages_; | 126 std::map<int, Message> sent_messages_; | 
| 127 // These are sent messages for which we got a reply while suspended. | 127 // These are sent messages for which we got a reply while suspended. | 
| 128 std::map<int, PendingMessage> sent_messages_whose_reply_came_while_suspended_; | 128 std::map<int, Message> sent_messages_whose_reply_came_while_suspended_; | 
| 129 }; | 129 }; | 
| 130 | 130 | 
| 131 RenderFrameDevToolsAgentHost::FrameHostHolder::FrameHostHolder( | 131 RenderFrameDevToolsAgentHost::FrameHostHolder::FrameHostHolder( | 
| 132 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host) | 132 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host) | 
| 133 : agent_(agent), | 133 : agent_(agent), | 
| 134 host_(host), | 134 host_(host), | 
| 135 attached_(false), | 135 attached_(false), | 
| 136 suspended_(false), | 136 suspended_(false), | 
| 137 chunk_processor_(base::Bind( | 137 chunk_processor_(base::Bind( | 
| 138 &RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient, | 138 &RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient, | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 attached_ = true; | 178 attached_ = true; | 
| 179 } | 179 } | 
| 180 | 180 | 
| 181 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach(int session_id) { | 181 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach(int session_id) { | 
| 182 host_->Send(new DevToolsAgentMsg_Detach(host_->GetRoutingID(), session_id)); | 182 host_->Send(new DevToolsAgentMsg_Detach(host_->GetRoutingID(), session_id)); | 
| 183 RevokePolicy(); | 183 RevokePolicy(); | 
| 184 attached_ = false; | 184 attached_ = false; | 
| 185 } | 185 } | 
| 186 | 186 | 
| 187 void RenderFrameDevToolsAgentHost::FrameHostHolder::GrantPolicy() { | 187 void RenderFrameDevToolsAgentHost::FrameHostHolder::GrantPolicy() { | 
| 188 agent_->GrantPolicy(host_); | |
| 188 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( | 189 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( | 
| 
dgozman
2017/06/09 22:37:05
This should be removed.
 | |
| 189 host_->GetProcess()->GetID()); | 190 host_->GetProcess()->GetID()); | 
| 190 } | 191 } | 
| 191 | 192 | 
| 192 void RenderFrameDevToolsAgentHost::FrameHostHolder::RevokePolicy() { | 193 void RenderFrameDevToolsAgentHost::FrameHostHolder::RevokePolicy() { | 
| 194 agent_->RevokePolicy(host_); | |
| 193 bool process_has_agents = false; | 195 bool process_has_agents = false; | 
| 
dgozman
2017/06/09 22:37:05
And this (it got moved to RevokePolicy(host)).
 | |
| 194 RenderProcessHost* process_host = host_->GetProcess(); | 196 RenderProcessHost* process_host = host_->GetProcess(); | 
| 195 for (RenderFrameDevToolsAgentHost* agent : g_instances.Get()) { | 197 for (RenderFrameDevToolsAgentHost* agent : g_instances.Get()) { | 
| 196 if (!agent->IsAttached()) | 198 if (!agent->IsAttached()) | 
| 197 continue; | 199 continue; | 
| 198 if (agent->current_ && agent->current_->host() != host_ && | 200 if (agent->current_ && agent->current_->host() != host_ && | 
| 199 agent->current_->host()->GetProcess() == process_host) { | 201 agent->current_->host()->GetProcess() == process_host) { | 
| 200 process_has_agents = true; | 202 process_has_agents = true; | 
| 201 } | 203 } | 
| 202 if (agent->pending_ && agent->pending_->host() != host_ && | 204 if (agent->pending_ && agent->pending_->host() != host_ && | 
| 203 agent->pending_->host()->GetProcess() == process_host) { | 205 agent->pending_->host()->GetProcess() == process_host) { | 
| 204 process_has_agents = true; | 206 process_has_agents = true; | 
| 205 } | 207 } | 
| 206 } | 208 } | 
| 207 | 209 | 
| 208 // We are the last to disconnect from the renderer -> revoke permissions. | 210 // We are the last to disconnect from the renderer -> revoke permissions. | 
| 209 if (!process_has_agents) { | 211 if (!process_has_agents) { | 
| 210 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeReadRawCookies( | 212 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeReadRawCookies( | 
| 211 process_host->GetID()); | 213 process_host->GetID()); | 
| 212 } | 214 } | 
| 213 } | 215 } | 
| 216 | |
| 214 void RenderFrameDevToolsAgentHost::FrameHostHolder::DispatchProtocolMessage( | 217 void RenderFrameDevToolsAgentHost::FrameHostHolder::DispatchProtocolMessage( | 
| 215 int session_id, | 218 int session_id, | 
| 216 int call_id, | 219 int call_id, | 
| 217 const std::string& method, | 220 const std::string& method, | 
| 218 const std::string& message) { | 221 const std::string& message) { | 
| 219 host_->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( | 222 host_->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( | 
| 220 host_->GetRoutingID(), session_id, call_id, method, message)); | 223 host_->GetRoutingID(), session_id, call_id, method, message)); | 
| 221 sent_messages_[call_id] = { session_id, method, message }; | 224 sent_messages_[call_id] = { session_id, call_id, method, message }; | 
| 
caseq
2017/06/10 00:02:46
emplace()? ;-)
 
dgozman
2017/06/10 01:36:34
That's more code :(
 | |
| 222 } | 225 } | 
| 223 | 226 | 
| 224 void RenderFrameDevToolsAgentHost::FrameHostHolder::InspectElement( | 227 void RenderFrameDevToolsAgentHost::FrameHostHolder::InspectElement( | 
| 225 int session_id, int x, int y) { | 228 int session_id, int x, int y) { | 
| 226 DCHECK(attached_); | 229 DCHECK(attached_); | 
| 227 host_->Send(new DevToolsAgentMsg_InspectElement( | 230 host_->Send(new DevToolsAgentMsg_InspectElement( | 
| 228 host_->GetRoutingID(), session_id, x, y)); | 231 host_->GetRoutingID(), session_id, x, y)); | 
| 229 } | 232 } | 
| 230 | 233 | 
| 231 bool | 234 bool | 
| 232 RenderFrameDevToolsAgentHost::FrameHostHolder::ProcessChunkedMessageFromAgent( | 235 RenderFrameDevToolsAgentHost::FrameHostHolder::ProcessChunkedMessageFromAgent( | 
| 233 const DevToolsMessageChunk& chunk) { | 236 const DevToolsMessageChunk& chunk) { | 
| 234 return chunk_processor_.ProcessChunkedMessageFromAgent(chunk); | 237 return chunk_processor_.ProcessChunkedMessageFromAgent(chunk); | 
| 235 } | 238 } | 
| 236 | 239 | 
| 237 void RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient( | 240 void RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient( | 
| 238 int session_id, | 241 int session_id, | 
| 239 const std::string& message) { | 242 const std::string& message) { | 
| 240 int id = chunk_processor_.last_call_id(); | 243 int id = chunk_processor_.last_call_id(); | 
| 241 PendingMessage sent_message = sent_messages_[id]; | 244 Message sent_message = sent_messages_[id]; | 
| 242 sent_messages_.erase(id); | 245 sent_messages_.erase(id); | 
| 243 if (suspended_) { | 246 if (suspended_) { | 
| 244 sent_messages_whose_reply_came_while_suspended_[id] = sent_message; | 247 sent_messages_whose_reply_came_while_suspended_[id] = sent_message; | 
| 245 pending_messages_.push_back(std::make_pair(session_id, message)); | 248 pending_messages_.push_back(std::make_pair(session_id, message)); | 
| 246 } else { | 249 } else { | 
| 247 agent_->SendMessageToClient(session_id, message); | 250 agent_->SendMessageToClient(session_id, message); | 
| 248 // |this| may be deleted at this point. | 251 // |this| may be deleted at this point. | 
| 249 } | 252 } | 
| 250 } | 253 } | 
| 251 | 254 | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 // static | 339 // static | 
| 337 void RenderFrameDevToolsAgentHost::OnBeforeNavigation( | 340 void RenderFrameDevToolsAgentHost::OnBeforeNavigation( | 
| 338 RenderFrameHost* current, RenderFrameHost* pending) { | 341 RenderFrameHost* current, RenderFrameHost* pending) { | 
| 339 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost( | 342 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost( | 
| 340 static_cast<RenderFrameHostImpl*>(current)->frame_tree_node()); | 343 static_cast<RenderFrameHostImpl*>(current)->frame_tree_node()); | 
| 341 if (agent_host) | 344 if (agent_host) | 
| 342 agent_host->AboutToNavigateRenderFrame(current, pending); | 345 agent_host->AboutToNavigateRenderFrame(current, pending); | 
| 343 } | 346 } | 
| 344 | 347 | 
| 345 // static | 348 // static | 
| 346 void RenderFrameDevToolsAgentHost::OnBeforeNavigation( | |
| 347 NavigationHandle* navigation_handle) { | |
| 348 FrameTreeNode* frame_tree_node = | |
| 349 static_cast<NavigationHandleImpl*>(navigation_handle)->frame_tree_node(); | |
| 350 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); | |
| 351 if (agent_host) | |
| 352 agent_host->AboutToNavigate(navigation_handle); | |
| 353 } | |
| 354 | |
| 355 // static | |
| 356 void RenderFrameDevToolsAgentHost::OnFailedNavigation( | 349 void RenderFrameDevToolsAgentHost::OnFailedNavigation( | 
| 357 RenderFrameHost* host, | 350 RenderFrameHost* host, | 
| 358 const CommonNavigationParams& common_params, | 351 const CommonNavigationParams& common_params, | 
| 359 const BeginNavigationParams& begin_params, | 352 const BeginNavigationParams& begin_params, | 
| 360 net::Error error_code) { | 353 net::Error error_code) { | 
| 361 RenderFrameDevToolsAgentHost* agent_host = | 354 RenderFrameDevToolsAgentHost* agent_host = | 
| 362 FindAgentHost(static_cast<RenderFrameHostImpl*>(host)->frame_tree_node()); | 355 FindAgentHost(static_cast<RenderFrameHostImpl*>(host)->frame_tree_node()); | 
| 363 if (agent_host) | 356 if (!agent_host) | 
| 364 agent_host->OnFailedNavigation(common_params, begin_params, error_code); | 357 return; | 
| 358 for (auto* network : protocol::NetworkHandler::ForAgentHost(agent_host)) | |
| 359 network->NavigationFailed(common_params, begin_params, error_code); | |
| 365 } | 360 } | 
| 366 | 361 | 
| 367 // static | 362 // static | 
| 368 std::unique_ptr<NavigationThrottle> | 363 std::unique_ptr<NavigationThrottle> | 
| 369 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation( | 364 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation( | 
| 370 NavigationHandle* navigation_handle) { | 365 NavigationHandle* navigation_handle) { | 
| 371 FrameTreeNode* frame_tree_node = | 366 FrameTreeNode* frame_tree_node = | 
| 372 static_cast<NavigationHandleImpl*>(navigation_handle)->frame_tree_node(); | 367 static_cast<NavigationHandleImpl*>(navigation_handle)->frame_tree_node(); | 
| 373 while (frame_tree_node && frame_tree_node->parent()) { | 368 while (frame_tree_node && frame_tree_node->parent()) { | 
| 374 frame_tree_node = frame_tree_node->parent(); | 369 frame_tree_node = frame_tree_node->parent(); | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 DevToolsAgentHost::GetOrCreateFor(web_contents); | 420 DevToolsAgentHost::GetOrCreateFor(web_contents); | 
| 426 } | 421 } | 
| 427 } | 422 } | 
| 428 | 423 | 
| 429 RenderFrameDevToolsAgentHost::RenderFrameDevToolsAgentHost( | 424 RenderFrameDevToolsAgentHost::RenderFrameDevToolsAgentHost( | 
| 430 FrameTreeNode* frame_tree_node) | 425 FrameTreeNode* frame_tree_node) | 
| 431 : DevToolsAgentHostImpl(base::GenerateGUID()), | 426 : DevToolsAgentHostImpl(base::GenerateGUID()), | 
| 432 frame_trace_recorder_(nullptr), | 427 frame_trace_recorder_(nullptr), | 
| 433 handlers_frame_host_(nullptr), | 428 handlers_frame_host_(nullptr), | 
| 434 current_frame_crashed_(false), | 429 current_frame_crashed_(false), | 
| 435 pending_handle_(nullptr), | 430 chunk_processor_(base::Bind( | 
| 431 &RenderFrameDevToolsAgentHost::SendMessageFromProcessor, | |
| 432 base::Unretained(this))), | |
| 436 frame_tree_node_(frame_tree_node) { | 433 frame_tree_node_(frame_tree_node) { | 
| 437 if (frame_tree_node->current_frame_host()) { | 434 if (IsBrowserSideNavigationEnabled()) { | 
| 438 SetPending(frame_tree_node->current_frame_host()); | 435 frame_host_ = frame_tree_node->current_frame_host(); | 
| 439 CommitPending(); | 436 render_frame_alive_ = frame_host_ && frame_host_->IsRenderFrameLive(); | 
| 437 } else { | |
| 438 if (frame_tree_node->current_frame_host()) { | |
| 439 SetPending(frame_tree_node->current_frame_host()); | |
| 440 CommitPending(); | |
| 441 } | |
| 440 } | 442 } | 
| 441 WebContentsObserver::Observe( | 443 WebContentsObserver::Observe( | 
| 442 WebContentsImpl::FromFrameTreeNode(frame_tree_node)); | 444 WebContentsImpl::FromFrameTreeNode(frame_tree_node)); | 
| 443 | 445 | 
| 444 if (web_contents() && web_contents()->GetCrashedStatus() != | 446 if (web_contents() && web_contents()->GetCrashedStatus() != | 
| 445 base::TERMINATION_STATUS_STILL_RUNNING) { | 447 base::TERMINATION_STATUS_STILL_RUNNING) { | 
| 446 current_frame_crashed_ = true; | 448 current_frame_crashed_ = true; | 
| 447 } | 449 } | 
| 448 | 450 | 
| 449 g_instances.Get().push_back(this); | 451 g_instances.Get().push_back(this); | 
| 450 AddRef(); // Balanced in RenderFrameHostDestroyed. | 452 AddRef(); // Balanced in RenderFrameHostDestroyed. | 
| 451 | 453 | 
| 452 NotifyCreated(); | 454 NotifyCreated(); | 
| 453 } | 455 } | 
| 454 | 456 | 
| 455 void RenderFrameDevToolsAgentHost::SetPending(RenderFrameHostImpl* host) { | 457 void RenderFrameDevToolsAgentHost::SetPending(RenderFrameHostImpl* host) { | 
| 458 DCHECK(!IsBrowserSideNavigationEnabled()); | |
| 456 DCHECK(!pending_); | 459 DCHECK(!pending_); | 
| 457 current_frame_crashed_ = false; | 460 current_frame_crashed_ = false; | 
| 458 pending_.reset(new FrameHostHolder(this, host)); | 461 pending_.reset(new FrameHostHolder(this, host)); | 
| 459 if (IsAttached()) | 462 if (IsAttached()) | 
| 460 pending_->Reattach(current_.get()); | 463 pending_->Reattach(current_.get()); | 
| 461 | 464 | 
| 462 // Can only be null in constructor. | 465 // Can only be null in constructor. | 
| 463 if (current_) | 466 if (current_) | 
| 464 current_->Suspend(); | 467 current_->Suspend(); | 
| 465 pending_->Suspend(); | 468 pending_->Suspend(); | 
| 466 | 469 | 
| 467 UpdateProtocolHandlers(host); | 470 UpdateProtocolHandlers(host); | 
| 468 } | 471 } | 
| 469 | 472 | 
| 470 void RenderFrameDevToolsAgentHost::CommitPending() { | 473 void RenderFrameDevToolsAgentHost::CommitPending() { | 
| 474 DCHECK(!IsBrowserSideNavigationEnabled()); | |
| 471 DCHECK(pending_); | 475 DCHECK(pending_); | 
| 472 current_frame_crashed_ = false; | 476 current_frame_crashed_ = false; | 
| 473 | 477 | 
| 474 if (!ShouldCreateDevToolsForHost(pending_->host())) { | 478 if (!ShouldCreateDevToolsForHost(pending_->host())) { | 
| 475 DestroyOnRenderFrameGone(); | 479 DestroyOnRenderFrameGone(); | 
| 476 // |this| may be deleted at this point. | 480 // |this| may be deleted at this point. | 
| 477 return; | 481 return; | 
| 478 } | 482 } | 
| 479 | 483 | 
| 480 current_ = std::move(pending_); | 484 current_ = std::move(pending_); | 
| 481 UpdateProtocolHandlers(current_->host()); | 485 UpdateProtocolHandlers(current_->host()); | 
| 482 current_->Resume(); | 486 current_->Resume(); | 
| 483 } | 487 } | 
| 484 | 488 | 
| 485 void RenderFrameDevToolsAgentHost::DiscardPending() { | 489 void RenderFrameDevToolsAgentHost::DiscardPending() { | 
| 490 DCHECK(!IsBrowserSideNavigationEnabled()); | |
| 486 DCHECK(pending_); | 491 DCHECK(pending_); | 
| 487 DCHECK(current_); | 492 DCHECK(current_); | 
| 488 pending_.reset(); | 493 pending_.reset(); | 
| 489 UpdateProtocolHandlers(current_->host()); | 494 UpdateProtocolHandlers(current_->host()); | 
| 490 current_->Resume(); | 495 current_->Resume(); | 
| 491 } | 496 } | 
| 492 | 497 | 
| 493 BrowserContext* RenderFrameDevToolsAgentHost::GetBrowserContext() { | 498 BrowserContext* RenderFrameDevToolsAgentHost::GetBrowserContext() { | 
| 494 WebContents* contents = web_contents(); | 499 WebContents* contents = web_contents(); | 
| 495 return contents ? contents->GetBrowserContext() : nullptr; | 500 return contents ? contents->GetBrowserContext() : nullptr; | 
| 496 } | 501 } | 
| 497 | 502 | 
| 498 WebContents* RenderFrameDevToolsAgentHost::GetWebContents() { | 503 WebContents* RenderFrameDevToolsAgentHost::GetWebContents() { | 
| 499 return web_contents(); | 504 return web_contents(); | 
| 500 } | 505 } | 
| 501 | 506 | 
| 502 void RenderFrameDevToolsAgentHost::AttachSession(DevToolsSession* session) { | 507 void RenderFrameDevToolsAgentHost::AttachSession(DevToolsSession* session) { | 
| 503 session->SetFallThroughForNotFound(true); | 508 session->SetFallThroughForNotFound(true); | 
| 504 session->SetRenderFrameHost(handlers_frame_host_); | 509 if (IsBrowserSideNavigationEnabled()) | 
| 510 session->SetRenderFrameHost(frame_host_); | |
| 511 else | |
| 512 session->SetRenderFrameHost(handlers_frame_host_); | |
| 505 if (frame_tree_node_ && !frame_tree_node_->parent()) { | 513 if (frame_tree_node_ && !frame_tree_node_->parent()) { | 
| 506 session->AddHandler(base::WrapUnique(new protocol::PageHandler())); | 514 session->AddHandler(base::WrapUnique(new protocol::PageHandler())); | 
| 507 session->AddHandler(base::WrapUnique(new protocol::SecurityHandler())); | 515 session->AddHandler(base::WrapUnique(new protocol::SecurityHandler())); | 
| 508 } | 516 } | 
| 509 session->AddHandler(base::WrapUnique(new protocol::DOMHandler())); | 517 session->AddHandler(base::WrapUnique(new protocol::DOMHandler())); | 
| 510 session->AddHandler(base::WrapUnique(new protocol::EmulationHandler())); | 518 session->AddHandler(base::WrapUnique(new protocol::EmulationHandler())); | 
| 511 session->AddHandler(base::WrapUnique(new protocol::InputHandler())); | 519 session->AddHandler(base::WrapUnique(new protocol::InputHandler())); | 
| 512 session->AddHandler(base::WrapUnique(new protocol::InspectorHandler())); | 520 session->AddHandler(base::WrapUnique(new protocol::InspectorHandler())); | 
| 513 session->AddHandler(base::WrapUnique(new protocol::IOHandler( | 521 session->AddHandler(base::WrapUnique(new protocol::IOHandler( | 
| 514 GetIOContext()))); | 522 GetIOContext()))); | 
| 515 session->AddHandler(base::WrapUnique(new protocol::NetworkHandler())); | 523 session->AddHandler(base::WrapUnique(new protocol::NetworkHandler())); | 
| 516 session->AddHandler(base::WrapUnique(new protocol::SchemaHandler())); | 524 session->AddHandler(base::WrapUnique(new protocol::SchemaHandler())); | 
| 517 session->AddHandler(base::WrapUnique(new protocol::ServiceWorkerHandler())); | 525 session->AddHandler(base::WrapUnique(new protocol::ServiceWorkerHandler())); | 
| 518 session->AddHandler(base::WrapUnique(new protocol::StorageHandler())); | 526 session->AddHandler(base::WrapUnique(new protocol::StorageHandler())); | 
| 519 session->AddHandler(base::WrapUnique(new protocol::TargetHandler())); | 527 session->AddHandler(base::WrapUnique(new protocol::TargetHandler())); | 
| 520 session->AddHandler(base::WrapUnique(new protocol::TracingHandler( | 528 session->AddHandler(base::WrapUnique(new protocol::TracingHandler( | 
| 521 protocol::TracingHandler::Renderer, | 529 protocol::TracingHandler::Renderer, | 
| 522 frame_tree_node_ ? frame_tree_node_->frame_tree_node_id() : 0, | 530 frame_tree_node_ ? frame_tree_node_->frame_tree_node_id() : 0, | 
| 523 GetIOContext()))); | 531 GetIOContext()))); | 
| 524 | 532 | 
| 525 if (current_) | 533 if (IsBrowserSideNavigationEnabled()) { | 
| 526 current_->Attach(session); | 534 if (frame_host_) { | 
| 527 if (pending_) | 535 frame_host_->Send(new DevToolsAgentMsg_Attach( | 
| 528 pending_->Attach(session); | 536 frame_host_->GetRoutingID(), GetId(), session->session_id())); | 
| 537 } | |
| 538 } else { | |
| 539 if (current_) | |
| 540 current_->Attach(session); | |
| 541 if (pending_) | |
| 542 pending_->Attach(session); | |
| 543 } | |
| 529 OnClientAttached(); | 544 OnClientAttached(); | 
| 530 } | 545 } | 
| 531 | 546 | 
| 532 void RenderFrameDevToolsAgentHost::DetachSession(int session_id) { | 547 void RenderFrameDevToolsAgentHost::DetachSession(int session_id) { | 
| 533 if (current_) | 548 if (IsBrowserSideNavigationEnabled()) { | 
| 534 current_->Detach(session_id); | 549 if (frame_host_) { | 
| 535 if (pending_) | 550 frame_host_->Send(new DevToolsAgentMsg_Detach(frame_host_->GetRoutingID(), session_id)); | 
| 536 pending_->Detach(session_id); | 551 } | 
| 552 } else { | |
| 553 if (current_) | |
| 554 current_->Detach(session_id); | |
| 555 if (pending_) | |
| 556 pending_->Detach(session_id); | |
| 557 } | |
| 537 OnClientDetached(); | 558 OnClientDetached(); | 
| 538 } | 559 } | 
| 539 | 560 | 
| 540 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( | 561 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( | 
| 541 DevToolsSession* session, | 562 DevToolsSession* session, | 
| 542 const std::string& message) { | 563 const std::string& message) { | 
| 543 int call_id = 0; | 564 int call_id = 0; | 
| 544 std::string method; | 565 std::string method; | 
| 566 int session_id = session->session_id(); | |
| 545 if (session->Dispatch(message, &call_id, &method) != | 567 if (session->Dispatch(message, &call_id, &method) != | 
| 546 protocol::Response::kFallThrough) { | 568 protocol::Response::kFallThrough) { | 
| 547 return true; | 569 return true; | 
| 548 } | 570 } | 
| 549 | 571 | 
| 550 if (!navigating_handles_.empty()) { | 572 if (IsBrowserSideNavigationEnabled()) { | 
| 
caseq
2017/06/10 00:02:46
nit: where possible, this is better written as
if
 
dgozman
2017/06/10 01:36:35
Acknowledged.
 | |
| 551 DCHECK(IsBrowserSideNavigationEnabled()); | 573 if (suspended_count_) { | 
| 552 in_navigation_protocol_message_buffer_[call_id] = | 574 suspended_messages_[call_id] = {session_id, call_id, method, message}; | 
| 553 { session->session_id(), method, message }; | 575 return true; | 
| 554 return true; | 576 } | 
| 555 } | 577 if (frame_host_) { | 
| 556 | 578 frame_host_->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( | 
| 557 if (current_) { | 579 frame_host_->GetRoutingID(), session_id, call_id, method, message)); | 
| 558 current_->DispatchProtocolMessage( | 580 } | 
| 559 session->session_id(), call_id, method, message); | 581 waiting_for_response_messages_[call_id] = | 
| 560 } | 582 {session_id, call_id, method, message}; | 
| 561 if (pending_) { | 583 } else { | 
| 562 pending_->DispatchProtocolMessage( | 584 if (current_) | 
| 563 session->session_id(), call_id, method, message); | 585 current_->DispatchProtocolMessage(session_id, call_id, method, message); | 
| 586 if (pending_) | |
| 587 pending_->DispatchProtocolMessage(session_id, call_id, method, message); | |
| 564 } | 588 } | 
| 565 return true; | 589 return true; | 
| 566 } | 590 } | 
| 567 | 591 | 
| 568 void RenderFrameDevToolsAgentHost::InspectElement( | 592 void RenderFrameDevToolsAgentHost::InspectElement( | 
| 569 DevToolsSession* session, | 593 DevToolsSession* session, | 
| 570 int x, | 594 int x, | 
| 571 int y) { | 595 int y) { | 
| 572 if (current_) | 596 if (IsBrowserSideNavigationEnabled()) { | 
| 573 current_->InspectElement(session->session_id(), x, y); | 597 if (frame_host_) { | 
| 574 if (pending_) | 598 frame_host_->Send(new DevToolsAgentMsg_InspectElement( | 
| 575 pending_->InspectElement(session->session_id(), x, y); | 599 frame_host_->GetRoutingID(), session->session_id(), x, y)); | 
| 600 } | |
| 601 } else { | |
| 602 if (current_) | |
| 603 current_->InspectElement(session->session_id(), x, y); | |
| 604 if (pending_) | |
| 605 pending_->InspectElement(session->session_id(), x, y); | |
| 606 } | |
| 576 } | 607 } | 
| 577 | 608 | 
| 578 void RenderFrameDevToolsAgentHost::OnClientAttached() { | 609 void RenderFrameDevToolsAgentHost::OnClientAttached() { | 
| 579 if (!web_contents()) | 610 if (!web_contents()) | 
| 580 return; | 611 return; | 
| 581 | 612 | 
| 582 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); | 613 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); | 
| 583 #if defined(OS_ANDROID) | 614 #if defined(OS_ANDROID) | 
| 584 GetWakeLock()->RequestWakeLock(); | 615 GetWakeLock()->RequestWakeLock(); | 
| 585 #endif | 616 #endif | 
| 617 if (IsBrowserSideNavigationEnabled()) | |
| 618 GrantPolicy(frame_host_); | |
| 586 } | 619 } | 
| 587 | 620 | 
| 588 void RenderFrameDevToolsAgentHost::OnClientDetached() { | 621 void RenderFrameDevToolsAgentHost::OnClientDetached() { | 
| 589 #if defined(OS_ANDROID) | 622 #if defined(OS_ANDROID) | 
| 590 GetWakeLock()->CancelWakeLock(); | 623 GetWakeLock()->CancelWakeLock(); | 
| 591 #endif | 624 #endif | 
| 592 frame_trace_recorder_.reset(); | 625 frame_trace_recorder_.reset(); | 
| 593 in_navigation_protocol_message_buffer_.clear(); | 626 waiting_for_response_messages_.clear(); | 
| 627 suspended_messages_.clear(); | |
| 628 chunk_processor_.Reset(); | |
| 629 if (IsBrowserSideNavigationEnabled()) | |
| 630 RevokePolicy(frame_host_); | |
| 594 } | 631 } | 
| 595 | 632 | 
| 596 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { | 633 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { | 
| 597 Instances::iterator it = std::find(g_instances.Get().begin(), | 634 Instances::iterator it = std::find(g_instances.Get().begin(), | 
| 598 g_instances.Get().end(), | 635 g_instances.Get().end(), | 
| 599 this); | 636 this); | 
| 600 if (it != g_instances.Get().end()) | 637 if (it != g_instances.Get().end()) | 
| 601 g_instances.Get().erase(it); | 638 g_instances.Get().erase(it); | 
| 602 } | 639 } | 
| 603 | 640 | 
| 604 void RenderFrameDevToolsAgentHost::ReadyToCommitNavigation( | 641 void RenderFrameDevToolsAgentHost::ReadyToCommitNavigation( | 
| 605 NavigationHandle* navigation_handle) { | 642 NavigationHandle* navigation_handle) { | 
| 606 // CommitPending may destruct |this|. | 643 fprintf(stderr, "[%p] ReadyToCommitNavigation [handle=%p, committed=%d] to %p\ n", frame_host_, navigation_handle, navigation_handle->HasCommitted(), navigatio n_handle->GetRenderFrameHost()); | 
| 607 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | |
| 608 | |
| 609 // TODO(clamy): Switch RenderFrameDevToolsAgentHost to always buffer messages | |
| 610 // until ReadyToCommitNavigation is called, now that it is also called in | |
| 611 // non-PlzNavigate mode. | |
| 612 if (!IsBrowserSideNavigationEnabled()) | 644 if (!IsBrowserSideNavigationEnabled()) | 
| 613 return; | 645 return; | 
| 614 | 646 NavigationHandleImpl* handle = | 
| 615 // If the navigation is not tracked, return; | 647 static_cast<NavigationHandleImpl*>(navigation_handle); | 
| 616 if (navigating_handles_.count(navigation_handle) == 0) | 648 if (handle->frame_tree_node() != frame_tree_node_) | 
| 617 return; | 649 return; | 
| 618 | 650 | 
| 619 RenderFrameHostImpl* render_frame_host_impl = | 651 // UpdateFrameHost may destruct |this|. | 
| 620 static_cast<RenderFrameHostImpl*>( | 652 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 
| 621 navigation_handle->GetRenderFrameHost()); | 653 UpdateFrameHost(handle->GetRenderFrameHost()); | 
| 622 if (current_->host() != render_frame_host_impl || current_frame_crashed_) { | |
| 623 SetPending(render_frame_host_impl); | |
| 624 pending_handle_ = navigation_handle; | |
| 625 // Commit when navigating the same frame after crash, avoiding the same | |
| 626 // host in current_ and pending_. | |
| 627 if (current_->host() == render_frame_host_impl) { | |
| 628 pending_handle_ = nullptr; | |
| 629 CommitPending(); | |
| 630 } | |
| 631 } | |
| 632 DCHECK(CheckConsistency()); | 654 DCHECK(CheckConsistency()); | 
| 633 } | 655 } | 
| 634 | 656 | 
| 635 void RenderFrameDevToolsAgentHost::DidFinishNavigation( | 657 void RenderFrameDevToolsAgentHost::DidFinishNavigation( | 
| 636 NavigationHandle* navigation_handle) { | 658 NavigationHandle* navigation_handle) { | 
| 637 // CommitPending may destruct |this|. | 659 if (navigation_handle->HasCommitted()) | 
| 638 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 660 fprintf(stderr, "[%p] DidFinishNavigation [handle=%p] committed to %p\n", fr ame_host_, navigation_handle, navigation_handle->GetRenderFrameHost()); | 
| 639 | 661 else | 
| 662 fprintf(stderr, "[%p] DidFinishNavigation [handle=%p] not committed\n", fram e_host_, navigation_handle); | |
| 640 if (!IsBrowserSideNavigationEnabled()) { | 663 if (!IsBrowserSideNavigationEnabled()) { | 
| 664 // CommitPending may destruct |this|. | |
| 665 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | |
| 641 if (navigation_handle->HasCommitted() && | 666 if (navigation_handle->HasCommitted() && | 
| 642 !navigation_handle->IsErrorPage()) { | 667 !navigation_handle->IsErrorPage()) { | 
| 643 if (pending_ && | 668 if (pending_ && | 
| 644 pending_->host() == navigation_handle->GetRenderFrameHost()) { | 669 pending_->host() == navigation_handle->GetRenderFrameHost()) { | 
| 645 CommitPending(); | 670 CommitPending(); | 
| 646 } | 671 } | 
| 647 for (auto* target : protocol::TargetHandler::ForAgentHost(this)) | 672 for (auto* target : protocol::TargetHandler::ForAgentHost(this)) | 
| 648 target->UpdateServiceWorkers(); | 673 target->UpdateServiceWorkers(); | 
| 649 } else if (pending_ && pending_->host()->GetFrameTreeNodeId() == | 674 } else if (pending_ && pending_->host()->GetFrameTreeNodeId() == | 
| 650 navigation_handle->GetFrameTreeNodeId()) { | 675 navigation_handle->GetFrameTreeNodeId()) { | 
| 651 DiscardPending(); | 676 DiscardPending(); | 
| 652 } | 677 } | 
| 653 DCHECK(CheckConsistency()); | 678 DCHECK(CheckConsistency()); | 
| 654 return; | 679 return; | 
| 655 } | 680 } | 
| 656 | 681 | 
| 657 // If the navigation is not tracked, return; | 682 NavigationHandleImpl* handle = | 
| 658 if (navigating_handles_.count(navigation_handle) == 0) | 683 static_cast<NavigationHandleImpl*>(navigation_handle); | 
| 684 if (handle->frame_tree_node() != frame_tree_node_) | |
| 659 return; | 685 return; | 
| 660 | 686 | 
| 661 // Now that the navigation is finished, remove the handle from the list of | 687 // UpdateFrameHost may destruct |this|. | 
| 662 // navigating handles. | 688 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 
| 663 navigating_handles_.erase(navigation_handle); | 689 if (handle->HasCommitted() && !handle->IsErrorPage()) | 
| 664 | 690 UpdateFrameHost(handle->GetRenderFrameHost()); | 
| 665 if (pending_handle_ == navigation_handle) { | 691 DCHECK(CheckConsistency()); | 
| 666 // This navigation handle did set the pending FrameHostHolder. | 692 if (!--suspended_count_) { | 
| 667 DCHECK(pending_); | 693 if (session() && frame_host_) { | 
| 668 if (navigation_handle->HasCommitted()) { | 694 for (const auto& pair : suspended_messages_) { | 
| 669 DCHECK(pending_->host() == navigation_handle->GetRenderFrameHost()); | 695 const Message& message = pair.second; | 
| 670 CommitPending(); | 696 frame_host_->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( | 
| 671 } else { | 697 frame_host_->GetRoutingID(), message.session_id, message.call_id, | 
| 672 DiscardPending(); | 698 message.method, message.message)); | 
| 699 } | |
| 673 } | 700 } | 
| 674 pending_handle_ = nullptr; | 701 suspended_messages_.clear(); | 
| 
pfeldman
2017/06/10 00:32:04
swap with waiting or extract method DispatchMessag
 
dgozman
2017/06/10 01:36:34
Done.
 | |
| 675 } else if (navigating_handles_.empty()) { | |
| 676 current_->Resume(); | |
| 677 } | 702 } | 
| 678 DispatchBufferedProtocolMessagesIfNecessary(); | 703 if (handle->HasCommitted()) { | 
| 679 | |
| 680 DCHECK(CheckConsistency()); | |
| 681 if (navigation_handle->HasCommitted()) { | |
| 682 for (auto* target : protocol::TargetHandler::ForAgentHost(this)) | 704 for (auto* target : protocol::TargetHandler::ForAgentHost(this)) | 
| 683 target->UpdateServiceWorkers(); | 705 target->UpdateServiceWorkers(); | 
| 684 } | 706 } | 
| 685 } | 707 } | 
| 686 | 708 | 
| 709 void RenderFrameDevToolsAgentHost::UpdateFrameHost(RenderFrameHostImpl* frame_ho st) { | |
| 710 if (frame_host == frame_host_) { | |
| 711 if (frame_host && !render_frame_alive_) { | |
| 712 render_frame_alive_ = true; | |
| 713 MaybeReattachToRenderFrame(); | |
| 714 } | |
| 715 return; | |
| 716 } | |
| 717 | |
| 718 if (session()) | |
| 719 RevokePolicy(frame_host_); | |
| 720 | |
| 721 if (frame_host && !ShouldCreateDevToolsForHost(frame_host)) { | |
| 722 DestroyOnRenderFrameGone(); | |
| 723 // |this| may be deleted at this point. | |
| 724 return; | |
| 725 } | |
| 726 | |
| 727 frame_host_ = frame_host; | |
| 728 render_frame_alive_ = true; | |
| 729 if (session()) { | |
| 730 GrantPolicy(frame_host_); | |
| 731 session()->SetRenderFrameHost(frame_host); | |
| 732 } | |
| 733 MaybeReattachToRenderFrame(); | |
| 
caseq
2017/06/10 00:02:46
nit: move into the if above.
 
dgozman
2017/06/10 01:36:35
Done.
 | |
| 734 } | |
| 735 | |
| 736 void RenderFrameDevToolsAgentHost::MaybeReattachToRenderFrame() { | |
| 737 DCHECK(IsBrowserSideNavigationEnabled()); | |
| 738 if (!session() || !frame_host_) | |
| 739 return; | |
| 740 int session_id = session()->session_id(); | |
| 741 frame_host_->Send(new DevToolsAgentMsg_Reattach( | |
| 742 frame_host_->GetRoutingID(), GetId(), session_id, | |
| 743 chunk_processor_.state_cookie())); | |
| 744 for (const auto& pair : waiting_for_response_messages_) { | |
| 745 const Message& message = pair.second; | |
| 746 frame_host_->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( | |
| 747 frame_host_->GetRoutingID(), message.session_id, message.call_id, | |
| 748 message.method, message.message)); | |
| 749 } | |
| 750 } | |
| 751 | |
| 752 void RenderFrameDevToolsAgentHost::SendMessageFromProcessor( | |
| 753 int session_id, | |
| 754 const std::string& message) { | |
| 755 int id = chunk_processor_.last_call_id(); | |
| 756 waiting_for_response_messages_.erase(id); | |
| 757 SendMessageToClient(session_id, message); | |
| 758 // |this| may be deleted at this point. | |
| 759 } | |
| 760 | |
| 761 void RenderFrameDevToolsAgentHost::GrantPolicy(RenderFrameHostImpl* host) { | |
| 762 if (!host) | |
| 763 return; | |
| 764 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( | |
| 765 host->GetProcess()->GetID()); | |
| 766 } | |
| 767 | |
| 768 void RenderFrameDevToolsAgentHost::RevokePolicy(RenderFrameHostImpl* host) { | |
| 769 if (!host) | |
| 770 return; | |
| 771 | |
| 772 bool process_has_agents = false; | |
| 773 RenderProcessHost* process_host = host->GetProcess(); | |
| 774 for (RenderFrameDevToolsAgentHost* agent : g_instances.Get()) { | |
| 775 if (!agent->IsAttached()) | |
| 776 continue; | |
| 777 if (IsBrowserSideNavigationEnabled()) { | |
| 778 if (agent->frame_host_ && agent->frame_host_ != host && | |
| 779 agent->frame_host_->GetProcess() == process_host) { | |
| 780 process_has_agents = true; | |
| 781 } | |
| 782 continue; | |
| 783 } | |
| 784 if (agent->current_ && agent->current_->host() != host && | |
| 785 agent->current_->host()->GetProcess() == process_host) { | |
| 786 process_has_agents = true; | |
| 787 } | |
| 788 if (agent->pending_ && agent->pending_->host() != host && | |
| 789 agent->pending_->host()->GetProcess() == process_host) { | |
| 790 process_has_agents = true; | |
| 791 } | |
| 792 } | |
| 793 | |
| 794 // We are the last to disconnect from the renderer -> revoke permissions. | |
| 795 if (!process_has_agents) { | |
| 796 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeReadRawCookies( | |
| 797 process_host->GetID()); | |
| 798 } | |
| 799 } | |
| 800 | |
| 687 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( | 801 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( | 
| 688 RenderFrameHost* old_host, | 802 RenderFrameHost* old_host, | 
| 689 RenderFrameHost* new_host) { | 803 RenderFrameHost* new_host) { | 
| 804 if (IsBrowserSideNavigationEnabled()) | |
| 805 return; | |
| 806 | |
| 690 // CommitPending may destruct |this|. | 807 // CommitPending may destruct |this|. | 
| 691 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 808 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 
| 692 | 809 | 
| 693 if (IsBrowserSideNavigationEnabled()) | |
| 694 return; | |
| 695 | |
| 696 DCHECK(!pending_ || pending_->host() != old_host); | 810 DCHECK(!pending_ || pending_->host() != old_host); | 
| 697 if (!current_ || current_->host() != old_host) { | 811 if (!current_ || current_->host() != old_host) { | 
| 698 DCHECK(CheckConsistency()); | 812 DCHECK(CheckConsistency()); | 
| 699 return; | 813 return; | 
| 700 } | 814 } | 
| 701 if (old_host == new_host && !current_frame_crashed_) { | 815 if (old_host == new_host && !current_frame_crashed_) { | 
| 702 DCHECK(CheckConsistency()); | 816 DCHECK(CheckConsistency()); | 
| 703 return; | 817 return; | 
| 704 } | 818 } | 
| 705 DCHECK(!pending_); | 819 DCHECK(!pending_); | 
| 706 SetPending(static_cast<RenderFrameHostImpl*>(new_host)); | 820 SetPending(static_cast<RenderFrameHostImpl*>(new_host)); | 
| 707 // Commit when navigating the same frame after crash, avoiding the same | 821 // Commit when navigating the same frame after crash, avoiding the same | 
| 708 // host in current_ and pending_. | 822 // host in current_ and pending_. | 
| 709 if (old_host == new_host) | 823 if (old_host == new_host) | 
| 710 CommitPending(); | 824 CommitPending(); | 
| 711 DCHECK(CheckConsistency()); | 825 DCHECK(CheckConsistency()); | 
| 712 } | 826 } | 
| 713 | 827 | 
| 714 void RenderFrameDevToolsAgentHost::AboutToNavigate( | 828 void RenderFrameDevToolsAgentHost::DidStartNavigation( | 
| 715 NavigationHandle* navigation_handle) { | 829 NavigationHandle* navigation_handle) { | 
| 830 fprintf(stderr, "[%p] DidStartNavigation\n", frame_host_); | |
| 716 if (!IsBrowserSideNavigationEnabled()) | 831 if (!IsBrowserSideNavigationEnabled()) | 
| 717 return; | 832 return; | 
| 718 DCHECK(current_); | 833 NavigationHandleImpl* handle = | 
| 719 navigating_handles_.insert(navigation_handle); | 834 static_cast<NavigationHandleImpl*>(navigation_handle); | 
| 720 current_->Suspend(); | 835 if (handle->frame_tree_node() != frame_tree_node_) | 
| 836 return; | |
| 837 suspended_count_++; | |
| 721 DCHECK(CheckConsistency()); | 838 DCHECK(CheckConsistency()); | 
| 722 } | 839 } | 
| 723 | 840 | 
| 724 void RenderFrameDevToolsAgentHost::OnFailedNavigation( | |
| 725 const CommonNavigationParams& common_params, | |
| 726 const BeginNavigationParams& begin_params, | |
| 727 net::Error error_code) { | |
| 728 DCHECK(IsBrowserSideNavigationEnabled()); | |
| 729 for (auto* network : protocol::NetworkHandler::ForAgentHost(this)) | |
| 730 network->NavigationFailed(common_params, begin_params, error_code); | |
| 731 } | |
| 732 | |
| 733 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( | 841 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( | 
| 734 RenderFrameHost* old_host, | 842 RenderFrameHost* old_host, | 
| 735 RenderFrameHost* new_host) { | 843 RenderFrameHost* new_host) { | 
| 844 fprintf(stderr, "[%p] RenderFrameHostChanged from %p to %p\n", frame_host_, ol d_host, new_host); | |
| 845 for (auto* target : protocol::TargetHandler::ForAgentHost(this)) | |
| 846 target->UpdateFrames(); | |
| 847 | |
| 848 if (IsBrowserSideNavigationEnabled()) { | |
| 849 if (old_host != frame_host_) | |
| 850 return; | |
| 851 | |
| 852 // UpdateFrameHost may destruct |this|. | |
| 853 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | |
| 854 UpdateFrameHost(static_cast<RenderFrameHostImpl*>(new_host)); | |
| 
pfeldman
2017/06/10 00:32:05
Try passing null here.
 | |
| 855 DCHECK(CheckConsistency()); | |
| 856 return; | |
| 857 } | |
| 858 | |
| 736 // CommitPending may destruct |this|. | 859 // CommitPending may destruct |this|. | 
| 737 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 860 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 
| 738 | 861 | 
| 739 for (auto* target : protocol::TargetHandler::ForAgentHost(this)) | |
| 740 target->UpdateFrames(); | |
| 741 | |
| 742 if (IsBrowserSideNavigationEnabled() && !current_frame_crashed_) | |
| 743 return; | |
| 744 | |
| 745 DCHECK(!pending_ || pending_->host() != old_host); | 862 DCHECK(!pending_ || pending_->host() != old_host); | 
| 746 if (!current_ || current_->host() != old_host) { | 863 if (!current_ || current_->host() != old_host) { | 
| 747 DCHECK(CheckConsistency()); | 864 DCHECK(CheckConsistency()); | 
| 748 return; | 865 return; | 
| 749 } | 866 } | 
| 750 | 867 | 
| 751 // AboutToNavigateRenderFrame was not called for renderer-initiated | 868 // AboutToNavigateRenderFrame was not called for renderer-initiated | 
| 752 // navigation. | 869 // navigation. | 
| 753 if (!pending_) | 870 if (!pending_) | 
| 754 SetPending(static_cast<RenderFrameHostImpl*>(new_host)); | 871 SetPending(static_cast<RenderFrameHostImpl*>(new_host)); | 
| 755 CommitPending(); | 872 CommitPending(); | 
| 756 DCHECK(CheckConsistency()); | 873 DCHECK(CheckConsistency()); | 
| 757 } | 874 } | 
| 758 | 875 | 
| 759 void RenderFrameDevToolsAgentHost::FrameDeleted(RenderFrameHost* rfh) { | 876 void RenderFrameDevToolsAgentHost::FrameDeleted(RenderFrameHost* rfh) { | 
| 877 fprintf(stderr, "[%p] FrameDeleted %p\n", frame_host_, rfh); | |
| 878 if (IsBrowserSideNavigationEnabled()) { | |
| 879 if (static_cast<RenderFrameHostImpl*>(rfh)->frame_tree_node() == frame_tree_ node_) | |
| 880 DestroyOnRenderFrameGone(); // |this| may be deleted at this point. | |
| 881 else | |
| 882 DCHECK(CheckConsistency()); | |
| 883 return; | |
| 884 } | |
| 885 | |
| 760 if (pending_ && pending_->host() == rfh) { | 886 if (pending_ && pending_->host() == rfh) { | 
| 761 if (!IsBrowserSideNavigationEnabled()) | 887 if (!IsBrowserSideNavigationEnabled()) | 
| 762 DiscardPending(); | 888 DiscardPending(); | 
| 763 DCHECK(CheckConsistency()); | 889 DCHECK(CheckConsistency()); | 
| 764 return; | 890 return; | 
| 765 } | 891 } | 
| 766 | 892 | 
| 767 if (current_ && current_->host() == rfh) | 893 if (current_ && current_->host() == rfh) | 
| 768 DestroyOnRenderFrameGone(); // |this| may be deleted at this point. | 894 DestroyOnRenderFrameGone(); // |this| may be deleted at this point. | 
| 769 } | 895 } | 
| 770 | 896 | 
| 771 void RenderFrameDevToolsAgentHost::RenderFrameDeleted(RenderFrameHost* rfh) { | 897 void RenderFrameDevToolsAgentHost::RenderFrameDeleted(RenderFrameHost* rfh) { | 
| 898 fprintf(stderr, "[%p] RenderFrameDeleted %p\n", frame_host_, rfh); | |
| 899 if (IsBrowserSideNavigationEnabled()) { | |
| 900 if (rfh == frame_host_) | |
| 901 render_frame_alive_ = false; | |
| 
caseq
2017/06/10 00:02:46
should we also have frame_host_ = nullptr here?
 
dgozman
2017/06/10 01:36:35
Nope, this means renderer is dead, but not the hos
 | |
| 902 DCHECK(CheckConsistency()); | |
| 903 return; | |
| 904 } | |
| 905 | |
| 772 if (!current_frame_crashed_) | 906 if (!current_frame_crashed_) | 
| 773 FrameDeleted(rfh); | 907 FrameDeleted(rfh); | 
| 774 else | 908 else | 
| 775 DCHECK(CheckConsistency()); | 909 DCHECK(CheckConsistency()); | 
| 776 } | 910 } | 
| 777 | 911 | 
| 778 void RenderFrameDevToolsAgentHost::DestroyOnRenderFrameGone() { | 912 void RenderFrameDevToolsAgentHost::DestroyOnRenderFrameGone() { | 
| 779 DCHECK(current_); | |
| 780 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 913 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 
| 781 UpdateProtocolHandlers(nullptr); | 914 UpdateProtocolHandlers(nullptr); | 
| 782 if (IsAttached()) | 915 if (IsAttached()) | 
| 783 OnClientDetached(); | 916 OnClientDetached(); | 
| 784 ForceDetach(false); | 917 ForceDetach(false); | 
| 918 frame_host_ = nullptr; | |
| 785 pending_.reset(); | 919 pending_.reset(); | 
| 786 current_.reset(); | 920 current_.reset(); | 
| 787 frame_tree_node_ = nullptr; | 921 frame_tree_node_ = nullptr; | 
| 788 pending_handle_ = nullptr; | |
| 789 WebContentsObserver::Observe(nullptr); | 922 WebContentsObserver::Observe(nullptr); | 
| 790 Release(); | 923 Release(); | 
| 791 } | 924 } | 
| 792 | 925 | 
| 793 bool RenderFrameDevToolsAgentHost::CheckConsistency() { | 926 bool RenderFrameDevToolsAgentHost::CheckConsistency() { | 
| 794 if (current_ && pending_ && current_->host() == pending_->host()) | 927 if (!IsBrowserSideNavigationEnabled()) { | 
| 795 return false; | 928 if (current_ && pending_ && current_->host() == pending_->host()) | 
| 796 if (IsBrowserSideNavigationEnabled()) | 929 return false; | 
| 797 return true; | 930 } | 
| 931 | |
| 798 if (!frame_tree_node_) | 932 if (!frame_tree_node_) | 
| 799 return !handlers_frame_host_; | 933 return !frame_host_; | 
| 934 | |
| 800 RenderFrameHostManager* manager = frame_tree_node_->render_manager(); | 935 RenderFrameHostManager* manager = frame_tree_node_->render_manager(); | 
| 801 return handlers_frame_host_ == manager->current_frame_host() || | 936 RenderFrameHostImpl* current = manager->current_frame_host(); | 
| 802 handlers_frame_host_ == manager->pending_frame_host(); | 937 RenderFrameHostImpl* pending = manager->pending_frame_host(); | 
| 938 RenderFrameHostImpl* speculative = manager->speculative_frame_host(); | |
| 939 RenderFrameHostImpl* host = IsBrowserSideNavigationEnabled() ? frame_host_ : h andlers_frame_host_; | |
| 940 if (host != current && host != pending && host != speculative) | |
| 941 fprintf(stderr, "[%p] CheckConsistency differs from %p, %p and %p\n", host, current, pending, speculative); | |
| 942 return host == current || host == pending || host == speculative; | |
| 
caseq
2017/06/10 00:02:46
can we add a check for !current_ && !pending_ here
 
dgozman
2017/06/10 01:36:34
Done.
 | |
| 803 } | 943 } | 
| 804 | 944 | 
| 805 #if defined(OS_ANDROID) | 945 #if defined(OS_ANDROID) | 
| 806 device::mojom::WakeLock* RenderFrameDevToolsAgentHost::GetWakeLock() { | 946 device::mojom::WakeLock* RenderFrameDevToolsAgentHost::GetWakeLock() { | 
| 807 // Here is a lazy binding, and will not reconnect after connection error. | 947 // Here is a lazy binding, and will not reconnect after connection error. | 
| 808 if (!wake_lock_) { | 948 if (!wake_lock_) { | 
| 809 device::mojom::WakeLockRequest request = mojo::MakeRequest(&wake_lock_); | 949 device::mojom::WakeLockRequest request = mojo::MakeRequest(&wake_lock_); | 
| 810 device::mojom::WakeLockContext* wake_lock_context = | 950 device::mojom::WakeLockContext* wake_lock_context = | 
| 811 web_contents()->GetWakeLockContext(); | 951 web_contents()->GetWakeLockContext(); | 
| 812 if (wake_lock_context) { | 952 if (wake_lock_context) { | 
| (...skipping 28 matching lines...) Expand all Loading... | |
| 841 for (auto* inspector : protocol::InspectorHandler::ForAgentHost(this)) | 981 for (auto* inspector : protocol::InspectorHandler::ForAgentHost(this)) | 
| 842 inspector->TargetDetached("Render process gone."); | 982 inspector->TargetDetached("Render process gone."); | 
| 843 break; | 983 break; | 
| 844 } | 984 } | 
| 845 DCHECK(CheckConsistency()); | 985 DCHECK(CheckConsistency()); | 
| 846 } | 986 } | 
| 847 | 987 | 
| 848 bool RenderFrameDevToolsAgentHost::OnMessageReceived( | 988 bool RenderFrameDevToolsAgentHost::OnMessageReceived( | 
| 849 const IPC::Message& message, | 989 const IPC::Message& message, | 
| 850 RenderFrameHost* render_frame_host) { | 990 RenderFrameHost* render_frame_host) { | 
| 851 bool is_current = current_ && current_->host() == render_frame_host; | 991 if (IsBrowserSideNavigationEnabled()) { | 
| 852 bool is_pending = pending_ && pending_->host() == render_frame_host; | 992 if (render_frame_host != frame_host_) | 
| 853 if (!is_current && !is_pending) | 993 return false; | 
| 854 return false; | 994 } else { | 
| 995 bool is_current = current_ && current_->host() == render_frame_host; | |
| 996 bool is_pending = pending_ && pending_->host() == render_frame_host; | |
| 997 if (!is_current && !is_pending) | |
| 998 return false; | |
| 999 } | |
| 855 if (!IsAttached()) | 1000 if (!IsAttached()) | 
| 856 return false; | 1001 return false; | 
| 857 bool handled = true; | 1002 bool handled = true; | 
| 858 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(RenderFrameDevToolsAgentHost, message, | 1003 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(RenderFrameDevToolsAgentHost, message, | 
| 859 render_frame_host) | 1004 render_frame_host) | 
| 860 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, | 1005 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, | 
| 861 OnDispatchOnInspectorFrontend) | 1006 OnDispatchOnInspectorFrontend) | 
| 862 IPC_MESSAGE_HANDLER(DevToolsAgentHostMsg_RequestNewWindow, | 1007 IPC_MESSAGE_HANDLER(DevToolsAgentHostMsg_RequestNewWindow, | 
| 863 OnRequestNewWindow) | 1008 OnRequestNewWindow) | 
| 864 IPC_MESSAGE_UNHANDLED(handled = false) | 1009 IPC_MESSAGE_UNHANDLED(handled = false) | 
| 865 IPC_END_MESSAGE_MAP() | 1010 IPC_END_MESSAGE_MAP() | 
| 866 return handled; | 1011 return handled; | 
| 867 } | 1012 } | 
| 868 | 1013 | 
| 869 void RenderFrameDevToolsAgentHost::DidAttachInterstitialPage() { | 1014 void RenderFrameDevToolsAgentHost::DidAttachInterstitialPage() { | 
| 870 for (auto* page : protocol::PageHandler::ForAgentHost(this)) | 1015 for (auto* page : protocol::PageHandler::ForAgentHost(this)) | 
| 871 page->DidAttachInterstitialPage(); | 1016 page->DidAttachInterstitialPage(); | 
| 872 | 1017 | 
| 1018 if (IsBrowserSideNavigationEnabled()) | |
| 1019 return; | |
| 1020 | |
| 873 // TODO(dgozman): this may break for cross-process subframes. | 1021 // TODO(dgozman): this may break for cross-process subframes. | 
| 874 if (!pending_) { | 1022 if (!pending_) { | 
| 875 DCHECK(CheckConsistency()); | 1023 DCHECK(CheckConsistency()); | 
| 876 return; | 1024 return; | 
| 877 } | 1025 } | 
| 878 // Pending set in AboutToNavigateRenderFrame turned out to be interstitial. | 1026 // Pending set in AboutToNavigateRenderFrame turned out to be interstitial. | 
| 879 // Connect back to the real one. | 1027 // Connect back to the real one. | 
| 880 DiscardPending(); | 1028 DiscardPending(); | 
| 881 pending_handle_ = nullptr; | |
| 882 DCHECK(CheckConsistency()); | 1029 DCHECK(CheckConsistency()); | 
| 883 } | 1030 } | 
| 884 | 1031 | 
| 885 void RenderFrameDevToolsAgentHost::DidDetachInterstitialPage() { | 1032 void RenderFrameDevToolsAgentHost::DidDetachInterstitialPage() { | 
| 886 for (auto* page : protocol::PageHandler::ForAgentHost(this)) | 1033 for (auto* page : protocol::PageHandler::ForAgentHost(this)) | 
| 887 page->DidDetachInterstitialPage(); | 1034 page->DidDetachInterstitialPage(); | 
| 888 } | 1035 } | 
| 889 | 1036 | 
| 890 void RenderFrameDevToolsAgentHost::WasShown() { | 1037 void RenderFrameDevToolsAgentHost::WasShown() { | 
| 891 #if defined(OS_ANDROID) | 1038 #if defined(OS_ANDROID) | 
| (...skipping 21 matching lines...) Expand all Loading... | |
| 913 return; | 1060 return; | 
| 914 bool did_initiate_recording = false; | 1061 bool did_initiate_recording = false; | 
| 915 for (auto* tracing : protocol::TracingHandler::ForAgentHost(this)) | 1062 for (auto* tracing : protocol::TracingHandler::ForAgentHost(this)) | 
| 916 did_initiate_recording |= tracing->did_initiate_recording(); | 1063 did_initiate_recording |= tracing->did_initiate_recording(); | 
| 917 if (did_initiate_recording) { | 1064 if (did_initiate_recording) { | 
| 918 frame_trace_recorder_->OnSwapCompositorFrame( | 1065 frame_trace_recorder_->OnSwapCompositorFrame( | 
| 919 current_ ? current_->host() : nullptr, metadata); | 1066 current_ ? current_->host() : nullptr, metadata); | 
| 920 } | 1067 } | 
| 921 } | 1068 } | 
| 922 | 1069 | 
| 923 void RenderFrameDevToolsAgentHost:: | |
| 924 DispatchBufferedProtocolMessagesIfNecessary() { | |
| 925 if (navigating_handles_.empty() && | |
| 926 in_navigation_protocol_message_buffer_.size()) { | |
| 927 DCHECK(current_); | |
| 928 for (const auto& pair : in_navigation_protocol_message_buffer_) { | |
| 929 current_->DispatchProtocolMessage( | |
| 930 pair.second.session_id, pair.first, pair.second.method, | |
| 931 pair.second.message); | |
| 932 } | |
| 933 in_navigation_protocol_message_buffer_.clear(); | |
| 934 } | |
| 935 } | |
| 936 | |
| 937 void RenderFrameDevToolsAgentHost::UpdateProtocolHandlers( | 1070 void RenderFrameDevToolsAgentHost::UpdateProtocolHandlers( | 
| 938 RenderFrameHostImpl* host) { | 1071 RenderFrameHostImpl* host) { | 
| 1072 if (IsBrowserSideNavigationEnabled()) | |
| 1073 return; | |
| 939 #if DCHECK_IS_ON() | 1074 #if DCHECK_IS_ON() | 
| 940 // TODO(dgozman): fix this for browser side navigation. | 1075 // Check that we don't have stale host object here by accessing some random | 
| 941 if (!IsBrowserSideNavigationEnabled()) { | 1076 // properties inside. | 
| 942 // Check that we don't have stale host object here by accessing some random | 1077 if (handlers_frame_host_ && handlers_frame_host_->GetRenderWidgetHost()) | 
| 943 // properties inside. | 1078 handlers_frame_host_->GetRenderWidgetHost()->GetRoutingID(); | 
| 944 if (handlers_frame_host_ && handlers_frame_host_->GetRenderWidgetHost()) | |
| 945 handlers_frame_host_->GetRenderWidgetHost()->GetRoutingID(); | |
| 946 } | |
| 947 #endif | 1079 #endif | 
| 948 handlers_frame_host_ = host; | 1080 handlers_frame_host_ = host; | 
| 949 if (session()) | 1081 if (session()) | 
| 950 session()->SetRenderFrameHost(host); | 1082 session()->SetRenderFrameHost(host); | 
| 951 } | 1083 } | 
| 952 | 1084 | 
| 953 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { | 1085 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { | 
| 1086 if (IsBrowserSideNavigationEnabled()) { | |
| 1087 UpdateFrameHost(nullptr); | |
| 1088 frame_tree_node_ = nullptr; | |
| 
pfeldman
2017/06/10 00:32:04
suspended_count = нулю;
 
dgozman
2017/06/10 01:36:35
Done.
 | |
| 1089 WebContentsObserver::Observe(nullptr); | |
| 1090 return; | |
| 1091 } | |
| 954 if (pending_) | 1092 if (pending_) | 
| 955 DiscardPending(); | 1093 DiscardPending(); | 
| 956 UpdateProtocolHandlers(nullptr); | 1094 UpdateProtocolHandlers(nullptr); | 
| 957 disconnected_ = std::move(current_); | 1095 disconnected_ = std::move(current_); | 
| 958 if (session()) | 1096 if (session()) | 
| 959 disconnected_->Detach(session()->session_id()); | 1097 disconnected_->Detach(session()->session_id()); | 
| 960 frame_tree_node_ = nullptr; | 1098 frame_tree_node_ = nullptr; | 
| 961 in_navigation_protocol_message_buffer_.clear(); | |
| 962 navigating_handles_.clear(); | |
| 963 pending_handle_ = nullptr; | |
| 964 WebContentsObserver::Observe(nullptr); | 1099 WebContentsObserver::Observe(nullptr); | 
| 965 } | 1100 } | 
| 966 | 1101 | 
| 967 void RenderFrameDevToolsAgentHost::ConnectWebContents(WebContents* wc) { | 1102 void RenderFrameDevToolsAgentHost::ConnectWebContents(WebContents* wc) { | 
| 1103 if (IsBrowserSideNavigationEnabled()) { | |
| 1104 RenderFrameHostImpl* host = | |
| 1105 static_cast<RenderFrameHostImpl*>(wc->GetMainFrame()); | |
| 1106 DCHECK(host); | |
| 1107 frame_tree_node_ = host->frame_tree_node(); | |
| 1108 WebContentsObserver::Observe(wc); | |
| 1109 UpdateFrameHost(host); | |
| 1110 return; | |
| 1111 } | |
| 1112 | |
| 968 // CommitPending may destruct |this|. | 1113 // CommitPending may destruct |this|. | 
| 969 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 1114 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 
| 970 | 1115 | 
| 971 DCHECK(!current_); | 1116 DCHECK(!current_); | 
| 972 DCHECK(!pending_); | 1117 DCHECK(!pending_); | 
| 973 RenderFrameHostImpl* host = | 1118 RenderFrameHostImpl* host = | 
| 974 static_cast<RenderFrameHostImpl*>(wc->GetMainFrame()); | 1119 static_cast<RenderFrameHostImpl*>(wc->GetMainFrame()); | 
| 975 DCHECK(host); | 1120 DCHECK(host); | 
| 976 frame_tree_node_ = host->frame_tree_node(); | 1121 frame_tree_node_ = host->frame_tree_node(); | 
| 977 current_ = std::move(disconnected_); | 1122 current_ = std::move(disconnected_); | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1013 return kTypePage; | 1158 return kTypePage; | 
| 1014 } | 1159 } | 
| 1015 | 1160 | 
| 1016 std::string RenderFrameDevToolsAgentHost::GetTitle() { | 1161 std::string RenderFrameDevToolsAgentHost::GetTitle() { | 
| 1017 DevToolsManager* manager = DevToolsManager::GetInstance(); | 1162 DevToolsManager* manager = DevToolsManager::GetInstance(); | 
| 1018 if (manager->delegate() && web_contents()) { | 1163 if (manager->delegate() && web_contents()) { | 
| 1019 std::string title = manager->delegate()->GetTargetTitle(web_contents()); | 1164 std::string title = manager->delegate()->GetTargetTitle(web_contents()); | 
| 1020 if (!title.empty()) | 1165 if (!title.empty()) | 
| 1021 return title; | 1166 return title; | 
| 1022 } | 1167 } | 
| 1023 if (current_ && current_->host()->GetParent()) | 1168 if (IsBrowserSideNavigationEnabled()) { | 
| 1024 return current_->host()->GetLastCommittedURL().spec(); | 1169 if (IsChildFrame() && frame_host_) | 
| 1170 return frame_host_->GetLastCommittedURL().spec(); | |
| 1171 } else { | |
| 1172 if (current_ && current_->host()->GetParent()) | |
| 1173 return current_->host()->GetLastCommittedURL().spec(); | |
| 1174 } | |
| 1025 if (web_contents()) | 1175 if (web_contents()) | 
| 1026 return base::UTF16ToUTF8(web_contents()->GetTitle()); | 1176 return base::UTF16ToUTF8(web_contents()->GetTitle()); | 
| 1027 return GetURL().spec(); | 1177 return GetURL().spec(); | 
| 1028 } | 1178 } | 
| 1029 | 1179 | 
| 1030 std::string RenderFrameDevToolsAgentHost::GetDescription() { | 1180 std::string RenderFrameDevToolsAgentHost::GetDescription() { | 
| 1031 DevToolsManager* manager = DevToolsManager::GetInstance(); | 1181 DevToolsManager* manager = DevToolsManager::GetInstance(); | 
| 1032 if (manager->delegate() && web_contents()) | 1182 if (manager->delegate() && web_contents()) | 
| 1033 return manager->delegate()->GetTargetDescription(web_contents()); | 1183 return manager->delegate()->GetTargetDescription(web_contents()); | 
| 1034 return std::string(); | 1184 return std::string(); | 
| 1035 } | 1185 } | 
| 1036 | 1186 | 
| 1037 GURL RenderFrameDevToolsAgentHost::GetURL() { | 1187 GURL RenderFrameDevToolsAgentHost::GetURL() { | 
| 1038 // Order is important here. | 1188 // Order is important here. | 
| 1039 WebContents* web_contents = GetWebContents(); | 1189 WebContents* web_contents = GetWebContents(); | 
| 1040 if (web_contents && !IsChildFrame()) | 1190 if (web_contents && !IsChildFrame()) | 
| 1041 return web_contents->GetVisibleURL(); | 1191 return web_contents->GetVisibleURL(); | 
| 1192 if (IsBrowserSideNavigationEnabled() && frame_host_) | |
| 
pfeldman
2017/06/10 00:32:04
nested ifs, return for browser-side early.
 
dgozman
2017/06/10 01:36:35
Done.
 | |
| 1193 return frame_host_->GetLastCommittedURL(); | |
| 1042 if (pending_) | 1194 if (pending_) | 
| 1043 return pending_->host()->GetLastCommittedURL(); | 1195 return pending_->host()->GetLastCommittedURL(); | 
| 1044 if (current_) | 1196 if (current_) | 
| 1045 return current_->host()->GetLastCommittedURL(); | 1197 return current_->host()->GetLastCommittedURL(); | 
| 1046 return GURL(); | 1198 return GURL(); | 
| 1047 } | 1199 } | 
| 1048 | 1200 | 
| 1049 GURL RenderFrameDevToolsAgentHost::GetFaviconURL() { | 1201 GURL RenderFrameDevToolsAgentHost::GetFaviconURL() { | 
| 1050 WebContents* wc = web_contents(); | 1202 WebContents* wc = web_contents(); | 
| 1051 if (!wc) | 1203 if (!wc) | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1107 page->OnSynchronousSwapCompositorFrame(frame_metadata.Clone()); | 1259 page->OnSynchronousSwapCompositorFrame(frame_metadata.Clone()); | 
| 1108 for (auto* input : protocol::InputHandler::ForAgentHost(this)) | 1260 for (auto* input : protocol::InputHandler::ForAgentHost(this)) | 
| 1109 input->OnSwapCompositorFrame(frame_metadata); | 1261 input->OnSwapCompositorFrame(frame_metadata); | 
| 1110 | 1262 | 
| 1111 if (!frame_trace_recorder_) | 1263 if (!frame_trace_recorder_) | 
| 1112 return; | 1264 return; | 
| 1113 bool did_initiate_recording = false; | 1265 bool did_initiate_recording = false; | 
| 1114 for (auto* tracing : protocol::TracingHandler::ForAgentHost(this)) | 1266 for (auto* tracing : protocol::TracingHandler::ForAgentHost(this)) | 
| 1115 did_initiate_recording |= tracing->did_initiate_recording(); | 1267 did_initiate_recording |= tracing->did_initiate_recording(); | 
| 1116 if (did_initiate_recording) { | 1268 if (did_initiate_recording) { | 
| 1117 frame_trace_recorder_->OnSynchronousSwapCompositorFrame( | 1269 if (IsBrowserSideNavigationEnabled()) { | 
| 1118 current_ ? current_->host() : nullptr, frame_metadata); | 1270 frame_trace_recorder_->OnSynchronousSwapCompositorFrame( | 
| 1271 frame_host_, frame_metadata); | |
| 1272 } else { | |
| 1273 frame_trace_recorder_->OnSynchronousSwapCompositorFrame( | |
| 1274 current_ ? current_->host() : nullptr, frame_metadata); | |
| 1275 } | |
| 1119 } | 1276 } | 
| 1120 } | 1277 } | 
| 1121 | 1278 | 
| 1122 void RenderFrameDevToolsAgentHost::OnDispatchOnInspectorFrontend( | 1279 void RenderFrameDevToolsAgentHost::OnDispatchOnInspectorFrontend( | 
| 1123 RenderFrameHost* sender, | 1280 RenderFrameHost* sender, | 
| 1124 const DevToolsMessageChunk& message) { | 1281 const DevToolsMessageChunk& message) { | 
| 1125 bool success = true; | 1282 bool success = true; | 
| 1126 if (current_ && current_->host() == sender) | 1283 if (IsBrowserSideNavigationEnabled()) { | 
| 1127 success = current_->ProcessChunkedMessageFromAgent(message); | 1284 if (sender == frame_host_) | 
| 1128 else if (pending_ && pending_->host() == sender) | 1285 success = chunk_processor_.ProcessChunkedMessageFromAgent(message); | 
| 1129 success = pending_->ProcessChunkedMessageFromAgent(message); | 1286 } else { | 
| 1287 if (current_ && current_->host() == sender) | |
| 1288 success = current_->ProcessChunkedMessageFromAgent(message); | |
| 1289 else if (pending_ && pending_->host() == sender) | |
| 1290 success = pending_->ProcessChunkedMessageFromAgent(message); | |
| 1291 } | |
| 1130 if (!success) { | 1292 if (!success) { | 
| 1131 bad_message::ReceivedBadMessage( | 1293 bad_message::ReceivedBadMessage( | 
| 1132 sender->GetProcess(), | 1294 sender->GetProcess(), | 
| 1133 bad_message::RFH_INCONSISTENT_DEVTOOLS_MESSAGE); | 1295 bad_message::RFH_INCONSISTENT_DEVTOOLS_MESSAGE); | 
| 1134 } | 1296 } | 
| 1135 } | 1297 } | 
| 1136 | 1298 | 
| 1137 void RenderFrameDevToolsAgentHost::OnRequestNewWindow( | 1299 void RenderFrameDevToolsAgentHost::OnRequestNewWindow( | 
| 1138 RenderFrameHost* sender, | 1300 RenderFrameHost* sender, | 
| 1139 int new_routing_id) { | 1301 int new_routing_id) { | 
| 1140 RenderFrameHostImpl* frame_host = RenderFrameHostImpl::FromID( | 1302 RenderFrameHostImpl* frame_host = RenderFrameHostImpl::FromID( | 
| 1141 sender->GetProcess()->GetID(), new_routing_id); | 1303 sender->GetProcess()->GetID(), new_routing_id); | 
| 1142 | 1304 | 
| 1143 bool success = false; | 1305 bool success = false; | 
| 1144 if (IsAttached() && sender->GetRoutingID() != new_routing_id && frame_host) { | 1306 if (IsAttached() && sender->GetRoutingID() != new_routing_id && frame_host) { | 
| 1145 scoped_refptr<DevToolsAgentHost> agent = | 1307 scoped_refptr<DevToolsAgentHost> agent = | 
| 1146 RenderFrameDevToolsAgentHost::GetOrCreateFor( | 1308 RenderFrameDevToolsAgentHost::GetOrCreateFor( | 
| 1147 frame_host->frame_tree_node()); | 1309 frame_host->frame_tree_node()); | 
| 1148 success = static_cast<DevToolsAgentHostImpl*>(agent.get())->Inspect(); | 1310 success = static_cast<DevToolsAgentHostImpl*>(agent.get())->Inspect(); | 
| 1149 } | 1311 } | 
| 1150 | 1312 | 
| 1151 sender->Send(new DevToolsAgentMsg_RequestNewWindow_ACK( | 1313 sender->Send(new DevToolsAgentMsg_RequestNewWindow_ACK( | 
| 1152 sender->GetRoutingID(), success)); | 1314 sender->GetRoutingID(), success)); | 
| 1153 } | 1315 } | 
| 1154 | 1316 | 
| 1155 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1317 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 
| 1156 return current_ && current_->host()->GetParent(); | 1318 return frame_tree_node_ && frame_tree_node_->parent(); | 
| 1157 } | 1319 } | 
| 1158 | 1320 | 
| 1159 } // namespace content | 1321 } // namespace content | 
| OLD | NEW |