Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / search / instant_search_prerenderer.h
blobab977bf6589c030a4a828e7311581716dd274403
1 // Copyright 2013 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_SEARCH_INSTANT_SEARCH_PRERENDERER_H_
6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_SEARCH_PRERENDERER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string16.h"
11 #include "chrome/common/instant_types.h"
12 #include "content/public/browser/navigation_controller.h"
14 class GURL;
15 class Profile;
16 struct AutocompleteMatch;
18 namespace chrome {
19 struct NavigateParams;
22 namespace content {
23 class WebContents;
26 namespace gfx {
27 class Size;
30 namespace prerender {
31 class PrerenderHandle;
34 // InstantSearchPrerenderer is responsible for prerendering the default search
35 // provider Instant search base page URL to prefetch high-confidence search
36 // suggestions. InstantSearchPrerenderer manages the prerender handle associated
37 // with the prerendered contents.
38 class InstantSearchPrerenderer {
39 public:
40 InstantSearchPrerenderer(Profile* profile, const GURL& url);
41 ~InstantSearchPrerenderer();
43 // Returns the InstantSearchPrerenderer instance for the given |profile|.
44 static InstantSearchPrerenderer* GetForProfile(Profile* profile);
46 // Prerender the |prerender_url_| contents. The
47 // |session_storage_namespace_map| is used to identify the namespace of the
48 // active tab at the time the prerender is generated. The |size| gives the
49 // initial size for the target prerender. InstantSearchPrerenderer will run at
50 // most one prerender at a time, so launching a prerender will cancel the
51 // previous prerenders (if any).
52 void Init(
53 const content::SessionStorageNamespaceMap& session_storage_namespace_map,
54 const gfx::Size& size);
56 // Cancels the current request.
57 void Cancel();
59 // Tells the Instant search base page to prerender |suggestion|.
60 void Prerender(const InstantSuggestion& suggestion);
62 // Tells the Instant search base page to render the prefetched search results.
63 void Commit(const base::string16& query);
65 // Returns true if the prerendered page can be used to process the search for
66 // the given |source|.
67 bool CanCommitQuery(content::WebContents* source,
68 const base::string16& query) const;
70 // Returns true and updates |params->target_contents| if a prerendered page
71 // exists for |url| and is swapped in.
72 bool UsePrerenderedPage(const GURL& url, chrome::NavigateParams* params);
74 // Returns the last prefetched search query.
75 const base::string16& get_last_query() const {
76 return last_instant_suggestion_.text;
79 // Returns true when prerendering is allowed for the given |source| and
80 // |match|.
81 bool IsAllowed(const AutocompleteMatch& match,
82 content::WebContents* source) const;
84 private:
85 friend class InstantSearchPrerendererTest;
87 content::WebContents* prerender_contents() const;
89 Profile* const profile_;
91 // Instant search base page URL.
92 const GURL prerender_url_;
94 scoped_ptr<prerender::PrerenderHandle> prerender_handle_;
96 InstantSuggestion last_instant_suggestion_;
98 DISALLOW_COPY_AND_ASSIGN(InstantSearchPrerenderer);
101 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_SEARCH_PRERENDERER_H_