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 <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 web_contents_->GetMainFrame(), | 415 web_contents_->GetMainFrame(), |
416 base::Bind(&DevToolsUIBindings::HandleMessageFromDevToolsFrontend, | 416 base::Bind(&DevToolsUIBindings::HandleMessageFromDevToolsFrontend, |
417 base::Unretained(this)))); | 417 base::Unretained(this)))); |
418 } | 418 } |
419 | 419 |
420 DevToolsUIBindings::~DevToolsUIBindings() { | 420 DevToolsUIBindings::~DevToolsUIBindings() { |
421 for (const auto& pair : pending_requests_) | 421 for (const auto& pair : pending_requests_) |
422 delete pair.first; | 422 delete pair.first; |
423 | 423 |
424 if (agent_host_.get()) | 424 if (agent_host_.get()) |
425 agent_host_->DetachClient(); | 425 agent_host_->DetachClient(this); |
426 | 426 |
427 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); | 427 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); |
428 jobs_it != indexing_jobs_.end(); ++jobs_it) { | 428 jobs_it != indexing_jobs_.end(); ++jobs_it) { |
429 jobs_it->second->Stop(); | 429 jobs_it->second->Stop(); |
430 } | 430 } |
431 indexing_jobs_.clear(); | 431 indexing_jobs_.clear(); |
432 SetDevicesUpdatesEnabled(false); | 432 SetDevicesUpdatesEnabled(false); |
433 | 433 |
434 // Remove self from global list. | 434 // Remove self from global list. |
435 DevToolsUIBindingsList* instances = g_instances.Pointer(); | 435 DevToolsUIBindingsList* instances = g_instances.Pointer(); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 update.Get()->Clear(); | 804 update.Get()->Clear(); |
805 } | 805 } |
806 | 806 |
807 void DevToolsUIBindings::ReadyForTest() { | 807 void DevToolsUIBindings::ReadyForTest() { |
808 delegate_->ReadyForTest(); | 808 delegate_->ReadyForTest(); |
809 } | 809 } |
810 | 810 |
811 void DevToolsUIBindings::DispatchProtocolMessageFromDevToolsFrontend( | 811 void DevToolsUIBindings::DispatchProtocolMessageFromDevToolsFrontend( |
812 const std::string& message) { | 812 const std::string& message) { |
813 if (agent_host_.get()) | 813 if (agent_host_.get()) |
814 agent_host_->DispatchProtocolMessage(message); | 814 agent_host_->DispatchProtocolMessage(this, message); |
815 } | 815 } |
816 | 816 |
817 void DevToolsUIBindings::RecordEnumeratedHistogram(const std::string& name, | 817 void DevToolsUIBindings::RecordEnumeratedHistogram(const std::string& name, |
818 int sample, | 818 int sample, |
819 int boundary_value) { | 819 int boundary_value) { |
820 if (!(boundary_value >= 0 && boundary_value <= 100 && sample >= 0 && | 820 if (!(boundary_value >= 0 && boundary_value <= 100 && sample >= 0 && |
821 sample < boundary_value)) { | 821 sample < boundary_value)) { |
822 // TODO(nick): Replace with chrome::bad_message::ReceivedBadMessage(). | 822 // TODO(nick): Replace with chrome::bad_message::ReceivedBadMessage(). |
823 frontend_host_->BadMessageRecieved(); | 823 frontend_host_->BadMessageRecieved(); |
824 return; | 824 return; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 | 1025 |
1026 void DevToolsUIBindings::SetDelegate(Delegate* delegate) { | 1026 void DevToolsUIBindings::SetDelegate(Delegate* delegate) { |
1027 delegate_.reset(delegate); | 1027 delegate_.reset(delegate); |
1028 } | 1028 } |
1029 | 1029 |
1030 void DevToolsUIBindings::AttachTo( | 1030 void DevToolsUIBindings::AttachTo( |
1031 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { | 1031 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { |
1032 if (agent_host_.get()) | 1032 if (agent_host_.get()) |
1033 Detach(); | 1033 Detach(); |
1034 agent_host_ = agent_host; | 1034 agent_host_ = agent_host; |
1035 agent_host_->AttachClient(this); | 1035 // DevToolsUIBindings terminates existing debugging connections and starts |
| 1036 // debugging. |
| 1037 agent_host_->ForceAttachClient(this); |
1036 } | 1038 } |
1037 | 1039 |
1038 void DevToolsUIBindings::Reattach() { | 1040 void DevToolsUIBindings::Reattach() { |
1039 DCHECK(agent_host_.get()); | 1041 DCHECK(agent_host_.get()); |
1040 reattaching_ = true; | 1042 reattaching_ = true; |
1041 } | 1043 } |
1042 | 1044 |
1043 void DevToolsUIBindings::Detach() { | 1045 void DevToolsUIBindings::Detach() { |
1044 if (agent_host_.get()) | 1046 if (agent_host_.get()) |
1045 agent_host_->DetachClient(); | 1047 agent_host_->DetachClient(this); |
1046 agent_host_ = NULL; | 1048 agent_host_ = NULL; |
1047 } | 1049 } |
1048 | 1050 |
1049 bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) { | 1051 bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) { |
1050 return agent_host_.get() == agent_host; | 1052 return agent_host_.get() == agent_host; |
1051 } | 1053 } |
1052 | 1054 |
1053 void DevToolsUIBindings::CallClientFunction(const std::string& function_name, | 1055 void DevToolsUIBindings::CallClientFunction(const std::string& function_name, |
1054 const base::Value* arg1, | 1056 const base::Value* arg1, |
1055 const base::Value* arg2, | 1057 const base::Value* arg2, |
(...skipping 14 matching lines...) Expand all Loading... |
1070 } | 1072 } |
1071 javascript.append(");"); | 1073 javascript.append(");"); |
1072 web_contents_->GetMainFrame()->ExecuteJavaScript( | 1074 web_contents_->GetMainFrame()->ExecuteJavaScript( |
1073 base::UTF8ToUTF16(javascript)); | 1075 base::UTF8ToUTF16(javascript)); |
1074 } | 1076 } |
1075 | 1077 |
1076 void DevToolsUIBindings::DocumentAvailableInMainFrame() { | 1078 void DevToolsUIBindings::DocumentAvailableInMainFrame() { |
1077 if (!reattaching_) | 1079 if (!reattaching_) |
1078 return; | 1080 return; |
1079 reattaching_ = false; | 1081 reattaching_ = false; |
1080 agent_host_->DetachClient(); | 1082 agent_host_->DetachClient(this); |
1081 agent_host_->AttachClient(this); | 1083 agent_host_->AttachClient(this); |
1082 } | 1084 } |
1083 | 1085 |
1084 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { | 1086 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { |
1085 // In the DEBUG_DEVTOOLS mode, the DocumentOnLoadCompletedInMainFrame event | 1087 // In the DEBUG_DEVTOOLS mode, the DocumentOnLoadCompletedInMainFrame event |
1086 // arrives before the LoadCompleted event, thus it should not trigger the | 1088 // arrives before the LoadCompleted event, thus it should not trigger the |
1087 // frontend load handling. | 1089 // frontend load handling. |
1088 #if !defined(DEBUG_DEVTOOLS) | 1090 #if !defined(DEBUG_DEVTOOLS) |
1089 FrontendLoaded(); | 1091 FrontendLoaded(); |
1090 #endif | 1092 #endif |
1091 } | 1093 } |
1092 | 1094 |
1093 void DevToolsUIBindings::DidNavigateMainFrame() { | 1095 void DevToolsUIBindings::DidNavigateMainFrame() { |
1094 frontend_loaded_ = false; | 1096 frontend_loaded_ = false; |
1095 } | 1097 } |
1096 | 1098 |
1097 void DevToolsUIBindings::FrontendLoaded() { | 1099 void DevToolsUIBindings::FrontendLoaded() { |
1098 if (frontend_loaded_) | 1100 if (frontend_loaded_) |
1099 return; | 1101 return; |
1100 frontend_loaded_ = true; | 1102 frontend_loaded_ = true; |
1101 | 1103 |
1102 // Call delegate first - it seeds importants bit of information. | 1104 // Call delegate first - it seeds importants bit of information. |
1103 delegate_->OnLoadCompleted(); | 1105 delegate_->OnLoadCompleted(); |
1104 | 1106 |
1105 AddDevToolsExtensionsToClient(); | 1107 AddDevToolsExtensionsToClient(); |
1106 } | 1108 } |
OLD | NEW |