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

Side by Side Diff: chrome/browser/devtools/devtools_ui_bindings.cc

Issue 2628863003: Fix remote trace recording via chrome://inspect?tracing (Closed)
Patch Set: drive by: stronger check for front-end URL Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) { 474 bool DevToolsUIBindings::IsValidFrontendURL(const GURL& url) {
475 if (url.SchemeIs(content::kChromeUIScheme) &&
476 url.host() == content::kChromeUITracingHost &&
477 !url.has_query() && !url.has_ref()) {
478 return true;
479 }
480
475 return SanitizeFrontendURL(url).spec() == url.spec(); 481 return SanitizeFrontendURL(url).spec() == url.spec();
476 } 482 }
477 483
478 void DevToolsUIBindings::FrontendWebContentsObserver::RenderProcessGone( 484 void DevToolsUIBindings::FrontendWebContentsObserver::RenderProcessGone(
479 base::TerminationStatus status) { 485 base::TerminationStatus status) {
480 bool crashed = true; 486 bool crashed = true;
481 switch (status) { 487 switch (status) {
482 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: 488 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
483 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: 489 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
484 #if defined(OS_CHROMEOS) 490 #if defined(OS_CHROMEOS)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 DevToolsUIBindingsList* instances = g_instances.Pointer(); 581 DevToolsUIBindingsList* instances = g_instances.Pointer();
576 DevToolsUIBindingsList::iterator it( 582 DevToolsUIBindingsList::iterator it(
577 std::find(instances->begin(), instances->end(), this)); 583 std::find(instances->begin(), instances->end(), this));
578 DCHECK(it != instances->end()); 584 DCHECK(it != instances->end());
579 instances->erase(it); 585 instances->erase(it);
580 } 586 }
581 587
582 // content::DevToolsFrontendHost::Delegate implementation --------------------- 588 // content::DevToolsFrontendHost::Delegate implementation ---------------------
583 void DevToolsUIBindings::HandleMessageFromDevToolsFrontend( 589 void DevToolsUIBindings::HandleMessageFromDevToolsFrontend(
584 const std::string& message) { 590 const std::string& message) {
585 if (!web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)) 591 if (!frontend_host_)
586 return; 592 return;
587 std::string method; 593 std::string method;
588 base::ListValue empty_params; 594 base::ListValue empty_params;
589 base::ListValue* params = &empty_params; 595 base::ListValue* params = &empty_params;
590 596
591 base::DictionaryValue* dict = NULL; 597 base::DictionaryValue* dict = NULL;
592 std::unique_ptr<base::Value> parsed_message = base::JSONReader::Read(message); 598 std::unique_ptr<base::Value> parsed_message = base::JSONReader::Read(message);
593 if (!parsed_message || 599 if (!parsed_message ||
594 !parsed_message->GetAsDictionary(&dict) || 600 !parsed_message->GetAsDictionary(&dict) ||
595 !dict->GetString(kFrontendHostMethod, &method) || 601 !dict->GetString(kFrontendHostMethod, &method) ||
596 (dict->HasKey(kFrontendHostParams) && 602 (dict->HasKey(kFrontendHostParams) &&
597 !dict->GetList(kFrontendHostParams, &params))) { 603 !dict->GetList(kFrontendHostParams, &params))) {
598 LOG(ERROR) << "Invalid message was sent to embedder: " << message; 604 LOG(ERROR) << "Invalid message was sent to embedder: " << message;
599 return; 605 return;
600 } 606 }
601 int id = 0; 607 int id = 0;
602 dict->GetInteger(kFrontendHostId, &id); 608 dict->GetInteger(kFrontendHostId, &id);
603 embedder_message_dispatcher_->Dispatch( 609 embedder_message_dispatcher_->Dispatch(
604 base::Bind(&DevToolsUIBindings::SendMessageAck, 610 base::Bind(&DevToolsUIBindings::SendMessageAck,
605 weak_factory_.GetWeakPtr(), 611 weak_factory_.GetWeakPtr(),
606 id), 612 id),
607 method, 613 method,
608 params); 614 params);
609 } 615 }
610 616
611 // content::DevToolsAgentHostClient implementation -------------------------- 617 // content::DevToolsAgentHostClient implementation --------------------------
612 void DevToolsUIBindings::DispatchProtocolMessage( 618 void DevToolsUIBindings::DispatchProtocolMessage(
613 content::DevToolsAgentHost* agent_host, const std::string& message) { 619 content::DevToolsAgentHost* agent_host, const std::string& message) {
614 DCHECK(agent_host == agent_host_.get()); 620 DCHECK(agent_host == agent_host_.get());
615 if (!web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)) 621 if (!frontend_host_)
616 return; 622 return;
617 623
618 if (message.length() < kMaxMessageChunkSize) { 624 if (message.length() < kMaxMessageChunkSize) {
619 std::string param; 625 std::string param;
620 base::EscapeJSONString(message, true, &param); 626 base::EscapeJSONString(message, true, &param);
621 base::string16 javascript = 627 base::string16 javascript =
622 base::UTF8ToUTF16("DevToolsAPI.dispatchMessage(" + param + ");"); 628 base::UTF8ToUTF16("DevToolsAPI.dispatchMessage(" + param + ");");
623 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); 629 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript);
624 return; 630 return;
625 } 631 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 } 727 }
722 728
723 void DevToolsUIBindings::AppendToFile(const std::string& url, 729 void DevToolsUIBindings::AppendToFile(const std::string& url,
724 const std::string& content) { 730 const std::string& content) {
725 file_helper_->Append(url, content, 731 file_helper_->Append(url, content,
726 base::Bind(&DevToolsUIBindings::AppendedTo, 732 base::Bind(&DevToolsUIBindings::AppendedTo,
727 weak_factory_.GetWeakPtr(), url)); 733 weak_factory_.GetWeakPtr(), url));
728 } 734 }
729 735
730 void DevToolsUIBindings::RequestFileSystems() { 736 void DevToolsUIBindings::RequestFileSystems() {
731 CHECK(web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)); 737 CHECK(IsValidFrontendURL(web_contents_->GetURL()) && frontend_host_);
732 std::vector<DevToolsFileHelper::FileSystem> file_systems = 738 std::vector<DevToolsFileHelper::FileSystem> file_systems =
733 file_helper_->GetFileSystems(); 739 file_helper_->GetFileSystems();
734 base::ListValue file_systems_value; 740 base::ListValue file_systems_value;
735 for (size_t i = 0; i < file_systems.size(); ++i) 741 for (size_t i = 0; i < file_systems.size(); ++i)
736 file_systems_value.Append(CreateFileSystemValue(file_systems[i])); 742 file_systems_value.Append(CreateFileSystemValue(file_systems[i]));
737 CallClientFunction("DevToolsAPI.fileSystemsLoaded", 743 CallClientFunction("DevToolsAPI.fileSystemsLoaded",
738 &file_systems_value, NULL, NULL); 744 &file_systems_value, NULL, NULL);
739 } 745 }
740 746
741 void DevToolsUIBindings::AddFileSystem(const std::string& file_system_path) { 747 void DevToolsUIBindings::AddFileSystem(const std::string& file_system_path) {
742 CHECK(web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)); 748 CHECK(IsValidFrontendURL(web_contents_->GetURL()) && frontend_host_);
743 file_helper_->AddFileSystem( 749 file_helper_->AddFileSystem(
744 file_system_path, 750 file_system_path,
745 base::Bind(&DevToolsUIBindings::ShowDevToolsConfirmInfoBar, 751 base::Bind(&DevToolsUIBindings::ShowDevToolsConfirmInfoBar,
746 weak_factory_.GetWeakPtr())); 752 weak_factory_.GetWeakPtr()));
747 } 753 }
748 754
749 void DevToolsUIBindings::RemoveFileSystem(const std::string& file_system_path) { 755 void DevToolsUIBindings::RemoveFileSystem(const std::string& file_system_path) {
750 CHECK(web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)); 756 CHECK(IsValidFrontendURL(web_contents_->GetURL()) && frontend_host_);
751 file_helper_->RemoveFileSystem(file_system_path); 757 file_helper_->RemoveFileSystem(file_system_path);
752 } 758 }
753 759
754 void DevToolsUIBindings::UpgradeDraggedFileSystemPermissions( 760 void DevToolsUIBindings::UpgradeDraggedFileSystemPermissions(
755 const std::string& file_system_url) { 761 const std::string& file_system_url) {
756 CHECK(web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)); 762 CHECK(IsValidFrontendURL(web_contents_->GetURL()) && frontend_host_);
757 file_helper_->UpgradeDraggedFileSystemPermissions( 763 file_helper_->UpgradeDraggedFileSystemPermissions(
758 file_system_url, 764 file_system_url,
759 base::Bind(&DevToolsUIBindings::ShowDevToolsConfirmInfoBar, 765 base::Bind(&DevToolsUIBindings::ShowDevToolsConfirmInfoBar,
760 weak_factory_.GetWeakPtr())); 766 weak_factory_.GetWeakPtr()));
761 } 767 }
762 768
763 void DevToolsUIBindings::IndexPath(int index_request_id, 769 void DevToolsUIBindings::IndexPath(int index_request_id,
764 const std::string& file_system_path) { 770 const std::string& file_system_path) {
765 DCHECK_CURRENTLY_ON(BrowserThread::UI); 771 DCHECK_CURRENTLY_ON(BrowserThread::UI);
766 CHECK(web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)); 772 CHECK(IsValidFrontendURL(web_contents_->GetURL()) && frontend_host_);
767 if (!file_helper_->IsFileSystemAdded(file_system_path)) { 773 if (!file_helper_->IsFileSystemAdded(file_system_path)) {
768 IndexingDone(index_request_id, file_system_path); 774 IndexingDone(index_request_id, file_system_path);
769 return; 775 return;
770 } 776 }
771 if (indexing_jobs_.count(index_request_id) != 0) 777 if (indexing_jobs_.count(index_request_id) != 0)
772 return; 778 return;
773 indexing_jobs_[index_request_id] = 779 indexing_jobs_[index_request_id] =
774 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob>( 780 scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob>(
775 file_system_indexer_->IndexPath( 781 file_system_indexer_->IndexPath(
776 file_system_path, 782 file_system_path,
(...skipping 17 matching lines...) Expand all
794 if (it == indexing_jobs_.end()) 800 if (it == indexing_jobs_.end())
795 return; 801 return;
796 it->second->Stop(); 802 it->second->Stop();
797 indexing_jobs_.erase(it); 803 indexing_jobs_.erase(it);
798 } 804 }
799 805
800 void DevToolsUIBindings::SearchInPath(int search_request_id, 806 void DevToolsUIBindings::SearchInPath(int search_request_id,
801 const std::string& file_system_path, 807 const std::string& file_system_path,
802 const std::string& query) { 808 const std::string& query) {
803 DCHECK_CURRENTLY_ON(BrowserThread::UI); 809 DCHECK_CURRENTLY_ON(BrowserThread::UI);
804 CHECK(web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme)); 810 CHECK(IsValidFrontendURL(web_contents_->GetURL()) && frontend_host_);
805 if (!file_helper_->IsFileSystemAdded(file_system_path)) { 811 if (!file_helper_->IsFileSystemAdded(file_system_path)) {
806 SearchCompleted(search_request_id, 812 SearchCompleted(search_request_id,
807 file_system_path, 813 file_system_path,
808 std::vector<std::string>()); 814 std::vector<std::string>());
809 return; 815 return;
810 } 816 }
811 file_system_indexer_->SearchInPath(file_system_path, 817 file_system_indexer_->SearchInPath(file_system_path,
812 query, 818 query,
813 Bind(&DevToolsUIBindings::SearchCompleted, 819 Bind(&DevToolsUIBindings::SearchCompleted,
814 weak_factory_.GetWeakPtr(), 820 weak_factory_.GetWeakPtr(),
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 } 1286 }
1281 1287
1282 bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) { 1288 bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) {
1283 return agent_host_.get() == agent_host; 1289 return agent_host_.get() == agent_host;
1284 } 1290 }
1285 1291
1286 void DevToolsUIBindings::CallClientFunction(const std::string& function_name, 1292 void DevToolsUIBindings::CallClientFunction(const std::string& function_name,
1287 const base::Value* arg1, 1293 const base::Value* arg1,
1288 const base::Value* arg2, 1294 const base::Value* arg2,
1289 const base::Value* arg3) { 1295 const base::Value* arg3) {
1290 if (!web_contents_->GetURL().SchemeIs(content::kChromeDevToolsScheme))
1291 return;
1292 // If we're not exposing bindings, we shouldn't call functions either. 1296 // If we're not exposing bindings, we shouldn't call functions either.
1293 if (!frontend_host_) 1297 if (!frontend_host_)
1294 return; 1298 return;
1295 std::string javascript = function_name + "("; 1299 std::string javascript = function_name + "(";
1296 if (arg1) { 1300 if (arg1) {
1297 std::string json; 1301 std::string json;
1298 base::JSONWriter::Write(*arg1, &json); 1302 base::JSONWriter::Write(*arg1, &json);
1299 javascript.append(json); 1303 javascript.append(json);
1300 if (arg2) { 1304 if (arg2) {
1301 base::JSONWriter::Write(*arg2, &json); 1305 base::JSONWriter::Write(*arg2, &json);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 void DevToolsUIBindings::FrontendLoaded() { 1341 void DevToolsUIBindings::FrontendLoaded() {
1338 if (frontend_loaded_) 1342 if (frontend_loaded_)
1339 return; 1343 return;
1340 frontend_loaded_ = true; 1344 frontend_loaded_ = true;
1341 1345
1342 // Call delegate first - it seeds importants bit of information. 1346 // Call delegate first - it seeds importants bit of information.
1343 delegate_->OnLoadCompleted(); 1347 delegate_->OnLoadCompleted();
1344 1348
1345 AddDevToolsExtensionsToClient(); 1349 AddDevToolsExtensionsToClient();
1346 } 1350 }
OLDNEW
« 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