Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / search / instant_page.cc
blob9b4625dce9d5e6e9be718554d64b474f7fbac92a
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/url_constants.h"
12 #include "content/public/browser/navigation_controller.h"
13 #include "content/public/browser/navigation_details.h"
14 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/notification_source.h"
17 #include "content/public/browser/render_frame_host.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 (web_contents()) {
26 SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver(
27 this);
31 bool InstantPage::supports_instant() const {
32 return web_contents() &&
33 SearchTabHelper::FromWebContents(web_contents())->SupportsInstant();
36 const std::string& InstantPage::instant_url() const {
37 return instant_url_;
40 bool InstantPage::IsLocal() const {
41 return web_contents() &&
42 web_contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl);
45 InstantPage::InstantPage(Delegate* delegate,
46 const std::string& instant_url,
47 Profile* profile)
48 : profile_(profile),
49 delegate_(delegate),
50 instant_url_(instant_url) {
53 void InstantPage::SetContents(content::WebContents* new_web_contents) {
54 ClearContents();
56 if (!new_web_contents)
57 return;
59 Observe(new_web_contents);
60 SearchModel* model =
61 SearchTabHelper::FromWebContents(web_contents())->model();
62 model->AddObserver(this);
64 // Already know whether the page supports instant.
65 if (model->instant_support() != INSTANT_SUPPORT_UNKNOWN)
66 InstantSupportDetermined(model->instant_support() == INSTANT_SUPPORT_YES);
69 bool InstantPage::ShouldProcessAboutToNavigateMainFrame() {
70 return false;
73 void InstantPage::DidCommitProvisionalLoadForFrame(
74 content::RenderFrameHost* render_frame_host,
75 const GURL& url,
76 ui::PageTransition /* transition_type */) {
77 if (!render_frame_host->GetParent() &&
78 ShouldProcessAboutToNavigateMainFrame())
79 delegate_->InstantPageAboutToNavigateMainFrame(web_contents(), url);
82 void InstantPage::ModelChanged(const SearchModel::State& old_state,
83 const SearchModel::State& new_state) {
84 if (old_state.instant_support != new_state.instant_support)
85 InstantSupportDetermined(new_state.instant_support == INSTANT_SUPPORT_YES);
88 void InstantPage::InstantSupportDetermined(bool supports_instant) {
89 delegate_->InstantSupportDetermined(web_contents(), supports_instant);
91 // If the page doesn't support Instant, stop listening to it.
92 if (!supports_instant)
93 ClearContents();
96 void InstantPage::ClearContents() {
97 if (web_contents()) {
98 SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver(
99 this);
102 Observe(NULL);