1 // Copyright 2012 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 #ifndef CHROME_BROWSER_UI_OMNIBOX_CHROME_OMNIBOX_NAVIGATION_OBSERVER_H_
6 #define CHROME_BROWSER_UI_OMNIBOX_CHROME_OMNIBOX_NAVIGATION_OBSERVER_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/omnibox/browser/autocomplete_match.h"
13 #include "components/omnibox/browser/omnibox_navigation_observer.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/web_contents_observer.h"
17 #include "net/url_request/url_fetcher_delegate.h"
20 class ShortcutsBackend
;
24 class URLRequestStatus
;
27 // Monitors omnibox navigations in order to trigger behaviors that depend on
28 // successful navigations.
30 // Currently two such behaviors exist:
31 // (1) For single-word queries where we can't tell if the entry was a search or
32 // an intranet hostname, the omnibox opens as a search by default, but this
33 // class attempts to open as a URL via an HTTP HEAD request. If successful,
34 // displays an infobar once the search result has also loaded. See
35 // AlternateNavInfoBarDelegate.
36 // (2) Omnibox navigations that complete successfully are added to the
39 // Please see the class comment on the base class for important information
40 // about the memory management of this object.
41 class ChromeOmniboxNavigationObserver
: public OmniboxNavigationObserver
,
42 public content::NotificationObserver
,
43 public content::WebContentsObserver
,
44 public net::URLFetcherDelegate
{
52 ChromeOmniboxNavigationObserver(Profile
* profile
,
53 const base::string16
& text
,
54 const AutocompleteMatch
& match
,
55 const AutocompleteMatch
& alternate_nav_match
);
56 ~ChromeOmniboxNavigationObserver() override
;
58 LoadState
load_state() const { return load_state_
; }
60 // Called directly by ChromeOmniboxClient when an extension-related navigation
61 // occurs. Such navigations don't trigger an immediate NAV_ENTRY_PENDING and
62 // must be handled separately.
63 void OnSuccessfulNavigation();
72 // OmniboxNavigationObserver:
73 bool HasSeenPendingLoad() const override
;
75 // content::NotificationObserver:
76 void Observe(int type
,
77 const content::NotificationSource
& source
,
78 const content::NotificationDetails
& details
) override
;
80 // content::WebContentsObserver:
81 void DidStartNavigationToPendingEntry(
83 content::NavigationController::ReloadType reload_type
) override
;
84 void DidFailProvisionalLoad(content::RenderFrameHost
* render_frame_host
,
85 const GURL
& validated_url
,
87 const base::string16
& error_description
,
88 bool was_ignored_by_handler
) override
;
89 void NavigationEntryCommitted(
90 const content::LoadCommittedDetails
& load_details
) override
;
91 void WebContentsDestroyed() override
;
93 // net::URLFetcherDelegate:
94 void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
96 // Once the load has committed and any URL fetch has completed, this displays
97 // the alternate nav infobar if necessary, and deletes |this|.
98 void OnAllLoadingFinished();
100 const base::string16 text_
;
101 const AutocompleteMatch match_
;
102 const AutocompleteMatch alternate_nav_match_
;
103 scoped_refptr
<ShortcutsBackend
> shortcuts_backend_
; // NULL in incognito.
104 scoped_ptr
<net::URLFetcher
> fetcher_
;
105 LoadState load_state_
;
106 FetchState fetch_state_
;
108 content::NotificationRegistrar registrar_
;
110 DISALLOW_COPY_AND_ASSIGN(ChromeOmniboxNavigationObserver
);
113 #endif // CHROME_BROWSER_UI_OMNIBOX_CHROME_OMNIBOX_NAVIGATION_OBSERVER_H_