OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/search/instant_page.h" | 5 #include "chrome/browser/ui/search/instant_page.h" |
6 | 6 |
7 #include "apps/app_launcher.h" | 7 #include "apps/app_launcher.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/history/most_visited_tiles_experiment.h" |
| 11 #include "chrome/browser/history/top_sites.h" |
10 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/search/instant_service.h" | 13 #include "chrome/browser/search/instant_service.h" |
12 #include "chrome/browser/search/instant_service_factory.h" | 14 #include "chrome/browser/search/instant_service_factory.h" |
13 #include "chrome/browser/search/search.h" | 15 #include "chrome/browser/search/search.h" |
| 16 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/search/instant_tab.h" | 17 #include "chrome/browser/ui/search/instant_tab.h" |
15 #include "chrome/browser/ui/search/search_model.h" | 18 #include "chrome/browser/ui/search/search_model.h" |
16 #include "chrome/browser/ui/search/search_tab_helper.h" | 19 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h" |
17 #include "chrome/common/render_messages.h" | 22 #include "chrome/common/render_messages.h" |
18 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
19 #include "content/public/browser/navigation_controller.h" | 24 #include "content/public/browser/navigation_controller.h" |
20 #include "content/public/browser/navigation_details.h" | 25 #include "content/public/browser/navigation_details.h" |
21 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.h" |
22 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
24 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
25 #include "content/public/common/frame_navigate_params.h" | 30 #include "content/public/common/frame_navigate_params.h" |
26 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (is_main_frame) | 185 if (is_main_frame) |
181 delegate_->InstantPageLoadFailed(contents()); | 186 delegate_->InstantPageLoadFailed(contents()); |
182 } | 187 } |
183 | 188 |
184 void InstantPage::ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) { | 189 void InstantPage::ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) { |
185 sender()->SendThemeBackgroundInfo(theme_info); | 190 sender()->SendThemeBackgroundInfo(theme_info); |
186 } | 191 } |
187 | 192 |
188 void InstantPage::MostVisitedItemsChanged( | 193 void InstantPage::MostVisitedItemsChanged( |
189 const std::vector<InstantMostVisitedItem>& items) { | 194 const std::vector<InstantMostVisitedItem>& items) { |
190 sender()->SendMostVisitedItems(items); | 195 std::vector<InstantMostVisitedItem> items_copy(items); |
| 196 MaybeRemoveMostVisitedItems(&items_copy); |
| 197 |
| 198 sender()->SendMostVisitedItems(items_copy); |
191 | 199 |
192 content::NotificationService::current()->Notify( | 200 content::NotificationService::current()->Notify( |
193 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, | 201 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
194 content::Source<InstantPage>(this), | 202 content::Source<InstantPage>(this), |
195 content::NotificationService::NoDetails()); | 203 content::NotificationService::NoDetails()); |
196 } | 204 } |
197 | 205 |
198 void InstantPage::ModelChanged(const SearchModel::State& old_state, | 206 void InstantPage::ModelChanged(const SearchModel::State& old_state, |
199 const SearchModel::State& new_state) { | 207 const SearchModel::State& new_state) { |
200 if (old_state.instant_support != new_state.instant_support) | 208 if (old_state.instant_support != new_state.instant_support) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 delegate_->UndoAllMostVisitedDeletions(); | 284 delegate_->UndoAllMostVisitedDeletions(); |
277 } | 285 } |
278 | 286 |
279 void InstantPage::ClearContents() { | 287 void InstantPage::ClearContents() { |
280 if (contents()) | 288 if (contents()) |
281 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this); | 289 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this); |
282 | 290 |
283 sender()->SetContents(NULL); | 291 sender()->SetContents(NULL); |
284 Observe(NULL); | 292 Observe(NULL); |
285 } | 293 } |
| 294 |
| 295 void InstantPage::MaybeRemoveMostVisitedItems( |
| 296 std::vector<InstantMostVisitedItem>* items) { |
| 297 // The code below uses APIs not available on Android and the experiment should |
| 298 // not run there. |
| 299 #if !defined(OS_ANDROID) |
| 300 if (!history::MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled()) |
| 301 return; |
| 302 |
| 303 TabStripModel* tab_strip_model = chrome::FindBrowserWithProfile( |
| 304 profile_, |
| 305 chrome::GetActiveDesktop())->tab_strip_model(); |
| 306 history::TopSites* top_sites = profile_->GetTopSites(); |
| 307 if (!tab_strip_model || !top_sites) { |
| 308 NOTREACHED(); |
| 309 return; |
| 310 } |
| 311 |
| 312 std::set<std::string> open_urls; |
| 313 chrome::GetOpenUrls(*tab_strip_model, *top_sites, &open_urls); |
| 314 history::MostVisitedTilesExperiment::RemoveItemsMatchingOpenTabs( |
| 315 open_urls, items); |
| 316 |
| 317 #endif |
| 318 } |
OLD | NEW |