Skip to content

Commit

Permalink
Merge pull request #3301 from ghostoy/fix-devtools-nw12
Browse files Browse the repository at this point in the history
Fixed devtools issue for nw12
  • Loading branch information
rogerwang committed Feb 19, 2016
2 parents ad9396f + 78bbb2c commit d93ac65
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/nw_shell.cc
Expand Up @@ -450,13 +450,12 @@ void Shell::ShowDevTools(const char* jail_id, bool headless) {

DevToolsHttpHandler* http_handler =
browser_client->shell_browser_main_parts()->devtools_handler();
GURL url = http_handler->GetFrontendURL(agent.get());
GURL url = http_handler->GetFrontendURL("/devtools/devtools.html");
http_handler->EnumerateTargets();

#if 0
if (headless) {
DevToolsAgentHost* agent_host = DevToolsAgentHost::GetOrCreateFor(web_contents()).get();

url = delegate->devtools_http_handler()->GetFrontendURL(agent_host);
DevToolsHttpHandlerImpl* http_handler = static_cast<DevToolsHttpHandlerImpl*>(delegate->devtools_http_handler());
http_handler->EnumerateTargets();
Expand Down Expand Up @@ -485,7 +484,7 @@ void Shell::ShowDevTools(const char* jail_id, bool headless) {

new ShellDevToolsFrontend(
shell,
DevToolsAgentHost::GetOrCreateFor(web_contents_.get()).get());
agent.get());

int rh_id = shell->web_contents_->GetRenderProcessHost()->GetID();
ChildProcessSecurityPolicyImpl::GetInstance()->GrantScheme(rh_id, url::kFileScheme);
Expand Down
37 changes: 25 additions & 12 deletions src/shell_devtools_frontend.cc
Expand Up @@ -26,6 +26,10 @@

namespace content {

// This constant should be in sync with
// the constant at devtools_ui_bindings.cc.
const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4;

#if 0
// static
ShellDevToolsFrontend* ShellDevToolsFrontend::Show(
Expand Down Expand Up @@ -70,17 +74,16 @@ ShellDevToolsFrontend::~ShellDevToolsFrontend() {

void ShellDevToolsFrontend::RenderViewCreated(
RenderViewHost* render_view_host) {
#if 0
if (!frontend_host_) {
frontend_host_.reset(DevToolsFrontendHost::Create(render_view_host, this));
DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
agent_host_.get(), this);
frontend_host_.reset(
DevToolsFrontendHost::Create(web_contents()->GetMainFrame(), this));
agent_host_->AttachClient(this);
}
#endif
}

void ShellDevToolsFrontend::WebContentsDestroyed() {
agent_host_->DetachClient();
if (agent_host_)
agent_host_->DetachClient();
delete this;
}

Expand Down Expand Up @@ -128,12 +131,22 @@ void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontendToBackend(

void ShellDevToolsFrontend::DispatchProtocolMessage(
DevToolsAgentHost* agent_host, const std::string& message) {
base::StringValue message_value(message);
std::string param;
base::JSONWriter::Write(&message_value, &param);
std::string code = "DevToolsAPI.dispatchMessage(" + param + ");";
base::string16 javascript = base::UTF8ToUTF16(code);
web_contents()->GetMainFrame()->ExecuteJavaScript(javascript);
if (message.length() < kMaxMessageChunkSize) {
base::string16 javascript = base::UTF8ToUTF16(
"DevToolsAPI.dispatchMessage(" + message + ");");
web_contents()->GetMainFrame()->ExecuteJavaScript(javascript);
return;
}

base::FundamentalValue total_size(static_cast<int>(message.length()));
for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) {
base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize));
std::string param;
base::JSONWriter::Write(&message_value, &param);
std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + ");";
base::string16 javascript = base::UTF8ToUTF16(code);
web_contents()->GetMainFrame()->ExecuteJavaScript(javascript);
}
}

void ShellDevToolsFrontend::AgentHostClosed(
Expand Down

0 comments on commit d93ac65

Please sign in to comment.