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

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: Rebase. 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.
dhollowa 2013/01/22 22:34:58 nit: 2013
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
dhollowa 2013/01/22 22:34:58 DRY violation. Move to instant_page.h?
samarth 2013/01/25 21:08:40 I was leaving open the possibility that ntp and ov
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(InstantPage::Delegate* delegate,
43 const std::string& instant_url)
44 : InstantPage(delegate),
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 SetContents(loader_->contents());
58 contents()->SetUserData(&kUserDataKey, new InstantOverlayUserData(this));
59 }
60
61 content::WebContents* InstantOverlay::ReleaseContents() {
62 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 void InstantOverlay::Update(const string16& text,
77 size_t selection_start,
78 size_t selection_end,
79 bool verbatim) {
80 last_navigation_ = history::HistoryAddPageArgs();
81 InstantPage::Update(text, selection_start, selection_end, verbatim);
82 }
83
84 content::WebContents* InstantOverlay::ReplaceAndReleaseContents(
85 content::WebContents* new_contents) {
86 content::WebContents* old_contents = ReleaseContents();
87 loader_->SetContents(new_contents);
88 SetContents(new_contents);
89 contents()->SetUserData(&kUserDataKey, new InstantOverlayUserData(this));
90 delegate()->InstantPageSwappedContents(new_contents);
91 return old_contents;
92 }
93
94 void InstantOverlay::OnFocus() {
95 // The preview is getting focus. Equivalent to it being clicked.
96 bool tmp = is_pointer_down_from_activate_;
97 is_pointer_down_from_activate_ = true;
98 delegate()->InstantPageFocused(contents());
99 is_pointer_down_from_activate_ = tmp;
100 }
101
102 bool InstantOverlay::OnOpenURL() {
103 // The delegate determines if this navigation can continue.
104 return delegate()->InstantPageAboutToOpenURL(contents());
105 }
106
107 void InstantOverlay::OnPointerDown() {
108 is_pointer_down_from_activate_ = true;
109 }
110
111 void InstantOverlay::OnPointerRelease() {
112 if (is_pointer_down_from_activate_) {
113 is_pointer_down_from_activate_ = false;
114 delegate()->InstantPageClicked(contents());
115 }
116 }
117
118 void InstantOverlay::OnStalePage() {
119 is_stale_ = true;
120 delegate()->OnStalePage(contents());
121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698