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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 | 402 |
| 403 void DevToolsUIBindings::HandleMessageFromDevToolsFrontendToBackend( | 403 void DevToolsUIBindings::HandleMessageFromDevToolsFrontendToBackend( |
| 404 const std::string& message) { | 404 const std::string& message) { |
| 405 content::DevToolsManager::GetInstance()->DispatchOnInspectorBackend( | 405 content::DevToolsManager::GetInstance()->DispatchOnInspectorBackend( |
| 406 this, message); | 406 this, message); |
| 407 } | 407 } |
| 408 | 408 |
| 409 // content::DevToolsClientHost implementation --------------------------------- | 409 // content::DevToolsClientHost implementation --------------------------------- |
| 410 void DevToolsUIBindings::DispatchOnInspectorFrontend( | 410 void DevToolsUIBindings::DispatchOnInspectorFrontend( |
| 411 const std::string& message) { | 411 const std::string& message) { |
| 412 if (frontend_host_) | 412 base::StringValue message_value(message); |
| 413 frontend_host_->DispatchOnDevToolsFrontend(message); | 413 CallClientFunction("InspectorFrontendAPI.dispatchMessage", |
| 414 &message_value, NULL, NULL); | |
| 414 } | 415 } |
| 415 | 416 |
| 416 void DevToolsUIBindings::InspectedContentsClosing() { | 417 void DevToolsUIBindings::InspectedContentsClosing() { |
| 417 delegate_->InspectedContentsClosing(); | 418 delegate_->InspectedContentsClosing(); |
| 418 } | 419 } |
| 419 | 420 |
| 420 void DevToolsUIBindings::ReplacedWithAnotherClient() { | 421 void DevToolsUIBindings::ReplacedWithAnotherClient() { |
| 421 } | 422 } |
| 422 | 423 |
| 423 // DevToolsEmbedderMessageDispatcher::Delegate implementation ----------------- | 424 // DevToolsEmbedderMessageDispatcher::Delegate implementation ----------------- |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 params.append(json); | 790 params.append(json); |
| 790 if (arg2) { | 791 if (arg2) { |
| 791 base::JSONWriter::Write(arg2, &json); | 792 base::JSONWriter::Write(arg2, &json); |
| 792 params.append(", " + json); | 793 params.append(", " + json); |
| 793 if (arg3) { | 794 if (arg3) { |
| 794 base::JSONWriter::Write(arg3, &json); | 795 base::JSONWriter::Write(arg3, &json); |
| 795 params.append(", " + json); | 796 params.append(", " + json); |
| 796 } | 797 } |
| 797 } | 798 } |
| 798 } | 799 } |
| 799 base::string16 javascript = | 800 |
| 800 base::UTF8ToUTF16(function_name + "(" + params + ");"); | 801 std::string code = function_name + "(" + params + ");"; |
| 802 #if defined(DEBUG_DEVTOOLS) | |
| 803 // To debug DevTools itself, we should postpone incoming messages while | |
| 804 // paused in debugger. To achieve this, we wrap all calls in setTimeout | |
| 805 // and rely on the fact that timers are suspended when debugging. | |
| 806 code = "(function() {" | |
| 807 " if (!window.__callClientFunction) window.__callClientFunction = [];" | |
|
pfeldman
2014/07/31 14:25:08
Should we do this on the front-end side instead?
dgozman
2014/07/31 15:09:32
Done.
| |
| 808 "" | |
| 809 " function executeCall() {" + code + "}" | |
| 810 "" | |
| 811 " function onTimeout() {" | |
| 812 " while (window.__callClientFunction.length) {" | |
| 813 " window.__callClientFunction.shift()();" | |
| 814 " }" | |
| 815 " }" | |
| 816 "" | |
| 817 " window.__callClientFunction.push(executeCall);" | |
| 818 " if (window.__callClientFunction.length == 1)" | |
| 819 " window.setTimeout(onTimeout, 0);" | |
| 820 "})();"; | |
| 821 #endif // defined(DEBUG_DEVTOOLS) | |
| 822 | |
| 823 base::string16 javascript = base::UTF8ToUTF16(code); | |
| 801 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); | 824 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); |
| 802 } | 825 } |
| 803 | 826 |
| 804 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { | 827 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { |
| 805 // Call delegate first - it seeds importants bit of information. | 828 // Call delegate first - it seeds importants bit of information. |
| 806 delegate_->OnLoadCompleted(); | 829 delegate_->OnLoadCompleted(); |
| 807 | 830 |
| 808 UpdateTheme(); | 831 UpdateTheme(); |
| 809 AddDevToolsExtensionsToClient(); | 832 AddDevToolsExtensionsToClient(); |
| 810 } | 833 } |
| OLD | NEW |