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/instant/instant_controller.h" | 5 #include "chrome/browser/instant/instant_controller.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 13 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
14 #include "chrome/browser/google/google_util.h" | 14 #include "chrome/browser/google/google_util.h" |
15 #include "chrome/browser/history/history.h" | 15 #include "chrome/browser/history/history.h" |
16 #include "chrome/browser/history/history_service_factory.h" | 16 #include "chrome/browser/history/history_service_factory.h" |
17 #include "chrome/browser/history/history_tab_helper.h" | 17 #include "chrome/browser/history/history_tab_helper.h" |
18 #include "chrome/browser/instant/instant_controller_delegate.h" | |
19 #include "chrome/browser/instant/instant_loader.h" | 18 #include "chrome/browser/instant/instant_loader.h" |
20 #include "chrome/browser/platform_util.h" | 19 #include "chrome/browser/platform_util.h" |
21 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
22 #include "chrome/browser/search_engines/template_url_service.h" | 21 #include "chrome/browser/search_engines/template_url_service.h" |
23 #include "chrome/browser/search_engines/template_url_service_factory.h" | 22 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 23 #include "chrome/browser/ui/browser_instant_controller.h" |
24 #include "chrome/browser/ui/search/search.h" | 24 #include "chrome/browser/ui/search/search.h" |
25 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
26 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
29 #include "content/public/browser/favicon_status.h" | 29 #include "content/public/browser/favicon_status.h" |
30 #include "content/public/browser/navigation_entry.h" | 30 #include "content/public/browser/navigation_entry.h" |
31 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
32 #include "content/public/browser/render_widget_host_view.h" | 32 #include "content/public/browser/render_widget_host_view.h" |
33 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
(...skipping 26 matching lines...) Expand all Loading... |
60 const int kMaxInstantSupportFailures = 10; | 60 const int kMaxInstantSupportFailures = 10; |
61 | 61 |
62 // If an Instant page has not been used in these many milliseconds, it is | 62 // If an Instant page has not been used in these many milliseconds, it is |
63 // reloaded so that the page does not become stale. | 63 // reloaded so that the page does not become stale. |
64 const int kStaleLoaderTimeoutMS = 3 * 3600 * 1000; | 64 const int kStaleLoaderTimeoutMS = 3 * 3600 * 1000; |
65 | 65 |
66 std::string ModeToString(InstantController::Mode mode) { | 66 std::string ModeToString(InstantController::Mode mode) { |
67 switch (mode) { | 67 switch (mode) { |
68 case InstantController::EXTENDED: return "_Extended"; | 68 case InstantController::EXTENDED: return "_Extended"; |
69 case InstantController::INSTANT: return "_Instant"; | 69 case InstantController::INSTANT: return "_Instant"; |
70 case InstantController::SUGGEST: return "_Suggest"; | |
71 case InstantController::HIDDEN: return "_Hidden"; | |
72 case InstantController::SILENT: return "_Silent"; | |
73 case InstantController::DISABLED: return "_Disabled"; | 70 case InstantController::DISABLED: return "_Disabled"; |
74 } | 71 } |
75 | 72 |
76 NOTREACHED(); | 73 NOTREACHED(); |
77 return std::string(); | 74 return std::string(); |
78 } | 75 } |
79 | 76 |
80 void AddPreviewUsageForHistogram(InstantController::Mode mode, | 77 void AddPreviewUsageForHistogram(InstantController::Mode mode, |
81 PreviewUsageType usage) { | 78 PreviewUsageType usage) { |
82 DCHECK(0 <= usage && usage < PREVIEW_NUM_TYPES) << usage; | 79 DCHECK(0 <= usage && usage < PREVIEW_NUM_TYPES) << usage; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } // namespace | 150 } // namespace |
154 | 151 |
155 InstantController::~InstantController() { | 152 InstantController::~InstantController() { |
156 if (GetPreviewContents()) | 153 if (GetPreviewContents()) |
157 AddPreviewUsageForHistogram(mode_, PREVIEW_DELETED); | 154 AddPreviewUsageForHistogram(mode_, PREVIEW_DELETED); |
158 } | 155 } |
159 | 156 |
160 // static | 157 // static |
161 InstantController* InstantController::CreateInstant( | 158 InstantController* InstantController::CreateInstant( |
162 Profile* profile, | 159 Profile* profile, |
163 InstantControllerDelegate* delegate) { | 160 chrome::BrowserInstantController* browser) { |
164 const Mode mode = GetModeForProfile(profile); | 161 const Mode mode = GetModeForProfile(profile); |
165 return mode == DISABLED ? NULL : new InstantController(delegate, mode); | 162 return mode == DISABLED ? NULL : new InstantController(browser, mode); |
166 } | 163 } |
167 | 164 |
168 // static | 165 // static |
169 bool InstantController::IsExtendedAPIEnabled(Profile* profile) { | 166 bool InstantController::IsExtendedAPIEnabled(Profile* profile) { |
170 return GetModeForProfile(profile) == EXTENDED; | 167 return GetModeForProfile(profile) == EXTENDED; |
171 } | 168 } |
172 | 169 |
173 // static | 170 // static |
174 bool InstantController::IsInstantEnabled(Profile* profile) { | 171 bool InstantController::IsInstantEnabled(Profile* profile) { |
175 const Mode mode = GetModeForProfile(profile); | 172 const Mode mode = GetModeForProfile(profile); |
176 return mode == EXTENDED || mode == INSTANT; | 173 return mode == EXTENDED || mode == INSTANT; |
177 } | 174 } |
178 | 175 |
179 // static | 176 // static |
180 bool InstantController::IsSuggestEnabled(Profile* profile) { | |
181 const Mode mode = GetModeForProfile(profile); | |
182 return mode == EXTENDED || mode == INSTANT || mode == SUGGEST; | |
183 } | |
184 | |
185 // static | |
186 void InstantController::RegisterUserPrefs(PrefService* prefs) { | 177 void InstantController::RegisterUserPrefs(PrefService* prefs) { |
187 prefs->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, | 178 prefs->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, |
188 PrefService::SYNCABLE_PREF); | 179 PrefService::SYNCABLE_PREF); |
189 prefs->RegisterBooleanPref(prefs::kInstantEnabled, false, | 180 prefs->RegisterBooleanPref(prefs::kInstantEnabled, false, |
190 PrefService::SYNCABLE_PREF); | 181 PrefService::SYNCABLE_PREF); |
191 } | 182 } |
192 | 183 |
193 bool InstantController::Update(const AutocompleteMatch& match, | 184 bool InstantController::Update(const AutocompleteMatch& match, |
194 const string16& user_text, | 185 const string16& user_text, |
195 const string16& full_text, | 186 const string16& full_text, |
196 bool verbatim) { | 187 bool verbatim) { |
197 const TabContents* active_tab = delegate_->GetActiveTabContents(); | 188 const TabContents* active_tab = browser_->GetActiveTabContents(); |
198 | 189 |
199 // We could get here with no active tab if the Browser is closing. | 190 // We could get here with no active tab if the Browser is closing. |
200 if (!active_tab) { | 191 if (!active_tab) { |
201 Hide(); | 192 Hide(); |
202 return false; | 193 return false; |
203 } | 194 } |
204 | 195 |
205 std::string instant_url; | 196 std::string instant_url; |
206 Profile* profile = active_tab->profile(); | 197 Profile* profile = active_tab->profile(); |
207 | 198 |
(...skipping 23 matching lines...) Expand all Loading... |
231 // modes, we use the entire |full_text|. | 222 // modes, we use the entire |full_text|. |
232 const string16& query_text = mode_ == EXTENDED ? user_text : full_text; | 223 const string16& query_text = mode_ == EXTENDED ? user_text : full_text; |
233 string16 last_query_text = mode_ == EXTENDED ? | 224 string16 last_query_text = mode_ == EXTENDED ? |
234 last_user_text_ : last_full_text_; | 225 last_user_text_ : last_full_text_; |
235 last_user_text_ = user_text; | 226 last_user_text_ = user_text; |
236 last_full_text_ = full_text; | 227 last_full_text_ = full_text; |
237 | 228 |
238 // Don't send an update to the loader if the query text hasn't changed. | 229 // Don't send an update to the loader if the query text hasn't changed. |
239 if (query_text == last_query_text && verbatim == last_verbatim_) { | 230 if (query_text == last_query_text && verbatim == last_verbatim_) { |
240 // Reuse the last suggestion, as it's still valid. | 231 // Reuse the last suggestion, as it's still valid. |
241 delegate_->SetInstantSuggestion(last_suggestion_); | 232 browser_->SetInstantSuggestion(last_suggestion_); |
242 | 233 |
243 // We need to call Show() here because of this: | 234 // We need to call Show() here because of this: |
244 // 1. User has typed a query (say Q). Instant overlay is showing results. | 235 // 1. User has typed a query (say Q). Instant overlay is showing results. |
245 // 2. User arrows-down to a URL entry or erases all omnibox text. Both of | 236 // 2. User arrows-down to a URL entry or erases all omnibox text. Both of |
246 // these cause the overlay to Hide(). | 237 // these cause the overlay to Hide(). |
247 // 3. User arrows-up to Q or types Q again. The last text we processed is | 238 // 3. User arrows-up to Q or types Q again. The last text we processed is |
248 // still Q, so we don't Update() the loader, but we do need to Show(). | 239 // still Q, so we don't Update() the loader, but we do need to Show(). |
249 if (loader_processed_last_update_ && | 240 if (loader_processed_last_update_) |
250 (mode_ == INSTANT || mode_ == EXTENDED)) | |
251 Show(100, INSTANT_SIZE_PERCENT); | 241 Show(100, INSTANT_SIZE_PERCENT); |
252 return true; | 242 return true; |
253 } | 243 } |
254 | 244 |
255 last_verbatim_ = verbatim; | 245 last_verbatim_ = verbatim; |
256 loader_processed_last_update_ = false; | 246 loader_processed_last_update_ = false; |
257 last_suggestion_ = InstantSuggestion(); | 247 last_suggestion_ = InstantSuggestion(); |
258 | 248 |
259 if (mode_ != SILENT) { | 249 loader_->Update(query_text, verbatim); |
260 loader_->Update(query_text, verbatim); | |
261 | 250 |
262 content::NotificationService::current()->Notify( | 251 content::NotificationService::current()->Notify( |
263 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, | 252 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, |
264 content::Source<InstantController>(this), | 253 content::Source<InstantController>(this), |
265 content::NotificationService::NoDetails()); | 254 content::NotificationService::NoDetails()); |
266 } | |
267 | 255 |
268 // We don't have suggestions yet, but need to reset any existing "gray text". | 256 // We don't have suggestions yet, but need to reset any existing "gray text". |
269 delegate_->SetInstantSuggestion(InstantSuggestion()); | 257 browser_->SetInstantSuggestion(InstantSuggestion()); |
270 | 258 |
271 // Though we may have handled a URL match above, we return false here, so that | 259 // Though we may have handled a URL match above, we return false here, so that |
272 // omnibox prerendering can kick in. TODO(sreeram): Remove this (and always | 260 // omnibox prerendering can kick in. TODO(sreeram): Remove this (and always |
273 // return true) once we are able to commit URLs as well. | 261 // return true) once we are able to commit URLs as well. |
274 return last_match_was_search_; | 262 return last_match_was_search_; |
275 } | 263 } |
276 | 264 |
277 // TODO(tonyg): This method only fires when the omnibox bounds change. It also | 265 // TODO(tonyg): This method only fires when the omnibox bounds change. It also |
278 // needs to fire when the preview bounds change (e.g.: open/close info bar). | 266 // needs to fire when the preview bounds change (e.g.: open/close info bar). |
279 void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { | 267 void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { |
280 if (omnibox_bounds_ == bounds || (mode_ != INSTANT && mode_ != EXTENDED)) | 268 if (omnibox_bounds_ == bounds) |
281 return; | 269 return; |
282 | 270 |
283 omnibox_bounds_ = bounds; | 271 omnibox_bounds_ = bounds; |
284 if (omnibox_bounds_.height() > last_omnibox_bounds_.height()) { | 272 if (omnibox_bounds_.height() > last_omnibox_bounds_.height()) { |
285 update_bounds_timer_.Stop(); | 273 update_bounds_timer_.Stop(); |
286 SendBoundsToPage(); | 274 SendBoundsToPage(); |
287 } else if (!update_bounds_timer_.IsRunning()) { | 275 } else if (!update_bounds_timer_.IsRunning()) { |
288 update_bounds_timer_.Start(FROM_HERE, | 276 update_bounds_timer_.Start(FROM_HERE, |
289 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, | 277 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, |
290 &InstantController::SendBoundsToPage); | 278 &InstantController::SendBoundsToPage); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 // still be on the stack. So, schedule a destruction for later. | 392 // still be on the stack. So, schedule a destruction for later. |
405 MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); | 393 MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); |
406 | 394 |
407 // This call is here to reset view state. It won't actually delete |loader_| | 395 // This call is here to reset view state. It won't actually delete |loader_| |
408 // because it was just released to DeleteSoon(). | 396 // because it was just released to DeleteSoon(). |
409 DeleteLoader(); | 397 DeleteLoader(); |
410 | 398 |
411 preview->web_contents()->GetController().PruneAllButActive(); | 399 preview->web_contents()->GetController().PruneAllButActive(); |
412 | 400 |
413 if (type != INSTANT_COMMIT_PRESSED_ALT_ENTER) { | 401 if (type != INSTANT_COMMIT_PRESSED_ALT_ENTER) { |
414 const TabContents* active_tab = delegate_->GetActiveTabContents(); | 402 const TabContents* active_tab = browser_->GetActiveTabContents(); |
415 AddSessionStorageHistogram(mode_, active_tab, preview); | 403 AddSessionStorageHistogram(mode_, active_tab, preview); |
416 preview->web_contents()->GetController().CopyStateFromAndPrune( | 404 preview->web_contents()->GetController().CopyStateFromAndPrune( |
417 &active_tab->web_contents()->GetController()); | 405 &active_tab->web_contents()->GetController()); |
418 } | 406 } |
419 | 407 |
420 // Delegate takes ownership of the preview. | 408 // Browser takes ownership of the preview. |
421 delegate_->CommitInstant(preview, type == INSTANT_COMMIT_PRESSED_ALT_ENTER); | 409 browser_->CommitInstant(preview, type == INSTANT_COMMIT_PRESSED_ALT_ENTER); |
422 | 410 |
423 content::NotificationService::current()->Notify( | 411 content::NotificationService::current()->Notify( |
424 chrome::NOTIFICATION_INSTANT_COMMITTED, | 412 chrome::NOTIFICATION_INSTANT_COMMITTED, |
425 content::Source<content::WebContents>(preview->web_contents()), | 413 content::Source<content::WebContents>(preview->web_contents()), |
426 content::NotificationService::NoDetails()); | 414 content::NotificationService::NoDetails()); |
427 | 415 |
428 // Try to create another loader immediately so that it is ready for the next | 416 // Try to create another loader immediately so that it is ready for the next |
429 // user interaction. | 417 // user interaction. |
430 CreateDefaultLoader(); | 418 CreateDefaultLoader(); |
431 } | 419 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 loader_->OnActiveTabModeChanged(active_tab_is_ntp_); | 516 loader_->OnActiveTabModeChanged(active_tab_is_ntp_); |
529 } | 517 } |
530 | 518 |
531 bool InstantController::commit_on_pointer_release() const { | 519 bool InstantController::commit_on_pointer_release() const { |
532 return GetPreviewContents() && loader_->IsPointerDownFromActivate(); | 520 return GetPreviewContents() && loader_->IsPointerDownFromActivate(); |
533 } | 521 } |
534 | 522 |
535 void InstantController::SetSuggestions( | 523 void InstantController::SetSuggestions( |
536 InstantLoader* loader, | 524 InstantLoader* loader, |
537 const std::vector<InstantSuggestion>& suggestions) { | 525 const std::vector<InstantSuggestion>& suggestions) { |
538 if (loader_ != loader || IsOutOfDate() || mode_ == SILENT || mode_ == HIDDEN) | 526 if (loader_ != loader || IsOutOfDate()) |
539 return; | 527 return; |
540 | 528 |
541 loader_processed_last_update_ = true; | 529 loader_processed_last_update_ = true; |
542 | 530 |
543 InstantSuggestion suggestion; | 531 InstantSuggestion suggestion; |
544 if (!suggestions.empty()) | 532 if (!suggestions.empty()) |
545 suggestion = suggestions[0]; | 533 suggestion = suggestions[0]; |
546 | 534 |
547 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { | 535 if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { |
548 // We don't get an Update() when changing the omnibox due to a REPLACE | 536 // We don't get an Update() when changing the omnibox due to a REPLACE |
549 // suggestion (so that we don't inadvertently cause the preview to change | 537 // suggestion (so that we don't inadvertently cause the preview to change |
550 // what it's showing, as the user arrows up/down through the page-provided | 538 // what it's showing, as the user arrows up/down through the page-provided |
551 // suggestions). So, update these state variables here. | 539 // suggestions). So, update these state variables here. |
552 last_full_text_ = suggestion.text; | 540 last_full_text_ = suggestion.text; |
553 last_user_text_.clear(); | 541 last_user_text_.clear(); |
554 last_verbatim_ = true; | 542 last_verbatim_ = true; |
555 last_suggestion_ = InstantSuggestion(); | 543 last_suggestion_ = InstantSuggestion(); |
556 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH; | 544 last_match_was_search_ = suggestion.type == INSTANT_SUGGESTION_SEARCH; |
557 delegate_->SetInstantSuggestion(suggestion); | 545 browser_->SetInstantSuggestion(suggestion); |
558 } else { | 546 } else { |
559 // Suggestion text should be a full URL for URL suggestions, or the | 547 // Suggestion text should be a full URL for URL suggestions, or the |
560 // completion of a query for query suggestions. | 548 // completion of a query for query suggestions. |
561 if (suggestion.type == INSTANT_SUGGESTION_URL) { | 549 if (suggestion.type == INSTANT_SUGGESTION_URL) { |
562 if (!StartsWith(suggestion.text, ASCIIToUTF16("http://"), false) && | 550 if (!StartsWith(suggestion.text, ASCIIToUTF16("http://"), false) && |
563 !StartsWith(suggestion.text, ASCIIToUTF16("https://"), false)) | 551 !StartsWith(suggestion.text, ASCIIToUTF16("https://"), false)) |
564 suggestion.text = ASCIIToUTF16("http://") + suggestion.text; | 552 suggestion.text = ASCIIToUTF16("http://") + suggestion.text; |
565 } else if (StartsWith(suggestion.text, last_user_text_, true)) { | 553 } else if (StartsWith(suggestion.text, last_user_text_, true)) { |
566 // The user typed an exact prefix of the suggestion. | 554 // The user typed an exact prefix of the suggestion. |
567 suggestion.text.erase(0, last_user_text_.size()); | 555 suggestion.text.erase(0, last_user_text_.size()); |
568 } else if (!NormalizeAndStripPrefix(&suggestion.text, last_user_text_)) { | 556 } else if (!NormalizeAndStripPrefix(&suggestion.text, last_user_text_)) { |
569 // Unicode normalize and case-fold the user text and suggestion. If the | 557 // Unicode normalize and case-fold the user text and suggestion. If the |
570 // user text is a prefix, suggest the normalized, case-folded completion; | 558 // user text is a prefix, suggest the normalized, case-folded completion; |
571 // for instance, if the user types 'i' and the suggestion is 'INSTANT', | 559 // for instance, if the user types 'i' and the suggestion is 'INSTANT', |
572 // suggestion 'nstant'. Otherwise, the user text really isn't a prefix, | 560 // suggestion 'nstant'. Otherwise, the user text really isn't a prefix, |
573 // so suggest nothing. | 561 // so suggest nothing. |
574 suggestion.text.clear(); | 562 suggestion.text.clear(); |
575 } | 563 } |
576 | 564 |
577 last_suggestion_ = suggestion; | 565 last_suggestion_ = suggestion; |
578 | 566 |
579 // Set the suggested text if the suggestion behavior is | 567 // Set the suggested text if the suggestion behavior is |
580 // INSTANT_COMPLETE_NEVER irrespective of verbatim because in this case | 568 // INSTANT_COMPLETE_NEVER irrespective of verbatim because in this case |
581 // the suggested text does not get committed if the user presses enter. | 569 // the suggested text does not get committed if the user presses enter. |
582 if (suggestion.behavior == INSTANT_COMPLETE_NEVER || !last_verbatim_) | 570 if (suggestion.behavior == INSTANT_COMPLETE_NEVER || !last_verbatim_) |
583 delegate_->SetInstantSuggestion(suggestion); | 571 browser_->SetInstantSuggestion(suggestion); |
584 } | 572 } |
585 | 573 |
586 if (mode_ != SUGGEST) | 574 Show(100, INSTANT_SIZE_PERCENT); |
587 Show(100, INSTANT_SIZE_PERCENT); | |
588 } | 575 } |
589 | 576 |
590 void InstantController::CommitInstantLoader(InstantLoader* loader) { | 577 void InstantController::CommitInstantLoader(InstantLoader* loader) { |
591 if (loader_ != loader || !model_.is_ready() || IsOutOfDate()) | 578 if (loader_ != loader || !model_.is_ready() || IsOutOfDate()) |
592 return; | 579 return; |
593 | 580 |
594 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); | 581 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); |
595 } | 582 } |
596 | 583 |
597 void InstantController::ShowInstantPreview(InstantLoader* loader, | 584 void InstantController::ShowInstantPreview(InstantLoader* loader, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 void InstantController::SwappedTabContents(InstantLoader* loader) { | 624 void InstantController::SwappedTabContents(InstantLoader* loader) { |
638 if (loader_ == loader) | 625 if (loader_ == loader) |
639 model_.SetPreviewContents(GetPreviewContents()); | 626 model_.SetPreviewContents(GetPreviewContents()); |
640 } | 627 } |
641 | 628 |
642 void InstantController::InstantLoaderContentsFocused(InstantLoader* loader) { | 629 void InstantController::InstantLoaderContentsFocused(InstantLoader* loader) { |
643 #if defined(USE_AURA) | 630 #if defined(USE_AURA) |
644 // On aura the omnibox only receives a focus lost if we initiate the focus | 631 // On aura the omnibox only receives a focus lost if we initiate the focus |
645 // change. This does that. | 632 // change. This does that. |
646 if (model_.is_ready() && !IsOutOfDate()) | 633 if (model_.is_ready() && !IsOutOfDate()) |
647 delegate_->InstantPreviewFocused(); | 634 browser_->InstantPreviewFocused(); |
648 #endif | 635 #endif |
649 } | 636 } |
650 | 637 |
651 InstantController::InstantController(InstantControllerDelegate* delegate, | 638 InstantController::InstantController(chrome::BrowserInstantController* browser, |
652 Mode mode) | 639 Mode mode) |
653 : delegate_(delegate), | 640 : browser_(browser), |
654 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 641 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
655 mode_(mode), | 642 mode_(mode), |
656 last_active_tab_(NULL), | 643 last_active_tab_(NULL), |
657 last_verbatim_(false), | 644 last_verbatim_(false), |
658 last_transition_type_(content::PAGE_TRANSITION_LINK), | 645 last_transition_type_(content::PAGE_TRANSITION_LINK), |
659 last_match_was_search_(false), | 646 last_match_was_search_(false), |
660 loader_processed_last_update_(false), | 647 loader_processed_last_update_(false), |
661 is_omnibox_focused_(false), | 648 is_omnibox_focused_(false), |
662 active_tab_is_ntp_(false) { | 649 active_tab_is_ntp_(false) { |
663 } | 650 } |
(...skipping 17 matching lines...) Expand all Loading... |
681 // Reset the loader timer. | 668 // Reset the loader timer. |
682 stale_loader_timer_.Stop(); | 669 stale_loader_timer_.Stop(); |
683 stale_loader_timer_.Start( | 670 stale_loader_timer_.Start( |
684 FROM_HERE, | 671 FROM_HERE, |
685 base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this, | 672 base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this, |
686 &InstantController::OnStaleLoader); | 673 &InstantController::OnStaleLoader); |
687 } | 674 } |
688 } | 675 } |
689 | 676 |
690 bool InstantController::CreateDefaultLoader() { | 677 bool InstantController::CreateDefaultLoader() { |
691 const TabContents* active_tab = delegate_->GetActiveTabContents(); | 678 const TabContents* active_tab = browser_->GetActiveTabContents(); |
692 | 679 |
693 // We could get here with no active tab if the Browser is closing. | 680 // We could get here with no active tab if the Browser is closing. |
694 if (!active_tab) | 681 if (!active_tab) |
695 return false; | 682 return false; |
696 | 683 |
697 const TemplateURL* template_url = | 684 const TemplateURL* template_url = |
698 TemplateURLServiceFactory::GetForProfile(active_tab->profile())-> | 685 TemplateURLServiceFactory::GetForProfile(active_tab->profile())-> |
699 GetDefaultSearchProvider(); | 686 GetDefaultSearchProvider(); |
700 const GURL& tab_url = active_tab->web_contents()->GetURL(); | 687 const GURL& tab_url = active_tab->web_contents()->GetURL(); |
701 std::string instant_url; | 688 std::string instant_url; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 AddPreviewUsageForHistogram(mode_, PREVIEW_SHOWED); | 730 AddPreviewUsageForHistogram(mode_, PREVIEW_SHOWED); |
744 model_.SetDisplayState(InstantModel::QUERY_RESULTS, height, units); | 731 model_.SetDisplayState(InstantModel::QUERY_RESULTS, height, units); |
745 } | 732 } |
746 | 733 |
747 void InstantController::SendBoundsToPage() { | 734 void InstantController::SendBoundsToPage() { |
748 if (last_omnibox_bounds_ == omnibox_bounds_ || IsOutOfDate() || | 735 if (last_omnibox_bounds_ == omnibox_bounds_ || IsOutOfDate() || |
749 !GetPreviewContents() || loader_->IsPointerDownFromActivate()) | 736 !GetPreviewContents() || loader_->IsPointerDownFromActivate()) |
750 return; | 737 return; |
751 | 738 |
752 last_omnibox_bounds_ = omnibox_bounds_; | 739 last_omnibox_bounds_ = omnibox_bounds_; |
753 gfx::Rect preview_bounds = delegate_->GetInstantBounds(); | 740 gfx::Rect preview_bounds = browser_->GetInstantBounds(); |
754 gfx::Rect intersection = omnibox_bounds_; | 741 gfx::Rect intersection = omnibox_bounds_; |
755 intersection.Intersect(preview_bounds); | 742 intersection.Intersect(preview_bounds); |
756 | 743 |
757 // Translate into window coordinates. | 744 // Translate into window coordinates. |
758 if (!intersection.IsEmpty()) { | 745 if (!intersection.IsEmpty()) { |
759 intersection.Offset(-preview_bounds.origin().x(), | 746 intersection.Offset(-preview_bounds.origin().x(), |
760 -preview_bounds.origin().y()); | 747 -preview_bounds.origin().y()); |
761 } | 748 } |
762 | 749 |
763 // In the current Chrome UI, these must always be true so they sanity check | 750 // In the current Chrome UI, these must always be true so they sanity check |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 blacklisted_urls_.find(*instant_url); | 807 blacklisted_urls_.find(*instant_url); |
821 if (iter != blacklisted_urls_.end() && | 808 if (iter != blacklisted_urls_.end() && |
822 iter->second > kMaxInstantSupportFailures) | 809 iter->second > kMaxInstantSupportFailures) |
823 return false; | 810 return false; |
824 | 811 |
825 return true; | 812 return true; |
826 } | 813 } |
827 | 814 |
828 bool InstantController::IsOutOfDate() const { | 815 bool InstantController::IsOutOfDate() const { |
829 return !last_active_tab_ || | 816 return !last_active_tab_ || |
830 last_active_tab_ != delegate_->GetActiveTabContents(); | 817 last_active_tab_ != browser_->GetActiveTabContents(); |
831 } | 818 } |
OLD | NEW |