Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / ui / search / instant_page.cc
blob9ffc0b76e3d04b59b0c76b9ad5cfbebdf60e63ba
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() {
25 if (contents())
26 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this);
29 bool InstantPage::supports_instant() const {
30 return contents() ?
31 SearchTabHelper::FromWebContents(contents())->SupportsInstant() : false;
34 const std::string& InstantPage::instant_url() const {
35 return instant_url_;
38 bool InstantPage::IsLocal() const {
39 return contents() &&
40 contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl);
43 InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url,
44 Profile* profile, bool is_incognito)
45 : profile_(profile),
46 delegate_(delegate),
47 instant_url_(instant_url),
48 is_incognito_(is_incognito) {
51 void InstantPage::SetContents(content::WebContents* web_contents) {
52 ClearContents();
54 if (!web_contents)
55 return;
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() {
67 return false;
70 void InstantPage::DidCommitProvisionalLoadForFrame(
71 int64 /* frame_id */,
72 const base::string16& frame_unique_name,
73 bool is_main_frame,
74 const GURL& url,
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)
92 ClearContents();
95 void InstantPage::ClearContents() {
96 if (contents())
97 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this);
99 Observe(NULL);