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 14 matching lines...) Expand all Loading... |
25 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/browser_iterator.h" | 26 #include "chrome/browser/ui/browser_iterator.h" |
27 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
28 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
29 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/common/extensions/manifest_url_handler.h" | 31 #include "chrome/common/extensions/manifest_url_handler.h" |
32 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
33 #include "components/infobars/core/confirm_infobar_delegate.h" | 33 #include "components/infobars/core/confirm_infobar_delegate.h" |
34 #include "components/infobars/core/infobar.h" | 34 #include "components/infobars/core/infobar.h" |
35 #include "content/public/browser/devtools_client_host.h" | |
36 #include "content/public/browser/devtools_manager.h" | |
37 #include "content/public/browser/favicon_status.h" | 35 #include "content/public/browser/favicon_status.h" |
38 #include "content/public/browser/invalidate_type.h" | 36 #include "content/public/browser/invalidate_type.h" |
39 #include "content/public/browser/navigation_controller.h" | 37 #include "content/public/browser/navigation_controller.h" |
40 #include "content/public/browser/navigation_entry.h" | 38 #include "content/public/browser/navigation_entry.h" |
41 #include "content/public/browser/notification_source.h" | 39 #include "content/public/browser/notification_source.h" |
42 #include "content/public/browser/render_frame_host.h" | 40 #include "content/public/browser/render_frame_host.h" |
43 #include "content/public/browser/render_view_host.h" | 41 #include "content/public/browser/render_view_host.h" |
44 #include "content/public/browser/user_metrics.h" | 42 #include "content/public/browser/user_metrics.h" |
45 #include "content/public/browser/web_contents.h" | 43 #include "content/public/browser/web_contents.h" |
46 #include "content/public/browser/web_contents_observer.h" | 44 #include "content/public/browser/web_contents_observer.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 void DevToolsUIBindings::FrontendWebContentsObserver::WebContentsDestroyed() { | 252 void DevToolsUIBindings::FrontendWebContentsObserver::WebContentsDestroyed() { |
255 delete devtools_bindings_; | 253 delete devtools_bindings_; |
256 } | 254 } |
257 | 255 |
258 void DevToolsUIBindings::FrontendWebContentsObserver::RenderProcessGone( | 256 void DevToolsUIBindings::FrontendWebContentsObserver::RenderProcessGone( |
259 base::TerminationStatus status) { | 257 base::TerminationStatus status) { |
260 switch (status) { | 258 switch (status) { |
261 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 259 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
262 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 260 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
263 case base::TERMINATION_STATUS_PROCESS_CRASHED: | 261 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
264 content::DevToolsManager::GetInstance()->ClientHostClosing( | 262 if (devtools_bindings_->agent_host_) |
265 devtools_bindings_); | 263 devtools_bindings_->Detach(); |
266 break; | 264 break; |
267 default: | 265 default: |
268 break; | 266 break; |
269 } | 267 } |
270 devtools_bindings_->delegate_->RenderProcessGone(); | 268 devtools_bindings_->delegate_->RenderProcessGone(); |
271 } | 269 } |
272 | 270 |
273 void DevToolsUIBindings::FrontendWebContentsObserver::AboutToNavigateRenderView( | 271 void DevToolsUIBindings::FrontendWebContentsObserver::AboutToNavigateRenderView( |
274 content::RenderViewHost* render_view_host) { | 272 content::RenderViewHost* render_view_host) { |
275 content::NavigationEntry* entry = | 273 content::NavigationEntry* entry = |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 registrar_.Add( | 342 registrar_.Add( |
345 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 343 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
346 content::Source<ThemeService>( | 344 content::Source<ThemeService>( |
347 ThemeServiceFactory::GetForProfile(profile_))); | 345 ThemeServiceFactory::GetForProfile(profile_))); |
348 | 346 |
349 embedder_message_dispatcher_.reset( | 347 embedder_message_dispatcher_.reset( |
350 DevToolsEmbedderMessageDispatcher::createForDevToolsFrontend(this)); | 348 DevToolsEmbedderMessageDispatcher::createForDevToolsFrontend(this)); |
351 } | 349 } |
352 | 350 |
353 DevToolsUIBindings::~DevToolsUIBindings() { | 351 DevToolsUIBindings::~DevToolsUIBindings() { |
354 content::DevToolsManager::GetInstance()->ClientHostClosing(this); | 352 if (agent_host_) |
| 353 agent_host_->DetachClient(); |
355 | 354 |
356 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); | 355 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); |
357 jobs_it != indexing_jobs_.end(); ++jobs_it) { | 356 jobs_it != indexing_jobs_.end(); ++jobs_it) { |
358 jobs_it->second->Stop(); | 357 jobs_it->second->Stop(); |
359 } | 358 } |
360 indexing_jobs_.clear(); | 359 indexing_jobs_.clear(); |
361 SetDeviceCountUpdatesEnabled(false); | 360 SetDeviceCountUpdatesEnabled(false); |
362 SetDevicesUpdatesEnabled(false); | 361 SetDevicesUpdatesEnabled(false); |
363 } | 362 } |
364 | 363 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 if (id) { | 395 if (id) { |
397 base::FundamentalValue id_value(id); | 396 base::FundamentalValue id_value(id); |
398 base::StringValue error_value(error); | 397 base::StringValue error_value(error); |
399 CallClientFunction("InspectorFrontendAPI.embedderMessageAck", | 398 CallClientFunction("InspectorFrontendAPI.embedderMessageAck", |
400 &id_value, &error_value, NULL); | 399 &id_value, &error_value, NULL); |
401 } | 400 } |
402 } | 401 } |
403 | 402 |
404 void DevToolsUIBindings::HandleMessageFromDevToolsFrontendToBackend( | 403 void DevToolsUIBindings::HandleMessageFromDevToolsFrontendToBackend( |
405 const std::string& message) { | 404 const std::string& message) { |
406 content::DevToolsManager::GetInstance()->DispatchOnInspectorBackend( | 405 if (agent_host_) |
407 this, message); | 406 agent_host_->DispatchProtocolMessage(message); |
408 } | 407 } |
409 | 408 |
410 // content::DevToolsClientHost implementation --------------------------------- | 409 // content::DevToolsAgentHostClient implementation -------------------------- |
411 void DevToolsUIBindings::DispatchOnInspectorFrontend( | 410 void DevToolsUIBindings::DispatchProtocolMessage( |
412 const std::string& message) { | 411 content::DevToolsAgentHost* agent_host, const std::string& message) { |
| 412 DCHECK(agent_host == agent_host_.get()); |
413 base::StringValue message_value(message); | 413 base::StringValue message_value(message); |
414 CallClientFunction("InspectorFrontendAPI.dispatchMessage", | 414 CallClientFunction("InspectorFrontendAPI.dispatchMessage", |
415 &message_value, NULL, NULL); | 415 &message_value, NULL, NULL); |
416 } | 416 } |
417 | 417 |
418 void DevToolsUIBindings::InspectedContentsClosing() { | 418 void DevToolsUIBindings::AgentHostClosed( |
| 419 content::DevToolsAgentHost* agent_host, |
| 420 bool replaced_with_another_client) { |
| 421 DCHECK(agent_host == agent_host_.get()); |
| 422 agent_host_ = NULL; |
419 delegate_->InspectedContentsClosing(); | 423 delegate_->InspectedContentsClosing(); |
420 } | 424 } |
421 | 425 |
422 void DevToolsUIBindings::ReplacedWithAnotherClient() { | |
423 } | |
424 | |
425 // DevToolsEmbedderMessageDispatcher::Delegate implementation ----------------- | 426 // DevToolsEmbedderMessageDispatcher::Delegate implementation ----------------- |
426 void DevToolsUIBindings::ActivateWindow() { | 427 void DevToolsUIBindings::ActivateWindow() { |
427 delegate_->ActivateWindow(); | 428 delegate_->ActivateWindow(); |
428 } | 429 } |
429 | 430 |
430 void DevToolsUIBindings::CloseWindow() { | 431 void DevToolsUIBindings::CloseWindow() { |
431 delegate_->CloseWindow(); | 432 delegate_->CloseWindow(); |
432 } | 433 } |
433 | 434 |
434 void DevToolsUIBindings::SetInspectedPageBounds(const gfx::Rect& rect) { | 435 void DevToolsUIBindings::SetInspectedPageBounds(const gfx::Rect& rect) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb( | 619 remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb( |
619 base::Bind(&DevToolsUIBindings::DevicesUpdated, | 620 base::Bind(&DevToolsUIBindings::DevicesUpdated, |
620 base::Unretained(this)), | 621 base::Unretained(this)), |
621 profile_); | 622 profile_); |
622 } else { | 623 } else { |
623 remote_targets_handler_.reset(); | 624 remote_targets_handler_.reset(); |
624 } | 625 } |
625 } | 626 } |
626 | 627 |
627 void DevToolsUIBindings::SendMessageToBrowser(const std::string& message) { | 628 void DevToolsUIBindings::SendMessageToBrowser(const std::string& message) { |
628 content::DevToolsManager::GetInstance()->DispatchOnInspectorBackend( | 629 if (agent_host_) |
629 this, message); | 630 agent_host_->DispatchProtocolMessage(message); |
630 } | 631 } |
631 | 632 |
632 void DevToolsUIBindings::DeviceCountChanged(int count) { | 633 void DevToolsUIBindings::DeviceCountChanged(int count) { |
633 base::FundamentalValue value(count); | 634 base::FundamentalValue value(count); |
634 CallClientFunction("InspectorFrontendAPI.deviceCountUpdated", &value, NULL, | 635 CallClientFunction("InspectorFrontendAPI.deviceCountUpdated", &value, NULL, |
635 NULL); | 636 NULL); |
636 } | 637 } |
637 | 638 |
638 void DevToolsUIBindings::DevicesUpdated( | 639 void DevToolsUIBindings::DevicesUpdated( |
639 const std::string& source, | 640 const std::string& source, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 extensions::APIPermission::kExperimental))); | 774 extensions::APIPermission::kExperimental))); |
774 results.Append(extension_info); | 775 results.Append(extension_info); |
775 } | 776 } |
776 CallClientFunction("WebInspector.addExtensions", &results, NULL, NULL); | 777 CallClientFunction("WebInspector.addExtensions", &results, NULL, NULL); |
777 } | 778 } |
778 | 779 |
779 void DevToolsUIBindings::SetDelegate(Delegate* delegate) { | 780 void DevToolsUIBindings::SetDelegate(Delegate* delegate) { |
780 delegate_.reset(delegate); | 781 delegate_.reset(delegate); |
781 } | 782 } |
782 | 783 |
| 784 void DevToolsUIBindings::AttachTo(content::DevToolsAgentHost* agent_host) { |
| 785 DCHECK(!agent_host_); |
| 786 agent_host_ = agent_host; |
| 787 agent_host_->AttachClient(this); |
| 788 } |
| 789 |
| 790 void DevToolsUIBindings::Reattach() { |
| 791 DCHECK(agent_host_); |
| 792 agent_host_->DetachClient(); |
| 793 agent_host_->AttachClient(this); |
| 794 } |
| 795 |
| 796 void DevToolsUIBindings::Detach() { |
| 797 DCHECK(agent_host_); |
| 798 agent_host_->DetachClient(); |
| 799 agent_host_ = NULL; |
| 800 } |
| 801 |
| 802 bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) { |
| 803 return agent_host_ == agent_host; |
| 804 } |
| 805 |
783 void DevToolsUIBindings::CallClientFunction(const std::string& function_name, | 806 void DevToolsUIBindings::CallClientFunction(const std::string& function_name, |
784 const base::Value* arg1, | 807 const base::Value* arg1, |
785 const base::Value* arg2, | 808 const base::Value* arg2, |
786 const base::Value* arg3) { | 809 const base::Value* arg3) { |
787 std::string params; | 810 std::string params; |
788 if (arg1) { | 811 if (arg1) { |
789 std::string json; | 812 std::string json; |
790 base::JSONWriter::Write(arg1, &json); | 813 base::JSONWriter::Write(arg1, &json); |
791 params.append(json); | 814 params.append(json); |
792 if (arg2) { | 815 if (arg2) { |
(...skipping 11 matching lines...) Expand all Loading... |
804 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); | 827 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); |
805 } | 828 } |
806 | 829 |
807 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { | 830 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { |
808 // Call delegate first - it seeds importants bit of information. | 831 // Call delegate first - it seeds importants bit of information. |
809 delegate_->OnLoadCompleted(); | 832 delegate_->OnLoadCompleted(); |
810 | 833 |
811 UpdateTheme(); | 834 UpdateTheme(); |
812 AddDevToolsExtensionsToClient(); | 835 AddDevToolsExtensionsToClient(); |
813 } | 836 } |
OLD | NEW |