Attempt at fixing possible crash in ModalHTMLDialogDelegate. It's
possible to get more than one NOTIFY_WEB_CONTENTS_DISCONNECTED. The
first time ModalHTMLDialogDelegate gets a
NOTIFY_WEB_CONTENTS_DISCONNECTED it sets the contents_ to NULL. This
is problematic because the destructor than removes the observer using
a source of NULL. Instead we should remove the observer immediately,
then NULL out the contents_.

BUG=4129
TEST=covered by QEMU

Review URL: http://codereview.chromium.org/11413

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5575 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/modal_html_dialog_delegate.h b/chrome/browser/modal_html_dialog_delegate.h
index 25afd706..34dd0ef6 100644
--- a/chrome/browser/modal_html_dialog_delegate.h
+++ b/chrome/browser/modal_html_dialog_delegate.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef CHROME_BROWSER_MODAL_HTML_DIALOG_DELEGATE_H__
-#define CHROME_BROWSER_MODAL_HTML_DIALOG_DELEGATE_H__
+#ifndef CHROME_BROWSER_MODAL_HTML_DIALOG_DELEGATE_H_
+#define CHROME_BROWSER_MODAL_HTML_DIALOG_DELEGATE_H_
 
 #include <vector>
 
@@ -37,6 +37,11 @@
   virtual void OnDialogClosed(const std::string& json_retval);
 
  private:
+  // Invoked from the destructor or when we receive notification the web
+  // contents has been disconnnected. Removes the observer from the WebContents
+  // and NULLs out contents_.
+  void RemoveObserver();
+
   // The WebContents that opened the dialog.
   WebContents* contents_;
 
@@ -47,8 +52,7 @@
   // plugin using this |sync_result| pointer so we store it between calls.
   IPC::Message* sync_response_;
 
-  DISALLOW_EVIL_CONSTRUCTORS(ModalHtmlDialogDelegate);
+  DISALLOW_COPY_AND_ASSIGN(ModalHtmlDialogDelegate);
 };
 
-#endif  // CHROME_BROWSER_MODAL_HTML_DIALOG_DELEGATE_H__
-
+#endif  // CHROME_BROWSER_MODAL_HTML_DIALOG_DELEGATE_H_