| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ui/search/instant_controller.h" | 5 #include "chrome/browser/ui/search/instant_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/single_thread_task_runner.h" | |
| 12 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/platform_util.h" | |
| 16 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/search/instant_service.h" | 15 #include "chrome/browser/search/instant_service.h" |
| 18 #include "chrome/browser/search/instant_service_factory.h" | 16 #include "chrome/browser/search/instant_service_factory.h" |
| 19 #include "chrome/browser/search/search.h" | 17 #include "chrome/browser/search/search.h" |
| 20 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
| 21 #include "chrome/browser/ui/browser_instant_controller.h" | 18 #include "chrome/browser/ui/browser_instant_controller.h" |
| 22 #include "chrome/browser/ui/search/instant_tab.h" | 19 #include "chrome/browser/ui/search/instant_tab.h" |
| 23 #include "chrome/browser/ui/search/search_tab_helper.h" | 20 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 24 #include "chrome/common/chrome_switches.h" | |
| 25 #include "chrome/common/search/search_urls.h" | |
| 26 #include "chrome/common/url_constants.h" | |
| 27 #include "components/prefs/pref_service.h" | |
| 28 #include "components/search_engines/template_url_service.h" | |
| 29 #include "components/sessions/core/serialized_navigation_entry.h" | 21 #include "components/sessions/core/serialized_navigation_entry.h" |
| 22 #include "content/public/browser/navigation_controller.h" |
| 30 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
| 31 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/browser/render_process_host.h" | |
| 33 #include "content/public/browser/render_widget_host_view.h" | |
| 34 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 35 #include "net/base/escape.h" | |
| 36 #include "net/base/network_change_notifier.h" | |
| 37 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 38 | 27 |
| 28 // Macro used for logging debug events. |message| should be a std::string. |
| 29 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ |
| 30 controller->LogDebugEvent(message) |
| 31 |
| 39 namespace { | 32 namespace { |
| 40 | 33 |
| 41 bool IsContentsFrom(const InstantPage* page, | 34 bool IsContentsFrom(const InstantPage* page, |
| 42 const content::WebContents* contents) { | 35 const content::WebContents* contents) { |
| 43 return page && (page->web_contents() == contents); | 36 return page && (page->web_contents() == contents); |
| 44 } | 37 } |
| 45 | 38 |
| 46 // Adds a transient NavigationEntry to the supplied |contents|'s | 39 // Adds a transient NavigationEntry to the supplied |contents|'s |
| 47 // NavigationController if the page's URL has not already been updated with the | 40 // NavigationController if the page's URL has not already been updated with the |
| 48 // supplied |search_terms|. Sets the |search_terms| on the transient entry for | 41 // supplied |search_terms|. Sets the |search_terms| on the transient entry for |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 161 |
| 169 // The Instant tab navigated. Send it the data it needs to display | 162 // The Instant tab navigated. Send it the data it needs to display |
| 170 // properly. | 163 // properly. |
| 171 UpdateInfoForInstantTab(); | 164 UpdateInfoForInstantTab(); |
| 172 } | 165 } |
| 173 | 166 |
| 174 void InstantController::ResetInstantTab() { | 167 void InstantController::ResetInstantTab() { |
| 175 if (!search_mode_.is_origin_default()) { | 168 if (!search_mode_.is_origin_default()) { |
| 176 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 169 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
| 177 if (!instant_tab_ || active_tab != instant_tab_->web_contents()) { | 170 if (!instant_tab_ || active_tab != instant_tab_->web_contents()) { |
| 178 instant_tab_.reset(new InstantTab(this, browser_->profile())); | 171 instant_tab_.reset(new InstantTab(this)); |
| 179 instant_tab_->Init(active_tab); | 172 instant_tab_->Init(active_tab); |
| 180 UpdateInfoForInstantTab(); | 173 UpdateInfoForInstantTab(); |
| 181 } | 174 } |
| 182 } else { | 175 } else { |
| 183 instant_tab_.reset(); | 176 instant_tab_.reset(); |
| 184 } | 177 } |
| 185 } | 178 } |
| 186 | 179 |
| 187 void InstantController::UpdateInfoForInstantTab() { | 180 void InstantController::UpdateInfoForInstantTab() { |
| 188 if (instant_tab_) { | 181 if (instant_tab_) { |
| 189 // Update theme details. | 182 // Update theme details. |
| 190 InstantService* instant_service = GetInstantService(); | 183 InstantService* instant_service = GetInstantService(); |
| 191 if (instant_service) { | 184 if (instant_service) { |
| 192 instant_service->UpdateThemeInfo(); | 185 instant_service->UpdateThemeInfo(); |
| 193 instant_service->UpdateMostVisitedItemsInfo(); | 186 instant_service->UpdateMostVisitedItemsInfo(); |
| 194 } | 187 } |
| 195 } | 188 } |
| 196 } | 189 } |
| 197 | 190 |
| 198 InstantService* InstantController::GetInstantService() const { | 191 InstantService* InstantController::GetInstantService() const { |
| 199 return InstantServiceFactory::GetForProfile(profile()); | 192 return InstantServiceFactory::GetForProfile(profile()); |
| 200 } | 193 } |
| OLD | NEW |