| 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/gfx/text_elider.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "base/file_version_info.h" | 10 #include "base/file_version_info.h" |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // First cleanly close all child windows. | 324 // First cleanly close all child windows. |
| 325 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked | 325 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked |
| 326 // some of these to close. CloseWindows is async, so it might get called | 326 // some of these to close. CloseWindows is async, so it might get called |
| 327 // twice before it runs. | 327 // twice before it runs. |
| 328 int size = static_cast<int>(child_windows_.size()); | 328 int size = static_cast<int>(child_windows_.size()); |
| 329 for (int i = size - 1; i >= 0; --i) { | 329 for (int i = size - 1; i >= 0; --i) { |
| 330 ConstrainedWindow* window = child_windows_[i]; | 330 ConstrainedWindow* window = child_windows_[i]; |
| 331 if (window) | 331 if (window) |
| 332 window->CloseConstrainedWindow(); | 332 window->CloseConstrainedWindow(); |
| 333 } | 333 } |
| 334 child_windows_.clear(); // Should be unnecessary, strictly speaking. |
| 334 | 335 |
| 335 if (blocked_popups_) | 336 if (blocked_popups_) |
| 336 blocked_popups_->Destroy(); | 337 blocked_popups_->Destroy(); |
| 337 | 338 |
| 338 // Notify any observer that have a reference on this tab contents. | 339 // Notify any observer that have a reference on this tab contents. |
| 339 NotificationService::current()->Notify( | 340 NotificationService::current()->Notify( |
| 340 NotificationType::TAB_CONTENTS_DESTROYED, | 341 NotificationType::TAB_CONTENTS_DESTROYED, |
| 341 Source<TabContents>(this), | 342 Source<TabContents>(this), |
| 342 NotificationService::NoDetails()); | 343 NotificationService::NoDetails()); |
| 343 | 344 |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 const NavigationEntry::SSLStatus& ssl, | 755 const NavigationEntry::SSLStatus& ssl, |
| 755 bool show_history) { | 756 bool show_history) { |
| 756 if (!delegate_) | 757 if (!delegate_) |
| 757 return; | 758 return; |
| 758 | 759 |
| 759 delegate_->ShowPageInfo(profile(), url, ssl, show_history); | 760 delegate_->ShowPageInfo(profile(), url, ssl, show_history); |
| 760 } | 761 } |
| 761 | 762 |
| 762 ConstrainedWindow* TabContents::CreateConstrainedDialog( | 763 ConstrainedWindow* TabContents::CreateConstrainedDialog( |
| 763 ConstrainedWindowDelegate* delegate) { | 764 ConstrainedWindowDelegate* delegate) { |
| 765 DCHECK(delegate); |
| 766 |
| 764 ConstrainedWindow* window = | 767 ConstrainedWindow* window = |
| 765 ConstrainedWindow::CreateConstrainedDialog(this, delegate); | 768 ConstrainedWindow::CreateConstrainedDialog(this, delegate); |
| 769 DCHECK(window); |
| 766 child_windows_.push_back(window); | 770 child_windows_.push_back(window); |
| 767 return window; | 771 return window; |
| 768 } | 772 } |
| 769 | 773 |
| 774 void TabContents::NotifyChildrenOfPendingEvent(ConstrainedWindow::Event event) { |
| 775 // Make a copy of the list, since child windows may delete themselves from it |
| 776 // (or conceivably worse) while we're iterating through. |
| 777 ConstrainedWindowList children = child_windows_; |
| 778 |
| 779 ConstrainedWindowList::iterator it, end; |
| 780 for (it = children.begin(), end = children.end(); it != end; ++it) { |
| 781 if (*it) |
| 782 (*it)->ParentWillDo(event); |
| 783 } |
| 784 } |
| 785 |
| 770 void TabContents::AddNewContents(TabContents* new_contents, | 786 void TabContents::AddNewContents(TabContents* new_contents, |
| 771 WindowOpenDisposition disposition, | 787 WindowOpenDisposition disposition, |
| 772 const gfx::Rect& initial_pos, | 788 const gfx::Rect& initial_pos, |
| 773 bool user_gesture, | 789 bool user_gesture, |
| 774 const GURL& creator_url) { | 790 const GURL& creator_url) { |
| 775 if (!delegate_) | 791 if (!delegate_) |
| 776 return; | 792 return; |
| 777 | 793 |
| 778 if ((disposition == NEW_POPUP) && !user_gesture && | 794 if ((disposition == NEW_POPUP) && !user_gesture && |
| 779 !CommandLine::ForCurrentProcess()->HasSwitch( | 795 !CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 | 1007 |
| 992 if (tab_contents && tab_contents->delegate()) | 1008 if (tab_contents && tab_contents->delegate()) |
| 993 tab_contents->delegate()->OnStartDownload(download); | 1009 tab_contents->delegate()->OnStartDownload(download); |
| 994 } | 1010 } |
| 995 | 1011 |
| 996 void TabContents::WillClose(ConstrainedWindow* window) { | 1012 void TabContents::WillClose(ConstrainedWindow* window) { |
| 997 ConstrainedWindowList::iterator it = | 1013 ConstrainedWindowList::iterator it = |
| 998 find(child_windows_.begin(), child_windows_.end(), window); | 1014 find(child_windows_.begin(), child_windows_.end(), window); |
| 999 if (it != child_windows_.end()) | 1015 if (it != child_windows_.end()) |
| 1000 child_windows_.erase(it); | 1016 child_windows_.erase(it); |
| 1017 else |
| 1018 NOTREACHED(); |
| 1001 } | 1019 } |
| 1002 | 1020 |
| 1003 void TabContents::WillCloseBlockedPopupContainer( | 1021 void TabContents::WillCloseBlockedPopupContainer( |
| 1004 BlockedPopupContainer* container) { | 1022 BlockedPopupContainer* container) { |
| 1005 DCHECK(blocked_popups_ == container); | 1023 DCHECK(blocked_popups_ == container); |
| 1006 blocked_popups_ = NULL; | 1024 blocked_popups_ = NULL; |
| 1007 } | 1025 } |
| 1008 | 1026 |
| 1009 void TabContents::DidMoveOrResize(ConstrainedWindow* window) { | 1027 void TabContents::DidMoveOrResize(ConstrainedWindow* window) { |
| 1010 #if defined(OS_WIN) | 1028 #if defined(OS_WIN) |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 if (params.password_form.origin.is_valid()) | 1398 if (params.password_form.origin.is_valid()) |
| 1381 GetPasswordManager()->ProvisionallySavePassword(params.password_form); | 1399 GetPasswordManager()->ProvisionallySavePassword(params.password_form); |
| 1382 } | 1400 } |
| 1383 | 1401 |
| 1384 void TabContents::MaybeCloseChildWindows(const GURL& previous_url, | 1402 void TabContents::MaybeCloseChildWindows(const GURL& previous_url, |
| 1385 const GURL& current_url) { | 1403 const GURL& current_url) { |
| 1386 if (net::RegistryControlledDomainService::SameDomainOrHost( | 1404 if (net::RegistryControlledDomainService::SameDomainOrHost( |
| 1387 previous_url, current_url)) | 1405 previous_url, current_url)) |
| 1388 return; | 1406 return; |
| 1389 | 1407 |
| 1390 // Clear out any child windows since we are leaving this page entirely. | 1408 // We inform constrained child windows that we are about to navigate away; |
| 1391 // We use indices instead of iterators in case CloseWindow does something | 1409 // they should close themselves in response if appropriate (e.g., if they are |
| 1392 // that may invalidate an iterator. | 1410 // "content-area" windows). |
| 1393 int size = static_cast<int>(child_windows_.size()); | 1411 NotifyChildrenOfPendingEvent(ConstrainedWindow::kEventNavigate); |
| 1394 for (int i = size - 1; i >= 0; --i) { | |
| 1395 ConstrainedWindow* window = child_windows_[i]; | |
| 1396 if (window) | |
| 1397 window->CloseConstrainedWindow(); | |
| 1398 } | |
| 1399 | 1412 |
| 1400 // Close the popup container. | 1413 // Close the popup container. |
| 1401 if (blocked_popups_) { | 1414 if (blocked_popups_) { |
| 1402 blocked_popups_->Destroy(); | 1415 blocked_popups_->Destroy(); |
| 1403 blocked_popups_ = NULL; | 1416 blocked_popups_ = NULL; |
| 1404 } | 1417 } |
| 1405 } | 1418 } |
| 1406 | 1419 |
| 1407 void TabContents::UpdateStarredStateForCurrentURL() { | 1420 void TabContents::UpdateStarredStateForCurrentURL() { |
| 1408 BookmarkModel* model = profile()->GetBookmarkModel(); | 1421 BookmarkModel* model = profile()->GetBookmarkModel(); |
| (...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2257 } | 2270 } |
| 2258 | 2271 |
| 2259 void TabContents::RunFileChooser(bool multiple_files, | 2272 void TabContents::RunFileChooser(bool multiple_files, |
| 2260 const string16& title, | 2273 const string16& title, |
| 2261 const FilePath& default_file) { | 2274 const FilePath& default_file) { |
| 2262 if (!select_file_dialog_.get()) | 2275 if (!select_file_dialog_.get()) |
| 2263 select_file_dialog_ = SelectFileDialog::Create(this); | 2276 select_file_dialog_ = SelectFileDialog::Create(this); |
| 2264 SelectFileDialog::Type dialog_type = | 2277 SelectFileDialog::Type dialog_type = |
| 2265 multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE : | 2278 multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE : |
| 2266 SelectFileDialog::SELECT_OPEN_FILE; | 2279 SelectFileDialog::SELECT_OPEN_FILE; |
| 2280 #if defined(OS_MACOSX) |
| 2281 select_file_dialog_->SelectFileInTab(dialog_type, title, default_file, NULL, |
| 2282 0, FILE_PATH_LITERAL(""), this, NULL); |
| 2283 #else |
| 2267 select_file_dialog_->SelectFile(dialog_type, title, default_file, | 2284 select_file_dialog_->SelectFile(dialog_type, title, default_file, |
| 2268 NULL, 0, FILE_PATH_LITERAL(""), | 2285 NULL, 0, FILE_PATH_LITERAL(""), |
| 2269 view_->GetTopLevelNativeWindow(), NULL); | 2286 view_->GetTopLevelNativeWindow(), NULL); |
| 2287 #endif |
| 2270 } | 2288 } |
| 2271 | 2289 |
| 2272 void TabContents::RunJavaScriptMessage( | 2290 void TabContents::RunJavaScriptMessage( |
| 2273 const std::wstring& message, | 2291 const std::wstring& message, |
| 2274 const std::wstring& default_prompt, | 2292 const std::wstring& default_prompt, |
| 2275 const GURL& frame_url, | 2293 const GURL& frame_url, |
| 2276 const int flags, | 2294 const int flags, |
| 2277 IPC::Message* reply_msg, | 2295 IPC::Message* reply_msg, |
| 2278 bool* did_suppress_message) { | 2296 bool* did_suppress_message) { |
| 2279 // Suppress javascript messages when requested and when inside a constrained | 2297 // Suppress javascript messages when requested and when inside a constrained |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2687 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt); | 2705 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt); |
| 2688 } | 2706 } |
| 2689 | 2707 |
| 2690 void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) { | 2708 void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) { |
| 2691 set_suppress_javascript_messages(suppress_message_boxes); | 2709 set_suppress_javascript_messages(suppress_message_boxes); |
| 2692 } | 2710 } |
| 2693 | 2711 |
| 2694 void TabContents::set_encoding(const std::string& encoding) { | 2712 void TabContents::set_encoding(const std::string& encoding) { |
| 2695 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); | 2713 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); |
| 2696 } | 2714 } |
| OLD | NEW |