| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ | |
| 6 #define CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/string16.h" | |
| 15 #include "chrome/browser/history/history_types.h" | |
| 16 #include "chrome/browser/instant/instant_client.h" | |
| 17 #include "content/public/browser/notification_observer.h" | |
| 18 #include "content/public/browser/notification_registrar.h" | |
| 19 | |
| 20 struct InstantAutocompleteResult; | |
| 21 class InstantController; | |
| 22 struct ThemeBackgroundInfo; | |
| 23 | |
| 24 namespace chrome { | |
| 25 namespace search { | |
| 26 struct Mode; | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 namespace content { | |
| 31 class WebContents; | |
| 32 } | |
| 33 | |
| 34 namespace gfx { | |
| 35 class Rect; | |
| 36 } | |
| 37 | |
| 38 // InstantLoader is used to communicate with a preview WebContents that it owns | |
| 39 // and loads the "Instant URL" into. This preview can appear and disappear at | |
| 40 // will as the user types in the omnibox (compare: InstantTab, which talks to a | |
| 41 // committed tab on the tab strip). | |
| 42 class InstantLoader : public InstantClient::Delegate, | |
| 43 public content::NotificationObserver { | |
| 44 public: | |
| 45 // Returns the Instant loader for |contents| if it's used for Instant. | |
| 46 static InstantLoader* FromWebContents(const content::WebContents* contents); | |
| 47 | |
| 48 // Doesn't take ownership of |controller|. | |
| 49 InstantLoader(InstantController* controller, const std::string& instant_url); | |
| 50 virtual ~InstantLoader(); | |
| 51 | |
| 52 // The preview WebContents. InstantLoader retains ownership. This will be | |
| 53 // non-NULL after InitFromContents(), and until ReleaseContents() is called. | |
| 54 content::WebContents* contents() const { return contents_.get(); } | |
| 55 | |
| 56 // Creates a new WebContents and loads |instant_url_| into it. |active_tab| is | |
| 57 // the page the preview will be shown on top of and potentially replace. | |
| 58 void InitContents(const content::WebContents* active_tab); | |
| 59 | |
| 60 // Releases the preview WebContents passing ownership to the caller. This | |
| 61 // should be called when the preview is committed. | |
| 62 content::WebContents* ReleaseContents() WARN_UNUSED_RESULT; | |
| 63 | |
| 64 // Returns the URL that we're loading. | |
| 65 const std::string& instant_url() const { return instant_url_; } | |
| 66 | |
| 67 // Returns true if the preview is known to support the Instant API. This | |
| 68 // starts out false, and becomes true whenever we get any message from the | |
| 69 // page. Once true, it never becomes false (the page isn't expected to drop | |
| 70 // Instant API support suddenly). | |
| 71 bool supports_instant() const { return supports_instant_; } | |
| 72 | |
| 73 // Returns true if the mouse or a touch pointer is down due to activating the | |
| 74 // preview contents. | |
| 75 bool is_pointer_down_from_activate() const { | |
| 76 return is_pointer_down_from_activate_; | |
| 77 } | |
| 78 | |
| 79 // Returns info about the last navigation by the Instant page. If the page | |
| 80 // hasn't navigated since the last Update(), the URL is empty. | |
| 81 const history::HistoryAddPageArgs& last_navigation() const { | |
| 82 return last_navigation_; | |
| 83 } | |
| 84 | |
| 85 // Called by the history tab helper with information that it would have added | |
| 86 // to the history service had this WebContents not been used for Instant. | |
| 87 void DidNavigate(const history::HistoryAddPageArgs& add_page_args); | |
| 88 | |
| 89 // Returns true if the loader is using | |
| 90 // InstantController::kLocalOmniboxPopupURL as the |instant_url_|. | |
| 91 bool IsUsingLocalPreview() const; | |
| 92 | |
| 93 // Calls through to methods of the same name on InstantClient. | |
| 94 void Update(const string16& text, | |
| 95 size_t selection_start, | |
| 96 size_t selection_end, | |
| 97 bool verbatim); | |
| 98 void Submit(const string16& text); | |
| 99 void Cancel(const string16& text); | |
| 100 void SetPopupBounds(const gfx::Rect& bounds); | |
| 101 void SetMarginSize(int start, int end); | |
| 102 void SendAutocompleteResults( | |
| 103 const std::vector<InstantAutocompleteResult>& results); | |
| 104 void UpOrDownKeyPressed(int count); | |
| 105 void SearchModeChanged(const chrome::search::Mode& mode); | |
| 106 void SendThemeBackgroundInfo(const ThemeBackgroundInfo& theme_info); | |
| 107 void SendThemeAreaHeight(int height); | |
| 108 void SetDisplayInstantResults(bool display_instant_results); | |
| 109 void KeyCaptureChanged(bool is_key_capture_enabled); | |
| 110 | |
| 111 private: | |
| 112 class WebContentsDelegateImpl; | |
| 113 | |
| 114 // Overridden from InstantClient::Delegate: | |
| 115 virtual void SetSuggestions( | |
| 116 const std::vector<InstantSuggestion>& suggestions) OVERRIDE; | |
| 117 virtual void InstantSupportDetermined(bool supports_instant) OVERRIDE; | |
| 118 virtual void ShowInstantPreview(InstantShownReason reason, | |
| 119 int height, | |
| 120 InstantSizeUnits units) OVERRIDE; | |
| 121 virtual void StartCapturingKeyStrokes() OVERRIDE; | |
| 122 virtual void StopCapturingKeyStrokes() OVERRIDE; | |
| 123 virtual void RenderViewGone() OVERRIDE; | |
| 124 virtual void AboutToNavigateMainFrame(const GURL& url) OVERRIDE; | |
| 125 virtual void NavigateToURL(const GURL& url, | |
| 126 content::PageTransition transition) OVERRIDE; | |
| 127 | |
| 128 // Overridden from content::NotificationObserver: | |
| 129 virtual void Observe(int type, | |
| 130 const content::NotificationSource& source, | |
| 131 const content::NotificationDetails& details) OVERRIDE; | |
| 132 | |
| 133 void SetupPreviewContents(); | |
| 134 void CleanupPreviewContents(); | |
| 135 void ReplacePreviewContents(content::WebContents* old_contents, | |
| 136 content::WebContents* new_contents); | |
| 137 | |
| 138 InstantClient client_; | |
| 139 InstantController* const controller_; | |
| 140 | |
| 141 // Delegate of the preview WebContents. Used when the user does some gesture | |
| 142 // on the preview and it needs to be activated. | |
| 143 scoped_ptr<WebContentsDelegateImpl> delegate_; | |
| 144 scoped_ptr<content::WebContents> contents_; | |
| 145 | |
| 146 const std::string instant_url_; | |
| 147 bool supports_instant_; | |
| 148 bool is_pointer_down_from_activate_; | |
| 149 history::HistoryAddPageArgs last_navigation_; | |
| 150 | |
| 151 // Used to get notifications about renderers coming and going. | |
| 152 content::NotificationRegistrar registrar_; | |
| 153 | |
| 154 DISALLOW_COPY_AND_ASSIGN(InstantLoader); | |
| 155 }; | |
| 156 | |
| 157 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ | |
| OLD | NEW |