Disclude Settings window and settings-frame from startup pages

BUG=528069

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

Cr-Commit-Position: refs/heads/master@{#356393}
diff --git a/chrome/browser/custom_home_pages_table_model.cc b/chrome/browser/custom_home_pages_table_model.cc
index 8b25d0a..75456dd2 100644
--- a/chrome/browser/custom_home_pages_table_model.cc
+++ b/chrome/browser/custom_home_pages_table_model.cc
@@ -14,6 +14,7 @@
 #include "chrome/browser/ui/browser.h"
 #include "chrome/browser/ui/browser_iterator.h"
 #include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/settings_window_manager.h"
 #include "chrome/browser/ui/tabs/tab_strip_model.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/common/url_constants.h"
@@ -38,8 +39,10 @@
     return false;
 
   if (url.SchemeIs(content::kChromeUIScheme)) {
-    if (url.host() == chrome::kChromeUISettingsHost)
+    if (url.host() == chrome::kChromeUISettingsHost ||
+        url.host() == chrome::kChromeUISettingsFrameHost) {
       return false;
+    }
 
     // For a settings page, the path will start with "/settings" not "settings"
     // so find() will return 1, not 0.
@@ -181,12 +184,12 @@
   while (RowCount())
     RemoveWithoutNotification(0);
 
-  // And add all tabs for all open browsers with our profile.
+  // Add tabs from appropriate browser windows.
   int add_index = 0;
   for (chrome::BrowserIterator it; !it.done(); it.Next()) {
     Browser* browser = *it;
-    if (browser->profile() != profile_)
-      continue;  // Skip incognito browsers.
+    if (!ShouldIncludeBrowser(browser))
+      continue;
 
     for (int tab_index = 0;
          tab_index < browser->tab_strip_model()->count();
@@ -227,6 +230,18 @@
   observer_ = observer;
 }
 
+bool CustomHomePagesTableModel::ShouldIncludeBrowser(Browser* browser) {
+  // Do not include incognito browsers.
+  if (browser->profile() != profile_)
+    return false;
+  // Do not include the Settings window.
+  if (chrome::SettingsWindowManager::GetInstance()->IsSettingsBrowser(
+          browser)) {
+    return false;
+  }
+  return true;
+}
+
 void CustomHomePagesTableModel::LoadTitle(Entry* entry) {
   history::HistoryService* history_service =
       HistoryServiceFactory::GetForProfile(profile_,
diff --git a/chrome/browser/custom_home_pages_table_model.h b/chrome/browser/custom_home_pages_table_model.h
index 60304b6..1b49e97 100644
--- a/chrome/browser/custom_home_pages_table_model.h
+++ b/chrome/browser/custom_home_pages_table_model.h
@@ -13,6 +13,7 @@
 #include "components/history/core/browser/history_types.h"
 #include "ui/base/models/table_model.h"
 
+class Browser;
 class GURL;
 class Profile;
 
@@ -64,6 +65,9 @@
   // and title of the page.
   struct Entry;
 
+  // Returns false if pages from |browser| should not be considered.
+  bool ShouldIncludeBrowser(Browser* browser);
+
   // Loads the title for the specified entry.
   void LoadTitle(Entry* entry);