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_tab.h" | 5 #include "chrome/browser/instant/instant_tab.h" |
6 | 6 |
7 #include "chrome/browser/instant/instant_controller.h" | 7 #include "chrome/browser/instant/instant_controller.h" |
8 | 8 |
9 InstantTab::InstantTab(InstantController* controller, | 9 InstantTab::InstantTab(InstantController* controller, |
10 content::WebContents* contents) | 10 content::WebContents* contents) |
11 : client_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 11 : InstantPage(controller), |
12 controller_(controller), | 12 contents_(contents) { |
13 contents_(contents), | |
14 supports_instant_(false) { | |
15 } | 13 } |
16 | 14 |
17 InstantTab::~InstantTab() { | 15 InstantTab::~InstantTab() { |
18 } | 16 } |
19 | 17 |
20 void InstantTab::Init() { | 18 void InstantTab::Init() { |
21 client_.SetContents(contents_); | 19 api()->SetContents(contents_); |
22 client_.DetermineIfPageSupportsInstant(); | 20 api()->DetermineIfPageSupportsInstant(); |
23 } | 21 } |
24 | 22 |
25 void InstantTab::Update(const string16& text, | 23 void InstantTab::OnUpdate() { |
26 size_t selection_start, | |
27 size_t selection_end, | |
28 bool verbatim) { | |
29 client_.Update(text, selection_start, selection_end, verbatim); | |
30 } | 24 } |
31 | 25 |
32 void InstantTab::Submit(const string16& text) { | 26 bool InstantTab::OnRenderViewGone() const { |
33 client_.Submit(text); | 27 // For a committed page, a crash should not be handled differently. |
| 28 return false; |
34 } | 29 } |
35 | 30 |
36 void InstantTab::SendAutocompleteResults( | 31 bool InstantTab::OnAboutToNavigateMainFrame() const { |
37 const std::vector<InstantAutocompleteResult>& results) { | 32 // The client is a committed tab, navigations will happen as expected. |
38 client_.SendAutocompleteResults(results); | 33 return false; |
39 } | 34 } |
40 | 35 |
41 void InstantTab::SetDisplayInstantResults(bool display_instant_results) { | 36 bool InstantTab::OnSetSuggestions() const { |
42 client_.SetDisplayInstantResults(display_instant_results); | 37 return true; |
43 } | 38 } |
44 | 39 |
45 void InstantTab::UpOrDownKeyPressed(int count) { | 40 bool InstantTab::OnShowInstantPreview() const { |
46 client_.UpOrDownKeyPressed(count); | 41 // The page is a committed tab (i.e., always showing), so nothing to do. |
| 42 return false; |
47 } | 43 } |
48 | 44 |
49 void InstantTab::SetMarginSize(int start, int end) { | 45 bool InstantTab::OnStartCapturingKeyStrokes() const { |
50 client_.SetMarginSize(start, end); | 46 return true; |
51 } | 47 } |
52 | 48 |
53 void InstantTab::SetSuggestions( | 49 bool InstantTab::OnStopCapturingKeyStrokes() const { |
54 const std::vector<InstantSuggestion>& suggestions) { | 50 return true; |
55 InstantSupportDetermined(true); | |
56 controller_->SetSuggestions(contents_, suggestions); | |
57 } | 51 } |
58 | 52 |
59 void InstantTab::InstantSupportDetermined(bool supports_instant) { | 53 bool InstantTab::OnNavigateToURL() const { |
60 // If we had already determined that the page supports Instant, nothing to do. | 54 return true; |
61 if (supports_instant_) | |
62 return; | |
63 | |
64 supports_instant_ = supports_instant; | |
65 | |
66 // If the page doesn't support Instant, stop communicating with it. | |
67 if (!supports_instant) | |
68 client_.SetContents(NULL); | |
69 | |
70 controller_->InstantSupportDetermined(contents_, supports_instant); | |
71 } | 55 } |
72 | |
73 void InstantTab::ShowInstantPreview(InstantShownReason /* reason */, | |
74 int /* height */, | |
75 InstantSizeUnits /* units */) { | |
76 // The page is a committed tab (i.e., always showing), so nothing to do. | |
77 } | |
78 | |
79 void InstantTab::StartCapturingKeyStrokes() { | |
80 // We don't honor this call from committed tabs. | |
81 } | |
82 | |
83 void InstantTab::StopCapturingKeyStrokes() { | |
84 // We don't honor this call from committed tabs. | |
85 } | |
86 | |
87 void InstantTab::RenderViewGone() { | |
88 // For a commit page, a crash should not be handled differently. | |
89 } | |
90 | |
91 void InstantTab::AboutToNavigateMainFrame(const GURL& url) { | |
92 // The client is a committed tab, navigations will happen as expected. | |
93 } | |
94 | |
95 void InstantTab::NavigateToURL(const GURL& url, | |
96 content::PageTransition transition) { | |
97 controller_->NavigateToURL(url, transition); | |
98 } | |
OLD | NEW |