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

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

Issue 4694008: Make pink's TabContentsWrapper change compile on Windows.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <utility> 8 #include <utility>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/timer.h" 13 #include "base/timer.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/favicon_service.h" 16 #include "chrome/browser/favicon_service.h"
17 #include "chrome/browser/history/history_marshaling.h" 17 #include "chrome/browser/history/history_marshaling.h"
18 #include "chrome/browser/instant/instant_loader_delegate.h" 18 #include "chrome/browser/instant/instant_loader_delegate.h"
19 #include "chrome/browser/profile.h" 19 #include "chrome/browser/profile.h"
20 #include "chrome/browser/renderer_host/render_view_host.h" 20 #include "chrome/browser/renderer_host/render_view_host.h"
21 #include "chrome/browser/renderer_host/render_widget_host.h" 21 #include "chrome/browser/renderer_host/render_widget_host.h"
22 #include "chrome/browser/renderer_host/render_widget_host_view.h" 22 #include "chrome/browser/renderer_host/render_widget_host_view.h"
23 #include "chrome/browser/search_engines/template_url.h" 23 #include "chrome/browser/search_engines/template_url.h"
24 #include "chrome/browser/tab_contents/navigation_controller.h" 24 #include "chrome/browser/tab_contents/navigation_controller.h"
25 #include "chrome/browser/tab_contents/navigation_entry.h" 25 #include "chrome/browser/tab_contents/navigation_entry.h"
26 #include "chrome/browser/tab_contents/tab_contents.h" 26 #include "chrome/browser/tab_contents/tab_contents.h"
27 #include "chrome/browser/tab_contents/tab_contents_delegate.h" 27 #include "chrome/browser/tab_contents/tab_contents_delegate.h"
28 #include "chrome/browser/tab_contents/tab_contents_view.h" 28 #include "chrome/browser/tab_contents/tab_contents_view.h"
29 #include "chrome/browser/tab_contents_wrapper.h"
29 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/notification_observer.h" 31 #include "chrome/common/notification_observer.h"
31 #include "chrome/common/notification_registrar.h" 32 #include "chrome/common/notification_registrar.h"
32 #include "chrome/common/notification_service.h" 33 #include "chrome/common/notification_service.h"
33 #include "chrome/common/notification_type.h" 34 #include "chrome/common/notification_type.h"
34 #include "chrome/common/page_transition_types.h" 35 #include "chrome/common/page_transition_types.h"
35 #include "chrome/common/render_messages.h" 36 #include "chrome/common/render_messages.h"
36 #include "chrome/common/renderer_preferences.h" 37 #include "chrome/common/renderer_preferences.h"
37 #include "gfx/codec/png_codec.h" 38 #include "gfx/codec/png_codec.h"
38 #include "ipc/ipc_message.h" 39 #include "ipc/ipc_message.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 146 }
146 147
147 bool is_mouse_down_from_activate() const { 148 bool is_mouse_down_from_activate() const {
148 return is_mouse_down_from_activate_; 149 return is_mouse_down_from_activate_;
149 } 150 }
150 151
151 void set_user_typed_before_load() { user_typed_before_load_ = true; } 152 void set_user_typed_before_load() { user_typed_before_load_ = true; }
152 153
153 // Commits the currently buffered history. 154 // Commits the currently buffered history.
154 void CommitHistory() { 155 void CommitHistory() {
155 TabContents* tab = loader_->preview_contents(); 156 TabContents* tab = loader_->preview_contents()->tab_contents();
156 if (tab->profile()->IsOffTheRecord()) 157 if (tab->profile()->IsOffTheRecord())
157 return; 158 return;
158 159
159 for (size_t i = 0; i < add_page_vector_.size(); ++i) 160 for (size_t i = 0; i < add_page_vector_.size(); ++i)
160 tab->UpdateHistoryForNavigation(add_page_vector_[i].get()); 161 tab->UpdateHistoryForNavigation(add_page_vector_[i].get());
161 162
162 NavigationEntry* active_entry = tab->controller().GetActiveEntry(); 163 NavigationEntry* active_entry = tab->controller().GetActiveEntry();
163 DCHECK(active_entry); 164 DCHECK(active_entry);
164 tab->UpdateHistoryPageTitle(*active_entry); 165 tab->UpdateHistoryPageTitle(*active_entry);
165 166
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 return NULL; 309 return NULL;
309 } 310 }
310 virtual void TabContentsCreated(TabContents* new_contents) {} 311 virtual void TabContentsCreated(TabContents* new_contents) {}
311 virtual bool infobars_enabled() { return false; } 312 virtual bool infobars_enabled() { return false; }
312 virtual bool ShouldEnablePreferredSizeNotifications() { return false; } 313 virtual bool ShouldEnablePreferredSizeNotifications() { return false; }
313 virtual void UpdatePreferredSize(const gfx::Size& pref_size) {} 314 virtual void UpdatePreferredSize(const gfx::Size& pref_size) {}
314 virtual void ContentTypeChanged(TabContents* source) {} 315 virtual void ContentTypeChanged(TabContents* source) {}
315 316
316 virtual void OnSetSuggestions(int32 page_id, 317 virtual void OnSetSuggestions(int32 page_id,
317 const std::vector<std::string>& suggestions) { 318 const std::vector<std::string>& suggestions) {
318 TabContents* source = loader_->preview_contents(); 319 TabContentsWrapper* source = loader_->preview_contents();
319 if (!source->controller().GetActiveEntry() || 320 if (!source->controller().GetActiveEntry() ||
320 page_id != source->controller().GetActiveEntry()->page_id()) 321 page_id != source->controller().GetActiveEntry()->page_id())
321 return; 322 return;
322 323
323 // TODO: only allow for default search provider. 324 // TODO: only allow for default search provider.
324 // TODO(sky): Handle multiple suggestions. 325 // TODO(sky): Handle multiple suggestions.
325 if (suggestions.empty()) 326 if (suggestions.empty())
326 loader_->SetCompleteSuggestedText(string16()); 327 loader_->SetCompleteSuggestedText(string16());
327 else 328 else
328 loader_->SetCompleteSuggestedText(UTF8ToUTF16(suggestions[0])); 329 loader_->SetCompleteSuggestedText(UTF8ToUTF16(suggestions[0]));
329 } 330 }
330 331
331 virtual void OnInstantSupportDetermined(int32 page_id, bool result) { 332 virtual void OnInstantSupportDetermined(int32 page_id, bool result) {
332 TabContents* source = loader_->preview_contents(); 333 TabContents* source = loader_->preview_contents()->tab_contents();
333 if (!source->controller().GetActiveEntry() || 334 if (!source->controller().GetActiveEntry() ||
334 page_id != source->controller().GetActiveEntry()->page_id()) 335 page_id != source->controller().GetActiveEntry()->page_id())
335 return; 336 return;
336 337
337 if (result) { 338 if (result) {
338 gfx::Rect bounds = loader_->GetOmniboxBoundsInTermsOfPreview(); 339 gfx::Rect bounds = loader_->GetOmniboxBoundsInTermsOfPreview();
339 loader_->last_omnibox_bounds_ = loader_->omnibox_bounds_; 340 loader_->last_omnibox_bounds_ = loader_->omnibox_bounds_;
340 loader_->PageFinishedLoading(); 341 loader_->PageFinishedLoading();
341 } else { 342 } else {
342 loader_->PageDoesntSupportInstant(user_typed_before_load_); 343 loader_->PageDoesntSupportInstant(user_typed_before_load_);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } 389 }
389 390
390 InstantLoader::~InstantLoader() { 391 InstantLoader::~InstantLoader() {
391 registrar_.RemoveAll(); 392 registrar_.RemoveAll();
392 393
393 // Delete the TabContents before the delegate as the TabContents holds a 394 // Delete the TabContents before the delegate as the TabContents holds a
394 // reference to the delegate. 395 // reference to the delegate.
395 preview_contents_.reset(NULL); 396 preview_contents_.reset(NULL);
396 } 397 }
397 398
398 void InstantLoader::Update(TabContents* tab_contents, 399 void InstantLoader::Update(TabContentsWrapper* tab_contents,
399 const TemplateURL* template_url, 400 const TemplateURL* template_url,
400 const GURL& url, 401 const GURL& url,
401 PageTransition::Type transition_type, 402 PageTransition::Type transition_type,
402 const string16& user_text, 403 const string16& user_text,
403 string16* suggested_text) { 404 string16* suggested_text) {
404 if (url_ == url) 405 if (url_ == url)
405 return; 406 return;
406 407
407 DCHECK(!url.is_empty() && url.is_valid()); 408 DCHECK(!url.is_empty() && url.is_valid());
408 409
409 last_transition_type_ = transition_type; 410 last_transition_type_ = transition_type;
410 url_ = url; 411 url_ = url;
411 user_text_ = user_text; 412 user_text_ = user_text;
412 413
413 bool created_preview_contents; 414 bool created_preview_contents;
414 if (preview_contents_.get() == NULL) { 415 if (preview_contents_.get() == NULL) {
415 preview_contents_.reset( 416 TabContents* new_contents =
416 new TabContents(tab_contents->profile(), NULL, MSG_ROUTING_NONE, 417 new TabContents(
417 NULL, NULL)); 418 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
418 preview_contents_->SetAllContentsBlocked(true); 419 preview_contents_.reset(new TabContentsWrapper(new_contents));
420 new_contents->SetAllContentsBlocked(true);
419 // Propagate the max page id. That way if we end up merging the two 421 // Propagate the max page id. That way if we end up merging the two
420 // NavigationControllers (which happens if we commit) none of the page ids 422 // NavigationControllers (which happens if we commit) none of the page ids
421 // will overlap. 423 // will overlap.
422 int32 max_page_id = tab_contents->GetMaxPageID(); 424 int32 max_page_id = tab_contents->tab_contents()->GetMaxPageID();
423 if (max_page_id != -1) 425 if (max_page_id != -1)
424 preview_contents_->controller().set_max_restored_page_id(max_page_id + 1); 426 preview_contents_->controller().set_max_restored_page_id(max_page_id + 1);
425 427
426 preview_contents_->set_delegate(preview_tab_contents_delegate_.get()); 428 new_contents->set_delegate(preview_tab_contents_delegate_.get());
427 429
428 gfx::Rect tab_bounds; 430 gfx::Rect tab_bounds;
429 tab_contents->view()->GetContainerBounds(&tab_bounds); 431 tab_contents->view()->GetContainerBounds(&tab_bounds);
430 preview_contents_->view()->SizeContents(tab_bounds.size()); 432 preview_contents_->view()->SizeContents(tab_bounds.size());
431 433
432 #if defined(OS_MACOSX) 434 #if defined(OS_MACOSX)
433 // If |preview_contents_| does not currently have a RWHV, we will call 435 // If |preview_contents_| does not currently have a RWHV, we will call
434 // SetTakesFocusOnlyOnMouseDown() as a result of the 436 // SetTakesFocusOnlyOnMouseDown() as a result of the
435 // RENDER_VIEW_HOST_CHANGED notification. 437 // RENDER_VIEW_HOST_CHANGED notification.
436 if (preview_contents_->GetRenderWidgetHostView()) { 438 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) {
437 preview_contents_->GetRenderWidgetHostView()-> 439 preview_contents_->tab_contents()->GetRenderWidgetHostView()->
438 SetTakesFocusOnlyOnMouseDown(true); 440 SetTakesFocusOnlyOnMouseDown(true);
439 } 441 }
440 registrar_.Add( 442 registrar_.Add(
441 this, 443 this,
442 NotificationType::RENDER_VIEW_HOST_CHANGED, 444 NotificationType::RENDER_VIEW_HOST_CHANGED,
443 Source<NavigationController>(&preview_contents_->controller())); 445 Source<NavigationController>(&preview_contents_->controller()));
444 #endif 446 #endif
445 447
446 preview_contents_->ShowContents(); 448 preview_contents_->tab_contents()->ShowContents();
447 created_preview_contents = true; 449 created_preview_contents = true;
448 } else { 450 } else {
449 created_preview_contents = false; 451 created_preview_contents = false;
450 } 452 }
451 preview_tab_contents_delegate_->PrepareForNewLoad(); 453 preview_tab_contents_delegate_->PrepareForNewLoad();
452 454
453 if (template_url) { 455 if (template_url) {
454 DCHECK(template_url_id_ == template_url->id()); 456 DCHECK(template_url_id_ == template_url->id());
455 if (!created_preview_contents) { 457 if (!created_preview_contents) {
456 if (is_waiting_for_load()) { 458 if (is_waiting_for_load()) {
(...skipping 25 matching lines...) Expand all
482 GURL instant_url( 484 GURL instant_url(
483 template_url->instant_url()->ReplaceSearchTerms( 485 template_url->instant_url()->ReplaceSearchTerms(
484 *template_url, std::wstring(), -1, std::wstring())); 486 *template_url, std::wstring(), -1, std::wstring()));
485 CommandLine* cl = CommandLine::ForCurrentProcess(); 487 CommandLine* cl = CommandLine::ForCurrentProcess();
486 if (cl->HasSwitch(switches::kInstantURL)) 488 if (cl->HasSwitch(switches::kInstantURL))
487 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); 489 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL));
488 initial_instant_url_ = url; 490 initial_instant_url_ = url;
489 preview_contents_->controller().LoadURL( 491 preview_contents_->controller().LoadURL(
490 instant_url, GURL(), transition_type); 492 instant_url, GURL(), transition_type);
491 frame_load_observer_.reset( 493 frame_load_observer_.reset(
492 new FrameLoadObserver(preview_contents(), user_text_)); 494 new FrameLoadObserver(preview_contents()->tab_contents(),
495 user_text_));
493 } 496 }
494 } else { 497 } else {
495 DCHECK(template_url_id_ == 0); 498 DCHECK(template_url_id_ == 0);
496 frame_load_observer_.reset(NULL); 499 frame_load_observer_.reset(NULL);
497 preview_contents_->controller().LoadURL(url_, GURL(), transition_type); 500 preview_contents_->controller().LoadURL(url_, GURL(), transition_type);
498 } 501 }
499 } 502 }
500 503
501 void InstantLoader::SetOmniboxBounds(const gfx::Rect& bounds) { 504 void InstantLoader::SetOmniboxBounds(const gfx::Rect& bounds) {
502 if (omnibox_bounds_ == bounds) 505 if (omnibox_bounds_ == bounds)
(...skipping 10 matching lines...) Expand all
513 update_bounds_timer_.Start( 516 update_bounds_timer_.Start(
514 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), 517 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS),
515 this, &InstantLoader::ProcessBoundsChange); 518 this, &InstantLoader::ProcessBoundsChange);
516 } 519 }
517 } 520 }
518 521
519 bool InstantLoader::IsMouseDownFromActivate() { 522 bool InstantLoader::IsMouseDownFromActivate() {
520 return preview_tab_contents_delegate_->is_mouse_down_from_activate(); 523 return preview_tab_contents_delegate_->is_mouse_down_from_activate();
521 } 524 }
522 525
523 TabContents* InstantLoader::ReleasePreviewContents(InstantCommitType type) { 526 TabContentsWrapper* InstantLoader::ReleasePreviewContents(
527 InstantCommitType type) {
524 if (!preview_contents_.get()) 528 if (!preview_contents_.get())
525 return NULL; 529 return NULL;
526 530
527 // FrameLoadObserver is only used for instant results, and instant results are 531 // FrameLoadObserver is only used for instant results, and instant results are
528 // only committed if active (when the FrameLoadObserver isn't installed). 532 // only committed if active (when the FrameLoadObserver isn't installed).
529 DCHECK(type == INSTANT_COMMIT_DESTROY || !frame_load_observer_.get()); 533 DCHECK(type == INSTANT_COMMIT_DESTROY || !frame_load_observer_.get());
530 534
531 if (type != INSTANT_COMMIT_DESTROY && is_showing_instant()) { 535 if (type != INSTANT_COMMIT_DESTROY && is_showing_instant()) {
532 if (type == INSTANT_COMMIT_FOCUS_LOST) 536 if (type == INSTANT_COMMIT_FOCUS_LOST)
533 preview_contents_->render_view_host()->SearchBoxCancel(); 537 preview_contents_->render_view_host()->SearchBoxCancel();
534 else 538 else
535 preview_contents_->render_view_host()->SearchBoxSubmit( 539 preview_contents_->render_view_host()->SearchBoxSubmit(
536 user_text_, type == INSTANT_COMMIT_PRESSED_ENTER); 540 user_text_, type == INSTANT_COMMIT_PRESSED_ENTER);
537 } 541 }
538 omnibox_bounds_ = gfx::Rect(); 542 omnibox_bounds_ = gfx::Rect();
539 last_omnibox_bounds_ = gfx::Rect(); 543 last_omnibox_bounds_ = gfx::Rect();
540 url_ = GURL(); 544 url_ = GURL();
541 user_text_.clear(); 545 user_text_.clear();
542 complete_suggested_text_.clear(); 546 complete_suggested_text_.clear();
543 if (preview_contents_.get()) { 547 if (preview_contents_.get()) {
544 if (type != INSTANT_COMMIT_DESTROY) 548 if (type != INSTANT_COMMIT_DESTROY)
545 preview_tab_contents_delegate_->CommitHistory(); 549 preview_tab_contents_delegate_->CommitHistory();
546 // Destroy the paint observer. 550 // Destroy the paint observer.
547 // RenderWidgetHostView may be null during shutdown. 551 // RenderWidgetHostView may be null during shutdown.
548 if (preview_contents_->GetRenderWidgetHostView()) { 552 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) {
549 preview_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()-> 553 preview_contents_->tab_contents()->GetRenderWidgetHostView()->
550 set_paint_observer(NULL); 554 GetRenderWidgetHost()->set_paint_observer(NULL);
551 #if defined(OS_MACOSX) 555 #if defined(OS_MACOSX)
552 preview_contents_->GetRenderWidgetHostView()-> 556 preview_contents_->tab_contents()->GetRenderWidgetHostView()->
553 SetTakesFocusOnlyOnMouseDown(false); 557 SetTakesFocusOnlyOnMouseDown(false);
554 registrar_.Remove( 558 registrar_.Remove(
555 this, 559 this,
556 NotificationType::RENDER_VIEW_HOST_CHANGED, 560 NotificationType::RENDER_VIEW_HOST_CHANGED,
557 Source<NavigationController>(&preview_contents_->controller())); 561 Source<NavigationController>(&preview_contents_->controller()));
558 #endif 562 #endif
559 } 563 }
560 preview_contents_->set_delegate(NULL); 564 preview_contents_->set_delegate(NULL);
561 preview_tab_contents_delegate_->Reset(); 565 preview_tab_contents_delegate_->Reset();
562 ready_ = false; 566 ready_ = false;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 if (last_omnibox_bounds_ == omnibox_bounds_) 691 if (last_omnibox_bounds_ == omnibox_bounds_)
688 return; 692 return;
689 693
690 last_omnibox_bounds_ = omnibox_bounds_; 694 last_omnibox_bounds_ = omnibox_bounds_;
691 if (preview_contents_.get() && is_showing_instant() && 695 if (preview_contents_.get() && is_showing_instant() &&
692 !is_waiting_for_load()) { 696 !is_waiting_for_load()) {
693 preview_contents_->render_view_host()->SearchBoxResize( 697 preview_contents_->render_view_host()->SearchBoxResize(
694 GetOmniboxBoundsInTermsOfPreview()); 698 GetOmniboxBoundsInTermsOfPreview());
695 } 699 }
696 } 700 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698