OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 using content::DownloadManager; | 114 using content::DownloadManager; |
115 using content::GlobalRequestID; | 115 using content::GlobalRequestID; |
116 using content::NavigationController; | 116 using content::NavigationController; |
117 using content::NavigationEntry; | 117 using content::NavigationEntry; |
118 using content::NavigationEntryImpl; | 118 using content::NavigationEntryImpl; |
119 using content::OpenURLParams; | 119 using content::OpenURLParams; |
120 using content::SSLStatus; | 120 using content::SSLStatus; |
121 using content::UserMetricsAction; | 121 using content::UserMetricsAction; |
122 using content::WebContents; | 122 using content::WebContents; |
123 using content::WebContentsObserver; | 123 using content::WebContentsObserver; |
| 124 using content::WebUIController; |
124 | 125 |
125 namespace { | 126 namespace { |
126 | 127 |
127 // Amount of time we wait between when a key event is received and the renderer | 128 // Amount of time we wait between when a key event is received and the renderer |
128 // is queried for its state and pushed to the NavigationEntry. | 129 // is queried for its state and pushed to the NavigationEntry. |
129 const int kQueryStateDelay = 5000; | 130 const int kQueryStateDelay = 5000; |
130 | 131 |
131 const int kSyncWaitDelay = 40; | 132 const int kSyncWaitDelay = 40; |
132 | 133 |
133 static const char kDotGoogleDotCom[] = ".google.com"; | 134 static const char kDotGoogleDotCom[] = ".google.com"; |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 } | 425 } |
425 | 426 |
426 RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const { | 427 RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const { |
427 return render_manager_.GetRenderWidgetHostView(); | 428 return render_manager_.GetRenderWidgetHostView(); |
428 } | 429 } |
429 | 430 |
430 TabContentsView* TabContents::GetView() const { | 431 TabContentsView* TabContents::GetView() const { |
431 return view_.get(); | 432 return view_.get(); |
432 } | 433 } |
433 | 434 |
| 435 WebUI* TabContents::CreateWebUI(const GURL& url) { |
| 436 WebUI* web_ui = new WebUI(this); |
| 437 WebUIController* controller = |
| 438 content::GetContentClient()->browser()->GetWebUIFactory()-> |
| 439 CreateWebUIForURL(web_ui, url); |
| 440 if (controller) { |
| 441 web_ui->SetController(controller); |
| 442 return web_ui; |
| 443 } |
| 444 |
| 445 delete web_ui; |
| 446 return NULL; |
| 447 } |
| 448 |
434 WebUI* TabContents::GetWebUI() const { | 449 WebUI* TabContents::GetWebUI() const { |
435 return render_manager_.web_ui() ? render_manager_.web_ui() | 450 return render_manager_.web_ui() ? render_manager_.web_ui() |
436 : render_manager_.pending_web_ui(); | 451 : render_manager_.pending_web_ui(); |
437 } | 452 } |
438 | 453 |
439 WebUI* TabContents::GetCommittedWebUI() const { | 454 WebUI* TabContents::GetCommittedWebUI() const { |
440 return render_manager_.web_ui(); | 455 return render_manager_.web_ui(); |
441 } | 456 } |
442 | 457 |
443 const string16& TabContents::GetTitle() const { | 458 const string16& TabContents::GetTitle() const { |
444 // Transient entries take precedence. They are used for interstitial pages | 459 // Transient entries take precedence. They are used for interstitial pages |
445 // that are shown on top of existing pages. | 460 // that are shown on top of existing pages. |
446 NavigationEntry* entry = controller_.GetTransientEntry(); | 461 NavigationEntry* entry = controller_.GetTransientEntry(); |
447 std::string accept_languages = | 462 std::string accept_languages = |
448 content::GetContentClient()->browser()->GetAcceptLangs( | 463 content::GetContentClient()->browser()->GetAcceptLangs( |
449 GetBrowserContext()); | 464 GetBrowserContext()); |
450 if (entry) { | 465 if (entry) { |
451 return entry->GetTitleForDisplay(accept_languages); | 466 return entry->GetTitleForDisplay(accept_languages); |
452 } | 467 } |
453 WebUI* our_web_ui = render_manager_.pending_web_ui() ? | 468 WebUI* our_web_ui = render_manager_.pending_web_ui() ? |
454 render_manager_.pending_web_ui() : render_manager_.web_ui(); | 469 render_manager_.pending_web_ui() : render_manager_.web_ui(); |
455 if (our_web_ui) { | 470 if (our_web_ui) { |
456 // Don't override the title in view source mode. | 471 // Don't override the title in view source mode. |
457 entry = controller_.GetActiveEntry(); | 472 entry = controller_.GetActiveEntry(); |
458 if (!(entry && entry->IsViewSourceMode())) { | 473 if (!(entry && entry->IsViewSourceMode())) { |
459 // Give the Web UI the chance to override our title. | 474 // Give the Web UI the chance to override our title. |
460 const string16& title = our_web_ui->overridden_title(); | 475 const string16& title = our_web_ui->GetOverriddenTitle(); |
461 if (!title.empty()) | 476 if (!title.empty()) |
462 return title; | 477 return title; |
463 } | 478 } |
464 } | 479 } |
465 | 480 |
466 // We use the title for the last committed entry rather than a pending | 481 // We use the title for the last committed entry rather than a pending |
467 // navigation entry. For example, when the user types in a URL, we want to | 482 // navigation entry. For example, when the user types in a URL, we want to |
468 // keep the old page's title until the new load has committed and we get a new | 483 // keep the old page's title until the new load has committed and we get a new |
469 // title. | 484 // title. |
470 entry = controller_.GetLastCommittedEntry(); | 485 entry = controller_.GetLastCommittedEntry(); |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 } | 1129 } |
1115 | 1130 |
1116 bool TabContents::GotResponseToLockMouseRequest(bool allowed) { | 1131 bool TabContents::GotResponseToLockMouseRequest(bool allowed) { |
1117 return GetRenderViewHost() ? | 1132 return GetRenderViewHost() ? |
1118 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false; | 1133 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false; |
1119 } | 1134 } |
1120 | 1135 |
1121 bool TabContents::FocusLocationBarByDefault() { | 1136 bool TabContents::FocusLocationBarByDefault() { |
1122 WebUI* web_ui = GetWebUIForCurrentState(); | 1137 WebUI* web_ui = GetWebUIForCurrentState(); |
1123 if (web_ui) | 1138 if (web_ui) |
1124 return web_ui->focus_location_bar_by_default(); | 1139 return web_ui->ShouldFocusLocationBarByDefault(); |
1125 NavigationEntry* entry = controller_.GetActiveEntry(); | 1140 NavigationEntry* entry = controller_.GetActiveEntry(); |
1126 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL)) | 1141 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL)) |
1127 return true; | 1142 return true; |
1128 return false; | 1143 return false; |
1129 } | 1144 } |
1130 | 1145 |
1131 void TabContents::SetFocusToLocationBar(bool select_all) { | 1146 void TabContents::SetFocusToLocationBar(bool select_all) { |
1132 if (delegate_) | 1147 if (delegate_) |
1133 delegate_->SetFocusToLocationBar(select_all); | 1148 delegate_->SetFocusToLocationBar(select_all); |
1134 } | 1149 } |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 } | 1473 } |
1459 | 1474 |
1460 void TabContents::DidNavigateMainFramePostCommit( | 1475 void TabContents::DidNavigateMainFramePostCommit( |
1461 const content::LoadCommittedDetails& details, | 1476 const content::LoadCommittedDetails& details, |
1462 const ViewHostMsg_FrameNavigate_Params& params) { | 1477 const ViewHostMsg_FrameNavigate_Params& params) { |
1463 if (opener_web_ui_type_ != WebUI::kNoWebUI) { | 1478 if (opener_web_ui_type_ != WebUI::kNoWebUI) { |
1464 // If this is a window.open navigation, use the same WebUI as the renderer | 1479 // If this is a window.open navigation, use the same WebUI as the renderer |
1465 // that opened the window, as long as both renderers have the same | 1480 // that opened the window, as long as both renderers have the same |
1466 // privileges. | 1481 // privileges. |
1467 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) { | 1482 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) { |
1468 WebUI* web_ui = content::GetContentClient()->browser()-> | 1483 WebUI* web_ui = CreateWebUI(GetURL()); |
1469 GetWebUIFactory()->CreateWebUIForURL(this, GetURL()); | |
1470 // web_ui might be NULL if the URL refers to a non-existent extension. | 1484 // web_ui might be NULL if the URL refers to a non-existent extension. |
1471 if (web_ui) { | 1485 if (web_ui) { |
1472 render_manager_.SetWebUIPostCommit(web_ui); | 1486 render_manager_.SetWebUIPostCommit(web_ui); |
1473 web_ui->RenderViewCreated(GetRenderViewHost()); | 1487 web_ui->RenderViewCreated(GetRenderViewHost()); |
1474 } | 1488 } |
1475 } | 1489 } |
1476 opener_web_ui_type_ = WebUI::kNoWebUI; | 1490 opener_web_ui_type_ = WebUI::kNoWebUI; |
1477 } | 1491 } |
1478 | 1492 |
1479 if (details.is_navigation_to_different_page()) { | 1493 if (details.is_navigation_to_different_page()) { |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 if (render_manager_.web_ui()) { | 1951 if (render_manager_.web_ui()) { |
1938 // When we're a Web UI, it will provide a page transition type for us (this | 1952 // When we're a Web UI, it will provide a page transition type for us (this |
1939 // is so the new tab page can specify AUTO_BOOKMARK for automatically | 1953 // is so the new tab page can specify AUTO_BOOKMARK for automatically |
1940 // generated suggestions). | 1954 // generated suggestions). |
1941 // | 1955 // |
1942 // Note also that we hide the referrer for Web UI pages. We don't really | 1956 // Note also that we hide the referrer for Web UI pages. We don't really |
1943 // want web sites to see a referrer of "chrome://blah" (and some | 1957 // want web sites to see a referrer of "chrome://blah" (and some |
1944 // chrome: URLs might have search terms or other stuff we don't want to | 1958 // chrome: URLs might have search terms or other stuff we don't want to |
1945 // send to the site), so we send no referrer. | 1959 // send to the site), so we send no referrer. |
1946 OpenURLParams params(url, content::Referrer(), disposition, | 1960 OpenURLParams params(url, content::Referrer(), disposition, |
1947 render_manager_.web_ui()->link_transition_type(), | 1961 render_manager_.web_ui()->GetLinkTransitionType(), |
1948 false /* is_renderer_initiated */); | 1962 false /* is_renderer_initiated */); |
1949 params.transferred_global_request_id = old_request_id; | 1963 params.transferred_global_request_id = old_request_id; |
1950 new_contents = OpenURL(params); | 1964 new_contents = OpenURL(params); |
1951 transition_type = render_manager_.web_ui()->link_transition_type(); | 1965 transition_type = render_manager_.web_ui()->GetLinkTransitionType(); |
1952 } else { | 1966 } else { |
1953 OpenURLParams params(url, referrer, disposition, | 1967 OpenURLParams params(url, referrer, disposition, |
1954 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */); | 1968 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */); |
1955 params.transferred_global_request_id = old_request_id; | 1969 params.transferred_global_request_id = old_request_id; |
1956 new_contents = OpenURL(params); | 1970 new_contents = OpenURL(params); |
1957 } | 1971 } |
1958 if (new_contents) { | 1972 if (new_contents) { |
1959 // Notify observers. | 1973 // Notify observers. |
1960 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 1974 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
1961 DidOpenRequestedURL(new_contents, | 1975 DidOpenRequestedURL(new_contents, |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2171 | 2185 |
2172 void TabContents::NotifySwappedFromRenderManager() { | 2186 void TabContents::NotifySwappedFromRenderManager() { |
2173 NotifySwapped(); | 2187 NotifySwapped(); |
2174 } | 2188 } |
2175 | 2189 |
2176 NavigationControllerImpl& TabContents::GetControllerForRenderManager() { | 2190 NavigationControllerImpl& TabContents::GetControllerForRenderManager() { |
2177 return GetControllerImpl(); | 2191 return GetControllerImpl(); |
2178 } | 2192 } |
2179 | 2193 |
2180 WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) { | 2194 WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) { |
2181 return content::GetContentClient()->browser()->GetWebUIFactory()-> | 2195 return CreateWebUI(url); |
2182 CreateWebUIForURL(this, url); | |
2183 } | 2196 } |
2184 | 2197 |
2185 NavigationEntry* | 2198 NavigationEntry* |
2186 TabContents::GetLastCommittedNavigationEntryForRenderManager() { | 2199 TabContents::GetLastCommittedNavigationEntryForRenderManager() { |
2187 return controller_.GetLastCommittedEntry(); | 2200 return controller_.GetLastCommittedEntry(); |
2188 } | 2201 } |
2189 | 2202 |
2190 bool TabContents::CreateRenderViewForRenderManager( | 2203 bool TabContents::CreateRenderViewForRenderManager( |
2191 RenderViewHost* render_view_host) { | 2204 RenderViewHost* render_view_host) { |
2192 // Can be NULL during tests. | 2205 // Can be NULL during tests. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2242 encoding_ = content::GetContentClient()->browser()-> | 2255 encoding_ = content::GetContentClient()->browser()-> |
2243 GetCanonicalEncodingNameByAliasName(encoding); | 2256 GetCanonicalEncodingNameByAliasName(encoding); |
2244 } | 2257 } |
2245 | 2258 |
2246 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2259 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
2247 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); | 2260 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); |
2248 // Can be NULL during tests. | 2261 // Can be NULL during tests. |
2249 if (rwh_view) | 2262 if (rwh_view) |
2250 rwh_view->SetSize(GetView()->GetContainerSize()); | 2263 rwh_view->SetSize(GetView()->GetContainerSize()); |
2251 } | 2264 } |
OLD | NEW |