summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui/html_dialog_controller.cc
blob: a4642ced63f8ccdf06edb7e12c8b7da3254eccd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/html_dialog_controller.h"

#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"

HtmlDialogController::HtmlDialogController(HtmlDialogUIDelegate* delegate,
                                           Profile* profile,
                                           Browser* browser)
      : dialog_delegate_(delegate) {
  // It's only safe to show an off the record profile if we have a browser which
  // has this profile to maintain its existence.
  DCHECK(!profile->IsOffTheRecord() || (browser &&
                                        browser->profile() == profile));
  // If we're passed a browser it should own the profile we're using.
  DCHECK(!browser || browser->profile() == profile);
  if (browser) {
    registrar_.Add(this,
                   chrome::NOTIFICATION_BROWSER_CLOSING,
                   content::Source<Browser>(browser));
  }
}

// content::NotificationObserver implementation:
void HtmlDialogController::Observe(
    int type,
    const content::NotificationSource& source,
    const content::NotificationDetails& details) {
  DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSING);

  // If the browser creating this dialog is closed, close the dialog to prevent
  // using potentially destroyed profiles.
  dialog_delegate_->OnDialogClosed(std::string());
}