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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 #include "content/public/browser/notification_source.h" | 40 #include "content/public/browser/notification_source.h" |
| 41 #include "content/public/browser/render_frame_host.h" | 41 #include "content/public/browser/render_frame_host.h" |
| 42 #include "content/public/browser/render_view_host.h" | 42 #include "content/public/browser/render_view_host.h" |
| 43 #include "content/public/browser/user_metrics.h" | 43 #include "content/public/browser/user_metrics.h" |
| 44 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
| 45 #include "content/public/browser/web_contents_observer.h" | 45 #include "content/public/browser/web_contents_observer.h" |
| 46 #include "content/public/common/renderer_preferences.h" | 46 #include "content/public/common/renderer_preferences.h" |
| 47 #include "content/public/common/url_constants.h" | 47 #include "content/public/common/url_constants.h" |
| 48 #include "extensions/browser/extension_registry.h" | 48 #include "extensions/browser/extension_registry.h" |
| 49 #include "extensions/common/permissions/permissions_data.h" | 49 #include "extensions/common/permissions/permissions_data.h" |
| 50 #include "net/http/http_response_headers.h" | |
| 51 #include "net/url_request/url_fetcher.h" | |
| 50 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 51 #include "ui/base/page_transition_types.h" | 53 #include "ui/base/page_transition_types.h" |
| 52 | 54 |
| 53 using base::DictionaryValue; | 55 using base::DictionaryValue; |
| 54 using content::BrowserThread; | 56 using content::BrowserThread; |
| 55 | 57 |
| 56 namespace content { | 58 namespace content { |
| 57 struct LoadCommittedDetails; | 59 struct LoadCommittedDetails; |
| 58 struct FrameNavigateParams; | 60 struct FrameNavigateParams; |
| 59 } | 61 } |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 } | 461 } |
| 460 | 462 |
| 461 void DevToolsUIBindings::AgentHostClosed( | 463 void DevToolsUIBindings::AgentHostClosed( |
| 462 content::DevToolsAgentHost* agent_host, | 464 content::DevToolsAgentHost* agent_host, |
| 463 bool replaced_with_another_client) { | 465 bool replaced_with_another_client) { |
| 464 DCHECK(agent_host == agent_host_.get()); | 466 DCHECK(agent_host == agent_host_.get()); |
| 465 agent_host_ = NULL; | 467 agent_host_ = NULL; |
| 466 delegate_->InspectedContentsClosing(); | 468 delegate_->InspectedContentsClosing(); |
| 467 } | 469 } |
| 468 | 470 |
| 469 void DevToolsUIBindings::SendMessageAck(int request_id) { | 471 void DevToolsUIBindings::SendMessageAck(int request_id, |
| 472 const base::Value* arg) { | |
| 470 base::FundamentalValue id_value(request_id); | 473 base::FundamentalValue id_value(request_id); |
| 471 CallClientFunction("DevToolsAPI.embedderMessageAck", | 474 CallClientFunction("DevToolsAPI.embedderMessageAck", |
| 472 &id_value, nullptr, nullptr); | 475 &id_value, arg, nullptr); |
| 473 } | 476 } |
| 474 | 477 |
| 475 // DevToolsEmbedderMessageDispatcher::Delegate implementation ----------------- | 478 // DevToolsEmbedderMessageDispatcher::Delegate implementation ----------------- |
| 476 void DevToolsUIBindings::ActivateWindow(int request_id) { | 479 void DevToolsUIBindings::ActivateWindow(int request_id) { |
| 477 delegate_->ActivateWindow(); | 480 delegate_->ActivateWindow(); |
| 478 } | 481 } |
| 479 | 482 |
| 480 void DevToolsUIBindings::CloseWindow(int request_id) { | 483 void DevToolsUIBindings::CloseWindow(int request_id) { |
| 481 delegate_->CloseWindow(); | 484 delegate_->CloseWindow(); |
| 482 } | 485 } |
| 483 | 486 |
| 484 void DevToolsUIBindings::LoadCompleted(int request_id) { | 487 void DevToolsUIBindings::LoadCompleted(int request_id) { |
| 485 FrontendLoaded(); | 488 FrontendLoaded(); |
| 486 } | 489 } |
| 487 | 490 |
| 488 void DevToolsUIBindings::SetInspectedPageBounds(int request_id, | 491 void DevToolsUIBindings::SetInspectedPageBounds(int request_id, |
| 489 const gfx::Rect& rect) { | 492 const gfx::Rect& rect) { |
| 490 delegate_->SetInspectedPageBounds(rect); | 493 delegate_->SetInspectedPageBounds(rect); |
| 491 } | 494 } |
| 492 | 495 |
| 493 void DevToolsUIBindings::SetIsDocked(int request_id, bool dock_requested) { | 496 void DevToolsUIBindings::SetIsDocked(int request_id, bool dock_requested) { |
| 494 delegate_->SetIsDocked(dock_requested); | 497 delegate_->SetIsDocked(dock_requested); |
| 495 SendMessageAck(request_id); | 498 SendMessageAck(request_id, nullptr); |
| 496 } | 499 } |
| 497 | 500 |
| 498 void DevToolsUIBindings::InspectElementCompleted(int request_id) { | 501 void DevToolsUIBindings::InspectElementCompleted(int request_id) { |
| 499 delegate_->InspectElementCompleted(); | 502 delegate_->InspectElementCompleted(); |
| 500 } | 503 } |
| 501 | 504 |
| 502 void DevToolsUIBindings::InspectedURLChanged(int request_id, | 505 void DevToolsUIBindings::InspectedURLChanged(int request_id, |
| 503 const std::string& url) { | 506 const std::string& url) { |
| 504 content::NavigationController& controller = web_contents()->GetController(); | 507 content::NavigationController& controller = web_contents()->GetController(); |
| 505 content::NavigationEntry* entry = controller.GetActiveEntry(); | 508 content::NavigationEntry* entry = controller.GetActiveEntry(); |
| 506 // DevTools UI is not localized. | 509 // DevTools UI is not localized. |
| 507 entry->SetTitle( | 510 entry->SetTitle( |
| 508 base::UTF8ToUTF16(base::StringPrintf(kTitleFormat, url.c_str()))); | 511 base::UTF8ToUTF16(base::StringPrintf(kTitleFormat, url.c_str()))); |
| 509 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE); | 512 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE); |
| 510 } | 513 } |
| 511 | 514 |
| 515 void DevToolsUIBindings::LoadNetworkResource(int request_id, | |
| 516 const std::string& url, | |
| 517 const std::string& headers) { | |
| 518 GURL gurl(url); | |
| 519 if (!gurl.is_valid()) { | |
| 520 base::DictionaryValue response; | |
| 521 response.SetInteger("statusCode", 404); | |
| 522 SendMessageAck(request_id, &response); | |
| 523 return; | |
| 524 } | |
| 525 | |
| 526 net::URLFetcher* fetcher = | |
| 527 net::URLFetcher::Create(gurl, net::URLFetcher::GET, this); | |
|
dgozman
2015/02/27 12:22:04
You should delete all pending fetchers in destruct
pfeldman
2015/02/27 12:54:47
Ouch. Done.
| |
| 528 pending_requests_[fetcher] = request_id; | |
| 529 fetcher->SetRequestContext(profile_->GetRequestContext()); | |
| 530 fetcher->SetExtraRequestHeaders(headers); | |
| 531 fetcher->Start(); | |
| 532 } | |
| 533 | |
| 512 void DevToolsUIBindings::OpenInNewTab(int request_id, const std::string& url) { | 534 void DevToolsUIBindings::OpenInNewTab(int request_id, const std::string& url) { |
| 513 delegate_->OpenInNewTab(url); | 535 delegate_->OpenInNewTab(url); |
| 514 } | 536 } |
| 515 | 537 |
| 516 void DevToolsUIBindings::SaveToFile(int request_id, | 538 void DevToolsUIBindings::SaveToFile(int request_id, |
| 517 const std::string& url, | 539 const std::string& url, |
| 518 const std::string& content, | 540 const std::string& content, |
| 519 bool save_as) { | 541 bool save_as) { |
| 520 file_helper_->Save(url, content, save_as, | 542 file_helper_->Save(url, content, save_as, |
| 521 base::Bind(&DevToolsUIBindings::FileSavedAs, | 543 base::Bind(&DevToolsUIBindings::FileSavedAs, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 697 | 719 |
| 698 void DevToolsUIBindings::RecordActionUMA(int request_id, | 720 void DevToolsUIBindings::RecordActionUMA(int request_id, |
| 699 const std::string& name, | 721 const std::string& name, |
| 700 int action) { | 722 int action) { |
| 701 if (name == kDevToolsActionTakenHistogram) | 723 if (name == kDevToolsActionTakenHistogram) |
| 702 UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsActionTakenBoundary); | 724 UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsActionTakenBoundary); |
| 703 else if (name == kDevToolsPanelShownHistogram) | 725 else if (name == kDevToolsPanelShownHistogram) |
| 704 UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsPanelShownBoundary); | 726 UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsPanelShownBoundary); |
| 705 } | 727 } |
| 706 | 728 |
| 729 void DevToolsUIBindings::OnURLFetchComplete(const net::URLFetcher* source) { | |
| 730 DCHECK(source); | |
| 731 PendingRequestsMap::iterator it = pending_requests_.find(source); | |
| 732 DCHECK(it != pending_requests_.end()); | |
| 733 | |
| 734 std::string body; | |
| 735 source->GetResponseAsString(&body); | |
| 736 | |
| 737 base::FundamentalValue request_id(it->second); | |
| 738 | |
| 739 base::DictionaryValue response; | |
| 740 base::DictionaryValue* headers = new base::DictionaryValue(); | |
| 741 net::HttpResponseHeaders* rh = source->GetResponseHeaders(); | |
| 742 response.SetInteger("statusCode", rh ? rh->response_code() : 200); | |
| 743 response.Set("headers", headers); | |
| 744 response.SetString("body", body); | |
| 745 | |
| 746 void* iterator = NULL; | |
| 747 std::string name; | |
| 748 std::string value; | |
| 749 while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value)) | |
| 750 headers->SetString(name, value); | |
| 751 | |
| 752 SendMessageAck(it->second, &response); | |
| 753 pending_requests_.erase(it); | |
| 754 } | |
| 755 | |
| 707 void DevToolsUIBindings::DeviceCountChanged(int count) { | 756 void DevToolsUIBindings::DeviceCountChanged(int count) { |
| 708 base::FundamentalValue value(count); | 757 base::FundamentalValue value(count); |
| 709 CallClientFunction("DevToolsAPI.deviceCountUpdated", &value, NULL, | 758 CallClientFunction("DevToolsAPI.deviceCountUpdated", &value, NULL, |
| 710 NULL); | 759 NULL); |
| 711 } | 760 } |
| 712 | 761 |
| 713 void DevToolsUIBindings::DevicesUpdated( | 762 void DevToolsUIBindings::DevicesUpdated( |
| 714 const std::string& source, | 763 const std::string& source, |
| 715 const base::ListValue& targets) { | 764 const base::ListValue& targets) { |
| 716 CallClientFunction("DevToolsAPI.devicesUpdated", &targets, NULL, | 765 CallClientFunction("DevToolsAPI.devicesUpdated", &targets, NULL, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 919 if (frontend_loaded_) | 968 if (frontend_loaded_) |
| 920 return; | 969 return; |
| 921 frontend_loaded_ = true; | 970 frontend_loaded_ = true; |
| 922 | 971 |
| 923 // Call delegate first - it seeds importants bit of information. | 972 // Call delegate first - it seeds importants bit of information. |
| 924 delegate_->OnLoadCompleted(); | 973 delegate_->OnLoadCompleted(); |
| 925 | 974 |
| 926 UpdateTheme(); | 975 UpdateTheme(); |
| 927 AddDevToolsExtensionsToClient(); | 976 AddDevToolsExtensionsToClient(); |
| 928 } | 977 } |
| OLD | NEW |