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

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

Issue 6724014: Moves instant related tab contents messages into instant and out of (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/tab_contents/tab_contents.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/instant/instant_loader.h" 5 #include "chrome/browser/instant/instant_loader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 default: 130 default:
131 NOTREACHED(); 131 NOTREACHED();
132 break; 132 break;
133 } 133 }
134 } 134 }
135 135
136 // TabContentsDelegateImpl ----------------------------------------------------- 136 // TabContentsDelegateImpl -----------------------------------------------------
137 137
138 class InstantLoader::TabContentsDelegateImpl 138 class InstantLoader::TabContentsDelegateImpl
139 : public TabContentsDelegate, 139 : public TabContentsDelegate,
140 public NotificationObserver { 140 public NotificationObserver,
141 public TabContentsObserver {
141 public: 142 public:
142 explicit TabContentsDelegateImpl(InstantLoader* loader); 143 explicit TabContentsDelegateImpl(InstantLoader* loader);
143 144
144 // Invoked prior to loading a new URL. 145 // Invoked prior to loading a new URL.
145 void PrepareForNewLoad(); 146 void PrepareForNewLoad();
146 147
147 // Invoked when the preview paints. Invokes PreviewPainted on the loader. 148 // Invoked when the preview paints. Invokes PreviewPainted on the loader.
148 void PreviewPainted(); 149 void PreviewPainted();
149 150
150 bool is_mouse_down_from_activate() const { 151 bool is_mouse_down_from_activate() const {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // instant result when the drag ends, so that during the drag the page won't 206 // instant result when the drag ends, so that during the drag the page won't
206 // move around. 207 // move around.
207 virtual void DragEnded() OVERRIDE; 208 virtual void DragEnded() OVERRIDE;
208 virtual bool CanDownload(int request_id) OVERRIDE; 209 virtual bool CanDownload(int request_id) OVERRIDE;
209 virtual void HandleMouseUp() OVERRIDE; 210 virtual void HandleMouseUp() OVERRIDE;
210 virtual void HandleMouseActivate() OVERRIDE; 211 virtual void HandleMouseActivate() OVERRIDE;
211 virtual bool OnGoToEntryOffset(int offset) OVERRIDE; 212 virtual bool OnGoToEntryOffset(int offset) OVERRIDE;
212 virtual bool ShouldAddNavigationToHistory( 213 virtual bool ShouldAddNavigationToHistory(
213 const history::HistoryAddPageArgs& add_page_args, 214 const history::HistoryAddPageArgs& add_page_args,
214 NavigationType::Type navigation_type) OVERRIDE; 215 NavigationType::Type navigation_type) OVERRIDE;
215 virtual void OnSetSuggestions(
216 int32 page_id,
217 const std::vector<std::string>& suggestions,
218 InstantCompleteBehavior behavior) OVERRIDE;
219 virtual void OnInstantSupportDetermined(int32 page_id, bool result) OVERRIDE;
220 virtual bool ShouldShowHungRendererDialog() OVERRIDE; 216 virtual bool ShouldShowHungRendererDialog() OVERRIDE;
221 217
218 // TabContentsObserver:
219 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
220
222 private: 221 private:
223 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > 222 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> >
224 AddPageVector; 223 AddPageVector;
225 224
225 // Message from renderer indicating the page has suggestions.
226 void OnSetSuggestions(
227 int32 page_id,
228 const std::vector<std::string>& suggestions,
229 InstantCompleteBehavior behavior);
230
231 // Messages from the renderer when we've determined whether the page supports
232 // instant.
233 void OnInstantSupportDetermined(int32 page_id, bool result);
234
226 void CommitFromMouseReleaseIfNecessary(); 235 void CommitFromMouseReleaseIfNecessary();
227 236
228 InstantLoader* loader_; 237 InstantLoader* loader_;
229 238
230 NotificationRegistrar registrar_; 239 NotificationRegistrar registrar_;
231 240
232 // If we are registered for paint notifications on a RenderWidgetHost this 241 // If we are registered for paint notifications on a RenderWidgetHost this
233 // will contain a pointer to it. 242 // will contain a pointer to it.
234 RenderWidgetHost* registered_render_widget_host_; 243 RenderWidgetHost* registered_render_widget_host_;
235 244
(...skipping 11 matching lines...) Expand all
247 bool is_mouse_down_from_activate_; 256 bool is_mouse_down_from_activate_;
248 257
249 // True if the user typed in the search box before the page loaded. 258 // True if the user typed in the search box before the page loaded.
250 bool user_typed_before_load_; 259 bool user_typed_before_load_;
251 260
252 DISALLOW_COPY_AND_ASSIGN(TabContentsDelegateImpl); 261 DISALLOW_COPY_AND_ASSIGN(TabContentsDelegateImpl);
253 }; 262 };
254 263
255 InstantLoader::TabContentsDelegateImpl::TabContentsDelegateImpl( 264 InstantLoader::TabContentsDelegateImpl::TabContentsDelegateImpl(
256 InstantLoader* loader) 265 InstantLoader* loader)
257 : loader_(loader), 266 : TabContentsObserver(loader->preview_contents()->tab_contents()),
267 loader_(loader),
258 registered_render_widget_host_(NULL), 268 registered_render_widget_host_(NULL),
259 waiting_for_new_page_(true), 269 waiting_for_new_page_(true),
260 is_mouse_down_from_activate_(false), 270 is_mouse_down_from_activate_(false),
261 user_typed_before_load_(false) { 271 user_typed_before_load_(false) {
262 DCHECK(loader->preview_contents()); 272 DCHECK(loader->preview_contents());
263 registrar_.Add(this, NotificationType::INTERSTITIAL_ATTACHED, 273 registrar_.Add(this, NotificationType::INTERSTITIAL_ATTACHED,
264 Source<TabContents>(loader->preview_contents()->tab_contents())); 274 Source<TabContents>(loader->preview_contents()->tab_contents()));
265 } 275 }
266 276
267 void InstantLoader::TabContentsDelegateImpl::PrepareForNewLoad() { 277 void InstantLoader::TabContentsDelegateImpl::PrepareForNewLoad() {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 if (waiting_for_new_page_ && navigation_type == NavigationType::NEW_PAGE) 526 if (waiting_for_new_page_ && navigation_type == NavigationType::NEW_PAGE)
517 waiting_for_new_page_ = false; 527 waiting_for_new_page_ = false;
518 528
519 if (!waiting_for_new_page_) { 529 if (!waiting_for_new_page_) {
520 add_page_vector_.push_back( 530 add_page_vector_.push_back(
521 scoped_refptr<history::HistoryAddPageArgs>(add_page_args.Clone())); 531 scoped_refptr<history::HistoryAddPageArgs>(add_page_args.Clone()));
522 } 532 }
523 return false; 533 return false;
524 } 534 }
525 535
536 bool InstantLoader::TabContentsDelegateImpl::ShouldShowHungRendererDialog() {
537 // If we allow the hung renderer dialog to be shown it'll gain focus,
538 // stealing focus from the omnibox causing instant to be cancelled. Return
539 // false so that doesn't happen.
540 return false;
541 }
542
543 bool InstantLoader::TabContentsDelegateImpl::OnMessageReceived(
544 const IPC::Message& message) {
545 bool handled = true;
546 IPC_BEGIN_MESSAGE_MAP(TabContentsDelegateImpl, message)
547 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions)
548 IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined,
549 OnInstantSupportDetermined)
550 IPC_MESSAGE_UNHANDLED(handled = false)
551 IPC_END_MESSAGE_MAP()
552 return handled;
553 }
554
526 void InstantLoader::TabContentsDelegateImpl::OnSetSuggestions( 555 void InstantLoader::TabContentsDelegateImpl::OnSetSuggestions(
527 int32 page_id, 556 int32 page_id,
528 const std::vector<std::string>& suggestions, 557 const std::vector<std::string>& suggestions,
529 InstantCompleteBehavior behavior) { 558 InstantCompleteBehavior behavior) {
530 TabContentsWrapper* source = loader_->preview_contents(); 559 TabContentsWrapper* source = loader_->preview_contents();
531 if (!source->controller().GetActiveEntry() || 560 if (!source->controller().GetActiveEntry() ||
532 page_id != source->controller().GetActiveEntry()->page_id()) 561 page_id != source->controller().GetActiveEntry()->page_id())
533 return; 562 return;
534 563
535 if (suggestions.empty()) 564 if (suggestions.empty())
(...skipping 15 matching lines...) Expand all
551 NotificationType::INSTANT_SUPPORT_DETERMINED, 580 NotificationType::INSTANT_SUPPORT_DETERMINED,
552 NotificationService::AllSources(), 581 NotificationService::AllSources(),
553 details); 582 details);
554 583
555 if (result) 584 if (result)
556 loader_->PageFinishedLoading(); 585 loader_->PageFinishedLoading();
557 else 586 else
558 loader_->PageDoesntSupportInstant(user_typed_before_load_); 587 loader_->PageDoesntSupportInstant(user_typed_before_load_);
559 } 588 }
560 589
561 bool InstantLoader::TabContentsDelegateImpl::ShouldShowHungRendererDialog() {
562 // If we allow the hung renderer dialog to be shown it'll gain focus,
563 // stealing focus from the omnibox causing instant to be cancelled. Return
564 // false so that doesn't happen.
565 return false;
566 }
567
568 void InstantLoader::TabContentsDelegateImpl 590 void InstantLoader::TabContentsDelegateImpl
569 ::CommitFromMouseReleaseIfNecessary() { 591 ::CommitFromMouseReleaseIfNecessary() {
570 bool was_down = is_mouse_down_from_activate_; 592 bool was_down = is_mouse_down_from_activate_;
571 is_mouse_down_from_activate_ = false; 593 is_mouse_down_from_activate_ = false;
572 if (was_down && loader_->ShouldCommitInstantOnMouseUp()) 594 if (was_down && loader_->ShouldCommitInstantOnMouseUp())
573 loader_->CommitInstantLoader(); 595 loader_->CommitInstantLoader();
574 } 596 }
575 597
576 // InstantLoader --------------------------------------------------------------- 598 // InstantLoader ---------------------------------------------------------------
577 599
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 Source<NavigationController>(&preview_contents_->controller())); 982 Source<NavigationController>(&preview_contents_->controller()));
961 #endif 983 #endif
962 984
963 registrar_.Add( 985 registrar_.Add(
964 this, 986 this,
965 NotificationType::NAV_ENTRY_COMMITTED, 987 NotificationType::NAV_ENTRY_COMMITTED,
966 Source<NavigationController>(&preview_contents_->controller())); 988 Source<NavigationController>(&preview_contents_->controller()));
967 989
968 preview_contents_->tab_contents()->ShowContents(); 990 preview_contents_->tab_contents()->ShowContents();
969 } 991 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698