[Extensions UI Views] Fix bugs in the ExtensionInstalledBubble

- Have a custom view for the heading and close button so each can be properly
  positioned.
- Properly wait until the extension is loaded before initializing or showing the
  bubble.

BUG=569873
BUG=570238

Review URL: https://codereview.chromium.org/1535593002

Cr-Commit-Position: refs/heads/master@{#365868}
diff --git a/chrome/browser/ui/extensions/extension_installed_bubble.cc b/chrome/browser/ui/extensions/extension_installed_bubble.cc
index 7f0365dc..b914d77 100644
--- a/chrome/browser/ui/extensions/extension_installed_bubble.cc
+++ b/chrome/browser/ui/extensions/extension_installed_bubble.cc
@@ -79,13 +79,12 @@
   void OnExtensionLoaded(content::BrowserContext* browser_context,
                          const extensions::Extension* extension) override {
     if (extension == bubble_->extension()) {
-      bubble_->Initialize();
       // PostTask to ourself to allow all EXTENSION_LOADED Observers to run.
       // Only then can we be sure that a BrowserAction or PageAction has had
       // views created which we can inspect for the purpose of previewing of
       // pointing to them.
       base::ThreadTaskRunnerHandle::Get()->PostTask(
-          FROM_HERE, base::Bind(&ExtensionInstalledBubbleObserver::Show,
+          FROM_HERE, base::Bind(&ExtensionInstalledBubbleObserver::Initialize,
                                 weak_factory_.GetWeakPtr()));
     }
   }
@@ -100,6 +99,12 @@
     }
   }
 
+  void Initialize() {
+    DCHECK(bubble_);
+    bubble_->Initialize();
+    Show();
+  }
+
   // Called internally via PostTask to show the bubble.
   void Show() {
     DCHECK(bubble_);
@@ -192,15 +197,6 @@
       type_(GENERIC),
       options_(NONE),
       anchor_position_(ANCHOR_APP_MENU) {
-  if (!extensions::OmniboxInfo::GetKeyword(extension).empty())
-    type_ = OMNIBOX_KEYWORD;
-  else if (extensions::ActionInfo::GetBrowserActionInfo(extension))
-    type_ = BROWSER_ACTION;
-  else if (extensions::ActionInfo::GetPageActionInfo(extension) &&
-           extensions::ActionInfo::IsVerboseInstallMessage(extension))
-    type_ = PAGE_ACTION;
-  else
-    type_ = GENERIC;
 }
 
 ExtensionInstalledBubble::~ExtensionInstalledBubble() {}
@@ -245,6 +241,21 @@
 }
 
 void ExtensionInstalledBubble::Initialize() {
+  bool extension_action_redesign_on =
+      extensions::FeatureSwitch::extension_action_redesign()->IsEnabled();
+
+  if (extensions::ActionInfo::GetBrowserActionInfo(extension_)) {
+    type_ = BROWSER_ACTION;
+  } else if (extensions::ActionInfo::GetPageActionInfo(extension_) &&
+             (extensions::ActionInfo::IsVerboseInstallMessage(extension_) ||
+              extension_action_redesign_on)) {
+    type_ = PAGE_ACTION;
+  } else if (!extensions::OmniboxInfo::GetKeyword(extension_).empty()) {
+    type_ = OMNIBOX_KEYWORD;
+  } else {
+    type_ = GENERIC;
+  }
+
   action_command_ = GetCommand(extension_->id(), browser_->profile(), type_);
   if (extensions::sync_helper::IsSyncable(extension_) &&
       SyncPromoUI::ShouldShowSyncPromo(browser_->profile()))
@@ -264,8 +275,7 @@
         options_ |= HOW_TO_MANAGE;
       }
 
-      if (type_ == BROWSER_ACTION ||
-          extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) {
+      if (type_ == BROWSER_ACTION || extension_action_redesign_on) {
         // If the toolbar redesign is enabled, all bubbles for extensions point
         // to their toolbar action.
         anchor_position_ = ANCHOR_BROWSER_ACTION;