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

Side by Side Diff: chrome/browser/ui/search/search_tab_helper.cc

Issue 10644002: Add core plumbing for Instant Extended work (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address pkasting, tfarina, and remaining nits. Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.h ('k') | chrome/browser/ui/search/search_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 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/ui/search/search_tab_helper.h"
6
7 #include "chrome/browser/autocomplete/autocomplete_edit.h"
8 #include "chrome/browser/google/google_util.h"
9 #include "chrome/browser/ui/search/search_model.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents.h"
11 #include "chrome/common/url_constants.h"
12 #include "content/public/browser/navigation_controller.h"
13 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/notification_types.h"
16 #include "content/public/browser/render_widget_host.h"
17 #include "content/public/browser/render_widget_host_view.h"
18 #include "content/public/browser/web_contents.h"
19
20 namespace {
21
22 bool IsNTP(const GURL& url) {
23 return url.SchemeIs(chrome::kChromeUIScheme) &&
24 url.host() == chrome::kChromeUINewTabHost;
25 }
26
27 } // namespace
28
29 namespace chrome {
30 namespace search {
31
32 SearchTabHelper::SearchTabHelper(
33 TabContents* contents,
34 bool is_search_enabled)
35 : WebContentsObserver(contents->web_contents()),
36 is_search_enabled_(is_search_enabled),
37 model_(new SearchModel(contents)),
38 ntp_load_state_(DEFAULT),
39 main_frame_id_(0) {
40 }
41
42 SearchTabHelper::~SearchTabHelper() {
43 }
44
45 void SearchTabHelper::AutocompleteEditModelChanged(
46 AutocompleteEditModel* edit_model) {
47 if (!is_search_enabled_)
48 return;
49
50 if (model_->mode().is_ntp()) {
51 if (edit_model->user_input_in_progress())
52 model_->SetMode(Mode(Mode::MODE_SEARCH, true));
53 return;
54 }
55
56 Mode::Type mode = Mode::MODE_DEFAULT;
57 GURL url(web_contents()->GetURL());
58 if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec()) ||
59 edit_model->has_focus()) {
60 mode = Mode::MODE_SEARCH;
61 }
62 model_->SetMode(Mode(mode, true));
63 }
64
65 void SearchTabHelper::NavigateToPendingEntry(
66 const GURL& url,
67 content::NavigationController::ReloadType reload_type) {
68 if (!is_search_enabled_)
69 return;
70
71 registrar_.RemoveAll();
72 Mode::Type type = Mode::MODE_DEFAULT;
73 ntp_load_state_ = DEFAULT;
74 if (IsNTP(url)) {
75 type = Mode::MODE_NTP_LOADING;
76 ntp_load_state_ = WAITING_FOR_FRAME_ID;
77 } else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) {
78 type = Mode::MODE_SEARCH;
79 }
80 model_->SetMode(Mode(type, true));
81 }
82
83 void SearchTabHelper::DidStartProvisionalLoadForFrame(
84 int64 frame_id,
85 bool is_main_frame,
86 const GURL& validated_url,
87 bool is_error_page,
88 content::RenderViewHost* render_view_host) {
89 if (ntp_load_state_ == WAITING_FOR_FRAME_ID && is_main_frame &&
90 IsNTP(validated_url)) {
91 content::NavigationEntry* pending_entry =
92 web_contents()->GetController().GetPendingEntry();
93 if (pending_entry && IsNTP(pending_entry->GetURL())) {
94 ntp_load_state_ = WAITING_FOR_FRAME_LOAD;
95 main_frame_id_ = frame_id;
96 }
97 }
98 }
99
100 void SearchTabHelper::DocumentLoadedInFrame(int64 frame_id) {
101 if (ntp_load_state_ == WAITING_FOR_FRAME_LOAD && main_frame_id_ == frame_id) {
102 ntp_load_state_ = WAITING_FOR_PAINT;
103 registrar_.Add(
104 this,
105 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE,
106 content::Source<content::RenderWidgetHost>(GetRenderWidgetHost()));
107 }
108 }
109
110 void SearchTabHelper::Observe(
111 int type,
112 const content::NotificationSource& source,
113 const content::NotificationDetails& details) {
114 DCHECK_EQ(content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE,
115 type);
116 if (ntp_load_state_ == WAITING_FOR_PAINT) {
117 DCHECK_EQ(GetRenderWidgetHost(),
118 content::Source<content::RenderWidgetHost>(source).ptr());
119 ntp_load_state_ = DEFAULT;
120 model_->MaybeChangeMode(Mode::MODE_NTP_LOADING, Mode::MODE_NTP);
121 registrar_.RemoveAll();
122 }
123 }
124
125 content::RenderWidgetHost* SearchTabHelper::GetRenderWidgetHost() {
126 content::RenderWidgetHostView* rwhv =
127 web_contents()->GetRenderWidgetHostView();
128 return rwhv ? rwhv->GetRenderWidgetHost() : NULL;
129 }
130
131 } // namespace search
132 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.h ('k') | chrome/browser/ui/search/search_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698