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

Side by Side Diff: chrome/browser/instant/instant_overlay.cc

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 7 years, 11 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 #include "chrome/browser/instant/instant_overlay.h"
6
7 #include "base/supports_user_data.h"
8 #include "chrome/browser/instant/instant_controller.h"
9 #include "content/public/browser/web_contents.h"
10
11 namespace {
12
13 const int kStalePageTimeoutMS = 3 * 3600 * 1000; // 3 hours
14
15 int kUserDataKey;
16
17 class InstantOverlayUserData : public base::SupportsUserData::Data {
18 public:
19 explicit InstantOverlayUserData(InstantOverlay* overlay)
20 : overlay_(overlay) {}
21
22 InstantOverlay* overlay() const { return overlay_; }
23
24 private:
25 ~InstantOverlayUserData() {}
26
27 InstantOverlay* const overlay_;
28
29 DISALLOW_COPY_AND_ASSIGN(InstantOverlayUserData);
30 };
31
32 } // namespace
33
34 // static
35 InstantOverlay* InstantOverlay::FromWebContents(
36 const content::WebContents* web_contents) {
37 InstantOverlayUserData* data = static_cast<InstantOverlayUserData*>(
38 web_contents->GetUserData(&kUserDataKey));
39 return data ? data->overlay() : NULL;
40 }
41
42 InstantOverlay::InstantOverlay(InstantController* controller,
43 const std::string& instant_url)
44 : InstantPage(controller),
45 loader_(new InstantLoader(ALLOW_THIS_IN_INITIALIZER_LIST(this))),
46 instant_url_(instant_url),
47 is_stale_(false),
48 is_pointer_down_from_activate_(false) {
49 }
50
51 InstantOverlay::~InstantOverlay() {
52 }
53
54 void InstantOverlay::InitContents(Profile* profile,
55 const content::WebContents* active_tab) {
56 loader_->Load(GURL(instant_url_), profile, active_tab, kStalePageTimeoutMS);
57 api()->SetContents(contents());
58 contents()->SetUserData(&kUserDataKey, new InstantOverlayUserData(this));
59 }
60
61 content::WebContents* InstantOverlay::ReleaseContents() {
62 api()->SetContents(NULL);
63 contents()->RemoveUserData(&kUserDataKey);
64 return loader_->ReleaseContents();
65 }
66
67 void InstantOverlay::DidNavigate(
68 const history::HistoryAddPageArgs& add_page_args) {
69 last_navigation_ = add_page_args;
70 }
71
72 bool InstantOverlay::IsUsingLocalPreview() const {
73 return instant_url_ == InstantController::kLocalOmniboxPopupURL;
74 }
75
76 content::WebContents* InstantOverlay::ReplaceAndReleaseContents(
77 content::WebContents* new_contents) {
78 content::WebContents* old_contents = ReleaseContents();
79 loader_->SetContents(new_contents);
80 api()->SetContents(new_contents);
81 contents()->SetUserData(&kUserDataKey, new InstantOverlayUserData(this));
82 controller_->SwappedOverlayWebContents();
83 return old_contents;
84 }
85
86 void InstantOverlay::OnFocus() {
87 // The preview is getting focus. Equivalent to it being clicked.
88 bool tmp = is_pointer_down_from_activate_;
89 is_pointer_down_from_activate_ = true;
90 controller_->InstantOverlayContentsFocused();
91 is_pointer_down_from_activate_ = tmp;
92 }
93
94 bool InstantOverlay::OnOpenURL() {
95 // Allow navigation to continue if we can commit the overlay.
96 return controller_->CommitIfPossible(INSTANT_COMMIT_NAVIGATED);
97 }
98
99 void InstantOverlay::SetPointerDown() {
100 is_pointer_down_from_activate_ = true;
101 }
102
103 void InstantOverlay::MaybeCommitFromPointerRelease() {
104 if (is_pointer_down_from_activate_) {
105 is_pointer_down_from_activate_ = false;
106 controller_->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST);
107 }
108 }
109
110 void InstantOverlay::OnStalePage() {
111 is_stale_ = true;
112 controller_->OnStaleOverlay();
113 }
114
115 void InstantOverlay::OnUpdate() {
116 last_navigation_ = history::HistoryAddPageArgs();
117 }
118
119 bool InstantOverlay::OnRenderViewGone() const {
120 return true;
121 }
122
123 bool InstantOverlay::OnAboutToNavigateMainFrame() const {
124 return true;
125 }
126
127 bool InstantOverlay::OnSetSuggestions() const {
128 return true;
129 }
130
131 bool InstantOverlay::OnShowInstantPreview() const {
132 return true;
133 }
134
135 bool InstantOverlay::OnStartCapturingKeyStrokes() const {
136 return true;
137 }
138
139 bool InstantOverlay::OnStopCapturingKeyStrokes() const {
140 return true;
141 }
142
143 bool InstantOverlay::OnNavigateToURL() const {
144 return true;
145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698