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/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 public: | 279 public: |
280 explicit FrontendWebContentsObserver(DevToolsUIBindings* ui_bindings); | 280 explicit FrontendWebContentsObserver(DevToolsUIBindings* ui_bindings); |
281 ~FrontendWebContentsObserver() override; | 281 ~FrontendWebContentsObserver() override; |
282 | 282 |
283 private: | 283 private: |
284 // contents::WebContentsObserver: | 284 // contents::WebContentsObserver: |
285 void RenderProcessGone(base::TerminationStatus status) override; | 285 void RenderProcessGone(base::TerminationStatus status) override; |
286 void DidStartNavigationToPendingEntry( | 286 void DidStartNavigationToPendingEntry( |
287 const GURL& url, | 287 const GURL& url, |
288 content::NavigationController::ReloadType reload_type) override; | 288 content::NavigationController::ReloadType reload_type) override; |
| 289 void DocumentAvailableInMainFrame() override; |
289 void DocumentOnLoadCompletedInMainFrame() override; | 290 void DocumentOnLoadCompletedInMainFrame() override; |
290 void DidNavigateMainFrame( | 291 void DidNavigateMainFrame( |
291 const content::LoadCommittedDetails& details, | 292 const content::LoadCommittedDetails& details, |
292 const content::FrameNavigateParams& params) override; | 293 const content::FrameNavigateParams& params) override; |
293 | 294 |
294 DevToolsUIBindings* devtools_bindings_; | 295 DevToolsUIBindings* devtools_bindings_; |
295 DISALLOW_COPY_AND_ASSIGN(FrontendWebContentsObserver); | 296 DISALLOW_COPY_AND_ASSIGN(FrontendWebContentsObserver); |
296 }; | 297 }; |
297 | 298 |
298 DevToolsUIBindings::FrontendWebContentsObserver::FrontendWebContentsObserver( | 299 DevToolsUIBindings::FrontendWebContentsObserver::FrontendWebContentsObserver( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 const GURL& url, | 332 const GURL& url, |
332 content::NavigationController::ReloadType reload_type) { | 333 content::NavigationController::ReloadType reload_type) { |
333 devtools_bindings_->frontend_host_.reset( | 334 devtools_bindings_->frontend_host_.reset( |
334 content::DevToolsFrontendHost::Create( | 335 content::DevToolsFrontendHost::Create( |
335 web_contents()->GetMainFrame(), | 336 web_contents()->GetMainFrame(), |
336 base::Bind(&DevToolsUIBindings::HandleMessageFromDevToolsFrontend, | 337 base::Bind(&DevToolsUIBindings::HandleMessageFromDevToolsFrontend, |
337 base::Unretained(devtools_bindings_)))); | 338 base::Unretained(devtools_bindings_)))); |
338 } | 339 } |
339 | 340 |
340 void DevToolsUIBindings::FrontendWebContentsObserver:: | 341 void DevToolsUIBindings::FrontendWebContentsObserver:: |
| 342 DocumentAvailableInMainFrame() { |
| 343 devtools_bindings_->DocumentAvailableInMainFrame(); |
| 344 } |
| 345 |
| 346 void DevToolsUIBindings::FrontendWebContentsObserver:: |
341 DocumentOnLoadCompletedInMainFrame() { | 347 DocumentOnLoadCompletedInMainFrame() { |
342 devtools_bindings_->DocumentOnLoadCompletedInMainFrame(); | 348 devtools_bindings_->DocumentOnLoadCompletedInMainFrame(); |
343 } | 349 } |
344 | 350 |
345 void DevToolsUIBindings::FrontendWebContentsObserver:: | 351 void DevToolsUIBindings::FrontendWebContentsObserver:: |
346 DidNavigateMainFrame(const content::LoadCommittedDetails& details, | 352 DidNavigateMainFrame(const content::LoadCommittedDetails& details, |
347 const content::FrameNavigateParams& params) { | 353 const content::FrameNavigateParams& params) { |
348 devtools_bindings_->DidNavigateMainFrame(); | 354 devtools_bindings_->DidNavigateMainFrame(); |
349 } | 355 } |
350 | 356 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 return NULL; | 483 return NULL; |
478 } | 484 } |
479 | 485 |
480 DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents) | 486 DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents) |
481 : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 487 : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
482 android_bridge_(DevToolsAndroidBridge::Factory::GetForProfile(profile_)), | 488 android_bridge_(DevToolsAndroidBridge::Factory::GetForProfile(profile_)), |
483 web_contents_(web_contents), | 489 web_contents_(web_contents), |
484 delegate_(new DefaultBindingsDelegate(web_contents_)), | 490 delegate_(new DefaultBindingsDelegate(web_contents_)), |
485 devices_updates_enabled_(false), | 491 devices_updates_enabled_(false), |
486 frontend_loaded_(false), | 492 frontend_loaded_(false), |
| 493 reattaching_(false), |
487 weak_factory_(this) { | 494 weak_factory_(this) { |
488 g_instances.Get().push_back(this); | 495 g_instances.Get().push_back(this); |
489 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 496 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |
490 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false; | 497 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false; |
491 | 498 |
492 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_, this)); | 499 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_, this)); |
493 file_system_indexer_ = new DevToolsFileSystemIndexer(); | 500 file_system_indexer_ = new DevToolsFileSystemIndexer(); |
494 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 501 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
495 web_contents_); | 502 web_contents_); |
496 | 503 |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 void DevToolsUIBindings::AttachTo( | 1127 void DevToolsUIBindings::AttachTo( |
1121 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { | 1128 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { |
1122 if (agent_host_.get()) | 1129 if (agent_host_.get()) |
1123 Detach(); | 1130 Detach(); |
1124 agent_host_ = agent_host; | 1131 agent_host_ = agent_host; |
1125 agent_host_->AttachClient(this); | 1132 agent_host_->AttachClient(this); |
1126 } | 1133 } |
1127 | 1134 |
1128 void DevToolsUIBindings::Reattach() { | 1135 void DevToolsUIBindings::Reattach() { |
1129 DCHECK(agent_host_.get()); | 1136 DCHECK(agent_host_.get()); |
1130 agent_host_->DetachClient(); | 1137 reattaching_ = true; |
1131 agent_host_->AttachClient(this); | |
1132 } | 1138 } |
1133 | 1139 |
1134 void DevToolsUIBindings::Detach() { | 1140 void DevToolsUIBindings::Detach() { |
1135 if (agent_host_.get()) | 1141 if (agent_host_.get()) |
1136 agent_host_->DetachClient(); | 1142 agent_host_->DetachClient(); |
1137 agent_host_ = NULL; | 1143 agent_host_ = NULL; |
1138 } | 1144 } |
1139 | 1145 |
1140 bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) { | 1146 bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) { |
1141 return agent_host_.get() == agent_host; | 1147 return agent_host_.get() == agent_host; |
(...skipping 25 matching lines...) Expand all Loading... |
1167 base::JSONWriter::Write(*arg3, &json); | 1173 base::JSONWriter::Write(*arg3, &json); |
1168 javascript.append(", ").append(json); | 1174 javascript.append(", ").append(json); |
1169 } | 1175 } |
1170 } | 1176 } |
1171 } | 1177 } |
1172 javascript.append(");"); | 1178 javascript.append(");"); |
1173 web_contents_->GetMainFrame()->ExecuteJavaScript( | 1179 web_contents_->GetMainFrame()->ExecuteJavaScript( |
1174 base::UTF8ToUTF16(javascript)); | 1180 base::UTF8ToUTF16(javascript)); |
1175 } | 1181 } |
1176 | 1182 |
| 1183 void DevToolsUIBindings::DocumentAvailableInMainFrame() { |
| 1184 if (!reattaching_) |
| 1185 return; |
| 1186 reattaching_ = false; |
| 1187 agent_host_->DetachClient(); |
| 1188 agent_host_->AttachClient(this); |
| 1189 } |
| 1190 |
1177 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { | 1191 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { |
1178 // In the DEBUG_DEVTOOLS mode, the DocumentOnLoadCompletedInMainFrame event | 1192 // In the DEBUG_DEVTOOLS mode, the DocumentOnLoadCompletedInMainFrame event |
1179 // arrives before the LoadCompleted event, thus it should not trigger the | 1193 // arrives before the LoadCompleted event, thus it should not trigger the |
1180 // frontend load handling. | 1194 // frontend load handling. |
1181 #if !defined(DEBUG_DEVTOOLS) | 1195 #if !defined(DEBUG_DEVTOOLS) |
1182 FrontendLoaded(); | 1196 FrontendLoaded(); |
1183 #endif | 1197 #endif |
1184 } | 1198 } |
1185 | 1199 |
1186 void DevToolsUIBindings::DidNavigateMainFrame() { | 1200 void DevToolsUIBindings::DidNavigateMainFrame() { |
1187 frontend_loaded_ = false; | 1201 frontend_loaded_ = false; |
1188 } | 1202 } |
1189 | 1203 |
1190 void DevToolsUIBindings::FrontendLoaded() { | 1204 void DevToolsUIBindings::FrontendLoaded() { |
1191 if (frontend_loaded_) | 1205 if (frontend_loaded_) |
1192 return; | 1206 return; |
1193 frontend_loaded_ = true; | 1207 frontend_loaded_ = true; |
1194 | 1208 |
1195 // Call delegate first - it seeds importants bit of information. | 1209 // Call delegate first - it seeds importants bit of information. |
1196 delegate_->OnLoadCompleted(); | 1210 delegate_->OnLoadCompleted(); |
1197 | 1211 |
1198 AddDevToolsExtensionsToClient(); | 1212 AddDevToolsExtensionsToClient(); |
1199 if (g_web_socket_api_channel) | 1213 if (g_web_socket_api_channel) |
1200 g_web_socket_api_channel->AttachedToBindings(this); | 1214 g_web_socket_api_channel->AttachedToBindings(this); |
1201 } | 1215 } |
OLD | NEW |