OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/instant/instant_tab.h" |
| 6 |
| 7 #include "chrome/browser/instant/instant_controller.h" |
| 8 |
| 9 InstantTab::InstantTab(InstantController* controller, |
| 10 content::WebContents* contents) |
| 11 : client_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 12 controller_(controller), |
| 13 contents_(contents), |
| 14 supports_instant_(false) { |
| 15 } |
| 16 |
| 17 InstantTab::~InstantTab() { |
| 18 } |
| 19 |
| 20 void InstantTab::Init() { |
| 21 client_.SetContents(contents_); |
| 22 client_.DetermineIfPageSupportsInstant(); |
| 23 } |
| 24 |
| 25 void InstantTab::Update(const string16& text, |
| 26 size_t selection_start, |
| 27 size_t selection_end, |
| 28 bool verbatim) { |
| 29 client_.Update(text, selection_start, selection_end, verbatim); |
| 30 } |
| 31 |
| 32 void InstantTab::Submit(const string16& text) { |
| 33 client_.Submit(text); |
| 34 } |
| 35 |
| 36 void InstantTab::SendAutocompleteResults( |
| 37 const std::vector<InstantAutocompleteResult>& results) { |
| 38 client_.SendAutocompleteResults(results); |
| 39 } |
| 40 |
| 41 void InstantTab::UpOrDownKeyPressed(int count) { |
| 42 client_.UpOrDownKeyPressed(count); |
| 43 } |
| 44 |
| 45 void InstantTab::SetSuggestions( |
| 46 const std::vector<InstantSuggestion>& suggestions) { |
| 47 InstantSupportDetermined(true); |
| 48 controller_->SetSuggestions(contents_, suggestions); |
| 49 } |
| 50 |
| 51 void InstantTab::InstantSupportDetermined(bool supports_instant) { |
| 52 // If we had already determined that the page supports Instant, nothing to do. |
| 53 if (supports_instant_) |
| 54 return; |
| 55 |
| 56 supports_instant_ = supports_instant; |
| 57 |
| 58 // If the page doesn't support Instant, stop communicating with it. |
| 59 if (!supports_instant) |
| 60 client_.SetContents(NULL); |
| 61 |
| 62 controller_->InstantSupportDetermined(contents_, supports_instant); |
| 63 } |
| 64 |
| 65 void InstantTab::ShowInstantPreview(InstantShownReason /* reason */, |
| 66 int /* height */, |
| 67 InstantSizeUnits /* units */) { |
| 68 // The page is a committed tab (i.e., always showing), so nothing to do. |
| 69 } |
OLD | NEW |