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

Unified Diff: content/shell/browser/shell_devtools_frontend.cc

Issue 967513002: DevTools: do not use debug target when loading URLs for the front-end (chrome side). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@t5
Patch Set: using acks Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/shell/browser/shell_devtools_frontend.cc
diff --git a/content/shell/browser/shell_devtools_frontend.cc b/content/shell/browser/shell_devtools_frontend.cc
index a6bead64ffbe3ae8ddf232723c8ef1e70c7e4117..36455eeebf752cd7b624cd649971ca5c6117e687 100644
--- a/content/shell/browser/shell_devtools_frontend.cc
+++ b/content/shell/browser/shell_devtools_frontend.cc
@@ -23,6 +23,8 @@
#include "content/shell/browser/webkit_test_controller.h"
#include "content/shell/common/shell_switches.h"
#include "net/base/filename_util.h"
+#include "net/http/http_response_headers.h"
+#include "net/url_request/url_fetcher.h"
namespace content {
@@ -111,7 +113,6 @@ void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(
if (!agent_host_)
return;
std::string method;
- int id = 0;
base::ListValue* params = NULL;
base::DictionaryValue* dict = NULL;
scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message));
@@ -120,6 +121,8 @@ void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(
!dict->GetString("method", &method)) {
return;
}
+ int id = 0;
+ dict->GetInteger("id", &id);
dict->GetList("params", &params);
std::string browser_message;
@@ -129,11 +132,35 @@ void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(
} else if (method == "loadCompleted") {
web_contents()->GetMainFrame()->ExecuteJavaScript(
base::ASCIIToUTF16("DevToolsAPI.setUseSoftMenu(true);"));
+ } else if (method == "loadNetworkResource" && params->GetSize() == 2) {
+ // TODO(pfeldman): handle some of the embedder messages in content.
+ std::string url;
+ std::string headers;
+ if (!params->GetString(0, &url) ||
+ !params->GetString(1, &headers)) {
+ return;
+ }
+ GURL gurl(url);
+ if (!gurl.is_valid()) {
+ std::string code = base::StringPrintf(
+ "DevToolsAPI.embedderMessageAck(%d, { statusCode: 404 });", id);
+ web_contents()->GetMainFrame()->ExecuteJavaScript(
+ base::UTF8ToUTF16(code));
+ return;
+ }
+
+ net::URLFetcher* fetcher =
+ net::URLFetcher::Create(gurl, net::URLFetcher::GET, this);
dgozman 2015/02/27 12:22:04 Delete pending fetchers in destructor.
pfeldman 2015/02/27 12:54:47 Done.
+ pending_requests_[fetcher] = id;
+ fetcher->SetRequestContext(web_contents()->GetBrowserContext()->
+ GetRequestContext());
+ fetcher->SetExtraRequestHeaders(headers);
+ fetcher->Start();
+ return;
} else {
return;
}
- dict->GetInteger("id", &id);
if (id) {
std::string code = "DevToolsAPI.embedderMessageAck(" +
base::IntToString(id) + ",\"\");";
@@ -169,6 +196,42 @@ void ShellDevToolsFrontend::DispatchProtocolMessage(
}
}
+void ShellDevToolsFrontend::OnURLFetchComplete(const net::URLFetcher* source) {
+ // TODO(pfeldman): this is a copy of chrome's devtools_ui_bindings.cc.
+ // We should handle some of the commands including this one in content.
+ DCHECK(source);
+ PendingRequestsMap::iterator it = pending_requests_.find(source);
+ DCHECK(it != pending_requests_.end());
+
+ std::string body;
+ source->GetResponseAsString(&body);
+
+ base::DictionaryValue response;
+ base::DictionaryValue* headers = new base::DictionaryValue();
+ net::HttpResponseHeaders* rh = source->GetResponseHeaders();
+ response.SetInteger("statusCode", rh ? rh->response_code() : 200);
+ response.Set("headers", headers);
+ response.SetString("body", body);
+
+ void* iterator = NULL;
+ std::string name;
+ std::string value;
+ while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value))
+ headers->SetString(name, value);
+
+ std::string json;
+ base::JSONWriter::Write(&response, &json);
+
+ std::string message = base::StringPrintf(
+ "DevToolsAPI.embedderMessageAck(%d, %s)",
+ it->second,
+ json.c_str());
+ web_contents()->GetMainFrame()->
+ ExecuteJavaScript(base::UTF8ToUTF16(message));
+
+ pending_requests_.erase(it);
+}
+
void ShellDevToolsFrontend::AttachTo(WebContents* inspected_contents) {
DisconnectFromTarget();
agent_host_ = DevToolsAgentHost::GetOrCreateFor(inspected_contents);

Powered by Google App Engine
This is Rietveld 408576698