Skip to content

Commit 2e7421a

Browse files
author
Cong Liu
committed
Fixed title for devtools
1 parent ece6331 commit 2e7421a

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/shell_devtools_frontend.cc

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "base/path_service.h"
1010
#include "base/strings/string_number_conversions.h"
1111
#include "base/strings/utf_string_conversions.h"
12+
#include "base/strings/stringprintf.h"
1213
#include "content/public/browser/devtools_http_handler.h"
1314
#include "content/public/browser/devtools_manager.h"
1415
#include "content/public/browser/render_frame_host.h"
@@ -100,6 +101,7 @@ void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(
100101
const std::string& message) {
101102
std::string method;
102103
std::string browser_message;
104+
std::string url;
103105
int id = 0;
104106

105107
base::ListValue* params = NULL;
@@ -112,16 +114,24 @@ void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(
112114
return;
113115
}
114116

115-
if (method != "sendMessageToBrowser" ||
116-
params->GetSize() != 1 ||
117-
!params->GetString(0, &browser_message)) {
117+
// handle sendMessageToBrowser
118+
if (method == "sendMessageToBrowser" &&
119+
params->GetSize() == 1 &&
120+
params->GetString(0, &browser_message)) {
121+
DevToolsManager::GetInstance()->DispatchOnInspectorBackend(
122+
this, browser_message);
123+
// handle inspectedURLChanged
124+
} else if (method == "inspectedURLChanged" &&
125+
params->GetSize() == 1 &&
126+
params->GetString(0, &url)) {
127+
InspectedURLChanged(url);
128+
// ignore others
129+
} else {
118130
return;
119131
}
120-
dict->GetInteger("id", &id);
121-
122-
DevToolsManager::GetInstance()->DispatchOnInspectorBackend(
123-
this, browser_message);
124132

133+
dict->GetInteger("id", &id);
134+
125135
if (id) {
126136
std::string code = "InspectorFrontendAPI.embedderMessageAck(" +
127137
base::IntToString(id) + ",\"\");";
@@ -130,6 +140,14 @@ void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(
130140
}
131141
}
132142

143+
void ShellDevToolsFrontend::InspectedURLChanged(const std::string& url) {
144+
std::string title = base::StringPrintf("Developer Tools - %s", url.c_str());
145+
base::ReplaceChars(title, "\\", "\\\\", &title);
146+
base::ReplaceChars(title, "\"", "\\\"", &title);
147+
base::string16 javascript = base::UTF8ToUTF16(base::StringPrintf("document.title = \"%s\"", title.c_str()));
148+
web_contents()->GetMainFrame()->ExecuteJavaScript(javascript);
149+
}
150+
133151
void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontendToBackend(
134152
const std::string& message) {
135153
DevToolsManager::GetInstance()->DispatchOnInspectorBackend(

src/shell_devtools_frontend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class ShellDevToolsFrontend : public WebContentsObserver,
5151
virtual void InspectedContentsClosing() OVERRIDE;
5252
virtual void ReplacedWithAnotherClient() OVERRIDE {}
5353

54+
virtual void InspectedURLChanged(const std::string& url);
55+
5456
Shell* frontend_shell_;
5557
scoped_refptr<DevToolsAgentHost> agent_host_;
5658
scoped_ptr<DevToolsFrontendHost> frontend_host_;

0 commit comments

Comments
 (0)