| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 extended_enabled_(extended_enabled), | 173 extended_enabled_(extended_enabled), |
| 174 instant_enabled_(false), | 174 instant_enabled_(false), |
| 175 use_local_preview_only_(use_local_preview_only), | 175 use_local_preview_only_(use_local_preview_only), |
| 176 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 176 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 177 last_omnibox_text_has_inline_autocompletion_(false), | 177 last_omnibox_text_has_inline_autocompletion_(false), |
| 178 last_verbatim_(false), | 178 last_verbatim_(false), |
| 179 last_transition_type_(content::PAGE_TRANSITION_LINK), | 179 last_transition_type_(content::PAGE_TRANSITION_LINK), |
| 180 last_match_was_search_(false), | 180 last_match_was_search_(false), |
| 181 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), | 181 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), |
| 182 start_margin_(0), | 182 start_margin_(0), |
| 183 end_margin_(0), | 183 width_(0), |
| 184 allow_preview_to_show_search_suggestions_(false) { | 184 allow_preview_to_show_search_suggestions_(false) { |
| 185 } | 185 } |
| 186 | 186 |
| 187 InstantController::~InstantController() { | 187 InstantController::~InstantController() { |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool InstantController::Update(const AutocompleteMatch& match, | 190 bool InstantController::Update(const AutocompleteMatch& match, |
| 191 const string16& user_text, | 191 const string16& user_text, |
| 192 const string16& full_text, | 192 const string16& full_text, |
| 193 size_t selection_start, | 193 size_t selection_start, |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 if (popup_bounds_.height() > last_popup_bounds_.height()) { | 422 if (popup_bounds_.height() > last_popup_bounds_.height()) { |
| 423 update_bounds_timer_.Stop(); | 423 update_bounds_timer_.Stop(); |
| 424 SendPopupBoundsToPage(); | 424 SendPopupBoundsToPage(); |
| 425 } else if (!update_bounds_timer_.IsRunning()) { | 425 } else if (!update_bounds_timer_.IsRunning()) { |
| 426 update_bounds_timer_.Start(FROM_HERE, | 426 update_bounds_timer_.Start(FROM_HERE, |
| 427 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, | 427 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, |
| 428 &InstantController::SendPopupBoundsToPage); | 428 &InstantController::SendPopupBoundsToPage); |
| 429 } | 429 } |
| 430 } | 430 } |
| 431 | 431 |
| 432 void InstantController::SetMarginSize(int start, int end) { | 432 void InstantController::SetStartMarginAndWidth(int margin, int width) { |
| 433 if (!extended_enabled_ || (start_margin_ == start && end_margin_ == end)) | 433 if (!extended_enabled_ || (start_margin_ == margin && width_ == width)) |
| 434 return; | 434 return; |
| 435 | 435 |
| 436 start_margin_ = start; | 436 start_margin_ = margin; |
| 437 end_margin_ = end; | 437 width_ = width; |
| 438 if (loader_) | 438 if (loader_) |
| 439 loader_->SetMarginSize(start_margin_, end_margin_); | 439 loader_->SetStartMarginAndWidth(margin, width); |
| 440 if (instant_tab_) | 440 if (instant_tab_) |
| 441 instant_tab_->SetMarginSize(start_margin_, end_margin_); | 441 instant_tab_->SetStartMarginAndWidth(margin, width); |
| 442 } | 442 } |
| 443 | 443 |
| 444 void InstantController::HandleAutocompleteResults( | 444 void InstantController::HandleAutocompleteResults( |
| 445 const std::vector<AutocompleteProvider*>& providers) { | 445 const std::vector<AutocompleteProvider*>& providers) { |
| 446 if (!extended_enabled_) | 446 if (!extended_enabled_) |
| 447 return; | 447 return; |
| 448 | 448 |
| 449 if (!instant_tab_ && !loader_) | 449 if (!instant_tab_ && !loader_) |
| 450 return; | 450 return; |
| 451 | 451 |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 } | 957 } |
| 958 | 958 |
| 959 void InstantController::InstantLoaderRenderViewCreated() { | 959 void InstantController::InstantLoaderRenderViewCreated() { |
| 960 if (!extended_enabled_) | 960 if (!extended_enabled_) |
| 961 return; | 961 return; |
| 962 | 962 |
| 963 // Ensure the searchbox API has the correct initial state. | 963 // Ensure the searchbox API has the correct initial state. |
| 964 loader_->SetDisplayInstantResults(instant_enabled_); | 964 loader_->SetDisplayInstantResults(instant_enabled_); |
| 965 loader_->SearchModeChanged(search_mode_); | 965 loader_->SearchModeChanged(search_mode_); |
| 966 loader_->KeyCaptureChanged(omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); | 966 loader_->KeyCaptureChanged(omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); |
| 967 loader_->SetMarginSize(start_margin_, end_margin_); | 967 loader_->SetStartMarginAndWidth(start_margin_, width_); |
| 968 loader_->InitializeFonts(); | 968 loader_->InitializeFonts(); |
| 969 } | 969 } |
| 970 | 970 |
| 971 void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { | 971 void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { |
| 972 // If the preview is showing custom NTP content, don't hide it, commit it | 972 // If the preview is showing custom NTP content, don't hide it, commit it |
| 973 // (no matter where the user clicked) or try to recreate it. | 973 // (no matter where the user clicked) or try to recreate it. |
| 974 if (model_.mode().is_ntp()) | 974 if (model_.mode().is_ntp()) |
| 975 return; | 975 return; |
| 976 | 976 |
| 977 // If the preview is not showing at all, recreate it if it's stale. | 977 // If the preview is not showing at all, recreate it if it's stale. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 | 1087 |
| 1088 void InstantController::ResetInstantTab() { | 1088 void InstantController::ResetInstantTab() { |
| 1089 // Do not wire up the InstantTab if instant should only use local previews, to | 1089 // Do not wire up the InstantTab if instant should only use local previews, to |
| 1090 // prevent it from sending data to the page. | 1090 // prevent it from sending data to the page. |
| 1091 if (search_mode_.is_origin_search() && !use_local_preview_only_) { | 1091 if (search_mode_.is_origin_search() && !use_local_preview_only_) { |
| 1092 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 1092 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
| 1093 if (!instant_tab_ || active_tab != instant_tab_->contents()) { | 1093 if (!instant_tab_ || active_tab != instant_tab_->contents()) { |
| 1094 instant_tab_.reset(new InstantTab(this, active_tab)); | 1094 instant_tab_.reset(new InstantTab(this, active_tab)); |
| 1095 instant_tab_->Init(); | 1095 instant_tab_->Init(); |
| 1096 instant_tab_->SetDisplayInstantResults(instant_enabled_); | 1096 instant_tab_->SetDisplayInstantResults(instant_enabled_); |
| 1097 instant_tab_->SetMarginSize(start_margin_, end_margin_); | 1097 instant_tab_->SetStartMarginAndWidth(start_margin_, width_); |
| 1098 instant_tab_->InitializeFonts(); | 1098 instant_tab_->InitializeFonts(); |
| 1099 } | 1099 } |
| 1100 | 1100 |
| 1101 // Hide the |loader_| since we are now using |instant_tab_| instead. | 1101 // Hide the |loader_| since we are now using |instant_tab_| instead. |
| 1102 HideLoader(); | 1102 HideLoader(); |
| 1103 } else { | 1103 } else { |
| 1104 instant_tab_.reset(); | 1104 instant_tab_.reset(); |
| 1105 } | 1105 } |
| 1106 } | 1106 } |
| 1107 | 1107 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST); | 1299 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST); |
| 1300 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 1300 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
| 1301 "GetInstantURL: Instant URL blacklisted: url=%s", | 1301 "GetInstantURL: Instant URL blacklisted: url=%s", |
| 1302 instant_url->c_str())); | 1302 instant_url->c_str())); |
| 1303 return false; | 1303 return false; |
| 1304 } | 1304 } |
| 1305 } | 1305 } |
| 1306 | 1306 |
| 1307 return true; | 1307 return true; |
| 1308 } | 1308 } |
| OLD | NEW |