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