| 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 "content/browser/tab_contents/tab_contents.h" | 5 #include "content/browser/tab_contents/tab_contents.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "content/browser/webui/web_ui_factory.h" | 41 #include "content/browser/webui/web_ui_factory.h" |
| 42 #include "content/common/bindings_policy.h" | 42 #include "content/common/bindings_policy.h" |
| 43 #include "content/common/content_client.h" | 43 #include "content/common/content_client.h" |
| 44 #include "content/common/content_restriction.h" | 44 #include "content/common/content_restriction.h" |
| 45 #include "content/common/intents_messages.h" | 45 #include "content/common/intents_messages.h" |
| 46 #include "content/common/navigation_types.h" | 46 #include "content/common/navigation_types.h" |
| 47 #include "content/common/notification_service.h" | 47 #include "content/common/notification_service.h" |
| 48 #include "content/common/url_constants.h" | 48 #include "content/common/url_constants.h" |
| 49 #include "content/common/view_messages.h" | 49 #include "content/common/view_messages.h" |
| 50 #include "net/base/net_util.h" | 50 #include "net/base/net_util.h" |
| 51 #include "net/base/registry_controlled_domain.h" | |
| 52 #include "net/url_request/url_request_context_getter.h" | 51 #include "net/url_request/url_request_context_getter.h" |
| 53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 54 #include "ui/gfx/codec/png_codec.h" | 53 #include "ui/gfx/codec/png_codec.h" |
| 55 #include "webkit/glue/password_form.h" | 54 #include "webkit/glue/password_form.h" |
| 56 #include "webkit/glue/web_intent_data.h" | 55 #include "webkit/glue/web_intent_data.h" |
| 57 #include "webkit/glue/webpreferences.h" | 56 #include "webkit/glue/webpreferences.h" |
| 58 | 57 |
| 59 #if defined(OS_MACOSX) | 58 #if defined(OS_MACOSX) |
| 60 #include "ui/gfx/surface/io_surface_support_mac.h" | 59 #include "ui/gfx/surface/io_surface_support_mac.h" |
| 61 #endif // defined(OS_MACOSX) | 60 #endif // defined(OS_MACOSX) |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 213 |
| 215 TabContents::~TabContents() { | 214 TabContents::~TabContents() { |
| 216 is_being_destroyed_ = true; | 215 is_being_destroyed_ = true; |
| 217 | 216 |
| 218 // Clear out any JavaScript state. | 217 // Clear out any JavaScript state. |
| 219 if (dialog_creator_) | 218 if (dialog_creator_) |
| 220 dialog_creator_->ResetJavaScriptState(this); | 219 dialog_creator_->ResetJavaScriptState(this); |
| 221 | 220 |
| 222 NotifyDisconnected(); | 221 NotifyDisconnected(); |
| 223 | 222 |
| 224 // First cleanly close all child windows. | |
| 225 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked | |
| 226 // some of these to close. CloseWindows is async, so it might get called | |
| 227 // twice before it runs. | |
| 228 CloseConstrainedWindows(); | |
| 229 | |
| 230 // Notify any observer that have a reference on this tab contents. | 223 // Notify any observer that have a reference on this tab contents. |
| 231 NotificationService::current()->Notify( | 224 NotificationService::current()->Notify( |
| 232 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 225 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 233 Source<TabContents>(this), | 226 Source<TabContents>(this), |
| 234 NotificationService::NoDetails()); | 227 NotificationService::NoDetails()); |
| 235 | 228 |
| 236 // TODO(brettw) this should be moved to the view. | 229 // TODO(brettw) this should be moved to the view. |
| 237 #if defined(OS_WIN) | 230 #if defined(OS_WIN) |
| 238 // If we still have a window handle, destroy it. GetNativeView can return | 231 // If we still have a window handle, destroy it. GetNativeView can return |
| 239 // NULL if this contents was part of a window that closed. | 232 // NULL if this contents was part of a window that closed. |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 | 661 |
| 669 void TabContents::ShowPageInfo(const GURL& url, | 662 void TabContents::ShowPageInfo(const GURL& url, |
| 670 const NavigationEntry::SSLStatus& ssl, | 663 const NavigationEntry::SSLStatus& ssl, |
| 671 bool show_history) { | 664 bool show_history) { |
| 672 if (!delegate_) | 665 if (!delegate_) |
| 673 return; | 666 return; |
| 674 | 667 |
| 675 delegate_->ShowPageInfo(browser_context(), url, ssl, show_history); | 668 delegate_->ShowPageInfo(browser_context(), url, ssl, show_history); |
| 676 } | 669 } |
| 677 | 670 |
| 678 void TabContents::AddConstrainedDialog(ConstrainedWindow* window) { | |
| 679 child_windows_.push_back(window); | |
| 680 | |
| 681 if (child_windows_.size() == 1) { | |
| 682 window->ShowConstrainedWindow(); | |
| 683 BlockTabContent(true); | |
| 684 } | |
| 685 } | |
| 686 | |
| 687 void TabContents::BlockTabContent(bool blocked) { | |
| 688 RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); | |
| 689 // 70% opaque grey. | |
| 690 SkColor greyish = SkColorSetARGB(178, 0, 0, 0); | |
| 691 if (rwhv) | |
| 692 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false); | |
| 693 // RenderViewHost may be NULL during shutdown. | |
| 694 if (render_view_host()) | |
| 695 render_view_host()->set_ignore_input_events(blocked); | |
| 696 if (delegate_) | |
| 697 delegate_->SetTabContentBlocked(this, blocked); | |
| 698 } | |
| 699 | |
| 700 void TabContents::AddNewContents(TabContents* new_contents, | 671 void TabContents::AddNewContents(TabContents* new_contents, |
| 701 WindowOpenDisposition disposition, | 672 WindowOpenDisposition disposition, |
| 702 const gfx::Rect& initial_pos, | 673 const gfx::Rect& initial_pos, |
| 703 bool user_gesture) { | 674 bool user_gesture) { |
| 704 if (!delegate_) | 675 if (!delegate_) |
| 705 return; | 676 return; |
| 706 | 677 |
| 707 delegate_->AddNewContents(this, new_contents, disposition, initial_pos, | 678 delegate_->AddNewContents(this, new_contents, disposition, initial_pos, |
| 708 user_gesture); | 679 user_gesture); |
| 709 } | 680 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 return d->CanDownload(this, request_id); | 724 return d->CanDownload(this, request_id); |
| 754 return true; | 725 return true; |
| 755 } | 726 } |
| 756 | 727 |
| 757 void TabContents::OnStartDownload(DownloadItem* download) { | 728 void TabContents::OnStartDownload(DownloadItem* download) { |
| 758 TabContentsDelegate* d = delegate(); | 729 TabContentsDelegate* d = delegate(); |
| 759 if (d) | 730 if (d) |
| 760 d->OnStartDownload(this, download); | 731 d->OnStartDownload(this, download); |
| 761 } | 732 } |
| 762 | 733 |
| 763 void TabContents::WillClose(ConstrainedWindow* window) { | |
| 764 ConstrainedWindowList::iterator i( | |
| 765 std::find(child_windows_.begin(), child_windows_.end(), window)); | |
| 766 bool removed_topmost_window = i == child_windows_.begin(); | |
| 767 if (i != child_windows_.end()) | |
| 768 child_windows_.erase(i); | |
| 769 if (child_windows_.empty()) { | |
| 770 BlockTabContent(false); | |
| 771 } else { | |
| 772 if (removed_topmost_window) | |
| 773 child_windows_[0]->ShowConstrainedWindow(); | |
| 774 BlockTabContent(true); | |
| 775 } | |
| 776 } | |
| 777 | |
| 778 void TabContents::OnSavePage() { | 734 void TabContents::OnSavePage() { |
| 779 // If we can not save the page, try to download it. | 735 // If we can not save the page, try to download it. |
| 780 if (!SavePackage::IsSavableContents(contents_mime_type())) { | 736 if (!SavePackage::IsSavableContents(contents_mime_type())) { |
| 781 DownloadManager* dlm = browser_context()->GetDownloadManager(); | 737 DownloadManager* dlm = browser_context()->GetDownloadManager(); |
| 782 const GURL& current_page_url = GetURL(); | 738 const GURL& current_page_url = GetURL(); |
| 783 if (dlm && current_page_url.is_valid()) { | 739 if (dlm && current_page_url.is_valid()) { |
| 784 dlm->DownloadUrl(current_page_url, GURL(), "", this); | 740 dlm->DownloadUrl(current_page_url, GURL(), "", this); |
| 785 download_stats::RecordDownloadCount( | 741 download_stats::RecordDownloadCount( |
| 786 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT); | 742 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT); |
| 787 return; | 743 return; |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 // page. | 1236 // page. |
| 1281 UpdateTargetURL(details.entry->page_id(), GURL()); | 1237 UpdateTargetURL(details.entry->page_id(), GURL()); |
| 1282 } | 1238 } |
| 1283 | 1239 |
| 1284 if (!details.is_in_page) { | 1240 if (!details.is_in_page) { |
| 1285 // Once the main frame is navigated, we're no longer considered to have | 1241 // Once the main frame is navigated, we're no longer considered to have |
| 1286 // displayed insecure content. | 1242 // displayed insecure content. |
| 1287 displayed_insecure_content_ = false; | 1243 displayed_insecure_content_ = false; |
| 1288 } | 1244 } |
| 1289 | 1245 |
| 1290 // Close constrained windows if necessary. | |
| 1291 if (!net::RegistryControlledDomainService::SameDomainOrHost( | |
| 1292 details.previous_url, details.entry->url())) | |
| 1293 CloseConstrainedWindows(); | |
| 1294 | |
| 1295 // Notify observers about navigation. | 1246 // Notify observers about navigation. |
| 1296 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1247 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
| 1297 DidNavigateMainFramePostCommit(details, params)); | 1248 DidNavigateMainFramePostCommit(details, params)); |
| 1298 } | 1249 } |
| 1299 | 1250 |
| 1300 void TabContents::DidNavigateAnyFramePostCommit( | 1251 void TabContents::DidNavigateAnyFramePostCommit( |
| 1301 RenderViewHost* render_view_host, | 1252 RenderViewHost* render_view_host, |
| 1302 const content::LoadCommittedDetails& details, | 1253 const content::LoadCommittedDetails& details, |
| 1303 const ViewHostMsg_FrameNavigate_Params& params) { | 1254 const ViewHostMsg_FrameNavigate_Params& params) { |
| 1304 // If we navigate, reset JavaScript state. This does nothing to prevent | 1255 // If we navigate, reset JavaScript state. This does nothing to prevent |
| 1305 // a malicious script from spamming messages, since the script could just | 1256 // a malicious script from spamming messages, since the script could just |
| 1306 // reload the page to stop blocking. | 1257 // reload the page to stop blocking. |
| 1307 if (dialog_creator_) { | 1258 if (dialog_creator_) { |
| 1308 dialog_creator_->ResetJavaScriptState(this); | 1259 dialog_creator_->ResetJavaScriptState(this); |
| 1309 dialog_creator_ = NULL; | 1260 dialog_creator_ = NULL; |
| 1310 } | 1261 } |
| 1311 | 1262 |
| 1312 // Notify observers about navigation. | 1263 // Notify observers about navigation. |
| 1313 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 1264 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
| 1314 DidNavigateAnyFramePostCommit(details, params)); | 1265 DidNavigateAnyFramePostCommit(details, params)); |
| 1315 } | 1266 } |
| 1316 | 1267 |
| 1317 void TabContents::CloseConstrainedWindows() { | |
| 1318 // Clear out any constrained windows since we are leaving this page entirely. | |
| 1319 // To ensure that we iterate over every element in child_windows_ we | |
| 1320 // need to use a copy of child_windows_. Otherwise if | |
| 1321 // window->CloseConstrainedWindow() modifies child_windows_ we could end up | |
| 1322 // skipping some elements. | |
| 1323 ConstrainedWindowList child_windows_copy(child_windows_); | |
| 1324 for (ConstrainedWindowList::iterator it = child_windows_copy.begin(); | |
| 1325 it != child_windows_copy.end(); ++it) { | |
| 1326 ConstrainedWindow* window = *it; | |
| 1327 if (window) { | |
| 1328 window->CloseConstrainedWindow(); | |
| 1329 BlockTabContent(false); | |
| 1330 } | |
| 1331 } | |
| 1332 } | |
| 1333 | |
| 1334 void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, | 1268 void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, |
| 1335 RenderViewHost* rvh) { | 1269 RenderViewHost* rvh) { |
| 1336 // If we are creating a RVH for a restored controller, then we might | 1270 // If we are creating a RVH for a restored controller, then we might |
| 1337 // have more page IDs than the SiteInstance's current max page ID. We must | 1271 // have more page IDs than the SiteInstance's current max page ID. We must |
| 1338 // make sure that the max page ID is larger than any restored page ID. | 1272 // make sure that the max page ID is larger than any restored page ID. |
| 1339 // Note that it is ok for conflicting page IDs to exist in another tab | 1273 // Note that it is ok for conflicting page IDs to exist in another tab |
| 1340 // (i.e., NavigationController), but if any page ID is larger than the max, | 1274 // (i.e., NavigationController), but if any page ID is larger than the max, |
| 1341 // the back/forward list will get confused. | 1275 // the back/forward list will get confused. |
| 1342 int max_restored_page_id = controller_.max_restored_page_id(); | 1276 int max_restored_page_id = controller_.max_restored_page_id(); |
| 1343 if (max_restored_page_id > 0) { | 1277 if (max_restored_page_id > 0) { |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1853 // Notify observers. | 1787 // Notify observers. |
| 1854 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetUserGesture()); | 1788 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetUserGesture()); |
| 1855 | 1789 |
| 1856 ResourceDispatcherHost* rdh = | 1790 ResourceDispatcherHost* rdh = |
| 1857 content::GetContentClient()->browser()->GetResourceDispatcherHost(); | 1791 content::GetContentClient()->browser()->GetResourceDispatcherHost(); |
| 1858 if (rdh) // NULL in unittests. | 1792 if (rdh) // NULL in unittests. |
| 1859 rdh->OnUserGesture(this); | 1793 rdh->OnUserGesture(this); |
| 1860 } | 1794 } |
| 1861 | 1795 |
| 1862 void TabContents::OnIgnoredUIEvent() { | 1796 void TabContents::OnIgnoredUIEvent() { |
| 1863 if (constrained_window_count()) { | 1797 // Notify observers. |
| 1864 ConstrainedWindow* window = *constrained_window_begin(); | 1798 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetIgnoredUIEvent()); |
| 1865 window->FocusConstrainedWindow(); | |
| 1866 } | |
| 1867 } | 1799 } |
| 1868 | 1800 |
| 1869 void TabContents::RendererUnresponsive(RenderViewHost* rvh, | 1801 void TabContents::RendererUnresponsive(RenderViewHost* rvh, |
| 1870 bool is_during_unload) { | 1802 bool is_during_unload) { |
| 1871 // Don't show hung renderer dialog for a swapped out RVH. | 1803 // Don't show hung renderer dialog for a swapped out RVH. |
| 1872 if (rvh != render_view_host()) | 1804 if (rvh != render_view_host()) |
| 1873 return; | 1805 return; |
| 1874 | 1806 |
| 1875 // Ignore renderer unresponsive event if debugger is attached to the tab | 1807 // Ignore renderer unresponsive event if debugger is attached to the tab |
| 1876 // since the event may be a result of the renderer sitting on a breakpoint. | 1808 // since the event may be a result of the renderer sitting on a breakpoint. |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2026 } | 1958 } |
| 2027 | 1959 |
| 2028 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { | 1960 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { |
| 2029 render_manager_.SwapInRenderViewHost(rvh); | 1961 render_manager_.SwapInRenderViewHost(rvh); |
| 2030 } | 1962 } |
| 2031 | 1963 |
| 2032 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 1964 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 2033 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 1965 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 2034 rwh_view->SetSize(view()->GetContainerSize()); | 1966 rwh_view->SetSize(view()->GetContainerSize()); |
| 2035 } | 1967 } |
| OLD | NEW |