Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/custom_home_pages_table_model.h" | 5 #include "chrome/browser/custom_home_pages_table_model.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/history/history_service_factory.h" | 12 #include "chrome/browser/history/history_service_factory.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_iterator.h" | 15 #include "chrome/browser/ui/browser_iterator.h" |
| 16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
| 17 #include "chrome/browser/ui/settings_window_manager.h" | |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 20 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 21 #include "components/history/core/browser/history_service.h" | 22 #include "components/history/core/browser/history_service.h" |
| 22 #include "components/url_formatter/url_formatter.h" | 23 #include "components/url_formatter/url_formatter.h" |
| 23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/models/table_model_observer.h" | 26 #include "ui/base/models/table_model_observer.h" |
| 26 #include "ui/gfx/codec/png_codec.h" | 27 #include "ui/gfx/codec/png_codec.h" |
| 27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 // Checks whether the given URL should count as one of the "current" pages. | 32 // Checks whether the given URL should count as one of the "current" pages. |
| 32 // Returns true for all pages except dev tools and settings. | 33 // Returns true for all pages except dev tools and settings. |
| 33 bool ShouldAddPage(const GURL& url) { | 34 bool ShouldAddPage(const GURL& url) { |
| 34 if (url.is_empty()) | 35 if (url.is_empty()) |
| 35 return false; | 36 return false; |
| 36 | 37 |
| 37 if (url.SchemeIs(content::kChromeDevToolsScheme)) | 38 if (url.SchemeIs(content::kChromeDevToolsScheme)) |
| 38 return false; | 39 return false; |
| 39 | 40 |
| 40 if (url.SchemeIs(content::kChromeUIScheme)) { | 41 if (url.SchemeIs(content::kChromeUIScheme)) { |
| 41 if (url.host() == chrome::kChromeUISettingsHost) | 42 if (url.host() == chrome::kChromeUISettingsHost || |
| 43 url.host() == chrome::kChromeUISettingsFrameHost) { | |
| 42 return false; | 44 return false; |
| 45 } | |
| 43 | 46 |
| 44 // For a settings page, the path will start with "/settings" not "settings" | 47 // For a settings page, the path will start with "/settings" not "settings" |
| 45 // so find() will return 1, not 0. | 48 // so find() will return 1, not 0. |
| 46 if (url.host() == chrome::kChromeUIUberHost && | 49 if (url.host() == chrome::kChromeUIUberHost && |
| 47 url.path().find(chrome::kChromeUISettingsHost) == 1) { | 50 url.path().find(chrome::kChromeUISettingsHost) == 1) { |
| 48 return false; | 51 return false; |
| 49 } | 52 } |
| 50 } | 53 } |
| 51 | 54 |
| 52 return true; | 55 return true; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 | 181 |
| 179 void CustomHomePagesTableModel::SetToCurrentlyOpenPages() { | 182 void CustomHomePagesTableModel::SetToCurrentlyOpenPages() { |
| 180 // Remove the current entries. | 183 // Remove the current entries. |
| 181 while (RowCount()) | 184 while (RowCount()) |
| 182 RemoveWithoutNotification(0); | 185 RemoveWithoutNotification(0); |
| 183 | 186 |
| 184 // And add all tabs for all open browsers with our profile. | 187 // And add all tabs for all open browsers with our profile. |
| 185 int add_index = 0; | 188 int add_index = 0; |
| 186 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 189 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 187 Browser* browser = *it; | 190 Browser* browser = *it; |
| 188 if (browser->profile() != profile_) | 191 if (browser->profile() != profile_) |
|
sky
2015/10/27 13:07:46
Can you move this and your new if into a ShouldAdd
stevenjb
2015/10/27 16:30:49
Done.
| |
| 189 continue; // Skip incognito browsers. | 192 continue; // Skip incognito browsers. |
| 193 if (chrome::SettingsWindowManager::GetInstance()->IsSettingsBrowser( | |
| 194 browser)) { | |
| 195 continue; // Skip the Settings window. | |
| 196 } | |
| 190 | 197 |
| 191 for (int tab_index = 0; | 198 for (int tab_index = 0; |
| 192 tab_index < browser->tab_strip_model()->count(); | 199 tab_index < browser->tab_strip_model()->count(); |
| 193 ++tab_index) { | 200 ++tab_index) { |
| 194 const GURL url = | 201 const GURL url = |
| 195 browser->tab_strip_model()->GetWebContentsAt(tab_index)->GetURL(); | 202 browser->tab_strip_model()->GetWebContentsAt(tab_index)->GetURL(); |
| 196 if (ShouldAddPage(url)) | 203 if (ShouldAddPage(url)) |
| 197 AddWithoutNotification(add_index++, url); | 204 AddWithoutNotification(add_index++, url); |
| 198 } | 205 } |
| 199 } | 206 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 } | 309 } |
| 303 } | 310 } |
| 304 | 311 |
| 305 base::string16 CustomHomePagesTableModel::FormattedURL(int row) const { | 312 base::string16 CustomHomePagesTableModel::FormattedURL(int row) const { |
| 306 std::string languages = | 313 std::string languages = |
| 307 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); | 314 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 308 base::string16 url = url_formatter::FormatUrl(entries_[row].url, languages); | 315 base::string16 url = url_formatter::FormatUrl(entries_[row].url, languages); |
| 309 url = base::i18n::GetDisplayStringInLTRDirectionality(url); | 316 url = base::i18n::GetDisplayStringInLTRDirectionality(url); |
| 310 return url; | 317 return url; |
| 311 } | 318 } |
| OLD | NEW |