| 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 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 return NULL; | 395 return NULL; |
| 396 } | 396 } |
| 397 | 397 |
| 398 DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents) | 398 DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents) |
| 399 : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 399 : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
| 400 android_bridge_(DevToolsAndroidBridge::Factory::GetForProfile(profile_)), | 400 android_bridge_(DevToolsAndroidBridge::Factory::GetForProfile(profile_)), |
| 401 web_contents_(web_contents), | 401 web_contents_(web_contents), |
| 402 delegate_(new DefaultBindingsDelegate(web_contents_)), | 402 delegate_(new DefaultBindingsDelegate(web_contents_)), |
| 403 devices_updates_enabled_(false), | 403 devices_updates_enabled_(false), |
| 404 frontend_loaded_(false), | 404 frontend_loaded_(false), |
| 405 reattaching_(false), | 405 reloading_(false), |
| 406 weak_factory_(this) { | 406 weak_factory_(this) { |
| 407 g_instances.Get().push_back(this); | 407 g_instances.Get().push_back(this); |
| 408 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 408 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |
| 409 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false; | 409 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 410 | 410 |
| 411 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_, this)); | 411 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_, this)); |
| 412 file_system_indexer_ = new DevToolsFileSystemIndexer(); | 412 file_system_indexer_ = new DevToolsFileSystemIndexer(); |
| 413 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 413 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
| 414 web_contents_); | 414 web_contents_); |
| 415 | 415 |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 prefs::kDevToolsPreferences); | 849 prefs::kDevToolsPreferences); |
| 850 update.Get()->RemoveWithoutPathExpansion(name, nullptr); | 850 update.Get()->RemoveWithoutPathExpansion(name, nullptr); |
| 851 } | 851 } |
| 852 | 852 |
| 853 void DevToolsUIBindings::ClearPreferences() { | 853 void DevToolsUIBindings::ClearPreferences() { |
| 854 DictionaryPrefUpdate update(profile_->GetPrefs(), | 854 DictionaryPrefUpdate update(profile_->GetPrefs(), |
| 855 prefs::kDevToolsPreferences); | 855 prefs::kDevToolsPreferences); |
| 856 update.Get()->Clear(); | 856 update.Get()->Clear(); |
| 857 } | 857 } |
| 858 | 858 |
| 859 void DevToolsUIBindings::Reattach(const DispatchCallback& callback) { |
| 860 DCHECK(agent_host_.get()); |
| 861 agent_host_->DetachClient(this); |
| 862 agent_host_->AttachClient(this); |
| 863 callback.Run(nullptr); |
| 864 } |
| 865 |
| 859 void DevToolsUIBindings::ReadyForTest() { | 866 void DevToolsUIBindings::ReadyForTest() { |
| 860 delegate_->ReadyForTest(); | 867 delegate_->ReadyForTest(); |
| 861 } | 868 } |
| 862 | 869 |
| 863 void DevToolsUIBindings::DispatchProtocolMessageFromDevToolsFrontend( | 870 void DevToolsUIBindings::DispatchProtocolMessageFromDevToolsFrontend( |
| 864 const std::string& message) { | 871 const std::string& message) { |
| 865 if (agent_host_.get()) | 872 if (agent_host_.get()) |
| 866 agent_host_->DispatchProtocolMessage(this, message); | 873 agent_host_->DispatchProtocolMessage(this, message); |
| 867 } | 874 } |
| 868 | 875 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 void DevToolsUIBindings::AttachTo( | 1106 void DevToolsUIBindings::AttachTo( |
| 1100 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { | 1107 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { |
| 1101 if (agent_host_.get()) | 1108 if (agent_host_.get()) |
| 1102 Detach(); | 1109 Detach(); |
| 1103 agent_host_ = agent_host; | 1110 agent_host_ = agent_host; |
| 1104 // DevToolsUIBindings terminates existing debugging connections and starts | 1111 // DevToolsUIBindings terminates existing debugging connections and starts |
| 1105 // debugging. | 1112 // debugging. |
| 1106 agent_host_->ForceAttachClient(this); | 1113 agent_host_->ForceAttachClient(this); |
| 1107 } | 1114 } |
| 1108 | 1115 |
| 1109 void DevToolsUIBindings::Reattach() { | 1116 void DevToolsUIBindings::Reload() { |
| 1110 DCHECK(agent_host_.get()); | 1117 DCHECK(agent_host_.get()); |
| 1111 reattaching_ = true; | 1118 reloading_ = true; |
| 1119 web_contents_->GetController().Reload(false); |
| 1112 } | 1120 } |
| 1113 | 1121 |
| 1114 void DevToolsUIBindings::Detach() { | 1122 void DevToolsUIBindings::Detach() { |
| 1115 if (agent_host_.get()) | 1123 if (agent_host_.get()) |
| 1116 agent_host_->DetachClient(this); | 1124 agent_host_->DetachClient(this); |
| 1117 agent_host_ = NULL; | 1125 agent_host_ = NULL; |
| 1118 } | 1126 } |
| 1119 | 1127 |
| 1120 bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) { | 1128 bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) { |
| 1121 return agent_host_.get() == agent_host; | 1129 return agent_host_.get() == agent_host; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1138 javascript.append(", ").append(json); | 1146 javascript.append(", ").append(json); |
| 1139 } | 1147 } |
| 1140 } | 1148 } |
| 1141 } | 1149 } |
| 1142 javascript.append(");"); | 1150 javascript.append(");"); |
| 1143 web_contents_->GetMainFrame()->ExecuteJavaScript( | 1151 web_contents_->GetMainFrame()->ExecuteJavaScript( |
| 1144 base::UTF8ToUTF16(javascript)); | 1152 base::UTF8ToUTF16(javascript)); |
| 1145 } | 1153 } |
| 1146 | 1154 |
| 1147 void DevToolsUIBindings::DocumentAvailableInMainFrame() { | 1155 void DevToolsUIBindings::DocumentAvailableInMainFrame() { |
| 1148 if (!reattaching_) | 1156 if (!reloading_) |
| 1149 return; | 1157 return; |
| 1150 reattaching_ = false; | 1158 reloading_ = false; |
| 1151 agent_host_->DetachClient(this); | 1159 agent_host_->DetachClient(this); |
| 1152 agent_host_->AttachClient(this); | 1160 agent_host_->AttachClient(this); |
| 1153 } | 1161 } |
| 1154 | 1162 |
| 1155 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { | 1163 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { |
| 1156 // In the DEBUG_DEVTOOLS mode, the DocumentOnLoadCompletedInMainFrame event | 1164 // In the DEBUG_DEVTOOLS mode, the DocumentOnLoadCompletedInMainFrame event |
| 1157 // arrives before the LoadCompleted event, thus it should not trigger the | 1165 // arrives before the LoadCompleted event, thus it should not trigger the |
| 1158 // frontend load handling. | 1166 // frontend load handling. |
| 1159 #if !defined(DEBUG_DEVTOOLS) | 1167 #if !defined(DEBUG_DEVTOOLS) |
| 1160 FrontendLoaded(); | 1168 FrontendLoaded(); |
| 1161 #endif | 1169 #endif |
| 1162 } | 1170 } |
| 1163 | 1171 |
| 1164 void DevToolsUIBindings::DidNavigateMainFrame() { | 1172 void DevToolsUIBindings::DidNavigateMainFrame() { |
| 1165 frontend_loaded_ = false; | 1173 frontend_loaded_ = false; |
| 1166 } | 1174 } |
| 1167 | 1175 |
| 1168 void DevToolsUIBindings::FrontendLoaded() { | 1176 void DevToolsUIBindings::FrontendLoaded() { |
| 1169 if (frontend_loaded_) | 1177 if (frontend_loaded_) |
| 1170 return; | 1178 return; |
| 1171 frontend_loaded_ = true; | 1179 frontend_loaded_ = true; |
| 1172 | 1180 |
| 1173 // Call delegate first - it seeds importants bit of information. | 1181 // Call delegate first - it seeds importants bit of information. |
| 1174 delegate_->OnLoadCompleted(); | 1182 delegate_->OnLoadCompleted(); |
| 1175 | 1183 |
| 1176 AddDevToolsExtensionsToClient(); | 1184 AddDevToolsExtensionsToClient(); |
| 1177 } | 1185 } |
| OLD | NEW |