Permalink
Browse files

Merge pull request #3301 from ghostoy/fix-devtools-nw12

Fixed devtools issue for nw12
2 parents ad9396f + 78bbb2c commit d93ac65d0f8772dd82189f2ce7367a92f3f25afd @rogerwang rogerwang committed Feb 19, 2016
Showing with 27 additions and 15 deletions.
  1. +2 −3 src/nw_shell.cc
  2. +25 −12 src/shell_devtools_frontend.cc
View
@@ -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();
@@ -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);
@@ -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(
@@ -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;
}
@@ -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(

0 comments on commit d93ac65

Please sign in to comment.