| 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/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/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 : browser_(browser), | 174 : browser_(browser), |
| 175 extended_enabled_(extended_enabled), | 175 extended_enabled_(extended_enabled), |
| 176 instant_enabled_(false), | 176 instant_enabled_(false), |
| 177 use_local_preview_only_(true), | 177 use_local_preview_only_(true), |
| 178 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 178 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 179 last_omnibox_text_has_inline_autocompletion_(false), | 179 last_omnibox_text_has_inline_autocompletion_(false), |
| 180 last_verbatim_(false), | 180 last_verbatim_(false), |
| 181 last_transition_type_(content::PAGE_TRANSITION_LINK), | 181 last_transition_type_(content::PAGE_TRANSITION_LINK), |
| 182 last_match_was_search_(false), | 182 last_match_was_search_(false), |
| 183 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), | 183 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), |
| 184 start_margin_(0), | 184 omnibox_start_margin_(0), |
| 185 end_margin_(0), | 185 omnibox_width_(0), |
| 186 allow_preview_to_show_search_suggestions_(false) { | 186 allow_preview_to_show_search_suggestions_(false) { |
| 187 } | 187 } |
| 188 | 188 |
| 189 InstantController::~InstantController() { | 189 InstantController::~InstantController() { |
| 190 } | 190 } |
| 191 | 191 |
| 192 bool InstantController::Update(const AutocompleteMatch& match, | 192 bool InstantController::Update(const AutocompleteMatch& match, |
| 193 const string16& user_text, | 193 const string16& user_text, |
| 194 const string16& full_text, | 194 const string16& full_text, |
| 195 size_t selection_start, | 195 size_t selection_start, |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 if (popup_bounds_.height() > last_popup_bounds_.height()) { | 436 if (popup_bounds_.height() > last_popup_bounds_.height()) { |
| 437 update_bounds_timer_.Stop(); | 437 update_bounds_timer_.Stop(); |
| 438 SendPopupBoundsToPage(); | 438 SendPopupBoundsToPage(); |
| 439 } else if (!update_bounds_timer_.IsRunning()) { | 439 } else if (!update_bounds_timer_.IsRunning()) { |
| 440 update_bounds_timer_.Start(FROM_HERE, | 440 update_bounds_timer_.Start(FROM_HERE, |
| 441 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, | 441 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, |
| 442 &InstantController::SendPopupBoundsToPage); | 442 &InstantController::SendPopupBoundsToPage); |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 | 445 |
| 446 void InstantController::SetMarginSize(int start, int end) { | 446 void InstantController::SetStartMarginAndWidth(int margin, int width) { |
| 447 if (!extended_enabled_ || (start_margin_ == start && end_margin_ == end)) | 447 if (!extended_enabled_ || |
| 448 (omnibox_start_margin_ == margin && omnibox_width_ == width)) |
| 448 return; | 449 return; |
| 449 | 450 |
| 450 start_margin_ = start; | 451 omnibox_start_margin_ = margin; |
| 451 end_margin_ = end; | 452 omnibox_width_ = width; |
| 452 if (overlay_) | 453 if (overlay_) |
| 453 overlay_->SetMarginSize(start_margin_, end_margin_); | 454 overlay_->SetStartMarginAndWidth(omnibox_start_margin_, omnibox_width_); |
| 454 if (ntp_) | 455 if (ntp_) |
| 455 ntp_->SetMarginSize(start_margin_, end_margin_); | 456 ntp_->SetStartMarginAndWidth(omnibox_start_margin_, omnibox_width_); |
| 456 if (instant_tab_) | 457 if (instant_tab_) |
| 457 instant_tab_->SetMarginSize(start_margin_, end_margin_); | 458 instant_tab_->SetStartMarginAndWidth(margin, width); |
| 458 } | 459 } |
| 459 | 460 |
| 460 void InstantController::HandleAutocompleteResults( | 461 void InstantController::HandleAutocompleteResults( |
| 461 const std::vector<AutocompleteProvider*>& providers) { | 462 const std::vector<AutocompleteProvider*>& providers) { |
| 462 if (!extended_enabled_) | 463 if (!extended_enabled_) |
| 463 return; | 464 return; |
| 464 | 465 |
| 465 if (!instant_tab_ && !overlay_) | 466 if (!instant_tab_ && !overlay_) |
| 466 return; | 467 return; |
| 467 | 468 |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 | 850 |
| 850 // Update theme info so that the page picks it up. | 851 // Update theme info so that the page picks it up. |
| 851 browser_->UpdateThemeInfoForPreview(); | 852 browser_->UpdateThemeInfoForPreview(); |
| 852 | 853 |
| 853 // Ensure the searchbox API has the correct initial state. | 854 // Ensure the searchbox API has the correct initial state. |
| 854 if (IsContentsFrom(overlay(), contents)) { | 855 if (IsContentsFrom(overlay(), contents)) { |
| 855 overlay_->SetDisplayInstantResults(instant_enabled_); | 856 overlay_->SetDisplayInstantResults(instant_enabled_); |
| 856 overlay_->SearchModeChanged(search_mode_); | 857 overlay_->SearchModeChanged(search_mode_); |
| 857 overlay_->KeyCaptureChanged( | 858 overlay_->KeyCaptureChanged( |
| 858 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); | 859 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); |
| 859 overlay_->SetMarginSize(start_margin_, end_margin_); | 860 overlay_->SetStartMarginAndWidth(omnibox_start_margin_, omnibox_width_); |
| 860 overlay_->InitializeFonts(); | 861 overlay_->InitializeFonts(); |
| 861 } else if (IsContentsFrom(ntp(), contents)) { | 862 } else if (IsContentsFrom(ntp(), contents)) { |
| 862 ntp_->SetDisplayInstantResults(instant_enabled_); | 863 ntp_->SetDisplayInstantResults(instant_enabled_); |
| 863 ntp_->SetMarginSize(start_margin_, end_margin_); | 864 ntp_->SetStartMarginAndWidth(omnibox_start_margin_, omnibox_width_); |
| 864 ntp_->InitializeFonts(); | 865 ntp_->InitializeFonts(); |
| 865 } else { | 866 } else { |
| 866 NOTREACHED(); | 867 NOTREACHED(); |
| 867 } | 868 } |
| 868 } | 869 } |
| 869 | 870 |
| 870 void InstantController::InstantSupportDetermined( | 871 void InstantController::InstantSupportDetermined( |
| 871 const content::WebContents* contents, | 872 const content::WebContents* contents, |
| 872 bool supports_instant) { | 873 bool supports_instant) { |
| 873 if (IsContentsFrom(instant_tab(), contents)) { | 874 if (IsContentsFrom(instant_tab(), contents)) { |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 // Do not wire up the InstantTab if instant should only use local previews, to | 1162 // Do not wire up the InstantTab if instant should only use local previews, to |
| 1162 // prevent it from sending data to the page. | 1163 // prevent it from sending data to the page. |
| 1163 if (!search_mode_.is_origin_default() && !use_local_preview_only_) { | 1164 if (!search_mode_.is_origin_default() && !use_local_preview_only_) { |
| 1164 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 1165 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
| 1165 if (!instant_tab_ || active_tab != instant_tab_->contents()) { | 1166 if (!instant_tab_ || active_tab != instant_tab_->contents()) { |
| 1166 instant_tab_.reset(new InstantTab(this)); | 1167 instant_tab_.reset(new InstantTab(this)); |
| 1167 instant_tab_->Init(active_tab); | 1168 instant_tab_->Init(active_tab); |
| 1168 // Update theme info for this tab. | 1169 // Update theme info for this tab. |
| 1169 browser_->UpdateThemeInfoForPreview(); | 1170 browser_->UpdateThemeInfoForPreview(); |
| 1170 instant_tab_->SetDisplayInstantResults(instant_enabled_); | 1171 instant_tab_->SetDisplayInstantResults(instant_enabled_); |
| 1171 instant_tab_->SetMarginSize(start_margin_, end_margin_); | 1172 instant_tab_->SetStartMarginAndWidth( |
| 1173 omnibox_start_margin_, omnibox_width_); |
| 1172 instant_tab_->InitializeFonts(); | 1174 instant_tab_->InitializeFonts(); |
| 1173 instant_tab_->KeyCaptureChanged( | 1175 instant_tab_->KeyCaptureChanged( |
| 1174 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); | 1176 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); |
| 1175 } | 1177 } |
| 1176 | 1178 |
| 1177 // Hide the |overlay_| since we are now using |instant_tab_| instead. | 1179 // Hide the |overlay_| since we are now using |instant_tab_| instead. |
| 1178 HideOverlay(); | 1180 HideOverlay(); |
| 1179 } else { | 1181 } else { |
| 1180 instant_tab_.reset(); | 1182 instant_tab_.reset(); |
| 1181 } | 1183 } |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1398 delete overlay_->ReleaseContents().release(); | 1400 delete overlay_->ReleaseContents().release(); |
| 1399 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); | 1401 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); |
| 1400 EnsureOverlayIsCurrent(false); | 1402 EnsureOverlayIsCurrent(false); |
| 1401 } | 1403 } |
| 1402 | 1404 |
| 1403 void InstantController::RemoveFromBlacklist(const std::string& url) { | 1405 void InstantController::RemoveFromBlacklist(const std::string& url) { |
| 1404 if (blacklisted_urls_.erase(url)) { | 1406 if (blacklisted_urls_.erase(url)) { |
| 1405 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); | 1407 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); |
| 1406 } | 1408 } |
| 1407 } | 1409 } |
| OLD | NEW |