| 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" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 load_state_(net::LOAD_STATE_IDLE), | 240 load_state_(net::LOAD_STATE_IDLE), |
| 241 load_state_host_(), | 241 load_state_host_(), |
| 242 upload_size_(0), | 242 upload_size_(0), |
| 243 upload_position_(0), | 243 upload_position_(0), |
| 244 received_page_title_(false), | 244 received_page_title_(false), |
| 245 is_starred_(false), | 245 is_starred_(false), |
| 246 contents_mime_type_(), | 246 contents_mime_type_(), |
| 247 encoding_(), | 247 encoding_(), |
| 248 blocked_popups_(NULL), | 248 blocked_popups_(NULL), |
| 249 infobar_delegates_(), | 249 infobar_delegates_(), |
| 250 tab_modal_count_(0), |
| 250 find_ui_active_(false), | 251 find_ui_active_(false), |
| 251 find_op_aborted_(false), | 252 find_op_aborted_(false), |
| 252 current_find_request_id_(find_request_id_counter_++), | 253 current_find_request_id_(find_request_id_counter_++), |
| 253 find_text_(), | 254 find_text_(), |
| 254 last_search_case_sensitive_(false), | 255 last_search_case_sensitive_(false), |
| 255 last_search_prepopulate_text_(NULL), | 256 last_search_prepopulate_text_(NULL), |
| 256 last_search_result_(), | 257 last_search_result_(), |
| 257 capturing_contents_(false), | 258 capturing_contents_(false), |
| 258 is_being_destroyed_(false), | 259 is_being_destroyed_(false), |
| 259 notify_disconnection_(false), | 260 notify_disconnection_(false), |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 // First cleanly close all child windows. | 336 // First cleanly close all child windows. |
| 336 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked | 337 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked |
| 337 // some of these to close. CloseWindows is async, so it might get called | 338 // some of these to close. CloseWindows is async, so it might get called |
| 338 // twice before it runs. | 339 // twice before it runs. |
| 339 int size = static_cast<int>(child_windows_.size()); | 340 int size = static_cast<int>(child_windows_.size()); |
| 340 for (int i = size - 1; i >= 0; --i) { | 341 for (int i = size - 1; i >= 0; --i) { |
| 341 ConstrainedWindow* window = child_windows_[i]; | 342 ConstrainedWindow* window = child_windows_[i]; |
| 342 if (window) | 343 if (window) |
| 343 window->CloseConstrainedWindow(); | 344 window->CloseConstrainedWindow(); |
| 344 } | 345 } |
| 346 child_windows_.clear(); // Should be unnecessary, strictly speaking. |
| 347 tab_modal_count_ = 0; |
| 348 |
| 349 // Notify whomever that things have changed. |
| 350 if (delegate_) |
| 351 delegate_->ChildWindowsChanged(this); |
| 345 | 352 |
| 346 if (blocked_popups_) | 353 if (blocked_popups_) |
| 347 blocked_popups_->Destroy(); | 354 blocked_popups_->Destroy(); |
| 348 | 355 |
| 349 // Notify any observer that have a reference on this tab contents. | 356 // Notify any observer that have a reference on this tab contents. |
| 350 NotificationService::current()->Notify( | 357 NotificationService::current()->Notify( |
| 351 NotificationType::TAB_CONTENTS_DESTROYED, | 358 NotificationType::TAB_CONTENTS_DESTROYED, |
| 352 Source<TabContents>(this), | 359 Source<TabContents>(this), |
| 353 NotificationService::NoDetails()); | 360 NotificationService::NoDetails()); |
| 354 | 361 |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 const NavigationEntry::SSLStatus& ssl, | 813 const NavigationEntry::SSLStatus& ssl, |
| 807 bool show_history) { | 814 bool show_history) { |
| 808 if (!delegate_) | 815 if (!delegate_) |
| 809 return; | 816 return; |
| 810 | 817 |
| 811 delegate_->ShowPageInfo(profile(), url, ssl, show_history); | 818 delegate_->ShowPageInfo(profile(), url, ssl, show_history); |
| 812 } | 819 } |
| 813 | 820 |
| 814 ConstrainedWindow* TabContents::CreateConstrainedDialog( | 821 ConstrainedWindow* TabContents::CreateConstrainedDialog( |
| 815 ConstrainedWindowDelegate* delegate) { | 822 ConstrainedWindowDelegate* delegate) { |
| 823 DCHECK(delegate); |
| 824 |
| 816 ConstrainedWindow* window = | 825 ConstrainedWindow* window = |
| 817 ConstrainedWindow::CreateConstrainedDialog(this, delegate); | 826 ConstrainedWindow::CreateConstrainedDialog(this, delegate); |
| 827 DCHECK(window); |
| 818 child_windows_.push_back(window); | 828 child_windows_.push_back(window); |
| 829 |
| 830 // Possibly enter into the fully-tab-modal state. |
| 831 if (window->GetModalityLevel() >= ConstrainedWindow::kModalForTab) { |
| 832 DCHECK(tab_modal_count_ == 0); |
| 833 tab_modal_count_++; |
| 834 } |
| 835 |
| 836 // Notify whomever that things have changed. |
| 837 if (delegate_) |
| 838 delegate_->ChildWindowsChanged(this); |
| 839 |
| 819 return window; | 840 return window; |
| 820 } | 841 } |
| 821 | 842 |
| 843 ConstrainedWindow::ModalityLevel TabContents::GetTabModalityLevel() { |
| 844 if (constrained_window_count() > 0) { |
| 845 return (tab_modal_count_ > 0) ? ConstrainedWindow::kModalForTab : |
| 846 ConstrainedWindow::kModalForContent; |
| 847 } |
| 848 return ConstrainedWindow::kModalNone; |
| 849 } |
| 850 |
| 851 void TabContents::NotifyChildrenOfPendingEvent(ConstrainedWindow::Event event) { |
| 852 // Make a copy of the list, since child windows may delete themselves from it |
| 853 // (or conceivably worse) while we're iterating through. |
| 854 ConstrainedWindowList children = child_windows_; |
| 855 |
| 856 ConstrainedWindowList::iterator it, end; |
| 857 for (it = children.begin(), end = children.end(); it != end; ++it) { |
| 858 if (*it) |
| 859 (*it)->ParentWillDo(event); |
| 860 } |
| 861 } |
| 862 |
| 822 void TabContents::AddNewContents(TabContents* new_contents, | 863 void TabContents::AddNewContents(TabContents* new_contents, |
| 823 WindowOpenDisposition disposition, | 864 WindowOpenDisposition disposition, |
| 824 const gfx::Rect& initial_pos, | 865 const gfx::Rect& initial_pos, |
| 825 bool user_gesture, | 866 bool user_gesture, |
| 826 const GURL& creator_url) { | 867 const GURL& creator_url) { |
| 827 if (!delegate_) | 868 if (!delegate_) |
| 828 return; | 869 return; |
| 829 | 870 |
| 830 if ((disposition == NEW_POPUP) && !user_gesture && | 871 if ((disposition == NEW_POPUP) && !user_gesture && |
| 831 !CommandLine::ForCurrentProcess()->HasSwitch( | 872 !CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 // Download in a constrained popup is shown in the tab that opened it. | 1070 // Download in a constrained popup is shown in the tab that opened it. |
| 1030 TabContents* tab_contents = delegate()->GetConstrainingContents(this); | 1071 TabContents* tab_contents = delegate()->GetConstrainingContents(this); |
| 1031 | 1072 |
| 1032 if (tab_contents && tab_contents->delegate()) | 1073 if (tab_contents && tab_contents->delegate()) |
| 1033 tab_contents->delegate()->OnStartDownload(download); | 1074 tab_contents->delegate()->OnStartDownload(download); |
| 1034 } | 1075 } |
| 1035 | 1076 |
| 1036 void TabContents::WillClose(ConstrainedWindow* window) { | 1077 void TabContents::WillClose(ConstrainedWindow* window) { |
| 1037 ConstrainedWindowList::iterator it = | 1078 ConstrainedWindowList::iterator it = |
| 1038 find(child_windows_.begin(), child_windows_.end(), window); | 1079 find(child_windows_.begin(), child_windows_.end(), window); |
| 1039 if (it != child_windows_.end()) | 1080 if (it != child_windows_.end()) { |
| 1081 // Possibly move out of fully-tab-modal state. |
| 1082 if (window->GetModalityLevel() >= ConstrainedWindow::kModalForTab) { |
| 1083 if (tab_modal_count_ > 0) |
| 1084 tab_modal_count_--; |
| 1085 else |
| 1086 NOTREACHED(); |
| 1087 } |
| 1088 |
| 1089 // Notify whomever that things have changed. |
| 1090 if (delegate_) |
| 1091 delegate_->ChildWindowsChanged(this); |
| 1092 |
| 1093 // Erase this child from our child-window list. |
| 1040 child_windows_.erase(it); | 1094 child_windows_.erase(it); |
| 1095 } else { |
| 1096 NOTREACHED() << "Did not find child window being removed."; |
| 1097 } |
| 1041 } | 1098 } |
| 1042 | 1099 |
| 1043 void TabContents::WillCloseBlockedPopupContainer( | 1100 void TabContents::WillCloseBlockedPopupContainer( |
| 1044 BlockedPopupContainer* container) { | 1101 BlockedPopupContainer* container) { |
| 1045 DCHECK(blocked_popups_ == container); | 1102 DCHECK(blocked_popups_ == container); |
| 1046 blocked_popups_ = NULL; | 1103 blocked_popups_ = NULL; |
| 1047 } | 1104 } |
| 1048 | 1105 |
| 1049 void TabContents::DidMoveOrResize(ConstrainedWindow* window) { | 1106 void TabContents::DidMoveOrResize(ConstrainedWindow* window) { |
| 1050 #if defined(OS_WIN) | 1107 #if defined(OS_WIN) |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 if (params.password_form.origin.is_valid()) | 1466 if (params.password_form.origin.is_valid()) |
| 1410 GetPasswordManager()->ProvisionallySavePassword(params.password_form); | 1467 GetPasswordManager()->ProvisionallySavePassword(params.password_form); |
| 1411 } | 1468 } |
| 1412 | 1469 |
| 1413 void TabContents::MaybeCloseChildWindows(const GURL& previous_url, | 1470 void TabContents::MaybeCloseChildWindows(const GURL& previous_url, |
| 1414 const GURL& current_url) { | 1471 const GURL& current_url) { |
| 1415 if (net::RegistryControlledDomainService::SameDomainOrHost( | 1472 if (net::RegistryControlledDomainService::SameDomainOrHost( |
| 1416 previous_url, current_url)) | 1473 previous_url, current_url)) |
| 1417 return; | 1474 return; |
| 1418 | 1475 |
| 1419 // Clear out any child windows since we are leaving this page entirely. | 1476 // We inform constrained child windows that we are about to navigate away. |
| 1420 // We use indices instead of iterators in case CloseWindow does something | 1477 // Those which are "content-area" windows should close themselves in response. |
| 1421 // that may invalidate an iterator. | 1478 NotifyChildrenOfPendingEvent(ConstrainedWindow::kEventNavigate); |
| 1422 int size = static_cast<int>(child_windows_.size()); | |
| 1423 for (int i = size - 1; i >= 0; --i) { | |
| 1424 ConstrainedWindow* window = child_windows_[i]; | |
| 1425 if (window) | |
| 1426 window->CloseConstrainedWindow(); | |
| 1427 } | |
| 1428 | 1479 |
| 1429 // Close the popup container. | 1480 // Close the popup container. |
| 1430 if (blocked_popups_) { | 1481 if (blocked_popups_) { |
| 1431 blocked_popups_->Destroy(); | 1482 blocked_popups_->Destroy(); |
| 1432 blocked_popups_ = NULL; | 1483 blocked_popups_ = NULL; |
| 1433 } | 1484 } |
| 1434 } | 1485 } |
| 1435 | 1486 |
| 1436 void TabContents::UpdateStarredStateForCurrentURL() { | 1487 void TabContents::UpdateStarredStateForCurrentURL() { |
| 1437 BookmarkModel* model = profile()->GetBookmarkModel(); | 1488 BookmarkModel* model = profile()->GetBookmarkModel(); |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2236 } | 2287 } |
| 2237 | 2288 |
| 2238 void TabContents::RunFileChooser(bool multiple_files, | 2289 void TabContents::RunFileChooser(bool multiple_files, |
| 2239 const string16& title, | 2290 const string16& title, |
| 2240 const FilePath& default_file) { | 2291 const FilePath& default_file) { |
| 2241 if (!select_file_dialog_.get()) | 2292 if (!select_file_dialog_.get()) |
| 2242 select_file_dialog_ = SelectFileDialog::Create(this); | 2293 select_file_dialog_ = SelectFileDialog::Create(this); |
| 2243 SelectFileDialog::Type dialog_type = | 2294 SelectFileDialog::Type dialog_type = |
| 2244 multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE : | 2295 multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE : |
| 2245 SelectFileDialog::SELECT_OPEN_FILE; | 2296 SelectFileDialog::SELECT_OPEN_FILE; |
| 2297 #if defined(OS_MACOSX) |
| 2298 select_file_dialog_->SelectFileInTab(dialog_type, title, default_file, NULL, |
| 2299 0, FILE_PATH_LITERAL(""), this, NULL); |
| 2300 #else |
| 2246 select_file_dialog_->SelectFile(dialog_type, title, default_file, | 2301 select_file_dialog_->SelectFile(dialog_type, title, default_file, |
| 2247 NULL, 0, FILE_PATH_LITERAL(""), | 2302 NULL, 0, FILE_PATH_LITERAL(""), |
| 2248 view_->GetTopLevelNativeWindow(), NULL); | 2303 view_->GetTopLevelNativeWindow(), NULL); |
| 2304 #endif |
| 2249 } | 2305 } |
| 2250 | 2306 |
| 2251 void TabContents::RunJavaScriptMessage( | 2307 void TabContents::RunJavaScriptMessage( |
| 2252 const std::wstring& message, | 2308 const std::wstring& message, |
| 2253 const std::wstring& default_prompt, | 2309 const std::wstring& default_prompt, |
| 2254 const GURL& frame_url, | 2310 const GURL& frame_url, |
| 2255 const int flags, | 2311 const int flags, |
| 2256 IPC::Message* reply_msg, | 2312 IPC::Message* reply_msg, |
| 2257 bool* did_suppress_message) { | 2313 bool* did_suppress_message) { |
| 2258 // Suppress javascript messages when requested and when inside a constrained | 2314 // Suppress javascript messages when requested and when inside a constrained |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2562 case NotificationType::PREF_CHANGED: { | 2618 case NotificationType::PREF_CHANGED: { |
| 2563 std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); | 2619 std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); |
| 2564 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs()); | 2620 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs()); |
| 2565 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) { | 2621 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) { |
| 2566 UpdateAlternateErrorPageURL(); | 2622 UpdateAlternateErrorPageURL(); |
| 2567 } else if (*pref_name_in == prefs::kDefaultCharset || | 2623 } else if (*pref_name_in == prefs::kDefaultCharset || |
| 2568 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true) | 2624 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true) |
| 2569 ) { | 2625 ) { |
| 2570 UpdateWebPreferences(); | 2626 UpdateWebPreferences(); |
| 2571 } else { | 2627 } else { |
| 2572 NOTREACHED() << "unexpected pref change notification" << *pref_name_in; | 2628 NOTREACHED() << "unexpected pref change notification " << *pref_name_in; |
| 2573 } | 2629 } |
| 2574 break; | 2630 break; |
| 2575 } | 2631 } |
| 2576 case NotificationType::RENDER_WIDGET_HOST_DESTROYED: | 2632 case NotificationType::RENDER_WIDGET_HOST_DESTROYED: |
| 2577 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr()); | 2633 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr()); |
| 2578 break; | 2634 break; |
| 2579 | 2635 |
| 2580 case NotificationType::NAV_ENTRY_COMMITTED: { | 2636 case NotificationType::NAV_ENTRY_COMMITTED: { |
| 2581 DCHECK(&controller_ == Source<NavigationController>(source).ptr()); | 2637 DCHECK(&controller_ == Source<NavigationController>(source).ptr()); |
| 2582 | 2638 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2595 | 2651 |
| 2596 default: | 2652 default: |
| 2597 NOTREACHED(); | 2653 NOTREACHED(); |
| 2598 } | 2654 } |
| 2599 } | 2655 } |
| 2600 | 2656 |
| 2601 void TabContents::set_encoding(const std::string& encoding) { | 2657 void TabContents::set_encoding(const std::string& encoding) { |
| 2602 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); | 2658 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); |
| 2603 } | 2659 } |
| 2604 | 2660 |
| OLD | NEW |