| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/tab_contents/web_contents.h" | 5 #include "chrome/browser/tab_contents/web_contents.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 // HACK!! This code suppresses javascript: URLs from being added to | 383 // HACK!! This code suppresses javascript: URLs from being added to |
| 384 // session history, which is what we want to do for javascript: URLs that | 384 // session history, which is what we want to do for javascript: URLs that |
| 385 // do not generate content. What we really need is a message from the | 385 // do not generate content. What we really need is a message from the |
| 386 // renderer telling us that a new page was not created. The same message | 386 // renderer telling us that a new page was not created. The same message |
| 387 // could be used for mailto: URLs and the like. | 387 // could be used for mailto: URLs and the like. |
| 388 if (entry->url().SchemeIs("javascript")) | 388 if (entry->url().SchemeIs("javascript")) |
| 389 return false; | 389 return false; |
| 390 } | 390 } |
| 391 | 391 |
| 392 // Clear any provisional password saves - this stops password infobars | 392 // Clear any provisional password saves - this stops password infobars |
| 393 // showing up on pages the user navigates to while the right page is | 393 // showing up on pages the user navigates to while the right page is |
| 394 // loading. | 394 // loading. |
| 395 GetPasswordManager()->ClearProvisionalSave(); | 395 GetPasswordManager()->ClearProvisionalSave(); |
| 396 | 396 |
| 397 if (reload && !profile()->IsOffTheRecord()) { | 397 if (reload && !profile()->IsOffTheRecord()) { |
| 398 HistoryService* history = | 398 HistoryService* history = |
| 399 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); | 399 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); |
| 400 if (history) | 400 if (history) |
| 401 history->SetFavIconOutOfDateForPage(entry->url()); | 401 history->SetFavIconOutOfDateForPage(entry->url()); |
| 402 } | 402 } |
| 403 | 403 |
| 404 return true; | 404 return true; |
| 405 } | 405 } |
| 406 | 406 |
| 407 void WebContents::Stop() { | 407 void WebContents::Stop() { |
| 408 render_manager_.Stop(); | 408 render_manager_.Stop(); |
| 409 printing_.Stop(); | 409 printing_.Stop(); |
| 410 } | 410 } |
| 411 | 411 |
| 412 void WebContents::Cut() { | 412 void WebContents::Cut() { |
| 413 render_view_host()->Cut(); | 413 render_view_host()->Cut(); |
| 414 } | 414 } |
| 415 | 415 |
| 416 void WebContents::Copy() { | 416 void WebContents::Copy() { |
| 417 render_view_host()->Copy(); | 417 render_view_host()->Copy(); |
| 418 } | 418 } |
| 419 | 419 |
| 420 void WebContents::Paste() { | 420 void WebContents::Paste() { |
| 421 render_view_host()->Paste(); | 421 render_view_host()->Paste(); |
| 422 } | 422 } |
| 423 | 423 |
| 424 void WebContents::DisassociateFromPopupCount() { | 424 void WebContents::DisassociateFromPopupCount() { |
| 425 render_view_host()->DisassociateFromPopupCount(); | 425 render_view_host()->DisassociateFromPopupCount(); |
| 426 } | 426 } |
| 427 | 427 |
| 428 void WebContents::DidBecomeSelected() { | 428 void WebContents::DidBecomeSelected() { |
| 429 TabContents::DidBecomeSelected(); | 429 TabContents::DidBecomeSelected(); |
| 430 | 430 |
| 431 if (render_widget_host_view()) | 431 if (render_widget_host_view()) |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 } | 591 } |
| 592 | 592 |
| 593 bool WebContents::IsActiveEntry(int32 page_id) { | 593 bool WebContents::IsActiveEntry(int32 page_id) { |
| 594 NavigationEntry* active_entry = controller()->GetActiveEntry(); | 594 NavigationEntry* active_entry = controller()->GetActiveEntry(); |
| 595 return (active_entry != NULL && | 595 return (active_entry != NULL && |
| 596 active_entry->site_instance() == GetSiteInstance() && | 596 active_entry->site_instance() == GetSiteInstance() && |
| 597 active_entry->page_id() == page_id); | 597 active_entry->page_id() == page_id); |
| 598 } | 598 } |
| 599 | 599 |
| 600 void WebContents::SetInitialFocus(bool reverse) { | 600 void WebContents::SetInitialFocus(bool reverse) { |
| 601 render_view_host()->SetInitialFocus(reverse); | 601 render_view_host()->SetInitialFocus(reverse); |
| 602 } | 602 } |
| 603 | 603 |
| 604 // Notifies the RenderWidgetHost instance about the fact that the page is | 604 // Notifies the RenderWidgetHost instance about the fact that the page is |
| 605 // loading, or done loading and calls the base implementation. | 605 // loading, or done loading and calls the base implementation. |
| 606 void WebContents::SetIsLoading(bool is_loading, | 606 void WebContents::SetIsLoading(bool is_loading, |
| 607 LoadNotificationDetails* details) { | 607 LoadNotificationDetails* details) { |
| 608 if (!is_loading) { | 608 if (!is_loading) { |
| 609 load_state_ = net::LOAD_STATE_IDLE; | 609 load_state_ = net::LOAD_STATE_IDLE; |
| 610 load_state_host_.clear(); | 610 load_state_host_.clear(); |
| 611 } | 611 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 HungRendererWarning::HideForWebContents(this); | 658 HungRendererWarning::HideForWebContents(this); |
| 659 } | 659 } |
| 660 | 660 |
| 661 void WebContents::DidNavigate(RenderViewHost* rvh, | 661 void WebContents::DidNavigate(RenderViewHost* rvh, |
| 662 const ViewHostMsg_FrameNavigate_Params& params) { | 662 const ViewHostMsg_FrameNavigate_Params& params) { |
| 663 if (PageTransition::IsMainFrame(params.transition)) | 663 if (PageTransition::IsMainFrame(params.transition)) |
| 664 render_manager_.DidNavigateMainFrame(rvh); | 664 render_manager_.DidNavigateMainFrame(rvh); |
| 665 | 665 |
| 666 // We can't do anything about navigations when we're inactive. | 666 // We can't do anything about navigations when we're inactive. |
| 667 if (!controller() || !is_active()) | 667 if (!controller() || !is_active()) |
| 668 return; | 668 return; |
| 669 | 669 |
| 670 // Update the site of the SiteInstance if it doesn't have one yet. | 670 // Update the site of the SiteInstance if it doesn't have one yet. |
| 671 if (!GetSiteInstance()->has_site()) | 671 if (!GetSiteInstance()->has_site()) |
| 672 GetSiteInstance()->SetSite(params.url); | 672 GetSiteInstance()->SetSite(params.url); |
| 673 | 673 |
| 674 // Need to update MIME type here because it's referred to in | 674 // Need to update MIME type here because it's referred to in |
| 675 // UpdateNavigationCommands() called by RendererDidNavigate() to | 675 // UpdateNavigationCommands() called by RendererDidNavigate() to |
| 676 // determine whether or not to enable the encoding menu. | 676 // determine whether or not to enable the encoding menu. |
| 677 // It's updated only for the main frame. For a subframe, | 677 // It's updated only for the main frame. For a subframe, |
| 678 // RenderView::UpdateURL does not set params.contents_mime_type. | 678 // RenderView::UpdateURL does not set params.contents_mime_type. |
| 679 // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) | 679 // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) |
| 680 // TODO(jungshik): Add a test for the encoding menu to avoid | 680 // TODO(jungshik): Add a test for the encoding menu to avoid |
| 681 // regressing it again. | 681 // regressing it again. |
| 682 if (PageTransition::IsMainFrame(params.transition)) | 682 if (PageTransition::IsMainFrame(params.transition)) |
| 683 contents_mime_type_ = params.contents_mime_type; | 683 contents_mime_type_ = params.contents_mime_type; |
| 684 | 684 |
| 685 NavigationController::LoadCommittedDetails details; | 685 NavigationController::LoadCommittedDetails details; |
| 686 if (!controller()->RendererDidNavigate(params, &details)) | 686 if (!controller()->RendererDidNavigate(params, &details)) |
| 687 return; // No navigation happened. | 687 return; // No navigation happened. |
| 688 | 688 |
| 689 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen | 689 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen |
| 690 // for the appropriate notification (best) or you can add it to | 690 // for the appropriate notification (best) or you can add it to |
| 691 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if | 691 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 void WebContents::PasswordFormsSeen( | 1037 void WebContents::PasswordFormsSeen( |
| 1038 const std::vector<PasswordForm>& forms) { | 1038 const std::vector<PasswordForm>& forms) { |
| 1039 GetPasswordManager()->PasswordFormsSeen(forms); | 1039 GetPasswordManager()->PasswordFormsSeen(forms); |
| 1040 } | 1040 } |
| 1041 | 1041 |
| 1042 void WebContents::AutofillFormSubmitted( | 1042 void WebContents::AutofillFormSubmitted( |
| 1043 const AutofillForm& form) { | 1043 const AutofillForm& form) { |
| 1044 GetAutofillManager()->AutofillFormSubmitted(form); | 1044 GetAutofillManager()->AutofillFormSubmitted(form); |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 void WebContents::GetAutofillSuggestions(const std::wstring& field_name, | 1047 void WebContents::GetAutofillSuggestions(const std::wstring& field_name, |
| 1048 const std::wstring& user_text, int64 node_id, int request_id) { | 1048 const std::wstring& user_text, int64 node_id, int request_id) { |
| 1049 GetAutofillManager()->FetchValuesForName(field_name, user_text, | 1049 GetAutofillManager()->FetchValuesForName(field_name, user_text, |
| 1050 kMaxAutofillMenuItems, node_id, request_id); | 1050 kMaxAutofillMenuItems, node_id, request_id); |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 // Checks to see if we should generate a keyword based on the OSDD, and if | 1053 // Checks to see if we should generate a keyword based on the OSDD, and if |
| 1054 // necessary uses TemplateURLFetcher to download the OSDD and create a keyword. | 1054 // necessary uses TemplateURLFetcher to download the OSDD and create a keyword. |
| 1055 void WebContents::PageHasOSDD(RenderViewHost* render_view_host, | 1055 void WebContents::PageHasOSDD(RenderViewHost* render_view_host, |
| 1056 int32 page_id, const GURL& url, | 1056 int32 page_id, const GURL& url, |
| 1057 bool autodetected) { | 1057 bool autodetected) { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 | 1263 |
| 1264 void WebContents::OnJSOutOfMemory() { | 1264 void WebContents::OnJSOutOfMemory() { |
| 1265 AddInfoBar(new SimpleAlertInfoBarDelegate( | 1265 AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 1266 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL)); | 1266 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL)); |
| 1267 } | 1267 } |
| 1268 | 1268 |
| 1269 bool WebContents::CanBlur() const { | 1269 bool WebContents::CanBlur() const { |
| 1270 return delegate() ? delegate()->CanBlur() : true; | 1270 return delegate() ? delegate()->CanBlur() : true; |
| 1271 } | 1271 } |
| 1272 | 1272 |
| 1273 void WebContents::RendererUnresponsive(RenderViewHost* rvh, | 1273 gfx::Rect WebContents::GetRootWindowResizerRect() const { |
| 1274 if (delegate()) |
| 1275 return delegate()->GetRootWindowResizerRect(); |
| 1276 return gfx::Rect(); |
| 1277 } |
| 1278 |
| 1279 void WebContents::RendererUnresponsive(RenderViewHost* rvh, |
| 1274 bool is_during_unload) { | 1280 bool is_during_unload) { |
| 1275 if (is_during_unload) { | 1281 if (is_during_unload) { |
| 1276 // Hang occurred while firing the beforeunload/unload handler. | 1282 // Hang occurred while firing the beforeunload/unload handler. |
| 1277 // Pretend the handler fired so tab closing continues as if it had. | 1283 // Pretend the handler fired so tab closing continues as if it had. |
| 1278 rvh->UnloadListenerHasFired(); | 1284 rvh->UnloadListenerHasFired(); |
| 1279 | 1285 |
| 1280 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer()) { | 1286 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer()) |
| 1281 return; | 1287 return; |
| 1282 } | |
| 1283 | 1288 |
| 1284 // If the tab hangs in the beforeunload/unload handler there's really | 1289 // If the tab hangs in the beforeunload/unload handler there's really |
| 1285 // nothing we can do to recover. Pretend the unload listeners have | 1290 // nothing we can do to recover. Pretend the unload listeners have |
| 1286 // all fired and close the tab. If the hang is in the beforeunload handler | 1291 // all fired and close the tab. If the hang is in the beforeunload handler |
| 1287 // then the user will not have the option of cancelling the close. | 1292 // then the user will not have the option of cancelling the close. |
| 1288 Close(rvh); | 1293 Close(rvh); |
| 1289 return; | 1294 return; |
| 1290 } | 1295 } |
| 1291 | 1296 |
| 1292 if (render_view_host() && render_view_host()->IsRenderViewLive()) | 1297 if (render_view_host() && render_view_host()->IsRenderViewLive()) |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1637 return false; // Nothing changed, don't bother. | 1642 return false; // Nothing changed, don't bother. |
| 1638 | 1643 |
| 1639 entry->set_title(final_title); | 1644 entry->set_title(final_title); |
| 1640 | 1645 |
| 1641 // Update the history system for this page. | 1646 // Update the history system for this page. |
| 1642 if (!profile()->IsOffTheRecord() && !received_page_title_) { | 1647 if (!profile()->IsOffTheRecord() && !received_page_title_) { |
| 1643 HistoryService* hs = | 1648 HistoryService* hs = |
| 1644 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); | 1649 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); |
| 1645 if (hs) | 1650 if (hs) |
| 1646 hs->SetPageTitle(entry->display_url(), final_title); | 1651 hs->SetPageTitle(entry->display_url(), final_title); |
| 1647 | 1652 |
| 1648 // Don't allow the title to be saved again for explicitly set ones. | 1653 // Don't allow the title to be saved again for explicitly set ones. |
| 1649 received_page_title_ = explicit_set; | 1654 received_page_title_ = explicit_set; |
| 1650 } | 1655 } |
| 1651 | 1656 |
| 1652 // Lastly, set the title for the view. | 1657 // Lastly, set the title for the view. |
| 1653 view_->SetPageTitle(final_title); | 1658 view_->SetPageTitle(final_title); |
| 1654 | 1659 |
| 1655 return true; | 1660 return true; |
| 1656 } | 1661 } |
| 1657 | 1662 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1752 // The favicon url isn't valid. This means there really isn't a favicon, | 1757 // The favicon url isn't valid. This means there really isn't a favicon, |
| 1753 // or the favicon url wasn't obtained before the load started. This assumes | 1758 // or the favicon url wasn't obtained before the load started. This assumes |
| 1754 // the later. | 1759 // the later. |
| 1755 // TODO(sky): Need a way to set the favicon that doesn't involve generating | 1760 // TODO(sky): Need a way to set the favicon that doesn't involve generating |
| 1756 // its url. | 1761 // its url. |
| 1757 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); | 1762 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); |
| 1758 } | 1763 } |
| 1759 new_url->set_safe_for_autoreplace(true); | 1764 new_url->set_safe_for_autoreplace(true); |
| 1760 url_model->Add(new_url); | 1765 url_model->Add(new_url); |
| 1761 } | 1766 } |
| OLD | NEW |