OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/web_contents.h" | 5 #include "chrome/browser/tab_contents/web_contents.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 // Clean up subwindows like plugins and the find in page bar. | 340 // Clean up subwindows like plugins and the find in page bar. |
341 view_->OnContentsDestroy(); | 341 view_->OnContentsDestroy(); |
342 | 342 |
343 NotifyDisconnected(); | 343 NotifyDisconnected(); |
344 HungRendererWarning::HideForWebContents(this); | 344 HungRendererWarning::HideForWebContents(this); |
345 render_manager_.Shutdown(); | 345 render_manager_.Shutdown(); |
346 TabContents::Destroy(); | 346 TabContents::Destroy(); |
347 } | 347 } |
348 | 348 |
349 const string16& WebContents::GetTitle() const { | 349 const string16& WebContents::GetTitle() const { |
350 if (dom_ui_.get()) { | 350 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ? |
351 render_manager_.pending_dom_ui() : render_manager_.dom_ui(); | |
352 if (our_dom_ui) { | |
351 // Give the DOM UI the chance to override our title. | 353 // Give the DOM UI the chance to override our title. |
352 const string16& title = dom_ui_->overridden_title(); | 354 const string16& title = our_dom_ui->overridden_title(); |
353 if (!title.empty()) | 355 if (!title.empty()) |
354 return title; | 356 return title; |
355 } | 357 } |
356 return TabContents::GetTitle(); | 358 return TabContents::GetTitle(); |
357 } | 359 } |
358 | 360 |
359 SiteInstance* WebContents::GetSiteInstance() const { | 361 SiteInstance* WebContents::GetSiteInstance() const { |
360 return render_manager_.current_host()->site_instance(); | 362 return render_manager_.current_host()->site_instance(); |
361 } | 363 } |
362 | 364 |
363 bool WebContents::ShouldDisplayURL() { | 365 bool WebContents::ShouldDisplayURL() { |
364 if (dom_ui_.get()) | 366 if (controller()->GetPendingEntry()) { |
365 return !dom_ui_->should_hide_url(); | 367 // When there is a pending entry, that should determine whether the URL is |
368 // displayed (including getting the default behavior if the DOMUI doesn't | |
369 // specify). | |
370 if (render_manager_.pending_dom_ui()) | |
371 return !render_manager_.pending_dom_ui()->should_hide_url(); | |
372 return true; | |
373 } | |
374 | |
375 if (render_manager_.dom_ui()) | |
376 return !render_manager_.dom_ui()->should_hide_url(); | |
366 return true; | 377 return true; |
367 } | 378 } |
368 | 379 |
369 bool WebContents::ShouldDisplayFavIcon() { | 380 bool WebContents::ShouldDisplayFavIcon() { |
370 if (dom_ui_.get()) | 381 if (controller()->GetPendingEntry()) { |
371 return !dom_ui_->hide_favicon(); | 382 // See ShouldDisplayURL. |
383 if (render_manager_.pending_dom_ui()) | |
384 return !render_manager_.pending_dom_ui()->hide_favicon(); | |
385 return true; | |
386 } | |
387 | |
388 if (render_manager_.dom_ui()) | |
389 return !render_manager_.dom_ui()->hide_favicon(); | |
372 return true; | 390 return true; |
373 } | 391 } |
374 | 392 |
375 std::wstring WebContents::GetStatusText() const { | 393 std::wstring WebContents::GetStatusText() const { |
376 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE) | 394 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE) |
377 return std::wstring(); | 395 return std::wstring(); |
378 | 396 |
379 switch (load_state_) { | 397 switch (load_state_) { |
380 case net::LOAD_STATE_WAITING_FOR_CACHE: | 398 case net::LOAD_STATE_WAITING_FOR_CACHE: |
381 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE); | 399 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE); |
(...skipping 13 matching lines...) Expand all Loading... | |
395 case net::LOAD_STATE_READING_RESPONSE: | 413 case net::LOAD_STATE_READING_RESPONSE: |
396 break; | 414 break; |
397 } | 415 } |
398 | 416 |
399 return std::wstring(); | 417 return std::wstring(); |
400 } | 418 } |
401 | 419 |
402 bool WebContents::NavigateToPendingEntry(bool reload) { | 420 bool WebContents::NavigateToPendingEntry(bool reload) { |
403 const NavigationEntry& entry = *controller()->GetPendingEntry(); | 421 const NavigationEntry& entry = *controller()->GetPendingEntry(); |
404 | 422 |
405 // This will possibly create (or NULL out) a DOM UI object for the page. We'll | |
406 // use this later when the page starts doing stuff to allow it to do so. | |
407 dom_ui_.reset(DOMUIFactory::CreateDOMUIForURL(this, entry.url())); | |
408 | |
409 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry); | 423 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry); |
410 if (!dest_render_view_host) | 424 if (!dest_render_view_host) |
411 return false; // Unable to create the desired render view host. | 425 return false; // Unable to create the desired render view host. |
412 | 426 |
413 // Used for page load time metrics. | 427 // Used for page load time metrics. |
414 current_load_start_ = TimeTicks::Now(); | 428 current_load_start_ = TimeTicks::Now(); |
415 | 429 |
416 // Navigate in the desired RenderViewHost. | 430 // Navigate in the desired RenderViewHost. |
417 dest_render_view_host->NavigateToEntry(entry, reload); | 431 dest_render_view_host->NavigateToEntry(entry, reload); |
418 | 432 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call | 525 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call |
512 // our superclass HideContents(), because some callers want to be very picky | 526 // our superclass HideContents(), because some callers want to be very picky |
513 // about the order in which these get called. In addition to making the code | 527 // about the order in which these get called. In addition to making the code |
514 // here practically impossible to understand, this also means we end up | 528 // here practically impossible to understand, this also means we end up |
515 // calling TabContents::WasHidden() twice if callers call both versions of | 529 // calling TabContents::WasHidden() twice if callers call both versions of |
516 // HideContents() on a WebContents. | 530 // HideContents() on a WebContents. |
517 WasHidden(); | 531 WasHidden(); |
518 } | 532 } |
519 | 533 |
520 bool WebContents::IsBookmarkBarAlwaysVisible() { | 534 bool WebContents::IsBookmarkBarAlwaysVisible() { |
521 if (dom_ui_.get()) | 535 // We want the bookmarks bar to go with the committed entry. This way, when |
522 return dom_ui_->force_bookmark_bar_visible(); | 536 // you're on the new tab page and navigate, the bookmarks bar doesn't |
537 // disappear until the next load commits (the same time the page changes). | |
538 if (!controller()->GetLastCommittedEntry()) { | |
539 // However, when there is no committed entry (the first load of the tab), | |
540 // then we fall back on the pending entry. This means that the bookmarks bar | |
541 // will be visible before the new tab page load commits. | |
542 if (render_manager_.pending_dom_ui()) | |
543 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible(); | |
544 return false; | |
545 } | |
546 | |
547 if (render_manager_.dom_ui()) | |
548 return render_manager_.dom_ui()->force_bookmark_bar_visible(); | |
523 return false; | 549 return false; |
524 } | 550 } |
525 | 551 |
526 void WebContents::SetDownloadShelfVisible(bool visible) { | 552 void WebContents::SetDownloadShelfVisible(bool visible) { |
527 TabContents::SetDownloadShelfVisible(visible); | 553 TabContents::SetDownloadShelfVisible(visible); |
528 if (visible) { | 554 if (visible) { |
529 // Always set this value as it reflects the last time the download shelf | 555 // Always set this value as it reflects the last time the download shelf |
530 // was made visible (even if it was already visible). | 556 // was made visible (even if it was already visible). |
531 last_download_shelf_show_ = TimeTicks::Now(); | 557 last_download_shelf_show_ = TimeTicks::Now(); |
532 } | 558 } |
533 } | 559 } |
534 | 560 |
535 void WebContents::PopupNotificationVisibilityChanged(bool visible) { | 561 void WebContents::PopupNotificationVisibilityChanged(bool visible) { |
536 render_view_host()->PopupNotificationVisibilityChanged(visible); | 562 render_view_host()->PopupNotificationVisibilityChanged(visible); |
537 } | 563 } |
538 | 564 |
539 bool WebContents::FocusLocationBarByDefault() { | 565 bool WebContents::FocusLocationBarByDefault() { |
540 // Allow the DOM Ui to override the default. | 566 // Allow the DOM UI to override the default. We use the pending DOM UI since |
541 if (dom_ui_.get()) | 567 // that's what the user "just did" so should control what happens after they |
542 return dom_ui_->focus_location_bar_by_default(); | 568 // did it. Using the committed one would mean when they navigate from a DOMUI |
569 // to a regular page, the location bar would be focused. | |
570 if (render_manager_.pending_dom_ui()) | |
571 return render_manager_.pending_dom_ui()->focus_location_bar_by_default(); | |
543 return false; | 572 return false; |
544 } | 573 } |
545 | 574 |
546 // Stupid view pass-throughs | 575 // Stupid view pass-throughs |
547 void WebContents::CreateView() { | 576 void WebContents::CreateView() { |
548 view_->CreateView(); | 577 view_->CreateView(); |
549 } | 578 } |
550 | 579 |
551 gfx::NativeView WebContents::GetNativeView() const { | 580 gfx::NativeView WebContents::GetNativeView() const { |
552 return view_->GetNativeView(); | 581 return view_->GetNativeView(); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 return profile(); | 748 return profile(); |
720 } | 749 } |
721 | 750 |
722 void WebContents::RenderViewCreated(RenderViewHost* render_view_host) { | 751 void WebContents::RenderViewCreated(RenderViewHost* render_view_host) { |
723 if (!controller()) | 752 if (!controller()) |
724 return; | 753 return; |
725 NavigationEntry* entry = controller()->GetActiveEntry(); | 754 NavigationEntry* entry = controller()->GetActiveEntry(); |
726 if (!entry) | 755 if (!entry) |
727 return; | 756 return; |
728 | 757 |
729 if (dom_ui_.get()) { | 758 // When we're creating views, we're still doing initial setup, so we always |
730 dom_ui_->RenderViewCreated(render_view_host); | 759 // use the pending DOM UI rather than any possibly existing committed one. |
760 if (render_manager_.pending_dom_ui()) { | |
761 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host); | |
731 } else if (entry->IsViewSourceMode()) { | 762 } else if (entry->IsViewSourceMode()) { |
732 // Put the renderer in view source mode. | 763 // Put the renderer in view source mode. |
733 render_view_host->Send( | 764 render_view_host->Send( |
734 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); | 765 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); |
735 } | 766 } |
736 } | 767 } |
737 | 768 |
738 void WebContents::RenderViewReady(RenderViewHost* rvh) { | 769 void WebContents::RenderViewReady(RenderViewHost* rvh) { |
739 if (rvh != render_view_host()) { | 770 if (rvh != render_view_host()) { |
740 // Don't notify the world, since this came from a renderer in the | 771 // Don't notify the world, since this came from a renderer in the |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1063 // request. If we end up with another place invoking DownloadImage, probably | 1094 // request. If we end up with another place invoking DownloadImage, probably |
1064 // best to refactor out into notification service, or something similar. | 1095 // best to refactor out into notification service, or something similar. |
1065 if (errored) | 1096 if (errored) |
1066 fav_icon_helper_.FavIconDownloadFailed(id); | 1097 fav_icon_helper_.FavIconDownloadFailed(id); |
1067 else | 1098 else |
1068 fav_icon_helper_.SetFavIcon(id, image_url, image); | 1099 fav_icon_helper_.SetFavIcon(id, image_url, image); |
1069 } | 1100 } |
1070 | 1101 |
1071 void WebContents::RequestOpenURL(const GURL& url, const GURL& referrer, | 1102 void WebContents::RequestOpenURL(const GURL& url, const GURL& referrer, |
1072 WindowOpenDisposition disposition) { | 1103 WindowOpenDisposition disposition) { |
1073 if (dom_ui_.get()) { | 1104 if (render_manager_.dom_ui()) { |
1074 // When we're a DOM UI, it will provide a page transition type for us (this | 1105 // When we're a DOM UI, it will provide a page transition type for us (this |
1075 // is so the new tab page can specify AUTO_BOOKMARK for automatically | 1106 // is so the new tab page can specify AUTO_BOOKMARK for automatically |
1076 // generated suggestions). | 1107 // generated suggestions). |
1077 // | 1108 // |
1078 // Note also that we hide the referrer for DOM UI pages. We don't really | 1109 // Note also that we hide the referrer for DOM UI pages. We don't really |
1079 // want web sites to see a referrer of "chrome-ui://blah" (and some | 1110 // want web sites to see a referrer of "chrome-ui://blah" (and some |
1080 // chrome-ui URLs might have search terms or other stuff we don't want to | 1111 // chrome-ui URLs might have search terms or other stuff we don't want to |
1081 // send to the site), so we send no referrer. | 1112 // send to the site), so we send no referrer. |
1082 OpenURL(url, GURL(), disposition, dom_ui_->link_transition_type()); | 1113 OpenURL(url, GURL(), disposition, |
1114 render_manager_.dom_ui()->link_transition_type()); | |
1083 } else { | 1115 } else { |
1084 OpenURL(url, referrer, disposition, PageTransition::LINK); | 1116 OpenURL(url, referrer, disposition, PageTransition::LINK); |
1085 } | 1117 } |
1086 } | 1118 } |
1087 | 1119 |
1088 void WebContents::DomOperationResponse(const std::string& json_string, | 1120 void WebContents::DomOperationResponse(const std::string& json_string, |
1089 int automation_id) { | 1121 int automation_id) { |
1090 DomOperationNotificationDetails details(json_string, automation_id); | 1122 DomOperationNotificationDetails details(json_string, automation_id); |
1091 NotificationService::current()->Notify( | 1123 NotificationService::current()->Notify( |
1092 NotificationType::DOM_OPERATION_RESPONSE, Source<WebContents>(this), | 1124 NotificationType::DOM_OPERATION_RESPONSE, Source<WebContents>(this), |
1093 Details<DomOperationNotificationDetails>(&details)); | 1125 Details<DomOperationNotificationDetails>(&details)); |
1094 } | 1126 } |
1095 | 1127 |
1096 void WebContents::ProcessDOMUIMessage(const std::string& message, | 1128 void WebContents::ProcessDOMUIMessage(const std::string& message, |
1097 const std::string& content) { | 1129 const std::string& content) { |
1098 if (!dom_ui_.get()) { | 1130 if (!render_manager_.dom_ui()) { |
1099 // We shouldn't get a DOM UI message when we haven't enabled the DOM UI. | 1131 // We shouldn't get a DOM UI message when we haven't enabled the DOM UI. |
1100 // Because the renderer might be owned and sending random messages, we need | 1132 // Because the renderer might be owned and sending random messages, we need |
1101 // to ignore these inproper ones. | 1133 // to ignore these inproper ones. |
1102 NOTREACHED(); | 1134 NOTREACHED(); |
1103 return; | 1135 return; |
1104 } | 1136 } |
1105 dom_ui_->ProcessDOMUIMessage(message, content); | 1137 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content); |
1106 } | 1138 } |
1107 | 1139 |
1108 void WebContents::ProcessExternalHostMessage(const std::string& message, | 1140 void WebContents::ProcessExternalHostMessage(const std::string& message, |
1109 const std::string& origin, | 1141 const std::string& origin, |
1110 const std::string& target) { | 1142 const std::string& target) { |
1111 if (delegate()) | 1143 if (delegate()) |
1112 delegate()->ForwardMessageToExternalHost(message, origin, target); | 1144 delegate()->ForwardMessageToExternalHost(message, origin, target); |
1113 } | 1145 } |
1114 | 1146 |
1115 void WebContents::GoToEntryAtOffset(int offset) { | 1147 void WebContents::GoToEntryAtOffset(int offset) { |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1397 web_prefs.default_encoding = | 1429 web_prefs.default_encoding = |
1398 CharacterEncoding::GetCanonicalEncodingNameByAliasName( | 1430 CharacterEncoding::GetCanonicalEncodingNameByAliasName( |
1399 web_prefs.default_encoding); | 1431 web_prefs.default_encoding); |
1400 if (web_prefs.default_encoding.empty()) { | 1432 if (web_prefs.default_encoding.empty()) { |
1401 prefs->ClearPref(prefs::kDefaultCharset); | 1433 prefs->ClearPref(prefs::kDefaultCharset); |
1402 web_prefs.default_encoding = prefs->GetString( | 1434 web_prefs.default_encoding = prefs->GetString( |
1403 prefs::kDefaultCharset); | 1435 prefs::kDefaultCharset); |
1404 } | 1436 } |
1405 DCHECK(!web_prefs.default_encoding.empty()); | 1437 DCHECK(!web_prefs.default_encoding.empty()); |
1406 | 1438 |
1407 // Override some prefs when we're a DOM UI, or the pages won't work. | 1439 // Override some prefs when we're a DOM UI, or the pages won't work. This is |
1408 if (dom_ui_.get()) { | 1440 // called during setup, so we will always use the pending one. |
1441 if (render_manager_.pending_dom_ui()) { | |
1409 web_prefs.loads_images_automatically = true; | 1442 web_prefs.loads_images_automatically = true; |
1410 web_prefs.javascript_enabled = true; | 1443 web_prefs.javascript_enabled = true; |
1411 } | 1444 } |
1412 | 1445 |
1413 return web_prefs; | 1446 return web_prefs; |
1414 } | 1447 } |
1415 | 1448 |
1416 void WebContents::OnMissingPluginStatus(int status) { | 1449 void WebContents::OnMissingPluginStatus(int status) { |
1417 #if defined(OS_WIN) | 1450 #if defined(OS_WIN) |
1418 // TODO(PORT): pull in when plug-ins work | 1451 // TODO(PORT): pull in when plug-ins work |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1574 bool* proceed_to_fire_unload) { | 1607 bool* proceed_to_fire_unload) { |
1575 if (delegate()) | 1608 if (delegate()) |
1576 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); | 1609 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); |
1577 } | 1610 } |
1578 | 1611 |
1579 void WebContents::UpdateRenderViewSizeForRenderManager() { | 1612 void WebContents::UpdateRenderViewSizeForRenderManager() { |
1580 // TODO(brettw) this is a hack. See WebContentsView::SizeContents. | 1613 // TODO(brettw) this is a hack. See WebContentsView::SizeContents. |
1581 view_->SizeContents(view_->GetContainerSize()); | 1614 view_->SizeContents(view_->GetContainerSize()); |
1582 } | 1615 } |
1583 | 1616 |
1617 DOMUI* WebContents::CreateDOMUIForRenderManager(const GURL& url) { | |
1618 return DOMUIFactory::CreateDOMUIForURL(this, url); | |
1619 } | |
1620 | |
1584 NavigationEntry* | 1621 NavigationEntry* |
1585 WebContents::GetLastCommittedNavigationEntryForRenderManager() { | 1622 WebContents::GetLastCommittedNavigationEntryForRenderManager() { |
1586 if (!controller()) | 1623 if (!controller()) |
1587 return NULL; | 1624 return NULL; |
1588 return controller()->GetLastCommittedEntry(); | 1625 return controller()->GetLastCommittedEntry(); |
1589 } | 1626 } |
1590 | 1627 |
1591 bool WebContents::CreateRenderViewForRenderManager( | 1628 bool WebContents::CreateRenderViewForRenderManager( |
1592 RenderViewHost* render_view_host) { | 1629 RenderViewHost* render_view_host) { |
1593 // When we're running a DOM UI, the RenderViewHost needs to be put in DOM UI | 1630 // When we're running a DOM UI, the RenderViewHost needs to be put in DOM UI |
1594 // mode before CreateRenderView is called. | 1631 // mode before CreateRenderView is called. When we're asked to create a |
1595 if (dom_ui_.get()) | 1632 // enderView, that means it's for the pending entry, so we have to use the |
jcampan
2009/03/25 17:01:43
Nit: typo enderView -> RenderView
| |
1633 // pending DOM UI. | |
1634 if (render_manager_.pending_dom_ui()) | |
1596 render_view_host->AllowDOMUIBindings(); | 1635 render_view_host->AllowDOMUIBindings(); |
1597 | 1636 |
1598 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); | 1637 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); |
1599 if (!render_view_host->CreateRenderView()) | 1638 if (!render_view_host->CreateRenderView()) |
1600 return false; | 1639 return false; |
1601 | 1640 |
1602 // Now that the RenderView has been created, we need to tell it its size. | 1641 // Now that the RenderView has been created, we need to tell it its size. |
1603 rwh_view->SetSize(view_->GetContainerSize()); | 1642 rwh_view->SetSize(view_->GetContainerSize()); |
1604 | 1643 |
1605 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(), | 1644 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(), |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1972 // The favicon url isn't valid. This means there really isn't a favicon, | 2011 // The favicon url isn't valid. This means there really isn't a favicon, |
1973 // or the favicon url wasn't obtained before the load started. This assumes | 2012 // or the favicon url wasn't obtained before the load started. This assumes |
1974 // the later. | 2013 // the later. |
1975 // TODO(sky): Need a way to set the favicon that doesn't involve generating | 2014 // TODO(sky): Need a way to set the favicon that doesn't involve generating |
1976 // its url. | 2015 // its url. |
1977 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); | 2016 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); |
1978 } | 2017 } |
1979 new_url->set_safe_for_autoreplace(true); | 2018 new_url->set_safe_for_autoreplace(true); |
1980 url_model->Add(new_url); | 2019 url_model->Add(new_url); |
1981 } | 2020 } |
OLD | NEW |