| 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/gfx/text_elider.h" |
| 7 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 9 #include "base/file_version_info.h" | 10 #include "base/file_version_info.h" |
| 10 #include "base/process_util.h" | 11 #include "base/process_util.h" |
| 11 #include "base/string16.h" | 12 #include "base/string16.h" |
| 12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| 14 #include "chrome/browser/autofill/autofill_manager.h" | 15 #include "chrome/browser/autofill/autofill_manager.h" |
| 15 #include "chrome/browser/blocked_popup_container.h" | 16 #include "chrome/browser/blocked_popup_container.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_model.h" | 17 #include "chrome/browser/bookmarks/bookmark_model.h" |
| (...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1107 find_text_.clear(); | 1108 find_text_.clear(); |
| 1108 find_op_aborted_ = true; | 1109 find_op_aborted_ = true; |
| 1109 last_search_result_ = FindNotificationDetails(); | 1110 last_search_result_ = FindNotificationDetails(); |
| 1110 render_view_host()->StopFinding(clear_selection); | 1111 render_view_host()->StopFinding(clear_selection); |
| 1111 } | 1112 } |
| 1112 | 1113 |
| 1113 void TabContents::GetPageLanguage() { | 1114 void TabContents::GetPageLanguage() { |
| 1114 render_view_host()->GetPageLanguage(); | 1115 render_view_host()->GetPageLanguage(); |
| 1115 } | 1116 } |
| 1116 | 1117 |
| 1117 void TabContents::OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg, | |
| 1118 bool success, | |
| 1119 const std::wstring& prompt) { | |
| 1120 last_javascript_message_dismissal_ = base::TimeTicks::Now(); | |
| 1121 if (is_showing_before_unload_dialog_ && !success) { | |
| 1122 // If a beforeunload dialog is canceled, we need to stop the throbber from | |
| 1123 // spinning, since we forced it to start spinning in Navigate. | |
| 1124 DidStopLoading(); | |
| 1125 | |
| 1126 tab_close_start_time_ = base::TimeTicks(); | |
| 1127 } | |
| 1128 is_showing_before_unload_dialog_ = false; | |
| 1129 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt); | |
| 1130 } | |
| 1131 | |
| 1132 void TabContents::OnSavePage() { | 1118 void TabContents::OnSavePage() { |
| 1133 // If we can not save the page, try to download it. | 1119 // If we can not save the page, try to download it. |
| 1134 if (!SavePackage::IsSavableContents(contents_mime_type())) { | 1120 if (!SavePackage::IsSavableContents(contents_mime_type())) { |
| 1135 DownloadManager* dlm = profile()->GetDownloadManager(); | 1121 DownloadManager* dlm = profile()->GetDownloadManager(); |
| 1136 const GURL& current_page_url = GetURL(); | 1122 const GURL& current_page_url = GetURL(); |
| 1137 if (dlm && current_page_url.is_valid()) | 1123 if (dlm && current_page_url.is_valid()) |
| 1138 dlm->DownloadUrl(current_page_url, GURL(), "", this); | 1124 dlm->DownloadUrl(current_page_url, GURL(), "", this); |
| 1139 return; | 1125 return; |
| 1140 } | 1126 } |
| 1141 | 1127 |
| (...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2326 // being displayed within kJavascriptMessageExpectedDelay of the last one. | 2312 // being displayed within kJavascriptMessageExpectedDelay of the last one. |
| 2327 if (time_since_last_message < | 2313 if (time_since_last_message < |
| 2328 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay)) | 2314 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay)) |
| 2329 show_suppress_checkbox = true; | 2315 show_suppress_checkbox = true; |
| 2330 | 2316 |
| 2331 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt, | 2317 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt, |
| 2332 show_suppress_checkbox, reply_msg); | 2318 show_suppress_checkbox, reply_msg); |
| 2333 } else { | 2319 } else { |
| 2334 // If we are suppressing messages, just reply as is if the user immediately | 2320 // If we are suppressing messages, just reply as is if the user immediately |
| 2335 // pressed "Cancel". | 2321 // pressed "Cancel". |
| 2336 OnJavaScriptMessageBoxClosed(reply_msg, false, std::wstring()); | 2322 OnMessageBoxClosed(reply_msg, false, std::wstring()); |
| 2337 } | 2323 } |
| 2338 } | 2324 } |
| 2339 | 2325 |
| 2340 void TabContents::RunBeforeUnloadConfirm(const std::wstring& message, | 2326 void TabContents::RunBeforeUnloadConfirm(const std::wstring& message, |
| 2341 IPC::Message* reply_msg) { | 2327 IPC::Message* reply_msg) { |
| 2342 is_showing_before_unload_dialog_ = true; | 2328 is_showing_before_unload_dialog_ = true; |
| 2343 RunBeforeUnloadDialog(this, message, reply_msg); | 2329 RunBeforeUnloadDialog(this, message, reply_msg); |
| 2344 } | 2330 } |
| 2345 | 2331 |
| 2346 void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height, | 2332 void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height, |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2641 render_view_host()->SyncRendererPrefs(); | 2627 render_view_host()->SyncRendererPrefs(); |
| 2642 break; | 2628 break; |
| 2643 } | 2629 } |
| 2644 #endif | 2630 #endif |
| 2645 | 2631 |
| 2646 default: | 2632 default: |
| 2647 NOTREACHED(); | 2633 NOTREACHED(); |
| 2648 } | 2634 } |
| 2649 } | 2635 } |
| 2650 | 2636 |
| 2637 std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url, |
| 2638 bool is_alert) { |
| 2639 if (!frame_url.has_host()) |
| 2640 return l10n_util::GetString( |
| 2641 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE |
| 2642 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE); |
| 2643 |
| 2644 // We really only want the scheme, hostname, and port. |
| 2645 GURL::Replacements replacements; |
| 2646 replacements.ClearUsername(); |
| 2647 replacements.ClearPassword(); |
| 2648 replacements.ClearPath(); |
| 2649 replacements.ClearQuery(); |
| 2650 replacements.ClearRef(); |
| 2651 GURL clean_url = frame_url.ReplaceComponents(replacements); |
| 2652 |
| 2653 // TODO(brettw) it should be easier than this to do the correct language |
| 2654 // handling without getting the accept language from the profile. |
| 2655 std::wstring base_address = gfx::ElideUrl(clean_url, gfx::Font(), 0, |
| 2656 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
| 2657 // Force URL to have LTR directionality. |
| 2658 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) |
| 2659 l10n_util::WrapStringWithLTRFormatting(&base_address); |
| 2660 |
| 2661 return l10n_util::GetStringF( |
| 2662 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE, |
| 2663 base_address); |
| 2664 } |
| 2665 |
| 2666 gfx::NativeWindow TabContents::GetMessageBoxRootWindow() { |
| 2667 return view_->GetTopLevelNativeWindow(); |
| 2668 } |
| 2669 |
| 2670 void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg, |
| 2671 bool success, |
| 2672 const std::wstring& prompt) { |
| 2673 last_javascript_message_dismissal_ = base::TimeTicks::Now(); |
| 2674 if (is_showing_before_unload_dialog_ && !success) { |
| 2675 // If a beforeunload dialog is canceled, we need to stop the throbber from |
| 2676 // spinning, since we forced it to start spinning in Navigate. |
| 2677 DidStopLoading(); |
| 2678 |
| 2679 tab_close_start_time_ = base::TimeTicks(); |
| 2680 } |
| 2681 is_showing_before_unload_dialog_ = false; |
| 2682 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt); |
| 2683 } |
| 2684 |
| 2685 void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) { |
| 2686 set_suppress_javascript_messages(suppress_message_boxes); |
| 2687 } |
| 2688 |
| 2651 void TabContents::set_encoding(const std::string& encoding) { | 2689 void TabContents::set_encoding(const std::string& encoding) { |
| 2652 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); | 2690 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); |
| 2653 } | 2691 } |
| OLD | NEW |