blob: dd808525e797ec988384dc6fa9d0340303858260 [file] [log] [blame]
[email protected]e41982a72012-11-20 07:16:511// Copyright 2012 The Chromium Authors. All rights reserved.
[email protected]fd2b9ce2010-08-11 04:03:572// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]03bb7102013-03-17 22:44:475#include "chrome/browser/ui/search/instant_controller.h"
[email protected]fd2b9ce2010-08-11 04:03:576
avi655876a2015-12-25 07:18:157#include <stddef.h>
8
Marc Treib5cacd242017-09-06 07:48:259#include "base/bind.h"
10#include "base/callback.h"
[email protected]d58688c62013-07-03 23:09:1211#include "chrome/browser/profiles/profile.h"
[email protected]a7b8e43d2013-03-18 18:52:4312#include "chrome/browser/search/instant_service.h"
13#include "chrome/browser/search/instant_service_factory.h"
Marc Treibbfe01712017-09-26 11:49:4514#include "chrome/browser/search/search.h"
Marc Treibf4e8daff2017-09-27 08:40:3415#include "chrome/browser/ui/tabs/tab_strip_model.h"
Marc Treibbfe01712017-09-26 11:49:4516#include "chrome/common/url_constants.h"
17#include "content/public/browser/navigation_details.h"
Marc Treib5cacd242017-09-06 07:48:2518#include "content/public/browser/navigation_handle.h"
[email protected]3d6a8952012-12-14 03:18:0719#include "content/public/browser/web_contents.h"
Marc Treib5cacd242017-09-06 07:48:2520#include "content/public/browser/web_contents_observer.h"
21
22class InstantController::TabObserver : public content::WebContentsObserver {
23 public:
Ella Ge4cd25382021-01-06 08:59:2824 TabObserver(content::WebContents* web_contents,
25 base::RepeatingClosure callback)
26 : content::WebContentsObserver(web_contents),
27 callback_(std::move(callback)) {}
Marc Treib5cacd242017-09-06 07:48:2528 ~TabObserver() override = default;
29
30 private:
31 // Overridden from content::WebContentsObserver:
Marc Treibbfe01712017-09-26 11:49:4532 void NavigationEntryCommitted(
33 const content::LoadCommittedDetails& load_details) override {
34 if (load_details.is_main_frame && search::IsInstantNTP(web_contents())) {
35 callback_.Run();
36 }
37 }
38
Ella Ge4cd25382021-01-06 08:59:2839 base::RepeatingClosure callback_;
Marc Treib5cacd242017-09-06 07:48:2540
41 DISALLOW_COPY_AND_ASSIGN(TabObserver);
42};
[email protected]fd2b9ce2010-08-11 04:03:5743
Marc Treibf4e8daff2017-09-27 08:40:3444InstantController::InstantController(Profile* profile,
45 TabStripModel* tab_strip_model)
Elly Fong-Jones4e3d25c72019-08-12 18:17:1546 : profile_(profile) {
47 tab_strip_model->AddObserver(this);
Marc Treibf4e8daff2017-09-27 08:40:3448}
Marc Treibbfe01712017-09-26 11:49:4549
50InstantController::~InstantController() = default;
51
sangwoo.ko1ae265f12018-10-18 08:30:2852void InstantController::OnTabStripModelChanged(
53 TabStripModel* tab_strip_model,
54 const TabStripModelChange& change,
55 const TabStripSelectionChange& selection) {