Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: chrome/browser/instant/instant_loader.h

Issue 12520005: Move desktop-specific Instant bits to c/b/ui/search. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/timer.h"
13 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/web_contents_delegate.h"
17
18 class GURL;
19 class Profile;
20
21 namespace content {
22 struct OpenURLParams;
23 class WebContents;
24 }
25
26 // InstantLoader is used to create and maintain a WebContents where we can
27 // preload a page into. It is used by InstantOverlay and InstantNTP to
28 // preload an Instant page.
29 class InstantLoader : public content::NotificationObserver,
30 public content::WebContentsDelegate,
31 public CoreTabHelperDelegate {
32 public:
33 // InstantLoader calls these methods on its delegate in response to certain
34 // changes in the underlying contents.
35 class Delegate {
36 public:
37 // Called after someone has swapped in a different WebContents for ours.
38 virtual void OnSwappedContents() = 0;
39
40 // Called when the underlying contents receive focus.
41 virtual void OnFocus() = 0;
42
43 // Called when the mouse pointer is down.
44 virtual void OnMouseDown() = 0;
45
46 // Called when the mouse pointer is released (or a drag event ends).
47 virtual void OnMouseUp() = 0;
48
49 // Called to open a URL using the underlying contents (see
50 // WebContentsDelegate::OpenURLFromTab). The Delegate should return the
51 // WebContents the URL is opened in, or NULL if the URL wasn't opened
52 // immediately.
53 virtual content::WebContents* OpenURLFromTab(
54 content::WebContents* source,
55 const content::OpenURLParams& params) = 0;
56
57 // Called when a main frame load is complete.
58 virtual void LoadCompletedMainFrame() = 0;
59
60 protected:
61 ~Delegate();
62 };
63
64 explicit InstantLoader(Delegate* delegate);
65 virtual ~InstantLoader();
66
67 // Creates a new WebContents in the context of |profile| that will be used to
68 // load |instant_url|. The page is not actually loaded until Load() is
69 // called. Uses |active_contents|, if non-NULL, to initialize the size of the
70 // new contents. |on_stale_callback| will be called after kStalePageTimeoutMS
71 // has elapsed after Load() being called.
72 void Init(const GURL& instant_url,
73 Profile* profile,
74 const content::WebContents* active_contents,
75 const base::Closure& on_stale_callback);
76
77 // Loads |instant_url_| in |contents_|.
78 void Load();
79
80 // Returns the contents currently held. May be NULL.
81 content::WebContents* contents() const { return contents_.get(); }
82
83 // Replaces the contents held with |contents|. Any existing contents is
84 // deleted. The expiration timer is not restarted.
85 void SetContents(scoped_ptr<content::WebContents> contents);
86
87 // Releases the contents currently held. Must only be called if contents() is
88 // not NULL.
89 scoped_ptr<content::WebContents> ReleaseContents() WARN_UNUSED_RESULT;
90
91 private:
92 // Overridden from content::NotificationObserver:
93 virtual void Observe(int type,
94 const content::NotificationSource& source,
95 const content::NotificationDetails& details) OVERRIDE;
96
97 // Overridden from CoreTabHelperDelegate:
98 virtual void SwapTabContents(content::WebContents* old_contents,
99 content::WebContents* new_contents) OVERRIDE;
100
101 // Overridden from content::WebContentsDelegate:
102 virtual bool ShouldSuppressDialogs() OVERRIDE;
103 virtual bool ShouldFocusPageAfterCrash() OVERRIDE;
104 virtual void LostCapture() OVERRIDE;
105 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE;
106 virtual bool CanDownload(content::RenderViewHost* render_view_host,
107 int request_id,
108 const std::string& request_method) OVERRIDE;
109 virtual void HandleMouseDown() OVERRIDE;
110 virtual void HandleMouseUp() OVERRIDE;
111 virtual void HandlePointerActivate() OVERRIDE;
112 virtual void HandleGestureEnd() OVERRIDE;
113 virtual void DragEnded() OVERRIDE;
114 virtual bool OnGoToEntryOffset(int offset) OVERRIDE;
115 virtual content::WebContents* OpenURLFromTab(
116 content::WebContents* source,
117 const content::OpenURLParams& params) OVERRIDE;
118
119 Delegate* const delegate_;
120 scoped_ptr<content::WebContents> contents_;
121
122 // The URL we will be loading.
123 GURL instant_url_;
124
125 // Called when |stale_page_timer_| fires.
126 base::Closure on_stale_callback_;
127
128 // Used to mark when the page is stale.
129 base::Timer stale_page_timer_;
130
131 // Used to get notifications about renderers.
132 content::NotificationRegistrar registrar_;
133
134 DISALLOW_COPY_AND_ASSIGN(InstantLoader);
135 };
136
137 #endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_extended_manual_browsertest.cc ('k') | chrome/browser/instant/instant_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698