| 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/tab_contents/tab_contents.h" | 5 #include "chrome/browser/tab_contents/tab_contents.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 NotificationService::AllSources()); | 465 NotificationService::AllSources()); |
| 466 | 466 |
| 467 // Set-up the showing of the omnibox search infobar if applicable. | 467 // Set-up the showing of the omnibox search infobar if applicable. |
| 468 if (OmniboxSearchHint::IsEnabled(profile)) | 468 if (OmniboxSearchHint::IsEnabled(profile)) |
| 469 omnibox_search_hint_.reset(new OmniboxSearchHint(this)); | 469 omnibox_search_hint_.reset(new OmniboxSearchHint(this)); |
| 470 | 470 |
| 471 autofill_manager_.reset(new AutoFillManager(this)); | 471 autofill_manager_.reset(new AutoFillManager(this)); |
| 472 AddNavigationObserver(autofill_manager_.get()); | 472 AddNavigationObserver(autofill_manager_.get()); |
| 473 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this)); | 473 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this)); |
| 474 AddNavigationObserver(autocomplete_history_manager_.get()); | 474 AddNavigationObserver(autocomplete_history_manager_.get()); |
| 475 AddNavigationObserver(&fav_icon_helper_); |
| 476 AddNavigationObserver(printing_.get()); |
| 475 } | 477 } |
| 476 | 478 |
| 477 TabContents::~TabContents() { | 479 TabContents::~TabContents() { |
| 478 is_being_destroyed_ = true; | 480 is_being_destroyed_ = true; |
| 479 | 481 |
| 480 // We don't want any notifications while we're running our destructor. | 482 // We don't want any notifications while we're running our destructor. |
| 481 registrar_.RemoveAll(); | 483 registrar_.RemoveAll(); |
| 482 pref_change_registrar_.RemoveAll(); | 484 pref_change_registrar_.RemoveAll(); |
| 483 | 485 |
| 484 NotifyDisconnected(); | 486 NotifyDisconnected(); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 OnBlockedOutdatedPlugin) | 630 OnBlockedOutdatedPlugin) |
| 629 IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetApplicationInfo, | 631 IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetApplicationInfo, |
| 630 OnDidGetApplicationInfo) | 632 OnDidGetApplicationInfo) |
| 631 IPC_MESSAGE_HANDLER(ViewHostMsg_InstallApplication, | 633 IPC_MESSAGE_HANDLER(ViewHostMsg_InstallApplication, |
| 632 OnInstallApplication) | 634 OnInstallApplication) |
| 633 IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents) | 635 IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents) |
| 634 IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated) | 636 IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated) |
| 635 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions) | 637 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions) |
| 636 IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined, | 638 IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined, |
| 637 OnInstantSupportDetermined) | 639 OnInstantSupportDetermined) |
| 640 IPC_MESSAGE_HANDLER(ViewHostMsg_RunFileChooser, OnRunFileChooser) |
| 638 IPC_MESSAGE_UNHANDLED(handled = false) | 641 IPC_MESSAGE_UNHANDLED(handled = false) |
| 639 IPC_END_MESSAGE_MAP_EX() | 642 IPC_END_MESSAGE_MAP_EX() |
| 640 | 643 |
| 641 if (!message_is_ok) { | 644 if (!message_is_ok) { |
| 642 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); | 645 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); |
| 643 GetRenderProcessHost()->ReceivedBadMessage(); | 646 GetRenderProcessHost()->ReceivedBadMessage(); |
| 644 } | 647 } |
| 645 | 648 |
| 646 return handled; | 649 return handled; |
| 647 } | 650 } |
| (...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1449 if (dlm && current_page_url.is_valid()) | 1452 if (dlm && current_page_url.is_valid()) |
| 1450 dlm->DownloadUrl(current_page_url, GURL(), "", this); | 1453 dlm->DownloadUrl(current_page_url, GURL(), "", this); |
| 1451 return; | 1454 return; |
| 1452 } | 1455 } |
| 1453 | 1456 |
| 1454 Stop(); | 1457 Stop(); |
| 1455 | 1458 |
| 1456 // Create the save package and possibly prompt the user for the name to save | 1459 // Create the save package and possibly prompt the user for the name to save |
| 1457 // the page as. The user prompt is an asynchronous operation that runs on | 1460 // the page as. The user prompt is an asynchronous operation that runs on |
| 1458 // another thread. | 1461 // another thread. |
| 1459 save_package_ = new SavePackage(this); | 1462 SetSavePackage(new SavePackage(this)); |
| 1460 save_package_->GetSaveInfo(); | 1463 save_package_->GetSaveInfo(); |
| 1461 } | 1464 } |
| 1462 | 1465 |
| 1463 // Used in automated testing to bypass prompting the user for file names. | 1466 // Used in automated testing to bypass prompting the user for file names. |
| 1464 // Instead, the names and paths are hard coded rather than running them through | 1467 // Instead, the names and paths are hard coded rather than running them through |
| 1465 // file name sanitation and extension / mime checking. | 1468 // file name sanitation and extension / mime checking. |
| 1466 bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, | 1469 bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, |
| 1467 SavePackage::SavePackageType save_type) { | 1470 SavePackage::SavePackageType save_type) { |
| 1468 // Stop the page from navigating. | 1471 // Stop the page from navigating. |
| 1469 Stop(); | 1472 Stop(); |
| 1470 | 1473 |
| 1471 save_package_ = new SavePackage(this, save_type, main_file, dir_path); | 1474 SetSavePackage(new SavePackage(this, save_type, main_file, dir_path)); |
| 1472 return save_package_->Init(); | 1475 return save_package_->Init(); |
| 1473 } | 1476 } |
| 1474 | 1477 |
| 1478 void TabContents::SetSavePackage(SavePackage* save_package) { |
| 1479 if (save_package_.get()) |
| 1480 RemoveNavigationObserver(save_package_.get()); |
| 1481 save_package_ = save_package; |
| 1482 AddNavigationObserver(save_package); |
| 1483 } |
| 1484 |
| 1475 void TabContents::EmailPageLocation() { | 1485 void TabContents::EmailPageLocation() { |
| 1476 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false); | 1486 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false); |
| 1477 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false); | 1487 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false); |
| 1478 std::string mailto = std::string("mailto:?subject=Fwd:%20") + | 1488 std::string mailto = std::string("mailto:?subject=Fwd:%20") + |
| 1479 title + "&body=%0A%0A" + page_url; | 1489 title + "&body=%0A%0A" + page_url; |
| 1480 platform_util::OpenExternal(GURL(mailto)); | 1490 platform_util::OpenExternal(GURL(mailto)); |
| 1481 } | 1491 } |
| 1482 | 1492 |
| 1483 void TabContents::PrintPreview() { | 1493 void TabContents::PrintPreview() { |
| 1484 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1494 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2416 const std::vector<std::string>& suggestions) { | 2426 const std::vector<std::string>& suggestions) { |
| 2417 if (delegate()) | 2427 if (delegate()) |
| 2418 delegate()->OnSetSuggestions(page_id, suggestions); | 2428 delegate()->OnSetSuggestions(page_id, suggestions); |
| 2419 } | 2429 } |
| 2420 | 2430 |
| 2421 void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) { | 2431 void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) { |
| 2422 if (delegate()) | 2432 if (delegate()) |
| 2423 delegate()->OnInstantSupportDetermined(page_id, result); | 2433 delegate()->OnInstantSupportDetermined(page_id, result); |
| 2424 } | 2434 } |
| 2425 | 2435 |
| 2436 void TabContents::OnRunFileChooser( |
| 2437 const ViewHostMsg_RunFileChooser_Params& params) { |
| 2438 if (file_select_helper_.get() == NULL) |
| 2439 file_select_helper_.reset(new FileSelectHelper(profile())); |
| 2440 file_select_helper_->RunFileChooser(render_view_host(), params); |
| 2441 } |
| 2442 |
| 2443 |
| 2426 void TabContents::OnContentSettingsAccessed(bool content_was_blocked) { | 2444 void TabContents::OnContentSettingsAccessed(bool content_was_blocked) { |
| 2427 if (delegate_) | 2445 if (delegate_) |
| 2428 delegate_->OnContentSettingsChange(this); | 2446 delegate_->OnContentSettingsChange(this); |
| 2429 } | 2447 } |
| 2430 | 2448 |
| 2431 RenderViewHostDelegate::View* TabContents::GetViewDelegate() { | 2449 RenderViewHostDelegate::View* TabContents::GetViewDelegate() { |
| 2432 return view_.get(); | 2450 return view_.get(); |
| 2433 } | 2451 } |
| 2434 | 2452 |
| 2435 RenderViewHostDelegate::RendererManagement* | 2453 RenderViewHostDelegate::RendererManagement* |
| 2436 TabContents::GetRendererManagementDelegate() { | 2454 TabContents::GetRendererManagementDelegate() { |
| 2437 return &render_manager_; | 2455 return &render_manager_; |
| 2438 } | 2456 } |
| 2439 | 2457 |
| 2440 RenderViewHostDelegate::ContentSettings* | 2458 RenderViewHostDelegate::ContentSettings* |
| 2441 TabContents::GetContentSettingsDelegate() { | 2459 TabContents::GetContentSettingsDelegate() { |
| 2442 return content_settings_delegate_.get(); | 2460 return content_settings_delegate_.get(); |
| 2443 } | 2461 } |
| 2444 | 2462 |
| 2445 RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() { | |
| 2446 return save_package_.get(); // May be NULL, but we can return NULL. | |
| 2447 } | |
| 2448 | |
| 2449 RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() { | |
| 2450 return printing_.get(); | |
| 2451 } | |
| 2452 | |
| 2453 RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() { | |
| 2454 return &fav_icon_helper_; | |
| 2455 } | |
| 2456 | |
| 2457 RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() { | 2463 RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() { |
| 2458 return GetSSLHelper(); | 2464 return GetSSLHelper(); |
| 2459 } | 2465 } |
| 2460 | 2466 |
| 2461 RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() { | |
| 2462 if (file_select_helper_.get() == NULL) | |
| 2463 file_select_helper_.reset(new FileSelectHelper(profile())); | |
| 2464 return file_select_helper_.get(); | |
| 2465 } | |
| 2466 | |
| 2467 AutomationResourceRoutingDelegate* | 2467 AutomationResourceRoutingDelegate* |
| 2468 TabContents::GetAutomationResourceRoutingDelegate() { | 2468 TabContents::GetAutomationResourceRoutingDelegate() { |
| 2469 return delegate(); | 2469 return delegate(); |
| 2470 } | 2470 } |
| 2471 | 2471 |
| 2472 RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() { | 2472 RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() { |
| 2473 return bookmark_drag_; | 2473 return bookmark_drag_; |
| 2474 } | 2474 } |
| 2475 | 2475 |
| 2476 void TabContents::SetBookmarkDragDelegate( | 2476 void TabContents::SetBookmarkDragDelegate( |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3395 if (pm != NULL) { | 3395 if (pm != NULL) { |
| 3396 if (pm->MaybeUsePreloadedPage(this, url)) { | 3396 if (pm->MaybeUsePreloadedPage(this, url)) { |
| 3397 // TODO(tburkard): If the preloaded page has not finished preloading | 3397 // TODO(tburkard): If the preloaded page has not finished preloading |
| 3398 // yet, we should not do this. | 3398 // yet, we should not do this. |
| 3399 DidStopLoading(); | 3399 DidStopLoading(); |
| 3400 return true; | 3400 return true; |
| 3401 } | 3401 } |
| 3402 } | 3402 } |
| 3403 return false; | 3403 return false; |
| 3404 } | 3404 } |
| OLD | NEW |