OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/inspect_ui.h" | 5 #include "chrome/browser/ui/webui/inspect_ui.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 | 363 |
364 InspectUI* discovery_ui_; | 364 InspectUI* discovery_ui_; |
365 }; | 365 }; |
366 | 366 |
367 InspectUI::InspectUI(content::WebUI* web_ui) | 367 InspectUI::InspectUI(content::WebUI* web_ui) |
368 : WebUIController(web_ui), | 368 : WebUIController(web_ui), |
369 observer_(new WorkerCreationDestructionListener()), | 369 observer_(new WorkerCreationDestructionListener()), |
370 weak_factory_(this) { | 370 weak_factory_(this) { |
371 observer_->Init(this); | 371 observer_->Init(this); |
372 Profile* profile = Profile::FromWebUI(web_ui); | 372 Profile* profile = Profile::FromWebUI(web_ui); |
373 adb_bridge_.reset(new DevToolsAdbBridge(profile)); | 373 adb_bridge_ = DevToolsAdbBridge::Factory::GetForProfile(profile); |
374 web_ui->AddMessageHandler(new InspectMessageHandler(adb_bridge_.get())); | 374 web_ui->AddMessageHandler(new InspectMessageHandler(adb_bridge_)); |
375 content::WebUIDataSource::Add(profile, CreateInspectUIHTMLSource()); | 375 content::WebUIDataSource::Add(profile, CreateInspectUIHTMLSource()); |
376 | 376 |
377 registrar_.Add(this, | 377 registrar_.Add(this, |
378 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 378 content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
379 content::NotificationService::AllSources()); | 379 content::NotificationService::AllSources()); |
380 registrar_.Add(this, | 380 registrar_.Add(this, |
381 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 381 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
382 content::NotificationService::AllSources()); | 382 content::NotificationService::AllSources()); |
383 registrar_.Add(this, | 383 registrar_.Add(this, |
384 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 384 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
(...skipping 24 matching lines...) Expand all Loading... |
409 if (source != content::Source<WebContents>(web_ui()->GetWebContents())) | 409 if (source != content::Source<WebContents>(web_ui()->GetWebContents())) |
410 RefreshUI(); | 410 RefreshUI(); |
411 else if (type == content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED) | 411 else if (type == content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED) |
412 StopListeningNotifications(); | 412 StopListeningNotifications(); |
413 } | 413 } |
414 | 414 |
415 void InspectUI::StopListeningNotifications() | 415 void InspectUI::StopListeningNotifications() |
416 { | 416 { |
417 if (!observer_.get()) | 417 if (!observer_.get()) |
418 return; | 418 return; |
419 adb_bridge_.reset(); | 419 adb_bridge_ = NULL; |
420 observer_->InspectUIDestroyed(); | 420 observer_->InspectUIDestroyed(); |
421 observer_ = NULL; | 421 observer_ = NULL; |
422 registrar_.RemoveAll(); | 422 registrar_.RemoveAll(); |
423 } | 423 } |
424 | 424 |
425 content::WebUIDataSource* InspectUI::CreateInspectUIHTMLSource() { | 425 content::WebUIDataSource* InspectUI::CreateInspectUIHTMLSource() { |
426 content::WebUIDataSource* source = | 426 content::WebUIDataSource* source = |
427 content::WebUIDataSource::Create(chrome::kChromeUIInspectHost); | 427 content::WebUIDataSource::Create(chrome::kChromeUIInspectHost); |
428 source->AddResourcePath("inspect.css", IDR_INSPECT_CSS); | 428 source->AddResourcePath("inspect.css", IDR_INSPECT_CSS); |
429 source->AddResourcePath("inspect.js", IDR_INSPECT_JS); | 429 source->AddResourcePath("inspect.js", IDR_INSPECT_JS); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 target_data->SetString(kAdbSocketField, page->socket()); | 472 target_data->SetString(kAdbSocketField, page->socket()); |
473 target_data->SetString(kAdbDebugUrlField, page->debug_url()); | 473 target_data->SetString(kAdbDebugUrlField, page->debug_url()); |
474 target_data->SetString(kAdbFrontendUrlField, page->frontend_url()); | 474 target_data->SetString(kAdbFrontendUrlField, page->frontend_url()); |
475 targets.Append(target_data); | 475 targets.Append(target_data); |
476 } | 476 } |
477 | 477 |
478 std::string json_string; | 478 std::string json_string; |
479 base::JSONWriter::Write(&targets, &json_string); | 479 base::JSONWriter::Write(&targets, &json_string); |
480 callback.Run(base::RefCountedString::TakeString(&json_string)); | 480 callback.Run(base::RefCountedString::TakeString(&json_string)); |
481 } | 481 } |
OLD | NEW |