| 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/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/search/instant_service.h" | 15 #include "chrome/browser/search/instant_service.h" |
| 16 #include "chrome/browser/search/instant_service_factory.h" | 16 #include "chrome/browser/search/instant_service_factory.h" |
| 17 #include "chrome/browser/search/search.h" | 17 #include "chrome/browser/search/search.h" |
| 18 #include "chrome/browser/ui/browser_instant_controller.h" | 18 #include "chrome/browser/ui/browser_instant_controller.h" |
| 19 #include "chrome/browser/ui/search/instant_page.h" | 19 #include "chrome/browser/ui/search/instant_tab.h" |
| 20 #include "chrome/browser/ui/search/search_tab_helper.h" | 20 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 21 #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" | 22 #include "content/public/browser/navigation_controller.h" |
| 23 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
| 24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 27 | 27 |
| 28 // Macro used for logging debug events. |message| should be a std::string. | 28 // Macro used for logging debug events. |message| should be a std::string. |
| 29 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ | 29 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ |
| 30 controller->LogDebugEvent(message) | 30 controller->LogDebugEvent(message) |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 bool IsContentsFrom(const InstantPage* page, | 34 bool IsContentsFrom(const InstantTab* page, |
| 35 const content::WebContents* contents) { | 35 const content::WebContents* contents) { |
| 36 return page && (page->web_contents() == contents); | 36 return page && (page->web_contents() == contents); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // Adds a transient NavigationEntry to the supplied |contents|'s | 39 // Adds a transient NavigationEntry to the supplied |contents|'s |
| 40 // 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 |
| 41 // 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 |
| 42 // search terms extraction to work correctly. | 42 // search terms extraction to work correctly. |
| 43 void EnsureSearchTermsAreSet(content::WebContents* contents, | 43 void EnsureSearchTermsAreSet(content::WebContents* contents, |
| 44 const base::string16& search_terms) { | 44 const base::string16& search_terms) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 111 } |
| 112 | 112 |
| 113 void InstantController::ClearDebugEvents() { | 113 void InstantController::ClearDebugEvents() { |
| 114 debug_events_.clear(); | 114 debug_events_.clear(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 Profile* InstantController::profile() const { | 117 Profile* InstantController::profile() const { |
| 118 return browser_->profile(); | 118 return browser_->profile(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 InstantPage* InstantController::instant_tab() const { | 121 InstantTab* InstantController::instant_tab() const { |
| 122 return instant_tab_.get(); | 122 return instant_tab_.get(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void InstantController::InstantSupportChanged( | 125 void InstantController::InstantSupportChanged( |
| 126 InstantSupportState instant_support) { | 126 InstantSupportState instant_support) { |
| 127 // Handle INSTANT_SUPPORT_YES here because InstantPage is not hooked up to the | 127 // Handle INSTANT_SUPPORT_YES here because InstantTab is not hooked up to the |
| 128 // active tab. Search model changed listener in InstantPage will handle other | 128 // active tab. Search model changed listener in InstantTab will handle other |
| 129 // cases. | 129 // cases. |
| 130 if (instant_support != INSTANT_SUPPORT_YES) | 130 if (instant_support != INSTANT_SUPPORT_YES) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 ResetInstantTab(); | 133 ResetInstantTab(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void InstantController::InstantSupportDetermined( | 136 void InstantController::InstantSupportDetermined( |
| 137 const content::WebContents* contents, | 137 const content::WebContents* contents, |
| 138 bool supports_instant) { | 138 bool supports_instant) { |
| 139 DCHECK(IsContentsFrom(instant_tab(), contents)); | 139 DCHECK(IsContentsFrom(instant_tab(), contents)); |
| 140 | 140 |
| 141 if (!supports_instant) | 141 if (!supports_instant) |
| 142 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, | 142 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, |
| 143 instant_tab_.release()); | 143 instant_tab_.release()); |
| 144 | 144 |
| 145 content::NotificationService::current()->Notify( | 145 content::NotificationService::current()->Notify( |
| 146 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 146 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
| 147 content::Source<InstantController>(this), | 147 content::Source<InstantController>(this), |
| 148 content::NotificationService::NoDetails()); | 148 content::NotificationService::NoDetails()); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void InstantController::InstantPageAboutToNavigateMainFrame( | 151 void InstantController::InstantTabAboutToNavigateMainFrame( |
| 152 const content::WebContents* contents, | 152 const content::WebContents* contents, |
| 153 const GURL& url) { | 153 const GURL& url) { |
| 154 DCHECK(IsContentsFrom(instant_tab(), contents)); | 154 DCHECK(IsContentsFrom(instant_tab(), contents)); |
| 155 | 155 |
| 156 // The Instant tab navigated. Send it the data it needs to display | 156 // The Instant tab navigated. Send it the data it needs to display |
| 157 // properly. | 157 // properly. |
| 158 UpdateInfoForInstantTab(); | 158 UpdateInfoForInstantTab(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void InstantController::ResetInstantTab() { | 161 void InstantController::ResetInstantTab() { |
| 162 if (!search_mode_.is_origin_default()) { | 162 if (!search_mode_.is_origin_default()) { |
| 163 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 163 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
| 164 if (!instant_tab_ || active_tab != instant_tab_->web_contents()) { | 164 if (!instant_tab_ || active_tab != instant_tab_->web_contents()) { |
| 165 instant_tab_.reset(new InstantPage(this)); | 165 instant_tab_.reset(new InstantTab(this)); |
| 166 instant_tab_->Init(active_tab); | 166 instant_tab_->Init(active_tab); |
| 167 UpdateInfoForInstantTab(); | 167 UpdateInfoForInstantTab(); |
| 168 } | 168 } |
| 169 } else { | 169 } else { |
| 170 instant_tab_.reset(); | 170 instant_tab_.reset(); |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 void InstantController::UpdateInfoForInstantTab() { | 174 void InstantController::UpdateInfoForInstantTab() { |
| 175 if (instant_tab_) { | 175 if (instant_tab_) { |
| 176 // Update theme details. | 176 // Update theme details. |
| 177 InstantService* instant_service = GetInstantService(); | 177 InstantService* instant_service = GetInstantService(); |
| 178 if (instant_service) { | 178 if (instant_service) { |
| 179 instant_service->UpdateThemeInfo(); | 179 instant_service->UpdateThemeInfo(); |
| 180 instant_service->UpdateMostVisitedItemsInfo(); | 180 instant_service->UpdateMostVisitedItemsInfo(); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 | 184 |
| 185 InstantService* InstantController::GetInstantService() const { | 185 InstantService* InstantController::GetInstantService() const { |
| 186 return InstantServiceFactory::GetForProfile(profile()); | 186 return InstantServiceFactory::GetForProfile(profile()); |
| 187 } | 187 } |
| OLD | NEW |