OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/search/instant_page.h" | 5 #include "chrome/browser/ui/search/instant_page.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/search/search.h" | 8 #include "chrome/browser/search/search.h" |
9 #include "chrome/browser/ui/search/search_model.h" | 9 #include "chrome/browser/ui/search/search_model.h" |
10 #include "chrome/browser/ui/search/search_tab_helper.h" | 10 #include "chrome/browser/ui/search/search_tab_helper.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 int64 /* frame_id */, | 73 int64 /* frame_id */, |
74 const base::string16& frame_unique_name, | 74 const base::string16& frame_unique_name, |
75 bool is_main_frame, | 75 bool is_main_frame, |
76 const GURL& url, | 76 const GURL& url, |
77 content::PageTransition /* transition_type */, | 77 content::PageTransition /* transition_type */, |
78 content::RenderViewHost* /* render_view_host */) { | 78 content::RenderViewHost* /* render_view_host */) { |
79 if (is_main_frame && ShouldProcessAboutToNavigateMainFrame()) | 79 if (is_main_frame && ShouldProcessAboutToNavigateMainFrame()) |
80 delegate_->InstantPageAboutToNavigateMainFrame(contents(), url); | 80 delegate_->InstantPageAboutToNavigateMainFrame(contents(), url); |
81 } | 81 } |
82 | 82 |
83 void InstantPage::DidNavigateMainFrame( | |
84 const content::LoadCommittedDetails& details, | |
85 const content::FrameNavigateParams& /* params */) { | |
86 // A 204 can be sent by the search provider as a lightweight signal | |
87 // to fall back to the local page, and we obviously want to fall back | |
88 // if we get any response code that indicates an error. | |
89 if (details.http_status_code == 204 || details.http_status_code >= 400) | |
90 delegate_->InstantPageLoadFailed(contents()); | |
91 } | |
92 | |
93 void InstantPage::DidFailProvisionalLoad( | |
94 int64 /* frame_id */, | |
95 const base::string16& frame_unique_name, | |
96 bool is_main_frame, | |
97 const GURL& /* validated_url */, | |
98 int /* error_code */, | |
99 const base::string16& /* error_description */, | |
100 content::RenderViewHost* /* render_view_host */) { | |
101 if (is_main_frame) | |
102 delegate_->InstantPageLoadFailed(contents()); | |
103 } | |
104 | |
105 void InstantPage::ModelChanged(const SearchModel::State& old_state, | 83 void InstantPage::ModelChanged(const SearchModel::State& old_state, |
106 const SearchModel::State& new_state) { | 84 const SearchModel::State& new_state) { |
107 if (old_state.instant_support != new_state.instant_support) | 85 if (old_state.instant_support != new_state.instant_support) |
108 InstantSupportDetermined(new_state.instant_support == INSTANT_SUPPORT_YES); | 86 InstantSupportDetermined(new_state.instant_support == INSTANT_SUPPORT_YES); |
109 } | 87 } |
110 | 88 |
111 void InstantPage::InstantSupportDetermined(bool supports_instant) { | 89 void InstantPage::InstantSupportDetermined(bool supports_instant) { |
112 delegate_->InstantSupportDetermined(contents(), supports_instant); | 90 delegate_->InstantSupportDetermined(contents(), supports_instant); |
113 | 91 |
114 // If the page doesn't support Instant, stop listening to it. | 92 // If the page doesn't support Instant, stop listening to it. |
115 if (!supports_instant) | 93 if (!supports_instant) |
116 ClearContents(); | 94 ClearContents(); |
117 } | 95 } |
118 | 96 |
119 void InstantPage::ClearContents() { | 97 void InstantPage::ClearContents() { |
120 if (contents()) | 98 if (contents()) |
121 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this); | 99 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this); |
122 | 100 |
123 sender()->SetContents(NULL); | 101 sender()->SetContents(NULL); |
124 Observe(NULL); | 102 Observe(NULL); |
125 } | 103 } |
OLD | NEW |