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

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

Issue 7880003: content: Move constrained window code from TabContents to TabContentsWrapper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Attempt to fix views merge part 2 Created 9 years, 2 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
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>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/i18n/case_conversion.h" 13 #include "base/i18n/case_conversion.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/timer.h" 15 #include "base/timer.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/favicon/favicon_service.h" 18 #include "chrome/browser/favicon/favicon_service.h"
19 #include "chrome/browser/history/history_marshaling.h" 19 #include "chrome/browser/history/history_marshaling.h"
20 #include "chrome/browser/history/history_tab_helper.h" 20 #include "chrome/browser/history/history_tab_helper.h"
21 #include "chrome/browser/instant/instant_loader_delegate.h" 21 #include "chrome/browser/instant/instant_loader_delegate.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/search_engines/template_url.h" 23 #include "chrome/browser/search_engines/template_url.h"
24 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" 24 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
25 #include "chrome/browser/ui/constrained_window_tab_helper.h"
26 #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h"
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" 28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h"
27 #include "chrome/common/chrome_notification_types.h" 29 #include "chrome/common/chrome_notification_types.h"
28 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/render_messages.h" 31 #include "chrome/common/render_messages.h"
30 #include "content/browser/renderer_host/render_view_host.h" 32 #include "content/browser/renderer_host/render_view_host.h"
31 #include "content/browser/renderer_host/render_widget_host.h" 33 #include "content/browser/renderer_host/render_widget_host.h"
32 #include "content/browser/renderer_host/render_widget_host_view.h" 34 #include "content/browser/renderer_host/render_widget_host_view.h"
33 #include "content/browser/tab_contents/navigation_details.h" 35 #include "content/browser/tab_contents/navigation_details.h"
34 #include "content/browser/tab_contents/navigation_entry.h" 36 #include "content/browser/tab_contents/navigation_entry.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 NOTREACHED(); 141 NOTREACHED();
140 break; 142 break;
141 } 143 }
142 } 144 }
143 145
144 // TabContentsDelegateImpl ----------------------------------------------------- 146 // TabContentsDelegateImpl -----------------------------------------------------
145 147
146 class InstantLoader::TabContentsDelegateImpl 148 class InstantLoader::TabContentsDelegateImpl
147 : public TabContentsDelegate, 149 : public TabContentsDelegate,
148 public TabContentsWrapperDelegate, 150 public TabContentsWrapperDelegate,
151 public ConstrainedWindowTabHelperDelegate,
149 public NotificationObserver, 152 public NotificationObserver,
150 public TabContentsObserver { 153 public TabContentsObserver {
151 public: 154 public:
152 explicit TabContentsDelegateImpl(InstantLoader* loader); 155 explicit TabContentsDelegateImpl(InstantLoader* loader);
153 156
154 // Invoked prior to loading a new URL. 157 // Invoked prior to loading a new URL.
155 void PrepareForNewLoad(); 158 void PrepareForNewLoad();
156 159
157 // Invoked when the preview paints. Invokes PreviewPainted on the loader. 160 // Invoked when the preview paints. Invokes PreviewPainted on the loader.
158 void PreviewPainted(); 161 void PreviewPainted();
(...skipping 18 matching lines...) Expand all
177 // NotificationObserver: 180 // NotificationObserver:
178 virtual void Observe(int type, 181 virtual void Observe(int type,
179 const NotificationSource& source, 182 const NotificationSource& source,
180 const NotificationDetails& details) OVERRIDE; 183 const NotificationDetails& details) OVERRIDE;
181 184
182 // TabContentsDelegate: 185 // TabContentsDelegate:
183 virtual void NavigationStateChanged(const TabContents* source, 186 virtual void NavigationStateChanged(const TabContents* source,
184 unsigned changed_flags) OVERRIDE; 187 unsigned changed_flags) OVERRIDE;
185 virtual void AddNavigationHeaders(const GURL& url, 188 virtual void AddNavigationHeaders(const GURL& url,
186 std::string* headers) OVERRIDE; 189 std::string* headers) OVERRIDE;
187 virtual bool ShouldFocusConstrainedWindow() OVERRIDE;
188 virtual void WillShowConstrainedWindow(TabContents* source) OVERRIDE;
189 virtual bool ShouldSuppressDialogs() OVERRIDE; 190 virtual bool ShouldSuppressDialogs() OVERRIDE;
190 virtual void BeforeUnloadFired(TabContents* tab, 191 virtual void BeforeUnloadFired(TabContents* tab,
191 bool proceed, 192 bool proceed,
192 bool* proceed_to_fire_unload) OVERRIDE; 193 bool* proceed_to_fire_unload) OVERRIDE;
193 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE; 194 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
194 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; 195 virtual bool ShouldFocusPageAfterCrash() OVERRIDE;
195 virtual void LostCapture() OVERRIDE; 196 virtual void LostCapture() OVERRIDE;
196 // If the user drags, we won't get a mouse up (at least on Linux). Commit the 197 // If the user drags, we won't get a mouse up (at least on Linux). Commit the
197 // instant result when the drag ends, so that during the drag the page won't 198 // instant result when the drag ends, so that during the drag the page won't
198 // move around. 199 // move around.
199 virtual void DragEnded() OVERRIDE; 200 virtual void DragEnded() OVERRIDE;
200 virtual bool CanDownload(TabContents* source, int request_id) OVERRIDE; 201 virtual bool CanDownload(TabContents* source, int request_id) OVERRIDE;
201 virtual void HandleMouseUp() OVERRIDE; 202 virtual void HandleMouseUp() OVERRIDE;
202 virtual void HandleMouseActivate() OVERRIDE; 203 virtual void HandleMouseActivate() OVERRIDE;
203 virtual bool OnGoToEntryOffset(int offset) OVERRIDE; 204 virtual bool OnGoToEntryOffset(int offset) OVERRIDE;
204 virtual bool ShouldAddNavigationToHistory( 205 virtual bool ShouldAddNavigationToHistory(
205 const history::HistoryAddPageArgs& add_page_args, 206 const history::HistoryAddPageArgs& add_page_args,
206 NavigationType::Type navigation_type) OVERRIDE; 207 NavigationType::Type navigation_type) OVERRIDE;
207 208
208 // TabContentsWrapperDelegate: 209 // TabContentsWrapperDelegate:
209 virtual void SwapTabContents(TabContentsWrapper* old_tc, 210 virtual void SwapTabContents(TabContentsWrapper* old_tc,
210 TabContentsWrapper* new_tc) OVERRIDE; 211 TabContentsWrapper* new_tc) OVERRIDE;
211 212
213 // ConstrainedWindowTabHelperDelegate:
214 virtual void WillShowConstrainedWindow(TabContentsWrapper* source) OVERRIDE;
215 virtual bool ShouldFocusConstrainedWindow() OVERRIDE;
216
212 // TabContentsObserver: 217 // TabContentsObserver:
213 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 218 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
214 219
215 private: 220 private:
216 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > 221 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> >
217 AddPageVector; 222 AddPageVector;
218 223
219 // Message from renderer indicating the page has suggestions. 224 // Message from renderer indicating the page has suggestions.
220 void OnSetSuggestions( 225 void OnSetSuggestions(
221 int32 page_id, 226 int32 page_id,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 419 }
415 } 420 }
416 421
417 void InstantLoader::TabContentsDelegateImpl::AddNavigationHeaders( 422 void InstantLoader::TabContentsDelegateImpl::AddNavigationHeaders(
418 const GURL& url, 423 const GURL& url,
419 std::string* headers) { 424 std::string* headers) {
420 net::HttpUtil::AppendHeaderIfMissing(kInstantHeader, kInstantHeaderValue, 425 net::HttpUtil::AppendHeaderIfMissing(kInstantHeader, kInstantHeaderValue,
421 headers); 426 headers);
422 } 427 }
423 428
424 bool InstantLoader::TabContentsDelegateImpl::ShouldFocusConstrainedWindow() {
425 // Return false so that constrained windows are not initially focused. If
426 // we did otherwise the preview would prematurely get committed when focus
427 // goes to the constrained window.
428 return false;
429 }
430
431 void InstantLoader::TabContentsDelegateImpl::WillShowConstrainedWindow(
432 TabContents* source) {
433 if (!loader_->ready()) {
434 // A constrained window shown for an auth may not paint. Show the preview
435 // contents.
436 UnregisterForPaintNotifications();
437 loader_->ShowPreview();
438 }
439 }
440
441 bool InstantLoader::TabContentsDelegateImpl::ShouldSuppressDialogs() { 429 bool InstantLoader::TabContentsDelegateImpl::ShouldSuppressDialogs() {
442 // Any message shown during instant cancels instant, so we suppress them. 430 // Any message shown during instant cancels instant, so we suppress them.
443 return true; 431 return true;
444 } 432 }
445 433
446 void InstantLoader::TabContentsDelegateImpl::BeforeUnloadFired( 434 void InstantLoader::TabContentsDelegateImpl::BeforeUnloadFired(
447 TabContents* tab, 435 TabContents* tab,
448 bool proceed, 436 bool proceed,
449 bool* proceed_to_fire_unload) { 437 bool* proceed_to_fire_unload) {
450 } 438 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 } 485 }
498 486
499 // If this is being called, something is swapping in to our preview_contents_ 487 // If this is being called, something is swapping in to our preview_contents_
500 // before we've added it to the tab strip. 488 // before we've added it to the tab strip.
501 void InstantLoader::TabContentsDelegateImpl::SwapTabContents( 489 void InstantLoader::TabContentsDelegateImpl::SwapTabContents(
502 TabContentsWrapper* old_tc, 490 TabContentsWrapper* old_tc,
503 TabContentsWrapper* new_tc) { 491 TabContentsWrapper* new_tc) {
504 loader_->ReplacePreviewContents(old_tc, new_tc); 492 loader_->ReplacePreviewContents(old_tc, new_tc);
505 } 493 }
506 494
495 bool InstantLoader::TabContentsDelegateImpl::ShouldFocusConstrainedWindow() {
496 // Return false so that constrained windows are not initially focused. If
497 // we did otherwise the preview would prematurely get committed when focus
498 // goes to the constrained window.
499 return false;
500 }
501
502 void InstantLoader::TabContentsDelegateImpl::WillShowConstrainedWindow(
503 TabContentsWrapper* source) {
504 if (!loader_->ready()) {
505 // A constrained window shown for an auth may not paint. Show the preview
506 // contents.
507 UnregisterForPaintNotifications();
508 loader_->ShowPreview();
509 }
510 }
507 511
508 bool InstantLoader::TabContentsDelegateImpl::OnMessageReceived( 512 bool InstantLoader::TabContentsDelegateImpl::OnMessageReceived(
509 const IPC::Message& message) { 513 const IPC::Message& message) {
510 bool handled = true; 514 bool handled = true;
511 IPC_BEGIN_MESSAGE_MAP(TabContentsDelegateImpl, message) 515 IPC_BEGIN_MESSAGE_MAP(TabContentsDelegateImpl, message)
512 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) 516 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions)
513 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, 517 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined,
514 OnInstantSupportDetermined) 518 OnInstantSupportDetermined)
515 IPC_MESSAGE_UNHANDLED(handled = false) 519 IPC_MESSAGE_UNHANDLED(handled = false)
516 IPC_END_MESSAGE_MAP() 520 IPC_END_MESSAGE_MAP()
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 DCHECK(old_tc == preview_contents_); 944 DCHECK(old_tc == preview_contents_);
941 // We release here without deleting so that the caller still has reponsibility 945 // We release here without deleting so that the caller still has reponsibility
942 // for deleting the TabContentsWrapper. 946 // for deleting the TabContentsWrapper.
943 ignore_result(preview_contents_.release()); 947 ignore_result(preview_contents_.release());
944 preview_contents_.reset(new_tc); 948 preview_contents_.reset(new_tc);
945 949
946 // Make sure the new preview contents acts like the old one. 950 // Make sure the new preview contents acts like the old one.
947 SetupPreviewContents(old_tc); 951 SetupPreviewContents(old_tc);
948 952
949 // Cleanup the old preview contents. 953 // Cleanup the old preview contents.
954 old_tc->constrained_window_tab_helper()->set_delegate(NULL);
950 old_tc->tab_contents()->set_delegate(NULL); 955 old_tc->tab_contents()->set_delegate(NULL);
951 old_tc->set_delegate(NULL); 956 old_tc->set_delegate(NULL);
952 957
953 #if defined(OS_MACOSX) 958 #if defined(OS_MACOSX)
954 registrar_.Remove(this, 959 registrar_.Remove(this,
955 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 960 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
956 Source<NavigationController>(&old_tc->controller())); 961 Source<NavigationController>(&old_tc->controller()));
957 #endif 962 #endif
958 registrar_.Remove(this, 963 registrar_.Remove(this,
959 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 964 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
960 Source<NavigationController>(&old_tc->controller())); 965 Source<NavigationController>(&old_tc->controller()));
961 966
962 // We prerendered so we should be ready to show. If we're ready, swap in 967 // We prerendered so we should be ready to show. If we're ready, swap in
963 // immediately, otherwise show the preview as normal. 968 // immediately, otherwise show the preview as normal.
964 if (ready_) 969 if (ready_)
965 delegate_->SwappedTabContents(this); 970 delegate_->SwappedTabContents(this);
966 else 971 else
967 ShowPreview(); 972 ShowPreview();
968 } 973 }
969 974
970 void InstantLoader::SetupPreviewContents(TabContentsWrapper* tab_contents) { 975 void InstantLoader::SetupPreviewContents(TabContentsWrapper* tab_contents) {
971 preview_contents_->set_delegate(preview_tab_contents_delegate_.get()); 976 preview_contents_->set_delegate(preview_tab_contents_delegate_.get());
972 preview_contents_->tab_contents()->set_delegate( 977 preview_contents_->tab_contents()->set_delegate(
973 preview_tab_contents_delegate_.get()); 978 preview_tab_contents_delegate_.get());
974 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true); 979 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true);
980 preview_contents_->constrained_window_tab_helper()->set_delegate(
981 preview_tab_contents_delegate_.get());
975 982
976 // Propagate the max page id. That way if we end up merging the two 983 // Propagate the max page id. That way if we end up merging the two
977 // NavigationControllers (which happens if we commit) none of the page ids 984 // NavigationControllers (which happens if we commit) none of the page ids
978 // will overlap. 985 // will overlap.
979 int32 max_page_id = tab_contents->tab_contents()->GetMaxPageID(); 986 int32 max_page_id = tab_contents->tab_contents()->GetMaxPageID();
980 if (max_page_id != -1) 987 if (max_page_id != -1)
981 preview_contents_->controller().set_max_restored_page_id(max_page_id + 1); 988 preview_contents_->controller().set_max_restored_page_id(max_page_id + 1);
982 989
983 #if defined(OS_MACOSX) 990 #if defined(OS_MACOSX)
984 // If |preview_contents_| does not currently have a RWHV, we will call 991 // If |preview_contents_| does not currently have a RWHV, we will call
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 if (cl->HasSwitch(switches::kInstantURL)) 1043 if (cl->HasSwitch(switches::kInstantURL))
1037 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); 1044 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL));
1038 preview_contents_->controller().LoadURL(instant_url, GURL(), transition_type, 1045 preview_contents_->controller().LoadURL(instant_url, GURL(), transition_type,
1039 std::string()); 1046 std::string());
1040 RenderViewHost* host = preview_contents_->render_view_host(); 1047 RenderViewHost* host = preview_contents_->render_view_host();
1041 host->Send(new ChromeViewMsg_SearchBoxChange( 1048 host->Send(new ChromeViewMsg_SearchBoxChange(
1042 host->routing_id(), user_text, verbatim, 0, 0)); 1049 host->routing_id(), user_text, verbatim, 0, 0));
1043 frame_load_observer_.reset(new FrameLoadObserver( 1050 frame_load_observer_.reset(new FrameLoadObserver(
1044 this, preview_contents()->tab_contents(), user_text, verbatim)); 1051 this, preview_contents()->tab_contents(), user_text, verbatim));
1045 } 1052 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698