Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: chrome/browser/devtools/devtools_ui_bindings.cc

Issue 449043002: [DevTools] Make DevTools clients talk directly to DevToolsAgentHost instead of using DevToolsManage… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 void DevToolsUIBindings::FrontendWebContentsObserver::WebContentsDestroyed() { 254 void DevToolsUIBindings::FrontendWebContentsObserver::WebContentsDestroyed() {
257 delete devtools_bindings_; 255 delete devtools_bindings_;
258 } 256 }
259 257
260 void DevToolsUIBindings::FrontendWebContentsObserver::RenderProcessGone( 258 void DevToolsUIBindings::FrontendWebContentsObserver::RenderProcessGone(
261 base::TerminationStatus status) { 259 base::TerminationStatus status) {
262 switch (status) { 260 switch (status) {
263 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: 261 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
264 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: 262 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
265 case base::TERMINATION_STATUS_PROCESS_CRASHED: 263 case base::TERMINATION_STATUS_PROCESS_CRASHED:
266 content::DevToolsManager::GetInstance()->ClientHostClosing( 264 if (devtools_bindings_->agent_host_)
267 devtools_bindings_); 265 devtools_bindings_->agent_host_->DetachClient();
268 break; 266 break;
269 default: 267 default:
270 break; 268 break;
271 } 269 }
272 devtools_bindings_->delegate_->RenderProcessGone(); 270 devtools_bindings_->delegate_->RenderProcessGone();
273 } 271 }
274 272
275 void DevToolsUIBindings::FrontendWebContentsObserver::AboutToNavigateRenderView( 273 void DevToolsUIBindings::FrontendWebContentsObserver::AboutToNavigateRenderView(
276 content::RenderViewHost* render_view_host) { 274 content::RenderViewHost* render_view_host) {
277 content::NavigationEntry* entry = 275 content::NavigationEntry* entry =
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 registrar_.Add( 344 registrar_.Add(
347 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 345 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
348 content::Source<ThemeService>( 346 content::Source<ThemeService>(
349 ThemeServiceFactory::GetForProfile(profile_))); 347 ThemeServiceFactory::GetForProfile(profile_)));
350 348
351 embedder_message_dispatcher_.reset( 349 embedder_message_dispatcher_.reset(
352 DevToolsEmbedderMessageDispatcher::createForDevToolsFrontend(this)); 350 DevToolsEmbedderMessageDispatcher::createForDevToolsFrontend(this));
353 } 351 }
354 352
355 DevToolsUIBindings::~DevToolsUIBindings() { 353 DevToolsUIBindings::~DevToolsUIBindings() {
356 content::DevToolsManager::GetInstance()->ClientHostClosing(this); 354 if (agent_host_)
355 agent_host_->DetachClient();
357 356
358 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); 357 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin());
359 jobs_it != indexing_jobs_.end(); ++jobs_it) { 358 jobs_it != indexing_jobs_.end(); ++jobs_it) {
360 jobs_it->second->Stop(); 359 jobs_it->second->Stop();
361 } 360 }
362 indexing_jobs_.clear(); 361 indexing_jobs_.clear();
363 SetDeviceCountUpdatesEnabled(false); 362 SetDeviceCountUpdatesEnabled(false);
364 SetDevicesUpdatesEnabled(false); 363 SetDevicesUpdatesEnabled(false);
365 } 364 }
366 365
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 if (id) { 397 if (id) {
399 base::FundamentalValue id_value(id); 398 base::FundamentalValue id_value(id);
400 base::StringValue error_value(error); 399 base::StringValue error_value(error);
401 CallClientFunction("InspectorFrontendAPI.embedderMessageAck", 400 CallClientFunction("InspectorFrontendAPI.embedderMessageAck",
402 &id_value, &error_value, NULL); 401 &id_value, &error_value, NULL);
403 } 402 }
404 } 403 }
405 404
406 void DevToolsUIBindings::HandleMessageFromDevToolsFrontendToBackend( 405 void DevToolsUIBindings::HandleMessageFromDevToolsFrontendToBackend(
407 const std::string& message) { 406 const std::string& message) {
408 content::DevToolsManager::GetInstance()->DispatchOnInspectorBackend( 407 if (agent_host_)
409 this, message); 408 agent_host_->DispatchOnInspectorBackend(message);
410 } 409 }
411 410
412 // content::DevToolsClientHost implementation --------------------------------- 411 // content::DevToolsAgentHost::Client implementation --------------------------
413 void DevToolsUIBindings::DispatchOnInspectorFrontend( 412 void DevToolsUIBindings::SendMessageFromAgentHost(
414 const std::string& message) { 413 content::DevToolsAgentHost* agent_host, const std::string& message) {
414 DCHECK(agent_host == agent_host_.get());
415 base::StringValue message_value(message); 415 base::StringValue message_value(message);
416 CallClientFunction("InspectorFrontendAPI.dispatchMessage", 416 CallClientFunction("InspectorFrontendAPI.dispatchMessage",
417 &message_value, NULL, NULL); 417 &message_value, NULL, NULL);
418 } 418 }
419 419
420 void DevToolsUIBindings::InspectedContentsClosing() { 420 void DevToolsUIBindings::AgentHostDetached(
421 delegate_->InspectedContentsClosing(); 421 content::DevToolsAgentHost* agent_host,
422 } 422 content::DevToolsAgentHost::DetachReason reason) {
423 423 DCHECK(agent_host == agent_host_.get());
424 void DevToolsUIBindings::ReplacedWithAnotherClient() { 424 if (reason != content::DevToolsAgentHost::DETACHED_BY_CLIENT)
425 delegate_->InspectedContentsClosing();
425 } 426 }
426 427
427 // DevToolsEmbedderMessageDispatcher::Delegate implementation ----------------- 428 // DevToolsEmbedderMessageDispatcher::Delegate implementation -----------------
428 void DevToolsUIBindings::ActivateWindow() { 429 void DevToolsUIBindings::ActivateWindow() {
429 delegate_->ActivateWindow(); 430 delegate_->ActivateWindow();
430 } 431 }
431 432
432 void DevToolsUIBindings::CloseWindow() { 433 void DevToolsUIBindings::CloseWindow() {
433 delegate_->CloseWindow(); 434 delegate_->CloseWindow();
434 } 435 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb( 626 remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb(
626 base::Bind(&DevToolsUIBindings::DevicesUpdated, 627 base::Bind(&DevToolsUIBindings::DevicesUpdated,
627 base::Unretained(this)), 628 base::Unretained(this)),
628 profile_); 629 profile_);
629 } else { 630 } else {
630 remote_targets_handler_.reset(); 631 remote_targets_handler_.reset();
631 } 632 }
632 } 633 }
633 634
634 void DevToolsUIBindings::SendMessageToBrowser(const std::string& message) { 635 void DevToolsUIBindings::SendMessageToBrowser(const std::string& message) {
635 content::DevToolsManager::GetInstance()->DispatchOnInspectorBackend( 636 if (agent_host_)
636 this, message); 637 agent_host_->DispatchOnInspectorBackend(message);
637 } 638 }
638 639
639 void DevToolsUIBindings::DeviceCountChanged(int count) { 640 void DevToolsUIBindings::DeviceCountChanged(int count) {
640 base::FundamentalValue value(count); 641 base::FundamentalValue value(count);
641 CallClientFunction("InspectorFrontendAPI.deviceCountUpdated", &value, NULL, 642 CallClientFunction("InspectorFrontendAPI.deviceCountUpdated", &value, NULL,
642 NULL); 643 NULL);
643 } 644 }
644 645
645 void DevToolsUIBindings::DevicesUpdated( 646 void DevToolsUIBindings::DevicesUpdated(
646 const std::string& source, 647 const std::string& source,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 extensions::APIPermission::kExperimental))); 781 extensions::APIPermission::kExperimental)));
781 results.Append(extension_info); 782 results.Append(extension_info);
782 } 783 }
783 CallClientFunction("WebInspector.addExtensions", &results, NULL, NULL); 784 CallClientFunction("WebInspector.addExtensions", &results, NULL, NULL);
784 } 785 }
785 786
786 void DevToolsUIBindings::SetDelegate(Delegate* delegate) { 787 void DevToolsUIBindings::SetDelegate(Delegate* delegate) {
787 delegate_.reset(delegate); 788 delegate_.reset(delegate);
788 } 789 }
789 790
791 void DevToolsUIBindings::InspectAgentHost(
792 content::DevToolsAgentHost* agent_host) {
793 if (agent_host_)
794 agent_host_->DetachClient();
795 agent_host_ = agent_host;
796 if (agent_host_)
797 agent_host_->AttachClient(this);
798 }
799
790 void DevToolsUIBindings::CallClientFunction(const std::string& function_name, 800 void DevToolsUIBindings::CallClientFunction(const std::string& function_name,
791 const base::Value* arg1, 801 const base::Value* arg1,
792 const base::Value* arg2, 802 const base::Value* arg2,
793 const base::Value* arg3) { 803 const base::Value* arg3) {
794 std::string params; 804 std::string params;
795 if (arg1) { 805 if (arg1) {
796 std::string json; 806 std::string json;
797 base::JSONWriter::Write(arg1, &json); 807 base::JSONWriter::Write(arg1, &json);
798 params.append(json); 808 params.append(json);
799 if (arg2) { 809 if (arg2) {
(...skipping 11 matching lines...) Expand all
811 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); 821 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript);
812 } 822 }
813 823
814 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { 824 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() {
815 // Call delegate first - it seeds importants bit of information. 825 // Call delegate first - it seeds importants bit of information.
816 delegate_->OnLoadCompleted(); 826 delegate_->OnLoadCompleted();
817 827
818 UpdateTheme(); 828 UpdateTheme();
819 AddDevToolsExtensionsToClient(); 829 AddDevToolsExtensionsToClient();
820 } 830 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698