Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_NAVIGATION_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_NAVIGATION_OBSERVER_H_ |
| 6 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_NAVIGATION_OBSERVER_H_ | 6 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_NAVIGATION_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete_match.h" | |
| 11 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
| 12 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
| 13 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 14 #include "net/url_request/url_fetcher_delegate.h" | 16 #include "net/url_request/url_fetcher_delegate.h" |
| 15 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 16 | 18 |
| 17 namespace content { | 19 namespace history { |
| 18 class NavigationController; | 20 class ShortcutsBackend; |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace net { | 23 namespace net { |
| 22 class URLFetcher; | 24 class URLFetcher; |
| 23 class URLRequestStatus; | 25 class URLRequestStatus; |
| 24 } | 26 } |
| 25 | 27 |
| 26 // Monitors omnibox navigations in order to trigger behaviors that depend on | 28 // Monitors omnibox navigations in order to trigger behaviors that depend on |
| 27 // successful navigations. | 29 // successful navigations. |
| 28 // | 30 // |
| 29 // Currently two such behaviors exist: | 31 // Currently two such behaviors exist: |
| 30 // (1) For single-word queries where we can't tell if the entry was a search or | 32 // (1) For single-word queries where we can't tell if the entry was a search or |
| 31 // an intranet hostname, the omnibox opens as a search by default, but this | 33 // an intranet hostname, the omnibox opens as a search by default, but this |
| 32 // class attempts to open as a URL via an HTTP HEAD request. If successful, | 34 // class attempts to open as a URL via an HTTP HEAD request. If successful, |
| 33 // displays an infobar once the search result has also loaded. See | 35 // displays an infobar once the search result has also loaded. See |
| 34 // AlternateNavInfoBarDelegate. | 36 // AlternateNavInfoBarDelegate. |
| 35 // (2) Omnibox navigations that complete successfully are added to the | 37 // (2) Omnibox navigations that complete successfully are added to the |
| 36 // Shortcuts backend. TODO(pkasting): Not yet implemented. | 38 // Shortcuts backend. |
| 37 // | 39 // |
| 38 // TODO(pkasting): Probably NOTIFICATION_OMNIBOX_OPENED_URL should disappear and | 40 // TODO(pkasting): Probably NOTIFICATION_OMNIBOX_OPENED_URL should disappear and |
| 39 // everyone who listened to it should be triggered from this class instead. | 41 // everyone who listened to it should be triggered from this class instead. |
| 40 // | 42 // |
| 41 // The memory management of this object is a bit tricky. The OmniboxEditModel | 43 // The memory management of this object is a bit tricky. The OmniboxEditModel |
| 42 // will create us and be responsible for us until we attach as an observer | 44 // will create us and be responsible for us until we attach as an observer |
| 43 // after a pending load starts (it will delete us if this doesn't happen). | 45 // after a pending load starts (it will delete us if this doesn't happen). |
| 44 // Once this pending load starts, we're responsible for deleting ourselves. | 46 // Once this pending load starts, we're responsible for deleting ourselves. |
| 45 class OmniboxNavigationObserver : public content::NotificationObserver, | 47 class OmniboxNavigationObserver : public content::NotificationObserver, |
| 46 public content::WebContentsObserver, | 48 public content::WebContentsObserver, |
| 47 public net::URLFetcherDelegate { | 49 public net::URLFetcherDelegate { |
| 48 public: | 50 public: |
| 49 enum LoadState { | 51 enum LoadState { |
| 50 LOAD_NOT_SEEN, | 52 LOAD_NOT_SEEN, |
| 51 LOAD_PENDING, | 53 LOAD_PENDING, |
| 52 LOAD_COMMITTED, | 54 LOAD_COMMITTED, |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 explicit OmniboxNavigationObserver(const GURL& alternate_nav_url); | 57 OmniboxNavigationObserver(Profile* profile, |
| 58 const string16& text, | |
| 59 const AutocompleteMatch& match, | |
| 60 const GURL& alternate_nav_url); | |
| 56 virtual ~OmniboxNavigationObserver(); | 61 virtual ~OmniboxNavigationObserver(); |
| 57 | 62 |
| 58 LoadState load_state() const { return load_state_; } | 63 LoadState load_state() const { return load_state_; } |
| 59 | 64 |
| 65 // Called directly by OmniboxEditModel when an extension-related navigation | |
| 66 // occurs. Such navigations don't trigger an immediate NAV_ENTRY_PENDING and | |
| 67 // must be handled separately. | |
| 68 void OnSuccessfulNavigation(); | |
| 69 | |
| 60 private: | 70 private: |
| 61 enum FetchState { | 71 enum FetchState { |
| 62 FETCH_NOT_COMPLETE, | 72 FETCH_NOT_COMPLETE, |
| 63 FETCH_SUCCEEDED, | 73 FETCH_SUCCEEDED, |
| 64 FETCH_FAILED, | 74 FETCH_FAILED, |
| 65 }; | 75 }; |
| 66 | 76 |
| 67 // content::NotificationObserver: | 77 // content::NotificationObserver: |
| 68 virtual void Observe(int type, | 78 virtual void Observe(int type, |
| 69 const content::NotificationSource& source, | 79 const content::NotificationSource& source, |
| 70 const content::NotificationDetails& details) OVERRIDE; | 80 const content::NotificationDetails& details) OVERRIDE; |
| 71 | 81 |
| 72 // content::WebContentsObserver: | 82 // content::WebContentsObserver: |
| 73 virtual void NavigateToPendingEntry( | 83 virtual void NavigateToPendingEntry( |
| 74 const GURL& url, | 84 const GURL& url, |
| 75 content::NavigationController::ReloadType reload_type) OVERRIDE; | 85 content::NavigationController::ReloadType reload_type) OVERRIDE; |
| 76 virtual void NavigationEntryCommitted( | 86 virtual void NavigationEntryCommitted( |
| 77 const content::LoadCommittedDetails& load_details) OVERRIDE; | 87 const content::LoadCommittedDetails& load_details) OVERRIDE; |
| 78 virtual void WebContentsDestroyed( | 88 virtual void WebContentsDestroyed( |
| 79 content::WebContents* web_contents) OVERRIDE; | 89 content::WebContents* web_contents) OVERRIDE; |
| 80 | 90 |
| 81 // net::URLFetcherDelegate: | 91 // net::URLFetcherDelegate: |
| 82 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 92 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 83 | 93 |
| 84 // Once the load has committed and any URL fetch has completed, this displays | 94 // Once the load has committed and any URL fetch has completed, this displays |
| 85 // the alternate nav infobar if necessary, and deletes |this|. | 95 // the alternate nav infobar if necessary, and deletes |this|. |
| 86 void OnAllLoadingFinished(); | 96 void OnAllLoadingFinished(); |
| 87 | 97 |
| 98 string16 text_; | |
|
Bart N.
2013/10/14 21:31:54
It looks like that both text_ and match_ can be co
Peter Kasting
2013/10/16 01:28:55
Done.
| |
| 99 AutocompleteMatch match_; | |
| 88 GURL alternate_nav_url_; | 100 GURL alternate_nav_url_; |
| 101 scoped_refptr<history::ShortcutsBackend> shortcuts_backend_; | |
| 89 scoped_ptr<net::URLFetcher> fetcher_; | 102 scoped_ptr<net::URLFetcher> fetcher_; |
| 90 LoadState load_state_; | 103 LoadState load_state_; |
| 91 FetchState fetch_state_; | 104 FetchState fetch_state_; |
| 92 | 105 |
| 93 content::NotificationRegistrar registrar_; | 106 content::NotificationRegistrar registrar_; |
| 94 | 107 |
| 95 DISALLOW_COPY_AND_ASSIGN(OmniboxNavigationObserver); | 108 DISALLOW_COPY_AND_ASSIGN(OmniboxNavigationObserver); |
| 96 }; | 109 }; |
| 97 | 110 |
| 98 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_NAVIGATION_OBSERVER_H_ | 111 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_NAVIGATION_OBSERVER_H_ |
| OLD | NEW |