avoid dereferencing NULL extension in ExtensionHost

BUG=chromium-os:13739
TEST=None

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84502 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc
index 003f563..7badebfc 100644
--- a/chrome/browser/extensions/extension_host.cc
+++ b/chrome/browser/extensions/extension_host.cc
@@ -126,6 +126,7 @@
                              const GURL& url,
                              ViewType::Type host_type)
     : extension_(extension),
+      extension_id_(extension->id()),
       profile_(site_instance->browsing_instance()->profile()),
       did_stop_loading_(false),
       document_element_available_(false),
@@ -234,8 +235,7 @@
   // Prevent explicit navigation to another extension id's pages.
   // This method is only called by some APIs, so we still need to protect
   // DidNavigate below (location = "").
-  if (url.SchemeIs(chrome::kExtensionScheme) &&
-      url.host() != extension_->id()) {
+  if (url.SchemeIs(chrome::kExtensionScheme) && url.host() != extension_id()) {
     // TODO(erikkay) communicate this back to the caller?
     return;
   }
@@ -259,7 +259,7 @@
   switch (type.value) {
     case NotificationType::EXTENSION_BACKGROUND_PAGE_READY:
       DCHECK(profile_->GetExtensionService()->
-           IsBackgroundPageReady(extension_));
+          IsBackgroundPageReady(extension_));
       NavigateToURL(url_);
       break;
     case NotificationType::RENDERER_PROCESS_CREATED:
@@ -342,7 +342,7 @@
   // will leave the host in kind of a bad state with poor UI and errors, but
   // it's better than the alternative.
   // TODO(erikkay) Perhaps we should display errors in developer mode.
-  if (params.url.host() != extension_->id()) {
+  if (params.url.host() != extension_id()) {
     extension_function_dispatcher_.reset(NULL);
     return;
   }
diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h
index 1a23d20..311975d 100644
--- a/chrome/browser/extensions/extension_host.h
+++ b/chrome/browser/extensions/extension_host.h
@@ -37,7 +37,7 @@
 // This class is the browser component of an extension component's RenderView.
 // It handles setting up the renderer process, if needed, with special
 // privileges available to extensions.  It may have a view to be shown in the
-// in the browser UI, or it may be hidden.
+// browser UI, or it may be hidden.
 class ExtensionHost : public RenderViewHostDelegate,
                       public RenderViewHostDelegate::View,
                       public ExtensionFunctionDispatcher::Delegate,
@@ -72,6 +72,7 @@
   void CreateView(Browser* browser);
 
   const Extension* extension() const { return extension_; }
+  const std::string& extension_id() const { return extension_id_; }
   RenderViewHost* render_view_host() const { return render_view_host_; }
   RenderProcessHost* render_process_host() const;
   SiteInstance* site_instance() const;
@@ -241,6 +242,9 @@
   // The extension that we're hosting in this view.
   const Extension* extension_;
 
+  // Id of extension that we're hosting in this view.
+  const std::string extension_id_;
+
   // The profile that this host is tied to.
   Profile* profile_;
 
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc
index f21c4f8..8a37287 100644
--- a/chrome/browser/extensions/extension_process_manager.cc
+++ b/chrome/browser/extensions/extension_process_manager.cc
@@ -291,7 +291,7 @@
       for (ExtensionHostSet::iterator iter = background_hosts_.begin();
            iter != background_hosts_.end(); ++iter) {
         ExtensionHost* host = *iter;
-        if (host->extension()->id() == extension->id()) {
+        if (host->extension_id() == extension->id()) {
           delete host;
           // |host| should deregister itself from our structures.
           DCHECK(background_hosts_.find(host) == background_hosts_.end());
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index fede5d7..fca68a1 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -2042,7 +2042,7 @@
 void ExtensionService::DidCreateRenderViewForBackgroundPage(
     ExtensionHost* host) {
   OrphanedDevTools::iterator iter =
-      orphaned_dev_tools_.find(host->extension()->id());
+      orphaned_dev_tools_.find(host->extension_id());
   if (iter == orphaned_dev_tools_.end())
     return;