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/web_contents/web_contents_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 28 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
29 #include "content/browser/download/download_stats.h" | 29 #include "content/browser/download/download_stats.h" |
30 #include "content/browser/download/mhtml_generation_manager.h" | 30 #include "content/browser/download/mhtml_generation_manager.h" |
31 #include "content/browser/download/save_package.h" | 31 #include "content/browser/download/save_package.h" |
32 #include "content/browser/gpu/compositor_util.h" | 32 #include "content/browser/gpu/compositor_util.h" |
33 #include "content/browser/gpu/gpu_data_manager_impl.h" | 33 #include "content/browser/gpu/gpu_data_manager_impl.h" |
34 #include "content/browser/gpu/gpu_process_host.h" | 34 #include "content/browser/gpu/gpu_process_host.h" |
35 #include "content/browser/host_zoom_map_impl.h" | 35 #include "content/browser/host_zoom_map_impl.h" |
36 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 36 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
37 #include "content/browser/power_save_blocker_impl.h" | 37 #include "content/browser/power_save_blocker_impl.h" |
| 38 #include "content/browser/renderer_host/navigator.h" |
| 39 #include "content/browser/renderer_host/render_frame_host_impl.h" |
38 #include "content/browser/renderer_host/render_process_host_impl.h" | 40 #include "content/browser/renderer_host/render_process_host_impl.h" |
39 #include "content/browser/renderer_host/render_view_host_impl.h" | 41 #include "content/browser/renderer_host/render_view_host_impl.h" |
40 #include "content/browser/renderer_host/render_widget_host_impl.h" | 42 #include "content/browser/renderer_host/render_widget_host_impl.h" |
41 #include "content/browser/site_instance_impl.h" | 43 #include "content/browser/site_instance_impl.h" |
42 #include "content/browser/web_contents/interstitial_page_impl.h" | 44 #include "content/browser/web_contents/interstitial_page_impl.h" |
43 #include "content/browser/web_contents/navigation_entry_impl.h" | 45 #include "content/browser/web_contents/navigation_entry_impl.h" |
44 #include "content/browser/web_contents/web_contents_view_guest.h" | 46 #include "content/browser/web_contents/web_contents_view_guest.h" |
45 #include "content/browser/webui/generic_handler.h" | 47 #include "content/browser/webui/generic_handler.h" |
46 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 48 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
47 #include "content/browser/webui/web_ui_impl.h" | 49 #include "content/browser/webui/web_ui_impl.h" |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 is_showing_before_unload_dialog_(false), | 367 is_showing_before_unload_dialog_(false), |
366 closed_by_user_gesture_(false), | 368 closed_by_user_gesture_(false), |
367 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), | 369 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), |
368 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), | 370 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), |
369 temporary_zoom_settings_(false), | 371 temporary_zoom_settings_(false), |
370 color_chooser_identifier_(0), | 372 color_chooser_identifier_(0), |
371 message_source_(NULL), | 373 message_source_(NULL), |
372 fullscreen_widget_routing_id_(MSG_ROUTING_NONE) { | 374 fullscreen_widget_routing_id_(MSG_ROUTING_NONE) { |
373 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) | 375 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
374 g_created_callbacks.Get().at(i).Run(this); | 376 g_created_callbacks.Get().at(i).Run(this); |
| 377 frame_tree_.Init(&controller_, this); |
375 frame_tree_.SetFrameRemoveListener( | 378 frame_tree_.SetFrameRemoveListener( |
376 base::Bind(&WebContentsImpl::OnFrameRemoved, | 379 base::Bind(&WebContentsImpl::OnFrameRemoved, |
377 base::Unretained(this))); | 380 base::Unretained(this))); |
378 } | 381 } |
379 | 382 |
380 WebContentsImpl::~WebContentsImpl() { | 383 WebContentsImpl::~WebContentsImpl() { |
381 is_being_destroyed_ = true; | 384 is_being_destroyed_ = true; |
382 | 385 |
383 ClearAllPowerSaveBlockers(); | 386 ClearAllPowerSaveBlockers(); |
384 | 387 |
(...skipping 1764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2149 if (entry && entry->GetURL() == GURL(kAboutBlankURL)) | 2152 if (entry && entry->GetURL() == GURL(kAboutBlankURL)) |
2150 return true; | 2153 return true; |
2151 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); | 2154 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); |
2152 } | 2155 } |
2153 | 2156 |
2154 void WebContentsImpl::SetFocusToLocationBar(bool select_all) { | 2157 void WebContentsImpl::SetFocusToLocationBar(bool select_all) { |
2155 if (delegate_) | 2158 if (delegate_) |
2156 delegate_->SetFocusToLocationBar(select_all); | 2159 delegate_->SetFocusToLocationBar(select_all); |
2157 } | 2160 } |
2158 | 2161 |
2159 void WebContentsImpl::DidStartProvisionalLoadForFrame( | 2162 void WebContentsImpl::DidStartProvisionalLoad( |
2160 RenderViewHost* render_view_host, | |
2161 int64 frame_id, | 2163 int64 frame_id, |
2162 int64 parent_frame_id, | 2164 int64 parent_frame_id, |
2163 bool is_main_frame, | 2165 bool is_main_frame, |
2164 const GURL& url) { | 2166 const GURL& validated_url, |
2165 bool is_error_page = (url.spec() == kUnreachableWebDataURL); | 2167 bool is_error_page, |
2166 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); | 2168 bool is_iframe_srcdoc, |
2167 GURL validated_url(url); | 2169 RenderFrameHost* render_frame_host) { |
2168 RenderProcessHost* render_process_host = | 2170 DidChangeLoadProgress(0); |
2169 render_view_host->GetProcess(); | |
2170 RenderViewHost::FilterURL(render_process_host, false, &validated_url); | |
2171 | 2171 |
2172 if (is_main_frame) { | 2172 RenderFrameHostImpl* rfh = |
2173 DidChangeLoadProgress(0); | 2173 static_cast<RenderFrameHostImpl*>(render_frame_host); |
2174 | |
2175 // If there is no browser-initiated pending entry for this navigation and it | |
2176 // is not for the error URL, create a pending entry using the current | |
2177 // SiteInstance, and ensure the address bar updates accordingly. We don't | |
2178 // know the referrer or extra headers at this point, but the referrer will | |
2179 // be set properly upon commit. | |
2180 NavigationEntry* pending_entry = controller_.GetPendingEntry(); | |
2181 bool has_browser_initiated_pending_entry = pending_entry && | |
2182 !NavigationEntryImpl::FromNavigationEntry(pending_entry)-> | |
2183 is_renderer_initiated(); | |
2184 if (!has_browser_initiated_pending_entry && !is_error_page) { | |
2185 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( | |
2186 controller_.CreateNavigationEntry(validated_url, | |
2187 content::Referrer(), | |
2188 content::PAGE_TRANSITION_LINK, | |
2189 true /* is_renderer_initiated */, | |
2190 std::string(), | |
2191 GetBrowserContext())); | |
2192 entry->set_site_instance( | |
2193 static_cast<SiteInstanceImpl*>(GetSiteInstance())); | |
2194 controller_.SetPendingEntry(entry); | |
2195 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL); | |
2196 } | |
2197 } | |
2198 | |
2199 // Notify observers about the start of the provisional load. | |
2200 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 2174 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
2201 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id, | 2175 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id, |
2202 is_main_frame, validated_url, is_error_page, | 2176 is_main_frame, validated_url, is_error_page, |
2203 is_iframe_srcdoc, render_view_host)); | 2177 is_iframe_srcdoc, rfh->render_view_host())); |
| 2178 } |
2204 | 2179 |
2205 if (is_main_frame) { | 2180 void WebContentsImpl::ProvisionalChangeToMainFrameUrl( |
2206 // Notify observers about the provisional change in the main frame URL. | 2181 const GURL& url, |
2207 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 2182 RenderFrameHost* render_frame_host) { |
2208 ProvisionalChangeToMainFrameUrl(validated_url, | 2183 RenderFrameHostImpl* rfh = |
2209 render_view_host)); | 2184 static_cast<RenderFrameHostImpl*>(render_frame_host); |
2210 } | 2185 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2186 ProvisionalChangeToMainFrameUrl( |
| 2187 url, rfh->render_view_host())); |
2211 } | 2188 } |
2212 | 2189 |
2213 void WebContentsImpl::DidRedirectProvisionalLoad( | 2190 void WebContentsImpl::DidRedirectProvisionalLoad( |
2214 RenderViewHost* render_view_host, | 2191 RenderViewHost* render_view_host, |
2215 int32 page_id, | 2192 int32 page_id, |
2216 const GURL& source_url, | 2193 const GURL& source_url, |
2217 const GURL& target_url) { | 2194 const GURL& target_url) { |
2218 // TODO(creis): Remove this method and have the pre-rendering code listen to | 2195 // TODO(creis): Remove this method and have the pre-rendering code listen to |
2219 // WebContentsObserver::DidGetRedirectForResourceRequest instead. | 2196 // WebContentsObserver::DidGetRedirectForResourceRequest instead. |
2220 // See http://crbug.com/78512. | 2197 // See http://crbug.com/78512. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2280 } | 2257 } |
2281 | 2258 |
2282 render_manager_.RendererAbortedProvisionalLoad(render_view_host); | 2259 render_manager_.RendererAbortedProvisionalLoad(render_view_host); |
2283 } | 2260 } |
2284 | 2261 |
2285 // Do not usually clear the pending entry if one exists, so that the user's | 2262 // Do not usually clear the pending entry if one exists, so that the user's |
2286 // typed URL is not lost when a navigation fails or is aborted. However, in | 2263 // typed URL is not lost when a navigation fails or is aborted. However, in |
2287 // cases that we don't show the pending entry (e.g., renderer-initiated | 2264 // cases that we don't show the pending entry (e.g., renderer-initiated |
2288 // navigations in an existing tab), we don't keep it around. That prevents | 2265 // navigations in an existing tab), we don't keep it around. That prevents |
2289 // spoofs on in-page navigations that don't go through | 2266 // spoofs on in-page navigations that don't go through |
2290 // DidStartProvisionalLoadForFrame. | 2267 // DidStartProvisionalLoad. |
2291 // In general, we allow the view to clear the pending entry and typed URL if | 2268 // In general, we allow the view to clear the pending entry and typed URL if |
2292 // the user requests (e.g., hitting Escape with focus in the address bar). | 2269 // the user requests (e.g., hitting Escape with focus in the address bar). |
2293 // Note: don't touch the transient entry, since an interstitial may exist. | 2270 // Note: don't touch the transient entry, since an interstitial may exist. |
2294 if (controller_.GetPendingEntry() != controller_.GetVisibleEntry()) | 2271 if (controller_.GetPendingEntry() != controller_.GetVisibleEntry()) |
2295 controller_.DiscardPendingEntry(); | 2272 controller_.DiscardPendingEntry(); |
2296 | 2273 |
2297 FOR_EACH_OBSERVER(WebContentsObserver, | 2274 FOR_EACH_OBSERVER(WebContentsObserver, |
2298 observers_, | 2275 observers_, |
2299 DidFailProvisionalLoad(params.frame_id, | 2276 DidFailProvisionalLoad(params.frame_id, |
2300 params.is_main_frame, | 2277 params.is_main_frame, |
(...skipping 1503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3804 } | 3781 } |
3805 | 3782 |
3806 void WebContentsImpl::OnFrameRemoved( | 3783 void WebContentsImpl::OnFrameRemoved( |
3807 RenderViewHostImpl* render_view_host, | 3784 RenderViewHostImpl* render_view_host, |
3808 int64 frame_id) { | 3785 int64 frame_id) { |
3809 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3786 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
3810 FrameDetached(render_view_host, frame_id)); | 3787 FrameDetached(render_view_host, frame_id)); |
3811 } | 3788 } |
3812 | 3789 |
3813 } // namespace content | 3790 } // namespace content |
OLD | NEW |