| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.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" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "chrome/browser/autofill_manager.h" | 13 #include "chrome/browser/autofill_manager.h" |
| 14 #include "chrome/browser/blocked_popup_container.h" | 14 #include "chrome/browser/blocked_popup_container.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_model.h" | 15 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/cert_store.h" | 17 #include "chrome/browser/cert_store.h" |
| 18 #include "chrome/browser/debugger/devtools_manager.h" | 18 #include "chrome/browser/debugger/devtools_manager.h" |
| 19 #include "chrome/browser/dom_operation_notification_details.h" | 19 #include "chrome/browser/dom_operation_notification_details.h" |
| 20 #include "chrome/browser/dom_ui/dom_ui.h" | 20 #include "chrome/browser/dom_ui/dom_ui.h" |
| 21 #include "chrome/browser/dom_ui/dom_ui_factory.h" | 21 #include "chrome/browser/dom_ui/dom_ui_factory.h" |
| 22 #include "chrome/browser/download/download_item_model.h" | 22 #include "chrome/browser/download/download_item_model.h" |
| 23 #include "chrome/browser/download/download_manager.h" | 23 #include "chrome/browser/download/download_manager.h" |
| 24 #include "chrome/browser/download/download_request_manager.h" | 24 #include "chrome/browser/download/download_request_manager.h" |
| 25 #include "chrome/browser/download/download_shelf.h" | |
| 26 #include "chrome/browser/download/download_started_animation.h" | |
| 27 #include "chrome/browser/gears_integration.h" | 25 #include "chrome/browser/gears_integration.h" |
| 28 #include "chrome/browser/google_util.h" | 26 #include "chrome/browser/google_util.h" |
| 29 #include "chrome/browser/hung_renderer_dialog.h" | 27 #include "chrome/browser/hung_renderer_dialog.h" |
| 30 #include "chrome/browser/jsmessage_box_handler.h" | 28 #include "chrome/browser/jsmessage_box_handler.h" |
| 31 #include "chrome/browser/load_from_memory_cache_details.h" | 29 #include "chrome/browser/load_from_memory_cache_details.h" |
| 32 #include "chrome/browser/load_notification_details.h" | 30 #include "chrome/browser/load_notification_details.h" |
| 33 #include "chrome/browser/password_manager/password_manager.h" | 31 #include "chrome/browser/password_manager/password_manager.h" |
| 34 #include "chrome/browser/plugin_installer.h" | 32 #include "chrome/browser/plugin_installer.h" |
| 35 #include "chrome/browser/profile.h" | 33 #include "chrome/browser/profile.h" |
| 36 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 34 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
| 37 #include "chrome/browser/renderer_host/web_cache_manager.h" | 35 #include "chrome/browser/renderer_host/web_cache_manager.h" |
| 38 #include "chrome/browser/tab_contents/infobar_delegate.h" | 36 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 39 #include "chrome/browser/tab_contents/navigation_entry.h" | 37 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 40 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 38 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
| 41 #include "chrome/browser/tab_contents/tab_contents_view.h" | 39 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 42 #include "chrome/browser/search_engines/template_url_fetcher.h" | 40 #include "chrome/browser/search_engines/template_url_fetcher.h" |
| 43 #include "chrome/browser/search_engines/template_url_model.h" | 41 #include "chrome/browser/search_engines/template_url_model.h" |
| 44 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
| 45 #include "chrome/common/notification_service.h" | 43 #include "chrome/common/notification_service.h" |
| 46 #include "chrome/common/page_action.h" | 44 #include "chrome/common/page_action.h" |
| 47 #include "chrome/common/platform_util.h" | |
| 48 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" |
| 49 #include "chrome/common/pref_service.h" | 46 #include "chrome/common/pref_service.h" |
| 50 #include "chrome/common/render_messages.h" | 47 #include "chrome/common/render_messages.h" |
| 51 #include "chrome/common/url_constants.h" | 48 #include "chrome/common/url_constants.h" |
| 52 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
| 53 #include "grit/locale_settings.h" | 50 #include "grit/locale_settings.h" |
| 54 #include "net/base/mime_util.h" | 51 #include "net/base/mime_util.h" |
| 55 #include "net/base/net_errors.h" | 52 #include "net/base/net_errors.h" |
| 56 #include "net/base/registry_controlled_domain.h" | 53 #include "net/base/registry_controlled_domain.h" |
| 57 | 54 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 const int kQueryStateDelay = 5000; | 104 const int kQueryStateDelay = 5000; |
| 108 | 105 |
| 109 const int kSyncWaitDelay = 40; | 106 const int kSyncWaitDelay = 40; |
| 110 | 107 |
| 111 // If another javascript message box is displayed within | 108 // If another javascript message box is displayed within |
| 112 // kJavascriptMessageExpectedDelay of a previous javascript message box being | 109 // kJavascriptMessageExpectedDelay of a previous javascript message box being |
| 113 // dismissed, display an option to suppress future message boxes from this | 110 // dismissed, display an option to suppress future message boxes from this |
| 114 // contents. | 111 // contents. |
| 115 const int kJavascriptMessageExpectedDelay = 1000; | 112 const int kJavascriptMessageExpectedDelay = 1000; |
| 116 | 113 |
| 117 // Minimum amount of time in ms that has to elapse since the download shelf was | |
| 118 // shown for us to hide it when navigating away from the current page. | |
| 119 const int kDownloadShelfHideDelay = 5000; | |
| 120 | |
| 121 const char kLinkDoctorBaseURL[] = | 114 const char kLinkDoctorBaseURL[] = |
| 122 "http://linkhelp.clients.google.com/tbproxy/lh/fixurl"; | 115 "http://linkhelp.clients.google.com/tbproxy/lh/fixurl"; |
| 123 | 116 |
| 124 // The printer icon in shell32.dll. That's a standard icon user will quickly | 117 // The printer icon in shell32.dll. That's a standard icon user will quickly |
| 125 // recognize. | 118 // recognize. |
| 126 const int kShell32PrinterIcon = 17; | 119 const int kShell32PrinterIcon = 17; |
| 127 | 120 |
| 128 // The list of prefs we want to observe. | 121 // The list of prefs we want to observe. |
| 129 const wchar_t* kPrefsToObserve[] = { | 122 const wchar_t* kPrefsToObserve[] = { |
| 130 prefs::kAlternateErrorPagesEnabled, | 123 prefs::kAlternateErrorPagesEnabled, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 is_crashed_(false), | 220 is_crashed_(false), |
| 228 waiting_for_response_(false), | 221 waiting_for_response_(false), |
| 229 max_page_id_(-1), | 222 max_page_id_(-1), |
| 230 current_load_start_(), | 223 current_load_start_(), |
| 231 load_state_(net::LOAD_STATE_IDLE), | 224 load_state_(net::LOAD_STATE_IDLE), |
| 232 load_state_host_(), | 225 load_state_host_(), |
| 233 received_page_title_(false), | 226 received_page_title_(false), |
| 234 is_starred_(false), | 227 is_starred_(false), |
| 235 contents_mime_type_(), | 228 contents_mime_type_(), |
| 236 encoding_(), | 229 encoding_(), |
| 237 download_shelf_(), | |
| 238 shelf_visible_(false), | |
| 239 blocked_popups_(NULL), | 230 blocked_popups_(NULL), |
| 240 infobar_delegates_(), | 231 infobar_delegates_(), |
| 241 last_download_shelf_show_(), | |
| 242 find_ui_active_(false), | 232 find_ui_active_(false), |
| 243 find_op_aborted_(false), | 233 find_op_aborted_(false), |
| 244 current_find_request_id_(find_request_id_counter_++), | 234 current_find_request_id_(find_request_id_counter_++), |
| 245 find_text_(), | 235 find_text_(), |
| 246 last_search_case_sensitive_(false), | 236 last_search_case_sensitive_(false), |
| 247 last_search_prepopulate_text_(NULL), | 237 last_search_prepopulate_text_(NULL), |
| 248 last_search_result_(), | 238 last_search_result_(), |
| 249 capturing_contents_(false), | 239 capturing_contents_(false), |
| 250 is_being_destroyed_(false), | 240 is_being_destroyed_(false), |
| 251 notify_disconnection_(false), | 241 notify_disconnection_(false), |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 // When it's the first load, we know either the pending one or the committed | 909 // When it's the first load, we know either the pending one or the committed |
| 920 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one | 910 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one |
| 921 // of them will be valid, so we can just check both. | 911 // of them will be valid, so we can just check both. |
| 922 if (render_manager_.pending_dom_ui()) | 912 if (render_manager_.pending_dom_ui()) |
| 923 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible(); | 913 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible(); |
| 924 if (render_manager_.dom_ui()) | 914 if (render_manager_.dom_ui()) |
| 925 return render_manager_.dom_ui()->force_bookmark_bar_visible(); | 915 return render_manager_.dom_ui()->force_bookmark_bar_visible(); |
| 926 return false; // Default. | 916 return false; // Default. |
| 927 } | 917 } |
| 928 | 918 |
| 929 void TabContents::SetDownloadShelfVisible(bool visible) { | |
| 930 if (shelf_visible_ != visible) { | |
| 931 if (visible) { | |
| 932 // Invoke GetDownloadShelf to force the shelf to be created. | |
| 933 GetDownloadShelf(true); | |
| 934 } | |
| 935 shelf_visible_ = visible; | |
| 936 | |
| 937 NotifyNavigationStateChanged(INVALIDATE_TAB); | |
| 938 | |
| 939 if (delegate()) | |
| 940 delegate()->UpdateDownloadShelfVisibility(visible); | |
| 941 } | |
| 942 | |
| 943 // SetShelfVisible can force-close the shelf, so make sure we lay out | |
| 944 // everything correctly, as if the animation had finished. This doesn't | |
| 945 // matter for showing the shelf, as the show animation will do it. | |
| 946 ToolbarSizeChanged(false); | |
| 947 | |
| 948 if (visible) { | |
| 949 // Always set this value as it reflects the last time the download shelf | |
| 950 // was made visible (even if it was already visible). | |
| 951 last_download_shelf_show_ = base::TimeTicks::Now(); | |
| 952 } | |
| 953 } | |
| 954 | |
| 955 void TabContents::ToolbarSizeChanged(bool is_animating) { | 919 void TabContents::ToolbarSizeChanged(bool is_animating) { |
| 956 TabContentsDelegate* d = delegate(); | 920 TabContentsDelegate* d = delegate(); |
| 957 if (d) | 921 if (d) |
| 958 d->ToolbarSizeChanged(this, is_animating); | 922 d->ToolbarSizeChanged(this, is_animating); |
| 959 } | 923 } |
| 960 | 924 |
| 961 void TabContents::OnStartDownload(DownloadItem* download) { | 925 void TabContents::OnStartDownload(DownloadItem* download) { |
| 962 DCHECK(download); | 926 DCHECK(download); |
| 963 | 927 |
| 964 // Download in a constrained popup is shown in the tab that opened it. | 928 // Download in a constrained popup is shown in the tab that opened it. |
| 965 TabContents* tab_contents = delegate()->GetConstrainingContents(this); | 929 TabContents* tab_contents = delegate()->GetConstrainingContents(this); |
| 966 | 930 |
| 967 // GetDownloadShelf creates the download shelf if it was not yet created. | 931 if (tab_contents && tab_contents->delegate()) |
| 968 tab_contents->GetDownloadShelf(true)->AddDownload( | 932 tab_contents->delegate()->OnStartDownload(download); |
| 969 new DownloadItemModel(download)); | |
| 970 tab_contents->SetDownloadShelfVisible(true); | |
| 971 | |
| 972 // TODO(port): port for mac. | |
| 973 #if defined(OS_WIN) || defined(OS_LINUX) | |
| 974 // We make this check for the case of minimized windows, unit tests, etc. | |
| 975 if (platform_util::IsVisible(GetNativeView())) { | |
| 976 DownloadStartedAnimation::Show(tab_contents); | |
| 977 } | |
| 978 #endif | |
| 979 } | |
| 980 | |
| 981 DownloadShelf* TabContents::GetDownloadShelf(bool create) { | |
| 982 if (!download_shelf_.get() && create) | |
| 983 download_shelf_.reset(DownloadShelf::Create(this)); | |
| 984 return download_shelf_.get(); | |
| 985 } | |
| 986 | |
| 987 void TabContents::MigrateShelfFrom(TabContents* tab_contents) { | |
| 988 download_shelf_.reset(tab_contents->GetDownloadShelf(true)); | |
| 989 download_shelf_->ChangeTabContents(tab_contents, this); | |
| 990 tab_contents->ReleaseDownloadShelf(); | |
| 991 } | |
| 992 | |
| 993 void TabContents::ReleaseDownloadShelf() { | |
| 994 download_shelf_.release(); | |
| 995 } | |
| 996 | |
| 997 // static | |
| 998 void TabContents::MigrateShelf(TabContents* from, TabContents* to) { | |
| 999 bool was_shelf_visible = from->IsDownloadShelfVisible(); | |
| 1000 if (was_shelf_visible) | |
| 1001 to->MigrateShelfFrom(from); | |
| 1002 to->SetDownloadShelfVisible(was_shelf_visible); | |
| 1003 } | 933 } |
| 1004 | 934 |
| 1005 void TabContents::WillClose(ConstrainedWindow* window) { | 935 void TabContents::WillClose(ConstrainedWindow* window) { |
| 1006 ConstrainedWindowList::iterator it = | 936 ConstrainedWindowList::iterator it = |
| 1007 find(child_windows_.begin(), child_windows_.end(), window); | 937 find(child_windows_.begin(), child_windows_.end(), window); |
| 1008 if (it != child_windows_.end()) | 938 if (it != child_windows_.end()) |
| 1009 child_windows_.erase(it); | 939 child_windows_.erase(it); |
| 1010 } | 940 } |
| 1011 | 941 |
| 1012 void TabContents::WillCloseBlockedPopupContainer( | 942 void TabContents::WillCloseBlockedPopupContainer( |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 if (controller_.pending_entry() && | 1202 if (controller_.pending_entry() && |
| 1273 (controller_.GetLastCommittedEntry() || | 1203 (controller_.GetLastCommittedEntry() || |
| 1274 render_manager_.pending_dom_ui())) | 1204 render_manager_.pending_dom_ui())) |
| 1275 return render_manager_.pending_dom_ui(); | 1205 return render_manager_.pending_dom_ui(); |
| 1276 return render_manager_.dom_ui(); | 1206 return render_manager_.dom_ui(); |
| 1277 } | 1207 } |
| 1278 | 1208 |
| 1279 void TabContents::DidNavigateMainFramePostCommit( | 1209 void TabContents::DidNavigateMainFramePostCommit( |
| 1280 const NavigationController::LoadCommittedDetails& details, | 1210 const NavigationController::LoadCommittedDetails& details, |
| 1281 const ViewHostMsg_FrameNavigate_Params& params) { | 1211 const ViewHostMsg_FrameNavigate_Params& params) { |
| 1282 // Hide the download shelf if all the following conditions are true: | |
| 1283 // - there are no active downloads. | |
| 1284 // - this is a navigation to a different TLD. | |
| 1285 // - at least 5 seconds have elapsed since the download shelf was shown. | |
| 1286 // TODO(jcampan): bug 1156075 when user gestures are reliable, they should | |
| 1287 // be used to ensure we are hiding only on user initiated | |
| 1288 // navigations. | |
| 1289 DownloadManager* download_manager = profile()->GetDownloadManager(); | |
| 1290 // download_manager can be NULL in unit test context. | |
| 1291 if (download_manager && download_manager->in_progress_count() == 0 && | |
| 1292 !details.previous_url.is_empty() && | |
| 1293 !net::RegistryControlledDomainService::SameDomainOrHost( | |
| 1294 details.previous_url, details.entry->url())) { | |
| 1295 base::TimeDelta time_delta( | |
| 1296 base::TimeTicks::Now() - last_download_shelf_show_); | |
| 1297 if (time_delta > | |
| 1298 base::TimeDelta::FromMilliseconds(kDownloadShelfHideDelay)) { | |
| 1299 SetDownloadShelfVisible(false); | |
| 1300 } | |
| 1301 } | |
| 1302 | |
| 1303 if (details.is_user_initiated_main_frame_load()) { | 1212 if (details.is_user_initiated_main_frame_load()) { |
| 1304 // Clear the status bubble. This is a workaround for a bug where WebKit | 1213 // Clear the status bubble. This is a workaround for a bug where WebKit |
| 1305 // doesn't let us know that the cursor left an element during a | 1214 // doesn't let us know that the cursor left an element during a |
| 1306 // transition (this is also why the mouse cursor remains as a hand after | 1215 // transition (this is also why the mouse cursor remains as a hand after |
| 1307 // clicking on a link); see bugs 1184641 and 980803. We don't want to | 1216 // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 1308 // clear the bubble when a user navigates to a named anchor in the same | 1217 // clear the bubble when a user navigates to a named anchor in the same |
| 1309 // page. | 1218 // page. |
| 1310 UpdateTargetURL(details.entry->page_id(), GURL()); | 1219 UpdateTargetURL(details.entry->page_id(), GURL()); |
| 1311 | 1220 |
| 1312 // UpdateHelpersForDidNavigate will handle the case where the password_form | 1221 // UpdateHelpersForDidNavigate will handle the case where the password_form |
| (...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2440 NavigationController::LoadCommittedDetails& committed_details = | 2349 NavigationController::LoadCommittedDetails& committed_details = |
| 2441 *(Details<NavigationController::LoadCommittedDetails>(details).ptr()); | 2350 *(Details<NavigationController::LoadCommittedDetails>(details).ptr()); |
| 2442 ExpireInfoBars(committed_details); | 2351 ExpireInfoBars(committed_details); |
| 2443 break; | 2352 break; |
| 2444 } | 2353 } |
| 2445 | 2354 |
| 2446 default: | 2355 default: |
| 2447 NOTREACHED(); | 2356 NOTREACHED(); |
| 2448 } | 2357 } |
| 2449 } | 2358 } |
| OLD | NEW |