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/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_list.h" | 14 #include "chrome/browser/ui/browser_list.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
20 #include "grit/ui_resources.h" | 20 #include "grit/ui_resources.h" |
21 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/models/table_model_observer.h" | 23 #include "ui/base/models/table_model_observer.h" |
24 #include "ui/gfx/codec/png_codec.h" | 24 #include "ui/gfx/codec/png_codec.h" |
25 | 25 |
26 namespace { | |
27 | |
28 // Checks whether the given URL should count as one of the "current" pages. | |
29 // Returns true for all pages except dev tools and settings. | |
30 bool ShouldAddPage(const GURL& url) { | |
31 if (url.is_empty()) | |
32 return false; | |
33 | |
34 if (url.SchemeIs(chrome::kChromeDevToolsScheme)) | |
35 return false; | |
36 | |
37 if (url.SchemeIs(chrome::kChromeUIScheme)) { | |
38 if (url.host() == chrome::kChromeUISettingsHost) | |
39 return false; | |
40 | |
41 // For a settings page, the path will start with "/settings" not "settings" | |
42 // so find() will return 1, not 0. | |
43 if (url.host() == chrome::kChromeUIUberHost && | |
44 url.path().find(chrome::kChromeUISettingsHost) == 1) { | |
Evan Stade
2012/03/12 20:14:11
This also catches chrome://chrome/settings-foo
I
| |
45 return false; | |
46 } | |
47 } | |
48 | |
49 return true; | |
50 } | |
51 | |
52 } // namespace | |
53 | |
26 struct CustomHomePagesTableModel::Entry { | 54 struct CustomHomePagesTableModel::Entry { |
27 Entry() : title_handle(0) {} | 55 Entry() : title_handle(0) {} |
28 | 56 |
29 // URL of the page. | 57 // URL of the page. |
30 GURL url; | 58 GURL url; |
31 | 59 |
32 // Page title. If this is empty, we'll display the URL as the entry. | 60 // Page title. If this is empty, we'll display the URL as the entry. |
33 string16 title; | 61 string16 title; |
34 | 62 |
35 // If non-zero, indicates we're loading the title for the page. | 63 // If non-zero, indicates we're loading the title for the page. |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 // And add all tabs for all open browsers with our profile. | 175 // And add all tabs for all open browsers with our profile. |
148 int add_index = 0; | 176 int add_index = 0; |
149 for (BrowserList::const_iterator browser_i = BrowserList::begin(); | 177 for (BrowserList::const_iterator browser_i = BrowserList::begin(); |
150 browser_i != BrowserList::end(); ++browser_i) { | 178 browser_i != BrowserList::end(); ++browser_i) { |
151 Browser* browser = *browser_i; | 179 Browser* browser = *browser_i; |
152 if (browser->profile() != profile_) | 180 if (browser->profile() != profile_) |
153 continue; // Skip incognito browsers. | 181 continue; // Skip incognito browsers. |
154 | 182 |
155 for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) { | 183 for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) { |
156 const GURL url = browser->GetWebContentsAt(tab_index)->GetURL(); | 184 const GURL url = browser->GetWebContentsAt(tab_index)->GetURL(); |
157 // TODO(tbreisacher) remove kChromeUISettingsHost once options is deleted | 185 if (ShouldAddPage(url)) { |
Evan Stade
2012/03/12 20:14:11
no curlies
| |
158 // and replaced by options2 | |
159 if (!url.is_empty() && | |
160 !(url.SchemeIs(chrome::kChromeUIScheme) && | |
161 (url.host() == chrome::kChromeUISettingsHost || | |
162 url.host() == chrome::kChromeUIUberHost))) { | |
163 Add(add_index++, url); | 186 Add(add_index++, url); |
164 } | 187 } |
165 } | 188 } |
166 } | 189 } |
167 } | 190 } |
168 | 191 |
169 std::vector<GURL> CustomHomePagesTableModel::GetURLs() { | 192 std::vector<GURL> CustomHomePagesTableModel::GetURLs() { |
170 std::vector<GURL> urls(entries_.size()); | 193 std::vector<GURL> urls(entries_.size()); |
171 for (size_t i = 0; i < entries_.size(); ++i) | 194 for (size_t i = 0; i < entries_.size(); ++i) |
172 urls[i] = entries_[i].url; | 195 urls[i] = entries_[i].url; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 return NULL; | 260 return NULL; |
238 } | 261 } |
239 | 262 |
240 string16 CustomHomePagesTableModel::FormattedURL(int row) const { | 263 string16 CustomHomePagesTableModel::FormattedURL(int row) const { |
241 std::string languages = | 264 std::string languages = |
242 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); | 265 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); |
243 string16 url = net::FormatUrl(entries_[row].url, languages); | 266 string16 url = net::FormatUrl(entries_[row].url, languages); |
244 url = base::i18n::GetDisplayStringInLTRDirectionality(url); | 267 url = base::i18n::GetDisplayStringInLTRDirectionality(url); |
245 return url; | 268 return url; |
246 } | 269 } |
OLD | NEW |