| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION && | 173 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION && |
| 174 profile->DidLastSessionExitCleanly()) | 174 profile->DidLastSessionExitCleanly()) |
| 175 return ViewMsg_Navigate_Type::RESTORE; | 175 return ViewMsg_Navigate_Type::RESTORE; |
| 176 | 176 |
| 177 return ViewMsg_Navigate_Type::NORMAL; | 177 return ViewMsg_Navigate_Type::NORMAL; |
| 178 } | 178 } |
| 179 | 179 |
| 180 void MakeNavigateParams(const NavigationEntry& entry, | 180 void MakeNavigateParams(const NavigationEntry& entry, |
| 181 const NavigationController& controller, | 181 const NavigationController& controller, |
| 182 NavigationController::ReloadType reload_type, | 182 NavigationController::ReloadType reload_type, |
| 183 bool is_hidden, |
| 183 ViewMsg_Navigate_Params* params) { | 184 ViewMsg_Navigate_Params* params) { |
| 184 params->page_id = entry.page_id(); | 185 params->page_id = entry.page_id(); |
| 185 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); | 186 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); |
| 186 params->current_history_list_offset = controller.last_committed_entry_index(); | 187 params->current_history_list_offset = controller.last_committed_entry_index(); |
| 187 params->current_history_list_length = controller.entry_count(); | 188 params->current_history_list_length = controller.entry_count(); |
| 188 params->url = entry.url(); | 189 params->url = entry.url(); |
| 189 params->referrer = entry.referrer(); | 190 params->referrer = entry.referrer(); |
| 190 params->transition = entry.transition_type(); | 191 params->transition = entry.transition_type(); |
| 191 params->state = entry.content_state(); | 192 params->state = entry.content_state(); |
| 192 params->navigation_type = | 193 params->navigation_type = |
| 193 GetNavigationType(controller.profile(), entry, reload_type); | 194 GetNavigationType(controller.profile(), entry, reload_type); |
| 195 params->is_hidden = is_hidden; |
| 194 params->request_time = base::Time::Now(); | 196 params->request_time = base::Time::Now(); |
| 195 } | 197 } |
| 196 | 198 |
| 197 } // namespace | 199 } // namespace |
| 198 | 200 |
| 199 | 201 |
| 200 // TabContents ---------------------------------------------------------------- | 202 // TabContents ---------------------------------------------------------------- |
| 201 | 203 |
| 202 TabContents::TabContents(Profile* profile, | 204 TabContents::TabContents(Profile* profile, |
| 203 SiteInstance* site_instance, | 205 SiteInstance* site_instance, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 229 #endif | 231 #endif |
| 230 suppress_javascript_messages_(false), | 232 suppress_javascript_messages_(false), |
| 231 is_showing_before_unload_dialog_(false), | 233 is_showing_before_unload_dialog_(false), |
| 232 opener_web_ui_type_(WebUI::kNoWebUI), | 234 opener_web_ui_type_(WebUI::kNoWebUI), |
| 233 closed_by_user_gesture_(false), | 235 closed_by_user_gesture_(false), |
| 234 minimum_zoom_percent_( | 236 minimum_zoom_percent_( |
| 235 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), | 237 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), |
| 236 maximum_zoom_percent_( | 238 maximum_zoom_percent_( |
| 237 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), | 239 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), |
| 238 temporary_zoom_settings_(false), | 240 temporary_zoom_settings_(false), |
| 239 content_restrictions_(0) { | 241 content_restrictions_(0), |
| 242 is_initially_hidden_(false) { |
| 240 renderer_preferences_util::UpdateFromSystemSettings( | 243 renderer_preferences_util::UpdateFromSystemSettings( |
| 241 &renderer_preferences_, profile); | 244 &renderer_preferences_, profile); |
| 242 | 245 |
| 243 render_manager_.Init(profile, site_instance, routing_id); | 246 render_manager_.Init(profile, site_instance, routing_id); |
| 244 | 247 |
| 245 // We have the initial size of the view be based on the size of the passed in | 248 // We have the initial size of the view be based on the size of the passed in |
| 246 // tab contents (normally a tab from the same window). | 249 // tab contents (normally a tab from the same window). |
| 247 view_->CreateView(base_tab_contents ? | 250 view_->CreateView(base_tab_contents ? |
| 248 base_tab_contents->view()->GetContainerSize() : gfx::Size()); | 251 base_tab_contents->view()->GetContainerSize() : gfx::Size()); |
| 249 | 252 |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 #if defined(OS_MACOSX) | 504 #if defined(OS_MACOSX) |
| 502 rwhv->SetActive(true); | 505 rwhv->SetActive(true); |
| 503 #endif | 506 #endif |
| 504 } | 507 } |
| 505 | 508 |
| 506 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id()); | 509 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id()); |
| 507 last_selected_time_ = base::TimeTicks::Now(); | 510 last_selected_time_ = base::TimeTicks::Now(); |
| 508 } | 511 } |
| 509 | 512 |
| 510 void TabContents::WasHidden() { | 513 void TabContents::WasHidden() { |
| 514 is_initially_hidden_ = true; |
| 515 |
| 511 if (!capturing_contents()) { | 516 if (!capturing_contents()) { |
| 512 // |render_view_host()| can be NULL if the user middle clicks a link to open | 517 // |render_view_host()| can be NULL if the user middle clicks a link to open |
| 513 // a tab in then background, then closes the tab before selecting it. This | 518 // a tab in then background, then closes the tab before selecting it. This |
| 514 // is because closing the tab calls TabContents::Destroy(), which removes | 519 // is because closing the tab calls TabContents::Destroy(), which removes |
| 515 // the |render_view_host()|; then when we actually destroy the window, | 520 // the |render_view_host()|; then when we actually destroy the window, |
| 516 // OnWindowPosChanged() notices and calls HideContents() (which calls us). | 521 // OnWindowPosChanged() notices and calls HideContents() (which calls us). |
| 517 RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); | 522 RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
| 518 if (rwhv) | 523 if (rwhv) |
| 519 rwhv->WasHidden(); | 524 rwhv->WasHidden(); |
| 520 } | 525 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 devtools_manager->OnNavigatingToPendingEntry(render_view_host(), | 606 devtools_manager->OnNavigatingToPendingEntry(render_view_host(), |
| 602 dest_render_view_host, | 607 dest_render_view_host, |
| 603 entry.url()); | 608 entry.url()); |
| 604 } | 609 } |
| 605 | 610 |
| 606 // Used for page load time metrics. | 611 // Used for page load time metrics. |
| 607 current_load_start_ = base::TimeTicks::Now(); | 612 current_load_start_ = base::TimeTicks::Now(); |
| 608 | 613 |
| 609 // Navigate in the desired RenderViewHost. | 614 // Navigate in the desired RenderViewHost. |
| 610 ViewMsg_Navigate_Params navigate_params; | 615 ViewMsg_Navigate_Params navigate_params; |
| 611 MakeNavigateParams(entry, controller_, reload_type, &navigate_params); | 616 MakeNavigateParams(entry, controller_, reload_type, |
| 617 IsHidden(), &navigate_params); |
| 612 if (delegate_) { | 618 if (delegate_) { |
| 613 navigate_params.extra_headers = | 619 navigate_params.extra_headers = |
| 614 delegate_->GetNavigationHeaders(navigate_params.url); | 620 delegate_->GetNavigationHeaders(navigate_params.url); |
| 615 } | 621 } |
| 616 dest_render_view_host->Navigate(navigate_params); | 622 dest_render_view_host->Navigate(navigate_params); |
| 617 | 623 |
| 618 if (entry.page_id() == -1) { | 624 if (entry.page_id() == -1) { |
| 619 // HACK!! This code suppresses javascript: URLs from being added to | 625 // HACK!! This code suppresses javascript: URLs from being added to |
| 620 // session history, which is what we want to do for javascript: URLs that | 626 // session history, which is what we want to do for javascript: URLs that |
| 621 // do not generate content. What we really need is a message from the | 627 // do not generate content. What we really need is a message from the |
| (...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2033 | 2039 |
| 2034 void TabContents::RequestDesktopNotificationPermission( | 2040 void TabContents::RequestDesktopNotificationPermission( |
| 2035 const GURL& source_origin, int callback_context) { | 2041 const GURL& source_origin, int callback_context) { |
| 2036 DesktopNotificationService* service = | 2042 DesktopNotificationService* service = |
| 2037 DesktopNotificationServiceFactory::GetForProfile(profile()); | 2043 DesktopNotificationServiceFactory::GetForProfile(profile()); |
| 2038 service->RequestPermission( | 2044 service->RequestPermission( |
| 2039 source_origin, GetRenderProcessHost()->id(), | 2045 source_origin, GetRenderProcessHost()->id(), |
| 2040 render_view_host()->routing_id(), callback_context, this); | 2046 render_view_host()->routing_id(), callback_context, this); |
| 2041 } | 2047 } |
| 2042 | 2048 |
| 2049 bool TabContents::IsHidden() const { |
| 2050 if (delegate()) |
| 2051 return delegate()->IsHidden(this); |
| 2052 return is_initially_hidden_; |
| 2053 } |
| 2054 |
| 2043 void TabContents::BeforeUnloadFiredFromRenderManager( | 2055 void TabContents::BeforeUnloadFiredFromRenderManager( |
| 2044 bool proceed, | 2056 bool proceed, |
| 2045 bool* proceed_to_fire_unload) { | 2057 bool* proceed_to_fire_unload) { |
| 2046 if (delegate()) | 2058 if (delegate()) |
| 2047 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); | 2059 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); |
| 2048 } | 2060 } |
| 2049 | 2061 |
| 2050 void TabContents::DidStartLoadingFromRenderManager( | 2062 void TabContents::DidStartLoadingFromRenderManager( |
| 2051 RenderViewHost* render_view_host) { | 2063 RenderViewHost* render_view_host) { |
| 2052 DidStartLoading(); | 2064 DidStartLoading(); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2201 | 2213 |
| 2202 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2214 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 2203 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 2215 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 2204 rwh_view->SetSize(view()->GetContainerSize()); | 2216 rwh_view->SetSize(view()->GetContainerSize()); |
| 2205 } | 2217 } |
| 2206 | 2218 |
| 2207 void TabContents::OnOnlineStateChanged(bool online) { | 2219 void TabContents::OnOnlineStateChanged(bool online) { |
| 2208 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 2220 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
| 2209 render_view_host()->routing_id(), online)); | 2221 render_view_host()->routing_id(), online)); |
| 2210 } | 2222 } |
| OLD | NEW |