Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/devtools/devtools_ui_bindings.h" | 5 #include "chrome/browser/devtools/devtools_ui_bindings.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 DevToolsUIBindings::FrontendWebContentsObserver:: | 464 DevToolsUIBindings::FrontendWebContentsObserver:: |
| 465 ~FrontendWebContentsObserver() { | 465 ~FrontendWebContentsObserver() { |
| 466 } | 466 } |
| 467 | 467 |
| 468 // static | 468 // static |
| 469 GURL DevToolsUIBindings::SanitizeFrontendURL(const GURL& url) { | 469 GURL DevToolsUIBindings::SanitizeFrontendURL(const GURL& url) { |
| 470 return ::SanitizeFrontendURL(url, content::kChromeDevToolsScheme, | 470 return ::SanitizeFrontendURL(url, content::kChromeDevToolsScheme, |
| 471 chrome::kChromeUIDevToolsHost, SanitizeFrontendPath(url.path()), true); | 471 chrome::kChromeUIDevToolsHost, SanitizeFrontendPath(url.path()), true); |
| 472 } | 472 } |
| 473 | 473 |
| 474 bool DevToolsUIBindings::IsValidFrontendURL(const GURL& url) { | |
| 475 return SanitizeFrontendURL(url).spec() == url.spec(); | |
| 476 } | |
| 477 | |
| 474 void DevToolsUIBindings::FrontendWebContentsObserver::RenderProcessGone( | 478 void DevToolsUIBindings::FrontendWebContentsObserver::RenderProcessGone( |
| 475 base::TerminationStatus status) { | 479 base::TerminationStatus status) { |
| 476 bool crashed = true; | 480 bool crashed = true; |
| 477 switch (status) { | 481 switch (status) { |
| 478 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 482 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 479 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 483 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 480 #if defined(OS_CHROMEOS) | 484 #if defined(OS_CHROMEOS) |
| 481 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: | 485 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: |
| 482 #endif | 486 #endif |
| 483 case base::TERMINATION_STATUS_PROCESS_CRASHED: | 487 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| 484 case base::TERMINATION_STATUS_LAUNCH_FAILED: | 488 case base::TERMINATION_STATUS_LAUNCH_FAILED: |
| 485 if (devtools_bindings_->agent_host_.get()) | 489 if (devtools_bindings_->agent_host_.get()) |
| 486 devtools_bindings_->Detach(); | 490 devtools_bindings_->Detach(); |
| 487 break; | 491 break; |
| 488 default: | 492 default: |
| 489 crashed = false; | 493 crashed = false; |
| 490 break; | 494 break; |
| 491 } | 495 } |
| 492 devtools_bindings_->delegate_->RenderProcessGone(crashed); | 496 devtools_bindings_->delegate_->RenderProcessGone(crashed); |
| 493 } | 497 } |
| 494 | 498 |
| 495 void DevToolsUIBindings::FrontendWebContentsObserver:: | 499 void DevToolsUIBindings::FrontendWebContentsObserver:: |
| 496 DidStartNavigationToPendingEntry(const GURL& url, | 500 DidStartNavigationToPendingEntry(const GURL& url, |
| 497 content::ReloadType reload_type) { | 501 content::ReloadType reload_type) { |
| 498 devtools_bindings_->UpdateFrontendHost(); | 502 devtools_bindings_->UpdateFrontendHost(url); |
| 499 } | 503 } |
| 500 | 504 |
| 501 void DevToolsUIBindings::FrontendWebContentsObserver:: | 505 void DevToolsUIBindings::FrontendWebContentsObserver:: |
| 502 DocumentAvailableInMainFrame() { | 506 DocumentAvailableInMainFrame() { |
| 503 devtools_bindings_->DocumentAvailableInMainFrame(); | 507 devtools_bindings_->DocumentAvailableInMainFrame(); |
| 504 } | 508 } |
| 505 | 509 |
| 506 void DevToolsUIBindings::FrontendWebContentsObserver:: | 510 void DevToolsUIBindings::FrontendWebContentsObserver:: |
| 507 DocumentOnLoadCompletedInMainFrame() { | 511 DocumentOnLoadCompletedInMainFrame() { |
| 508 devtools_bindings_->DocumentOnLoadCompletedInMainFrame(); | 512 devtools_bindings_->DocumentOnLoadCompletedInMainFrame(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 543 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false; | 547 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 544 | 548 |
| 545 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_, this)); | 549 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_, this)); |
| 546 file_system_indexer_ = new DevToolsFileSystemIndexer(); | 550 file_system_indexer_ = new DevToolsFileSystemIndexer(); |
| 547 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 551 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
| 548 web_contents_); | 552 web_contents_); |
| 549 | 553 |
| 550 // Register on-load actions. | 554 // Register on-load actions. |
| 551 embedder_message_dispatcher_.reset( | 555 embedder_message_dispatcher_.reset( |
| 552 DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(this)); | 556 DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(this)); |
| 553 UpdateFrontendHost(); | 557 UpdateFrontendHost(web_contents_->GetVisibleURL()); |
|
pfeldman
2017/01/10 22:31:51
I don't think you need this call - navigation shou
| |
| 554 } | 558 } |
| 555 | 559 |
| 556 DevToolsUIBindings::~DevToolsUIBindings() { | 560 DevToolsUIBindings::~DevToolsUIBindings() { |
| 557 for (const auto& pair : pending_requests_) | 561 for (const auto& pair : pending_requests_) |
| 558 delete pair.first; | 562 delete pair.first; |
| 559 | 563 |
| 560 if (agent_host_.get()) | 564 if (agent_host_.get()) |
| 561 agent_host_->DetachClient(this); | 565 agent_host_->DetachClient(this); |
| 562 | 566 |
| 563 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); | 567 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1191 const InfoBarCallback& callback) { | 1195 const InfoBarCallback& callback) { |
| 1192 if (!delegate_->GetInfoBarService()) { | 1196 if (!delegate_->GetInfoBarService()) { |
| 1193 callback.Run(false); | 1197 callback.Run(false); |
| 1194 return; | 1198 return; |
| 1195 } | 1199 } |
| 1196 std::unique_ptr<DevToolsConfirmInfoBarDelegate> delegate( | 1200 std::unique_ptr<DevToolsConfirmInfoBarDelegate> delegate( |
| 1197 new DevToolsConfirmInfoBarDelegate(callback, message)); | 1201 new DevToolsConfirmInfoBarDelegate(callback, message)); |
| 1198 GlobalConfirmInfoBar::Show(std::move(delegate)); | 1202 GlobalConfirmInfoBar::Show(std::move(delegate)); |
| 1199 } | 1203 } |
| 1200 | 1204 |
| 1201 void DevToolsUIBindings::UpdateFrontendHost() { | 1205 void DevToolsUIBindings::UpdateFrontendHost(const GURL& url) { |
| 1202 GURL url = web_contents_->GetVisibleURL(); | 1206 if (!IsValidFrontendURL(url)) { |
| 1203 if (url.spec() != SanitizeFrontendURL(url).spec()) { | |
| 1204 LOG(ERROR) << "Attempt to navigate to an invalid DevTools front-end URL: " | 1207 LOG(ERROR) << "Attempt to navigate to an invalid DevTools front-end URL: " |
| 1205 << url.spec(); | 1208 << url.spec(); |
| 1206 frontend_host_.reset(); | 1209 frontend_host_.reset(); |
| 1207 return; | 1210 return; |
| 1208 } | 1211 } |
| 1209 frontend_host_.reset(content::DevToolsFrontendHost::Create( | 1212 frontend_host_.reset(content::DevToolsFrontendHost::Create( |
| 1210 web_contents_->GetMainFrame(), | 1213 web_contents_, |
| 1211 base::Bind(&DevToolsUIBindings::HandleMessageFromDevToolsFrontend, | 1214 base::Bind(&DevToolsUIBindings::HandleMessageFromDevToolsFrontend, |
| 1212 base::Unretained(this)))); | 1215 base::Unretained(this)))); |
| 1213 } | 1216 } |
| 1214 | 1217 |
| 1215 void DevToolsUIBindings::AddDevToolsExtensionsToClient() { | 1218 void DevToolsUIBindings::AddDevToolsExtensionsToClient() { |
| 1216 const extensions::ExtensionRegistry* registry = | 1219 const extensions::ExtensionRegistry* registry = |
| 1217 extensions::ExtensionRegistry::Get(profile_->GetOriginalProfile()); | 1220 extensions::ExtensionRegistry::Get(profile_->GetOriginalProfile()); |
| 1218 if (!registry) | 1221 if (!registry) |
| 1219 return; | 1222 return; |
| 1220 | 1223 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1333 void DevToolsUIBindings::FrontendLoaded() { | 1336 void DevToolsUIBindings::FrontendLoaded() { |
| 1334 if (frontend_loaded_) | 1337 if (frontend_loaded_) |
| 1335 return; | 1338 return; |
| 1336 frontend_loaded_ = true; | 1339 frontend_loaded_ = true; |
| 1337 | 1340 |
| 1338 // Call delegate first - it seeds importants bit of information. | 1341 // Call delegate first - it seeds importants bit of information. |
| 1339 delegate_->OnLoadCompleted(); | 1342 delegate_->OnLoadCompleted(); |
| 1340 | 1343 |
| 1341 AddDevToolsExtensionsToClient(); | 1344 AddDevToolsExtensionsToClient(); |
| 1342 } | 1345 } |
| OLD | NEW |