| 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_INSTANT_INSTANT_LOADER_H_ | 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_H_ |
| 6 #define CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ | 6 #define CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "chrome/browser/history/history_types.h" | 15 #include "chrome/browser/history/history_types.h" |
| 16 #include "chrome/browser/instant/instant_client.h" | 16 #include "chrome/browser/instant/instant_client.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 | 19 |
| 20 struct InstantAutocompleteResult; | 20 struct InstantAutocompleteResult; |
| 21 class InstantController; | 21 class InstantController; |
| 22 class Profile; |
| 22 struct ThemeBackgroundInfo; | 23 struct ThemeBackgroundInfo; |
| 23 | 24 |
| 24 namespace chrome { | 25 namespace chrome { |
| 25 namespace search { | 26 namespace search { |
| 26 struct Mode; | 27 struct Mode; |
| 27 } | 28 } |
| 28 } | 29 } |
| 29 | 30 |
| 30 namespace content { | 31 namespace content { |
| 31 class WebContents; | 32 class WebContents; |
| 32 } | 33 } |
| 33 | 34 |
| 34 namespace gfx { | 35 namespace gfx { |
| 35 class Rect; | 36 class Rect; |
| 36 } | 37 } |
| 37 | 38 |
| 38 // InstantLoader is used to communicate with a preview WebContents that it owns | 39 // InstantOverlay 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 // 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 // will as the user types in the omnibox (compare: InstantTab, which talks to a |
| 41 // committed tab on the tab strip). | 42 // committed tab on the tab strip). |
| 42 class InstantLoader : public InstantClient::Delegate, | 43 class InstantOverlay : public InstantClient::Delegate, |
| 43 public content::NotificationObserver { | 44 public content::NotificationObserver { |
| 44 public: | 45 public: |
| 45 // Returns the Instant loader for |contents| if it's used for Instant. | 46 // Returns the Instant overlay for |contents| if it's used for Instant. |
| 46 static InstantLoader* FromWebContents(const content::WebContents* contents); | 47 static InstantOverlay* FromWebContents(const content::WebContents* contents); |
| 47 | 48 |
| 48 // Doesn't take ownership of |controller|. | 49 // Doesn't take ownership of |controller|. |
| 49 InstantLoader(InstantController* controller, const std::string& instant_url); | 50 InstantOverlay(InstantController* controller, const std::string& instant_url); |
| 50 virtual ~InstantLoader(); | 51 virtual ~InstantOverlay(); |
| 51 | 52 |
| 52 // The preview WebContents. InstantLoader retains ownership. This will be | 53 // The preview WebContents. InstantOverlay retains ownership. This will be |
| 53 // non-NULL after InitFromContents(), and until ReleaseContents() is called. | 54 // non-NULL after InitFromContents(), and until ReleaseContents() is called. |
| 54 content::WebContents* contents() const { return contents_.get(); } | 55 content::WebContents* contents() const { return contents_.get(); } |
| 55 | 56 |
| 56 // Creates a new WebContents and loads |instant_url_| into it. |active_tab| is | 57 // Creates a new WebContents and loads |instant_url_| into it. Uses |
| 57 // the page the preview will be shown on top of and potentially replace. | 58 // |active_tab|, if non-NULL, to initialize the size of the WebContents. |
| 58 void InitContents(const content::WebContents* active_tab); | 59 void InitContents(Profile* profile, |
| 60 const content::WebContents* active_tab); |
| 59 | 61 |
| 60 // Releases the preview WebContents passing ownership to the caller. This | 62 // Releases the preview WebContents passing ownership to the caller. This |
| 61 // should be called when the preview is committed. | 63 // should be called when the preview is committed. |
| 62 content::WebContents* ReleaseContents() WARN_UNUSED_RESULT; | 64 content::WebContents* ReleaseContents() WARN_UNUSED_RESULT; |
| 63 | 65 |
| 64 // Returns the URL that we're loading. | 66 // Returns the URL that we're loading. |
| 65 const std::string& instant_url() const { return instant_url_; } | 67 const std::string& instant_url() const { return instant_url_; } |
| 66 | 68 |
| 67 // Returns true if the preview is known to support the Instant API. This | 69 // 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 | 70 // starts out false, and becomes true whenever we get any message from the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 79 // Returns info about the last navigation by the Instant page. If the page | 81 // 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. | 82 // hasn't navigated since the last Update(), the URL is empty. |
| 81 const history::HistoryAddPageArgs& last_navigation() const { | 83 const history::HistoryAddPageArgs& last_navigation() const { |
| 82 return last_navigation_; | 84 return last_navigation_; |
| 83 } | 85 } |
| 84 | 86 |
| 85 // Called by the history tab helper with information that it would have added | 87 // 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. | 88 // to the history service had this WebContents not been used for Instant. |
| 87 void DidNavigate(const history::HistoryAddPageArgs& add_page_args); | 89 void DidNavigate(const history::HistoryAddPageArgs& add_page_args); |
| 88 | 90 |
| 89 // Returns true if the loader is using | 91 // Returns true if the overlay is using |
| 90 // InstantController::kLocalOmniboxPopupURL as the |instant_url_|. | 92 // InstantController::kLocalOmniboxPopupURL as the |instant_url_|. |
| 91 bool IsUsingLocalPreview() const; | 93 bool IsUsingLocalPreview() const; |
| 92 | 94 |
| 93 // Calls through to methods of the same name on InstantClient. | 95 // Calls through to methods of the same name on InstantClient. |
| 94 void Update(const string16& text, | 96 void Update(const string16& text, |
| 95 size_t selection_start, | 97 size_t selection_start, |
| 96 size_t selection_end, | 98 size_t selection_end, |
| 97 bool verbatim); | 99 bool verbatim); |
| 98 void Submit(const string16& text); | 100 void Submit(const string16& text); |
| 99 void Cancel(const string16& text); | 101 void Cancel(const string16& text); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 scoped_ptr<content::WebContents> contents_; | 146 scoped_ptr<content::WebContents> contents_; |
| 145 | 147 |
| 146 const std::string instant_url_; | 148 const std::string instant_url_; |
| 147 bool supports_instant_; | 149 bool supports_instant_; |
| 148 bool is_pointer_down_from_activate_; | 150 bool is_pointer_down_from_activate_; |
| 149 history::HistoryAddPageArgs last_navigation_; | 151 history::HistoryAddPageArgs last_navigation_; |
| 150 | 152 |
| 151 // Used to get notifications about renderers coming and going. | 153 // Used to get notifications about renderers coming and going. |
| 152 content::NotificationRegistrar registrar_; | 154 content::NotificationRegistrar registrar_; |
| 153 | 155 |
| 154 DISALLOW_COPY_AND_ASSIGN(InstantLoader); | 156 DISALLOW_COPY_AND_ASSIGN(InstantOverlay); |
| 155 }; | 157 }; |
| 156 | 158 |
| 157 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ | 159 #endif // CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_H_ |
| OLD | NEW |