| 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/ui/search/search_model.h" | 7 #include "chrome/browser/ui/search/search_model.h" |
| 8 #include "chrome/browser/ui/search/search_tab_helper.h" | 8 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 bool InstantPage::IsLocal() const { | 28 bool InstantPage::IsLocal() const { |
| 29 return web_contents() && | 29 return web_contents() && |
| 30 web_contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl); | 30 web_contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl); |
| 31 } | 31 } |
| 32 | 32 |
| 33 InstantPage::InstantPage(Delegate* delegate) | 33 InstantPage::InstantPage(Delegate* delegate) |
| 34 : delegate_(delegate) { | 34 : delegate_(delegate) { |
| 35 } | 35 } |
| 36 | 36 |
| 37 void InstantPage::SetContents(content::WebContents* new_web_contents) { | 37 void InstantPage::Init(content::WebContents* new_web_contents) { |
| 38 ClearContents(); | 38 ClearContents(); |
| 39 | 39 |
| 40 if (!new_web_contents) | 40 if (!new_web_contents) |
| 41 return; | 41 return; |
| 42 | 42 |
| 43 Observe(new_web_contents); | 43 Observe(new_web_contents); |
| 44 SearchModel* model = | 44 SearchModel* model = |
| 45 SearchTabHelper::FromWebContents(web_contents())->model(); | 45 SearchTabHelper::FromWebContents(web_contents())->model(); |
| 46 model->AddObserver(this); | 46 model->AddObserver(this); |
| 47 | 47 |
| 48 // Already know whether the page supports instant. | 48 // Already know whether the page supports instant. |
| 49 if (model->instant_support() != INSTANT_SUPPORT_UNKNOWN) | 49 if (model->instant_support() != INSTANT_SUPPORT_UNKNOWN) |
| 50 InstantSupportDetermined(model->instant_support() == INSTANT_SUPPORT_YES); | 50 InstantSupportDetermined(model->instant_support() == INSTANT_SUPPORT_YES); |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool InstantPage::ShouldProcessAboutToNavigateMainFrame() { | |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 void InstantPage::DidCommitProvisionalLoadForFrame( | 53 void InstantPage::DidCommitProvisionalLoadForFrame( |
| 58 content::RenderFrameHost* render_frame_host, | 54 content::RenderFrameHost* render_frame_host, |
| 59 const GURL& url, | 55 const GURL& url, |
| 60 ui::PageTransition /* transition_type */) { | 56 ui::PageTransition /* transition_type */) { |
| 61 if (!render_frame_host->GetParent() && | 57 if (!render_frame_host->GetParent()) { |
| 62 ShouldProcessAboutToNavigateMainFrame()) { | |
| 63 delegate_->InstantPageAboutToNavigateMainFrame(web_contents(), url); | 58 delegate_->InstantPageAboutToNavigateMainFrame(web_contents(), url); |
| 64 } | 59 } |
| 65 } | 60 } |
| 66 | 61 |
| 67 void InstantPage::ModelChanged(const SearchModel::State& old_state, | 62 void InstantPage::ModelChanged(const SearchModel::State& old_state, |
| 68 const SearchModel::State& new_state) { | 63 const SearchModel::State& new_state) { |
| 69 if (old_state.instant_support != new_state.instant_support) | 64 if (old_state.instant_support != new_state.instant_support) |
| 70 InstantSupportDetermined(new_state.instant_support == INSTANT_SUPPORT_YES); | 65 InstantSupportDetermined(new_state.instant_support == INSTANT_SUPPORT_YES); |
| 71 } | 66 } |
| 72 | 67 |
| 73 void InstantPage::InstantSupportDetermined(bool supports_instant) { | 68 void InstantPage::InstantSupportDetermined(bool supports_instant) { |
| 74 delegate_->InstantSupportDetermined(web_contents(), supports_instant); | 69 delegate_->InstantSupportDetermined(web_contents(), supports_instant); |
| 75 | 70 |
| 76 // If the page doesn't support Instant, stop listening to it. | 71 // If the page doesn't support Instant, stop listening to it. |
| 77 if (!supports_instant) | 72 if (!supports_instant) |
| 78 ClearContents(); | 73 ClearContents(); |
| 79 } | 74 } |
| 80 | 75 |
| 81 void InstantPage::ClearContents() { | 76 void InstantPage::ClearContents() { |
| 82 if (web_contents()) { | 77 if (web_contents()) { |
| 83 SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver( | 78 SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver( |
| 84 this); | 79 this); |
| 85 } | 80 } |
| 86 | 81 |
| 87 Observe(NULL); | 82 Observe(NULL); |
| 88 } | 83 } |
| OLD | NEW |