Chromium Code Reviews| 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" |
| 11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| 12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 13 #include "content/public/browser/navigation_controller.h" | 13 #include "content/public/browser/navigation_controller.h" |
| 14 #include "content/public/browser/navigation_details.h" | 14 #include "content/public/browser/navigation_details.h" |
| 15 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
| 16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/frame_navigate_params.h" | 20 #include "content/public/common/frame_navigate_params.h" |
| 21 | 21 |
| 22 InstantPage::Delegate::~Delegate() { | 22 InstantPage::Delegate::~Delegate() { |
| 23 } | 23 } |
| 24 | 24 |
| 25 InstantPage::~InstantPage() { | 25 InstantPage::~InstantPage() { |
| 26 if (contents()) | 26 if (web_contents()) { |
| 27 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this); | 27 SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver( |
| 28 this); | |
| 29 } | |
| 28 } | 30 } |
| 29 | 31 |
| 30 bool InstantPage::supports_instant() const { | 32 bool InstantPage::supports_instant() const { |
| 31 return contents() ? | 33 return web_contents() ? SearchTabHelper::FromWebContents(web_contents()) |
| 32 SearchTabHelper::FromWebContents(contents())->SupportsInstant() : false; | 34 ->SupportsInstant() |
| 35 : false; | |
|
Peter Kasting
2014/09/02 19:37:07
Nit: Shorter:
return web_contents() &&
Se
lucinka.brozkova
2014/09/03 08:16:25
Done.
| |
| 33 } | 36 } |
| 34 | 37 |
| 35 const std::string& InstantPage::instant_url() const { | 38 const std::string& InstantPage::instant_url() const { |
| 36 return instant_url_; | 39 return instant_url_; |
| 37 } | 40 } |
| 38 | 41 |
| 39 bool InstantPage::IsLocal() const { | 42 bool InstantPage::IsLocal() const { |
| 40 return contents() && | 43 return web_contents() && |
| 41 contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl); | 44 web_contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl); |
|
Peter Kasting
2014/09/02 19:37:07
Nit: Don't change indenting here
lucinka.brozkova
2014/09/03 08:16:25
Done.
| |
| 42 } | 45 } |
| 43 | 46 |
| 44 InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url, | 47 InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url, |
| 45 Profile* profile, bool is_incognito) | 48 Profile* profile, bool is_incognito) |
| 46 : profile_(profile), | 49 : profile_(profile), |
| 47 delegate_(delegate), | 50 delegate_(delegate), |
| 48 instant_url_(instant_url), | 51 instant_url_(instant_url), |
| 49 is_incognito_(is_incognito) { | 52 is_incognito_(is_incognito) { |
| 50 } | 53 } |
| 51 | 54 |
| 52 void InstantPage::SetContents(content::WebContents* web_contents) { | 55 void InstantPage::SetContents(content::WebContents* new_web_contents) { |
| 53 ClearContents(); | 56 ClearContents(); |
| 54 | 57 |
| 55 if (!web_contents) | 58 if (!new_web_contents) |
| 56 return; | 59 return; |
| 57 | 60 |
| 58 Observe(web_contents); | 61 Observe(new_web_contents); |
| 59 SearchModel* model = SearchTabHelper::FromWebContents(contents())->model(); | 62 SearchModel* model = |
| 63 SearchTabHelper::FromWebContents(web_contents())->model(); | |
| 60 model->AddObserver(this); | 64 model->AddObserver(this); |
| 61 | 65 |
| 62 // Already know whether the page supports instant. | 66 // Already know whether the page supports instant. |
| 63 if (model->instant_support() != INSTANT_SUPPORT_UNKNOWN) | 67 if (model->instant_support() != INSTANT_SUPPORT_UNKNOWN) |
| 64 InstantSupportDetermined(model->instant_support() == INSTANT_SUPPORT_YES); | 68 InstantSupportDetermined(model->instant_support() == INSTANT_SUPPORT_YES); |
| 65 } | 69 } |
| 66 | 70 |
| 67 bool InstantPage::ShouldProcessAboutToNavigateMainFrame() { | 71 bool InstantPage::ShouldProcessAboutToNavigateMainFrame() { |
| 68 return false; | 72 return false; |
| 69 } | 73 } |
| 70 | 74 |
| 71 void InstantPage::DidCommitProvisionalLoadForFrame( | 75 void InstantPage::DidCommitProvisionalLoadForFrame( |
| 72 content::RenderFrameHost* render_frame_host, | 76 content::RenderFrameHost* render_frame_host, |
| 73 const GURL& url, | 77 const GURL& url, |
| 74 content::PageTransition /* transition_type */) { | 78 content::PageTransition /* transition_type */) { |
| 75 if (!render_frame_host->GetParent() && | 79 if (!render_frame_host->GetParent() && |
| 76 ShouldProcessAboutToNavigateMainFrame()) | 80 ShouldProcessAboutToNavigateMainFrame()) |
| 77 delegate_->InstantPageAboutToNavigateMainFrame(contents(), url); | 81 delegate_->InstantPageAboutToNavigateMainFrame(web_contents(), url); |
| 78 } | 82 } |
| 79 | 83 |
| 80 void InstantPage::ModelChanged(const SearchModel::State& old_state, | 84 void InstantPage::ModelChanged(const SearchModel::State& old_state, |
| 81 const SearchModel::State& new_state) { | 85 const SearchModel::State& new_state) { |
| 82 if (old_state.instant_support != new_state.instant_support) | 86 if (old_state.instant_support != new_state.instant_support) |
| 83 InstantSupportDetermined(new_state.instant_support == INSTANT_SUPPORT_YES); | 87 InstantSupportDetermined(new_state.instant_support == INSTANT_SUPPORT_YES); |
| 84 } | 88 } |
| 85 | 89 |
| 86 void InstantPage::InstantSupportDetermined(bool supports_instant) { | 90 void InstantPage::InstantSupportDetermined(bool supports_instant) { |
| 87 delegate_->InstantSupportDetermined(contents(), supports_instant); | 91 delegate_->InstantSupportDetermined(web_contents(), supports_instant); |
| 88 | 92 |
| 89 // If the page doesn't support Instant, stop listening to it. | 93 // If the page doesn't support Instant, stop listening to it. |
| 90 if (!supports_instant) | 94 if (!supports_instant) |
| 91 ClearContents(); | 95 ClearContents(); |
| 92 } | 96 } |
| 93 | 97 |
| 94 void InstantPage::ClearContents() { | 98 void InstantPage::ClearContents() { |
| 95 if (contents()) | 99 if (web_contents()) { |
| 96 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this); | 100 SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver( |
| 101 this); | |
| 102 } | |
| 97 | 103 |
| 98 Observe(NULL); | 104 Observe(NULL); |
| 99 } | 105 } |
| OLD | NEW |