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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 DevToolsUIBindings::FrontendWebContentsObserver:: | 251 DevToolsUIBindings::FrontendWebContentsObserver:: |
252 ~FrontendWebContentsObserver() { | 252 ~FrontendWebContentsObserver() { |
253 } | 253 } |
254 | 254 |
255 void DevToolsUIBindings::FrontendWebContentsObserver::RenderProcessGone( | 255 void DevToolsUIBindings::FrontendWebContentsObserver::RenderProcessGone( |
256 base::TerminationStatus status) { | 256 base::TerminationStatus status) { |
257 switch (status) { | 257 switch (status) { |
258 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 258 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
259 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 259 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
260 case base::TERMINATION_STATUS_PROCESS_CRASHED: | 260 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
261 if (devtools_bindings_->agent_host_) | 261 if (devtools_bindings_->agent_host_.get()) |
262 devtools_bindings_->Detach(); | 262 devtools_bindings_->Detach(); |
263 break; | 263 break; |
264 default: | 264 default: |
265 break; | 265 break; |
266 } | 266 } |
267 devtools_bindings_->delegate_->RenderProcessGone(); | 267 devtools_bindings_->delegate_->RenderProcessGone(); |
268 } | 268 } |
269 | 269 |
270 void DevToolsUIBindings::FrontendWebContentsObserver::AboutToNavigateRenderView( | 270 void DevToolsUIBindings::FrontendWebContentsObserver::AboutToNavigateRenderView( |
271 content::RenderViewHost* render_view_host) { | 271 content::RenderViewHost* render_view_host) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 347 |
348 embedder_message_dispatcher_.reset( | 348 embedder_message_dispatcher_.reset( |
349 DevToolsEmbedderMessageDispatcher::createForDevToolsFrontend(this)); | 349 DevToolsEmbedderMessageDispatcher::createForDevToolsFrontend(this)); |
350 | 350 |
351 frontend_host_.reset( | 351 frontend_host_.reset( |
352 content::DevToolsFrontendHost::Create( | 352 content::DevToolsFrontendHost::Create( |
353 web_contents_->GetRenderViewHost(), this)); | 353 web_contents_->GetRenderViewHost(), this)); |
354 } | 354 } |
355 | 355 |
356 DevToolsUIBindings::~DevToolsUIBindings() { | 356 DevToolsUIBindings::~DevToolsUIBindings() { |
357 if (agent_host_) | 357 if (agent_host_.get()) |
358 agent_host_->DetachClient(); | 358 agent_host_->DetachClient(); |
359 | 359 |
360 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); | 360 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); |
361 jobs_it != indexing_jobs_.end(); ++jobs_it) { | 361 jobs_it != indexing_jobs_.end(); ++jobs_it) { |
362 jobs_it->second->Stop(); | 362 jobs_it->second->Stop(); |
363 } | 363 } |
364 indexing_jobs_.clear(); | 364 indexing_jobs_.clear(); |
365 SetDeviceCountUpdatesEnabled(false); | 365 SetDeviceCountUpdatesEnabled(false); |
366 SetDevicesUpdatesEnabled(false); | 366 SetDevicesUpdatesEnabled(false); |
367 | 367 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 if (id) { | 407 if (id) { |
408 base::FundamentalValue id_value(id); | 408 base::FundamentalValue id_value(id); |
409 base::StringValue error_value(error); | 409 base::StringValue error_value(error); |
410 CallClientFunction("InspectorFrontendAPI.embedderMessageAck", | 410 CallClientFunction("InspectorFrontendAPI.embedderMessageAck", |
411 &id_value, &error_value, NULL); | 411 &id_value, &error_value, NULL); |
412 } | 412 } |
413 } | 413 } |
414 | 414 |
415 void DevToolsUIBindings::HandleMessageFromDevToolsFrontendToBackend( | 415 void DevToolsUIBindings::HandleMessageFromDevToolsFrontendToBackend( |
416 const std::string& message) { | 416 const std::string& message) { |
417 if (agent_host_) | 417 if (agent_host_.get()) |
418 agent_host_->DispatchProtocolMessage(message); | 418 agent_host_->DispatchProtocolMessage(message); |
419 } | 419 } |
420 | 420 |
421 // content::DevToolsAgentHostClient implementation -------------------------- | 421 // content::DevToolsAgentHostClient implementation -------------------------- |
422 void DevToolsUIBindings::DispatchProtocolMessage( | 422 void DevToolsUIBindings::DispatchProtocolMessage( |
423 content::DevToolsAgentHost* agent_host, const std::string& message) { | 423 content::DevToolsAgentHost* agent_host, const std::string& message) { |
424 DCHECK(agent_host == agent_host_.get()); | 424 DCHECK(agent_host == agent_host_.get()); |
425 base::StringValue message_value(message); | 425 base::StringValue message_value(message); |
426 CallClientFunction("InspectorFrontendAPI.dispatchMessage", | 426 CallClientFunction("InspectorFrontendAPI.dispatchMessage", |
427 &message_value, NULL, NULL); | 427 &message_value, NULL, NULL); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb( | 631 remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb( |
632 base::Bind(&DevToolsUIBindings::DevicesUpdated, | 632 base::Bind(&DevToolsUIBindings::DevicesUpdated, |
633 base::Unretained(this)), | 633 base::Unretained(this)), |
634 profile_); | 634 profile_); |
635 } else { | 635 } else { |
636 remote_targets_handler_.reset(); | 636 remote_targets_handler_.reset(); |
637 } | 637 } |
638 } | 638 } |
639 | 639 |
640 void DevToolsUIBindings::SendMessageToBrowser(const std::string& message) { | 640 void DevToolsUIBindings::SendMessageToBrowser(const std::string& message) { |
641 if (agent_host_) | 641 if (agent_host_.get()) |
642 agent_host_->DispatchProtocolMessage(message); | 642 agent_host_->DispatchProtocolMessage(message); |
643 } | 643 } |
644 | 644 |
645 void DevToolsUIBindings::DeviceCountChanged(int count) { | 645 void DevToolsUIBindings::DeviceCountChanged(int count) { |
646 base::FundamentalValue value(count); | 646 base::FundamentalValue value(count); |
647 CallClientFunction("InspectorFrontendAPI.deviceCountUpdated", &value, NULL, | 647 CallClientFunction("InspectorFrontendAPI.deviceCountUpdated", &value, NULL, |
648 NULL); | 648 NULL); |
649 } | 649 } |
650 | 650 |
651 void DevToolsUIBindings::DevicesUpdated( | 651 void DevToolsUIBindings::DevicesUpdated( |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 results.Append(extension_info); | 787 results.Append(extension_info); |
788 } | 788 } |
789 CallClientFunction("WebInspector.addExtensions", &results, NULL, NULL); | 789 CallClientFunction("WebInspector.addExtensions", &results, NULL, NULL); |
790 } | 790 } |
791 | 791 |
792 void DevToolsUIBindings::SetDelegate(Delegate* delegate) { | 792 void DevToolsUIBindings::SetDelegate(Delegate* delegate) { |
793 delegate_.reset(delegate); | 793 delegate_.reset(delegate); |
794 } | 794 } |
795 | 795 |
796 void DevToolsUIBindings::AttachTo(content::DevToolsAgentHost* agent_host) { | 796 void DevToolsUIBindings::AttachTo(content::DevToolsAgentHost* agent_host) { |
797 if (agent_host_) | 797 if (agent_host_.get()) |
798 Detach(); | 798 Detach(); |
799 agent_host_ = agent_host; | 799 agent_host_ = agent_host; |
800 agent_host_->AttachClient(this); | 800 agent_host_->AttachClient(this); |
801 } | 801 } |
802 | 802 |
803 void DevToolsUIBindings::Reattach() { | 803 void DevToolsUIBindings::Reattach() { |
804 DCHECK(agent_host_); | 804 DCHECK(agent_host_.get()); |
805 agent_host_->DetachClient(); | 805 agent_host_->DetachClient(); |
806 agent_host_->AttachClient(this); | 806 agent_host_->AttachClient(this); |
807 } | 807 } |
808 | 808 |
809 void DevToolsUIBindings::Detach() { | 809 void DevToolsUIBindings::Detach() { |
810 if (agent_host_) | 810 if (agent_host_.get()) |
811 agent_host_->DetachClient(); | 811 agent_host_->DetachClient(); |
812 agent_host_ = NULL; | 812 agent_host_ = NULL; |
813 } | 813 } |
814 | 814 |
815 bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) { | 815 bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) { |
816 return agent_host_ == agent_host; | 816 return agent_host_.get() == agent_host; |
817 } | 817 } |
818 | 818 |
819 void DevToolsUIBindings::CallClientFunction(const std::string& function_name, | 819 void DevToolsUIBindings::CallClientFunction(const std::string& function_name, |
820 const base::Value* arg1, | 820 const base::Value* arg1, |
821 const base::Value* arg2, | 821 const base::Value* arg2, |
822 const base::Value* arg3) { | 822 const base::Value* arg3) { |
823 std::string params; | 823 std::string params; |
824 if (arg1) { | 824 if (arg1) { |
825 std::string json; | 825 std::string json; |
826 base::JSONWriter::Write(arg1, &json); | 826 base::JSONWriter::Write(arg1, &json); |
(...skipping 13 matching lines...) Expand all Loading... |
840 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); | 840 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); |
841 } | 841 } |
842 | 842 |
843 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { | 843 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { |
844 // Call delegate first - it seeds importants bit of information. | 844 // Call delegate first - it seeds importants bit of information. |
845 delegate_->OnLoadCompleted(); | 845 delegate_->OnLoadCompleted(); |
846 | 846 |
847 UpdateTheme(); | 847 UpdateTheme(); |
848 AddDevToolsExtensionsToClient(); | 848 AddDevToolsExtensionsToClient(); |
849 } | 849 } |
OLD | NEW |