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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/search/instant_page.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/search/search.h"
9 #include "chrome/browser/ui/search/search_model.h"
10 #include "chrome/browser/ui/search/search_tab_helper.h"
11 #include "chrome/common/render_messages.h"
12 #include "chrome/common/url_constants.h"
13 #include "content/public/browser/navigation_controller.h"
14 #include "content/public/browser/navigation_details.h"
15 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/notification_source.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/frame_navigate_params.h"
21 InstantPage::Delegate::~Delegate() {
24 InstantPage::~InstantPage() {
26 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this);
29 bool InstantPage::supports_instant() const {
31 SearchTabHelper::FromWebContents(contents())->SupportsInstant() : false;
34 const std::string
& InstantPage::instant_url() const {
38 bool InstantPage::IsLocal() const {
40 contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl
);
43 InstantPage::InstantPage(Delegate
* delegate
, const std::string
& instant_url
,
44 Profile
* profile
, bool is_incognito
)
47 instant_url_(instant_url
),
48 is_incognito_(is_incognito
) {
51 void InstantPage::SetContents(content::WebContents
* web_contents
) {
57 Observe(web_contents
);
58 SearchModel
* model
= SearchTabHelper::FromWebContents(contents())->model();
59 model
->AddObserver(this);
61 // Already know whether the page supports instant.
62 if (model
->instant_support() != INSTANT_SUPPORT_UNKNOWN
)
63 InstantSupportDetermined(model
->instant_support() == INSTANT_SUPPORT_YES
);
66 bool InstantPage::ShouldProcessAboutToNavigateMainFrame() {
70 void InstantPage::DidCommitProvisionalLoadForFrame(
72 const base::string16
& frame_unique_name
,
75 content::PageTransition
/* transition_type */,
76 content::RenderViewHost
* /* render_view_host */) {
77 if (is_main_frame
&& ShouldProcessAboutToNavigateMainFrame())
78 delegate_
->InstantPageAboutToNavigateMainFrame(contents(), url
);
81 void InstantPage::ModelChanged(const SearchModel::State
& old_state
,
82 const SearchModel::State
& new_state
) {
83 if (old_state
.instant_support
!= new_state
.instant_support
)
84 InstantSupportDetermined(new_state
.instant_support
== INSTANT_SUPPORT_YES
);
87 void InstantPage::InstantSupportDetermined(bool supports_instant
) {
88 delegate_
->InstantSupportDetermined(contents(), supports_instant
);
90 // If the page doesn't support Instant, stop listening to it.
91 if (!supports_instant
)
95 void InstantPage::ClearContents() {
97 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this);