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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 content::NotificationService::AllSources()); | 390 content::NotificationService::AllSources()); |
391 registrar_.Add(this, | 391 registrar_.Add(this, |
392 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 392 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
393 content::NotificationService::AllSources()); | 393 content::NotificationService::AllSources()); |
394 registrar_.Add(this, | 394 registrar_.Add(this, |
395 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 395 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
396 content::NotificationService::AllSources()); | 396 content::NotificationService::AllSources()); |
397 } | 397 } |
398 | 398 |
399 InspectUI::~InspectUI() { | 399 InspectUI::~InspectUI() { |
400 observer_->InspectUIDestroyed(); | 400 StopListeningNotifications(); |
401 observer_ = NULL; | |
402 } | 401 } |
403 | 402 |
404 void InspectUI::RefreshUI() { | 403 void InspectUI::RefreshUI() { |
405 web_ui()->CallJavascriptFunction("populateLists"); | 404 web_ui()->CallJavascriptFunction("populateLists"); |
406 } | 405 } |
407 | 406 |
408 void InspectUI::Observe(int type, | 407 void InspectUI::Observe(int type, |
409 const content::NotificationSource& source, | 408 const content::NotificationSource& source, |
410 const content::NotificationDetails& details) { | 409 const content::NotificationDetails& details) { |
| 410 if (source == content::Source<WebContents>(web_ui()->GetWebContents())) { |
| 411 if (type == content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED) |
| 412 StopListeningNotifications(); |
| 413 return; |
| 414 } |
411 RefreshUI(); | 415 RefreshUI(); |
412 } | 416 } |
| 417 |
| 418 void InspectUI::StopListeningNotifications() |
| 419 { |
| 420 if (!observer_) |
| 421 return; |
| 422 observer_->InspectUIDestroyed(); |
| 423 observer_ = NULL; |
| 424 registrar_.RemoveAll(); |
| 425 } |
OLD | NEW |