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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // NotificationObserver: | 177 // NotificationObserver: |
178 virtual void Observe(int type, | 178 virtual void Observe(int type, |
179 const NotificationSource& source, | 179 const NotificationSource& source, |
180 const NotificationDetails& details) OVERRIDE; | 180 const NotificationDetails& details) OVERRIDE; |
181 | 181 |
182 // TabContentsDelegate: | 182 // TabContentsDelegate: |
183 virtual void NavigationStateChanged(const TabContents* source, | 183 virtual void NavigationStateChanged(const TabContents* source, |
184 unsigned changed_flags) OVERRIDE; | 184 unsigned changed_flags) OVERRIDE; |
185 virtual void AddNavigationHeaders(const GURL& url, | 185 virtual void AddNavigationHeaders(const GURL& url, |
186 std::string* headers) OVERRIDE; | 186 std::string* headers) OVERRIDE; |
187 virtual bool ShouldFocusConstrainedWindow() OVERRIDE; | |
188 virtual void WillShowConstrainedWindow(TabContents* source) OVERRIDE; | |
189 virtual bool ShouldSuppressDialogs() OVERRIDE; | 187 virtual bool ShouldSuppressDialogs() OVERRIDE; |
190 virtual void BeforeUnloadFired(TabContents* tab, | 188 virtual void BeforeUnloadFired(TabContents* tab, |
191 bool proceed, | 189 bool proceed, |
192 bool* proceed_to_fire_unload) OVERRIDE; | 190 bool* proceed_to_fire_unload) OVERRIDE; |
193 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE; | 191 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE; |
194 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; | 192 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; |
195 virtual void LostCapture() OVERRIDE; | 193 virtual void LostCapture() OVERRIDE; |
196 // If the user drags, we won't get a mouse up (at least on Linux). Commit the | 194 // 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 | 195 // instant result when the drag ends, so that during the drag the page won't |
198 // move around. | 196 // move around. |
199 virtual void DragEnded() OVERRIDE; | 197 virtual void DragEnded() OVERRIDE; |
200 virtual bool CanDownload(TabContents* source, int request_id) OVERRIDE; | 198 virtual bool CanDownload(TabContents* source, int request_id) OVERRIDE; |
201 virtual void HandleMouseUp() OVERRIDE; | 199 virtual void HandleMouseUp() OVERRIDE; |
202 virtual void HandleMouseActivate() OVERRIDE; | 200 virtual void HandleMouseActivate() OVERRIDE; |
203 virtual bool OnGoToEntryOffset(int offset) OVERRIDE; | 201 virtual bool OnGoToEntryOffset(int offset) OVERRIDE; |
204 virtual bool ShouldAddNavigationToHistory( | 202 virtual bool ShouldAddNavigationToHistory( |
205 const history::HistoryAddPageArgs& add_page_args, | 203 const history::HistoryAddPageArgs& add_page_args, |
206 NavigationType::Type navigation_type) OVERRIDE; | 204 NavigationType::Type navigation_type) OVERRIDE; |
207 | 205 |
208 // TabContentsWrapperDelegate: | 206 // TabContentsWrapperDelegate: |
209 virtual void SwapTabContents(TabContentsWrapper* old_tc, | 207 virtual void SwapTabContents(TabContentsWrapper* old_tc, |
210 TabContentsWrapper* new_tc) OVERRIDE; | 208 TabContentsWrapper* new_tc) OVERRIDE; |
| 209 virtual void WillShowConstrainedWindow(TabContentsWrapper* source) OVERRIDE; |
| 210 virtual bool ShouldFocusConstrainedWindow() OVERRIDE; |
211 | 211 |
212 // TabContentsObserver: | 212 // TabContentsObserver: |
213 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 213 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
214 | 214 |
215 private: | 215 private: |
216 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > | 216 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > |
217 AddPageVector; | 217 AddPageVector; |
218 | 218 |
219 // Message from renderer indicating the page has suggestions. | 219 // Message from renderer indicating the page has suggestions. |
220 void OnSetSuggestions( | 220 void OnSetSuggestions( |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 } | 414 } |
415 } | 415 } |
416 | 416 |
417 void InstantLoader::TabContentsDelegateImpl::AddNavigationHeaders( | 417 void InstantLoader::TabContentsDelegateImpl::AddNavigationHeaders( |
418 const GURL& url, | 418 const GURL& url, |
419 std::string* headers) { | 419 std::string* headers) { |
420 net::HttpUtil::AppendHeaderIfMissing(kInstantHeader, kInstantHeaderValue, | 420 net::HttpUtil::AppendHeaderIfMissing(kInstantHeader, kInstantHeaderValue, |
421 headers); | 421 headers); |
422 } | 422 } |
423 | 423 |
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() { | 424 bool InstantLoader::TabContentsDelegateImpl::ShouldSuppressDialogs() { |
442 // Any message shown during instant cancels instant, so we suppress them. | 425 // Any message shown during instant cancels instant, so we suppress them. |
443 return true; | 426 return true; |
444 } | 427 } |
445 | 428 |
446 void InstantLoader::TabContentsDelegateImpl::BeforeUnloadFired( | 429 void InstantLoader::TabContentsDelegateImpl::BeforeUnloadFired( |
447 TabContents* tab, | 430 TabContents* tab, |
448 bool proceed, | 431 bool proceed, |
449 bool* proceed_to_fire_unload) { | 432 bool* proceed_to_fire_unload) { |
450 } | 433 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 } | 480 } |
498 | 481 |
499 // If this is being called, something is swapping in to our preview_contents_ | 482 // If this is being called, something is swapping in to our preview_contents_ |
500 // before we've added it to the tab strip. | 483 // before we've added it to the tab strip. |
501 void InstantLoader::TabContentsDelegateImpl::SwapTabContents( | 484 void InstantLoader::TabContentsDelegateImpl::SwapTabContents( |
502 TabContentsWrapper* old_tc, | 485 TabContentsWrapper* old_tc, |
503 TabContentsWrapper* new_tc) { | 486 TabContentsWrapper* new_tc) { |
504 loader_->ReplacePreviewContents(old_tc, new_tc); | 487 loader_->ReplacePreviewContents(old_tc, new_tc); |
505 } | 488 } |
506 | 489 |
| 490 bool InstantLoader::TabContentsDelegateImpl::ShouldFocusConstrainedWindow() { |
| 491 // Return false so that constrained windows are not initially focused. If |
| 492 // we did otherwise the preview would prematurely get committed when focus |
| 493 // goes to the constrained window. |
| 494 return false; |
| 495 } |
| 496 |
| 497 void InstantLoader::TabContentsDelegateImpl::WillShowConstrainedWindow( |
| 498 TabContentsWrapper* source) { |
| 499 if (!loader_->ready()) { |
| 500 // A constrained window shown for an auth may not paint. Show the preview |
| 501 // contents. |
| 502 UnregisterForPaintNotifications(); |
| 503 loader_->ShowPreview(); |
| 504 } |
| 505 } |
507 | 506 |
508 bool InstantLoader::TabContentsDelegateImpl::OnMessageReceived( | 507 bool InstantLoader::TabContentsDelegateImpl::OnMessageReceived( |
509 const IPC::Message& message) { | 508 const IPC::Message& message) { |
510 bool handled = true; | 509 bool handled = true; |
511 IPC_BEGIN_MESSAGE_MAP(TabContentsDelegateImpl, message) | 510 IPC_BEGIN_MESSAGE_MAP(TabContentsDelegateImpl, message) |
512 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) | 511 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) |
513 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, | 512 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, |
514 OnInstantSupportDetermined) | 513 OnInstantSupportDetermined) |
515 IPC_MESSAGE_UNHANDLED(handled = false) | 514 IPC_MESSAGE_UNHANDLED(handled = false) |
516 IPC_END_MESSAGE_MAP() | 515 IPC_END_MESSAGE_MAP() |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 if (cl->HasSwitch(switches::kInstantURL)) | 1035 if (cl->HasSwitch(switches::kInstantURL)) |
1037 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); | 1036 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); |
1038 preview_contents_->controller().LoadURL(instant_url, GURL(), transition_type, | 1037 preview_contents_->controller().LoadURL(instant_url, GURL(), transition_type, |
1039 std::string()); | 1038 std::string()); |
1040 RenderViewHost* host = preview_contents_->render_view_host(); | 1039 RenderViewHost* host = preview_contents_->render_view_host(); |
1041 host->Send(new ChromeViewMsg_SearchBoxChange( | 1040 host->Send(new ChromeViewMsg_SearchBoxChange( |
1042 host->routing_id(), user_text, verbatim, 0, 0)); | 1041 host->routing_id(), user_text, verbatim, 0, 0)); |
1043 frame_load_observer_.reset(new FrameLoadObserver( | 1042 frame_load_observer_.reset(new FrameLoadObserver( |
1044 this, preview_contents()->tab_contents(), user_text, verbatim)); | 1043 this, preview_contents()->tab_contents(), user_text, verbatim)); |
1045 } | 1044 } |
OLD | NEW |