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

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: Address comments. Created 7 years, 10 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 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.
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 int kUserDataKey;
14
15 class InstantOverlayUserData : public base::SupportsUserData::Data {
16 public:
17 explicit InstantOverlayUserData(InstantOverlay* overlay)
18 : overlay_(overlay) {}
19
20 InstantOverlay* overlay() const { return overlay_; }
21
22 private:
23 ~InstantOverlayUserData() {}
24
25 InstantOverlay* const overlay_;
26
27 DISALLOW_COPY_AND_ASSIGN(InstantOverlayUserData);
28 };
29
30 } // namespace
31
32 // static
33 InstantOverlay* InstantOverlay::FromWebContents(
34 const content::WebContents* web_contents) {
35 InstantOverlayUserData* data = static_cast<InstantOverlayUserData*>(
36 web_contents->GetUserData(&kUserDataKey));
37 return data ? data->overlay() : NULL;
38 }
39
40 InstantOverlay::InstantOverlay(InstantController* controller,
41 const std::string& instant_url)
42 : InstantPage(controller),
43 loader_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
44 instant_url_(instant_url),
45 is_stale_(false),
46 is_pointer_down_from_activate_(false) {
47 }
48
49 InstantOverlay::~InstantOverlay() {
50 }
51
52 void InstantOverlay::InitContents(Profile* profile,
53 const content::WebContents* active_tab) {
54 loader_.Load(GURL(instant_url_), profile, active_tab,
55 base::Bind(&InstantOverlay::HandleStalePage,
56 base::Unretained(this)));
57 SetContents(loader_.contents());
58 contents()->SetUserData(&kUserDataKey, new InstantOverlayUserData(this));
59 }
60
61 scoped_ptr<content::WebContents> InstantOverlay::ReleaseContents() {
62 contents()->RemoveUserData(&kUserDataKey);
63 SetContents(NULL);
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 scoped_ptr<content::WebContents> InstantOverlay::SwapContents(
85 scoped_ptr<content::WebContents> new_contents) {
86 scoped_ptr<content::WebContents> old_contents = ReleaseContents();
87 loader_.SetContents(new_contents.Pass());
88 SetContents(loader_.contents());
89 contents()->SetUserData(&kUserDataKey, new InstantOverlayUserData(this));
90 instant_controller()->SwappedOverlayContents();
91 return old_contents.Pass();
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 instant_controller()->FocusedOverlayContents();
99 is_pointer_down_from_activate_ = tmp;
100 }
101
102 bool InstantOverlay::OnOpenURL() {
103 // Navigation can continue if we are able to commit the overlay.
104 return instant_controller()->CommitIfPossible(INSTANT_COMMIT_NAVIGATED);
105 }
106
107 void InstantOverlay::OnMouseDown() {
108 is_pointer_down_from_activate_ = true;
109 }
110
111 void InstantOverlay::OnMouseUp() {
112 if (is_pointer_down_from_activate_) {
113 is_pointer_down_from_activate_ = false;
114 instant_controller()->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST);
115 }
116 }
117
118 void InstantOverlay::HandleStalePage() {
119 is_stale_ = true;
120 instant_controller()->ReloadOverlayIfStale();
121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698