| OLD | NEW |
| 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 26 matching lines...) Expand all Loading... |
| 37 #include "content/browser/tab_contents/provisional_load_details.h" | 37 #include "content/browser/tab_contents/provisional_load_details.h" |
| 38 #include "content/browser/tab_contents/tab_contents.h" | 38 #include "content/browser/tab_contents/tab_contents.h" |
| 39 #include "content/browser/tab_contents/tab_contents_delegate.h" | 39 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 40 #include "content/browser/tab_contents/tab_contents_view.h" | 40 #include "content/browser/tab_contents/tab_contents_view.h" |
| 41 #include "content/common/content_notification_types.h" | 41 #include "content/common/content_notification_types.h" |
| 42 #include "content/common/notification_details.h" | 42 #include "content/common/notification_details.h" |
| 43 #include "content/common/notification_observer.h" | 43 #include "content/common/notification_observer.h" |
| 44 #include "content/common/notification_registrar.h" | 44 #include "content/common/notification_registrar.h" |
| 45 #include "content/common/notification_service.h" | 45 #include "content/common/notification_service.h" |
| 46 #include "content/common/notification_source.h" | 46 #include "content/common/notification_source.h" |
| 47 #include "content/common/page_transition_types.h" | |
| 48 #include "content/common/renderer_preferences.h" | 47 #include "content/common/renderer_preferences.h" |
| 49 #include "net/http/http_util.h" | 48 #include "net/http/http_util.h" |
| 50 #include "ui/base/l10n/l10n_util.h" | 49 #include "ui/base/l10n/l10n_util.h" |
| 51 #include "ui/gfx/codec/png_codec.h" | 50 #include "ui/gfx/codec/png_codec.h" |
| 52 | 51 |
| 53 namespace { | 52 namespace { |
| 54 | 53 |
| 55 // Number of ms to delay before updating the omnibox bounds. This is only used | 54 // Number of ms to delay before updating the omnibox bounds. This is only used |
| 56 // when the bounds of the omnibox shrinks. If the bounds grows, we update | 55 // when the bounds of the omnibox shrinks. If the bounds grows, we update |
| 57 // immediately. | 56 // immediately. |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 loader_->CommitInstantLoader(); | 563 loader_->CommitInstantLoader(); |
| 565 } | 564 } |
| 566 | 565 |
| 567 // InstantLoader --------------------------------------------------------------- | 566 // InstantLoader --------------------------------------------------------------- |
| 568 | 567 |
| 569 InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, TemplateURLID id) | 568 InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, TemplateURLID id) |
| 570 : delegate_(delegate), | 569 : delegate_(delegate), |
| 571 template_url_id_(id), | 570 template_url_id_(id), |
| 572 ready_(false), | 571 ready_(false), |
| 573 http_status_ok_(true), | 572 http_status_ok_(true), |
| 574 last_transition_type_(PageTransition::LINK), | 573 last_transition_type_(content::PAGE_TRANSITION_LINK), |
| 575 verbatim_(false), | 574 verbatim_(false), |
| 576 needs_reload_(false) { | 575 needs_reload_(false) { |
| 577 } | 576 } |
| 578 | 577 |
| 579 InstantLoader::~InstantLoader() { | 578 InstantLoader::~InstantLoader() { |
| 580 registrar_.RemoveAll(); | 579 registrar_.RemoveAll(); |
| 581 | 580 |
| 582 // Delete the TabContents before the delegate as the TabContents holds a | 581 // Delete the TabContents before the delegate as the TabContents holds a |
| 583 // reference to the delegate. | 582 // reference to the delegate. |
| 584 preview_contents_.reset(); | 583 preview_contents_.reset(); |
| 585 } | 584 } |
| 586 | 585 |
| 587 bool InstantLoader::Update(TabContentsWrapper* tab_contents, | 586 bool InstantLoader::Update(TabContentsWrapper* tab_contents, |
| 588 const TemplateURL* template_url, | 587 const TemplateURL* template_url, |
| 589 const GURL& url, | 588 const GURL& url, |
| 590 PageTransition::Type transition_type, | 589 content::PageTransition transition_type, |
| 591 const string16& user_text, | 590 const string16& user_text, |
| 592 bool verbatim, | 591 bool verbatim, |
| 593 string16* suggested_text) { | 592 string16* suggested_text) { |
| 594 DCHECK(!url.is_empty() && url.is_valid()); | 593 DCHECK(!url.is_empty() && url.is_valid()); |
| 595 | 594 |
| 596 // Strip leading ?. | 595 // Strip leading ?. |
| 597 string16 new_user_text = | 596 string16 new_user_text = |
| 598 !user_text.empty() && (UTF16ToWide(user_text)[0] == L'?') ? | 597 !user_text.empty() && (UTF16ToWide(user_text)[0] == L'?') ? |
| 599 user_text.substr(1) : user_text; | 598 user_text.substr(1) : user_text; |
| 600 | 599 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 const TemplateURL* template_url) { | 765 const TemplateURL* template_url) { |
| 767 DCHECK(template_url_id_ == template_url->id()); | 766 DCHECK(template_url_id_ == template_url->id()); |
| 768 | 767 |
| 769 // If we already have a |preview_contents_|, future search queries will be | 768 // If we already have a |preview_contents_|, future search queries will be |
| 770 // issued into it (see the "if (!created_preview_contents)" block in |Update| | 769 // issued into it (see the "if (!created_preview_contents)" block in |Update| |
| 771 // above), so there is no need to load the |template_url|'s instant URL. | 770 // above), so there is no need to load the |template_url|'s instant URL. |
| 772 if (preview_contents_.get()) | 771 if (preview_contents_.get()) |
| 773 return; | 772 return; |
| 774 | 773 |
| 775 CreatePreviewContents(tab_contents); | 774 CreatePreviewContents(tab_contents); |
| 776 LoadInstantURL(tab_contents, template_url, PageTransition::GENERATED, | 775 LoadInstantURL(tab_contents, template_url, content::PAGE_TRANSITION_GENERATED, |
| 777 string16(), true); | 776 string16(), true); |
| 778 } | 777 } |
| 779 | 778 |
| 780 bool InstantLoader::IsNavigationPending() const { | 779 bool InstantLoader::IsNavigationPending() const { |
| 781 return preview_contents_.get() && | 780 return preview_contents_.get() && |
| 782 preview_contents_->controller().pending_entry(); | 781 preview_contents_->controller().pending_entry(); |
| 783 } | 782 } |
| 784 | 783 |
| 785 void InstantLoader::Observe(int type, | 784 void InstantLoader::Observe(int type, |
| 786 const NotificationSource& source, | 785 const NotificationSource& source, |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); | 1016 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
| 1018 preview_contents_.reset(new TabContentsWrapper(new_contents)); | 1017 preview_contents_.reset(new TabContentsWrapper(new_contents)); |
| 1019 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); | 1018 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); |
| 1020 SetupPreviewContents(tab_contents); | 1019 SetupPreviewContents(tab_contents); |
| 1021 | 1020 |
| 1022 preview_contents_->tab_contents()->ShowContents(); | 1021 preview_contents_->tab_contents()->ShowContents(); |
| 1023 } | 1022 } |
| 1024 | 1023 |
| 1025 void InstantLoader::LoadInstantURL(TabContentsWrapper* tab_contents, | 1024 void InstantLoader::LoadInstantURL(TabContentsWrapper* tab_contents, |
| 1026 const TemplateURL* template_url, | 1025 const TemplateURL* template_url, |
| 1027 PageTransition::Type transition_type, | 1026 content::PageTransition transition_type, |
| 1028 const string16& user_text, | 1027 const string16& user_text, |
| 1029 bool verbatim) { | 1028 bool verbatim) { |
| 1030 preview_tab_contents_delegate_->PrepareForNewLoad(); | 1029 preview_tab_contents_delegate_->PrepareForNewLoad(); |
| 1031 | 1030 |
| 1032 // Load the instant URL. We don't reflect the url we load in url() as | 1031 // Load the instant URL. We don't reflect the url we load in url() as |
| 1033 // callers expect that we're loading the URL they tell us to. | 1032 // callers expect that we're loading the URL they tell us to. |
| 1034 // | 1033 // |
| 1035 // This uses an empty string for the replacement text as the url doesn't | 1034 // This uses an empty string for the replacement text as the url doesn't |
| 1036 // really have the search params, but we need to use the replace | 1035 // really have the search params, but we need to use the replace |
| 1037 // functionality so that embeded tags (like {google:baseURL}) are escaped | 1036 // functionality so that embeded tags (like {google:baseURL}) are escaped |
| 1038 // correctly. | 1037 // correctly. |
| 1039 // TODO(sky): having to use a replaceable url is a bit of a hack here. | 1038 // TODO(sky): having to use a replaceable url is a bit of a hack here. |
| 1040 GURL instant_url(template_url->instant_url()->ReplaceSearchTermsUsingProfile( | 1039 GURL instant_url(template_url->instant_url()->ReplaceSearchTermsUsingProfile( |
| 1041 tab_contents->profile(), *template_url, string16(), -1, string16())); | 1040 tab_contents->profile(), *template_url, string16(), -1, string16())); |
| 1042 CommandLine* cl = CommandLine::ForCurrentProcess(); | 1041 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 1043 if (cl->HasSwitch(switches::kInstantURL)) | 1042 if (cl->HasSwitch(switches::kInstantURL)) |
| 1044 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); | 1043 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); |
| 1045 preview_contents_->controller().LoadURL(instant_url, GURL(), transition_type, | 1044 preview_contents_->controller().LoadURL(instant_url, GURL(), transition_type, |
| 1046 std::string()); | 1045 std::string()); |
| 1047 RenderViewHost* host = preview_contents_->render_view_host(); | 1046 RenderViewHost* host = preview_contents_->render_view_host(); |
| 1048 host->Send(new ChromeViewMsg_SearchBoxChange( | 1047 host->Send(new ChromeViewMsg_SearchBoxChange( |
| 1049 host->routing_id(), user_text, verbatim, 0, 0)); | 1048 host->routing_id(), user_text, verbatim, 0, 0)); |
| 1050 frame_load_observer_.reset(new FrameLoadObserver( | 1049 frame_load_observer_.reset(new FrameLoadObserver( |
| 1051 this, preview_contents()->tab_contents(), user_text, verbatim)); | 1050 this, preview_contents()->tab_contents(), user_text, verbatim)); |
| 1052 } | 1051 } |
| OLD | NEW |