navigator_impl.cc revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/browser/frame_host/navigator_impl.h"
6
7#include "content/browser/frame_host/frame_tree_node.h"
8#include "content/browser/frame_host/navigation_controller_impl.h"
9#include "content/browser/frame_host/navigation_entry_impl.h"
10#include "content/browser/frame_host/navigator_delegate.h"
11#include "content/browser/frame_host/render_frame_host_impl.h"
12#include "content/browser/renderer_host/render_view_host_impl.h"
13#include "content/browser/site_instance_impl.h"
14#include "content/public/browser/browser_context.h"
15#include "content/public/browser/invalidate_type.h"
16#include "content/public/browser/navigation_controller.h"
17#include "content/public/browser/render_view_host.h"
18#include "content/public/common/url_constants.h"
19
20namespace content {
21
22NavigatorImpl::NavigatorImpl(
23    NavigationControllerImpl* navigation_controller,
24    NavigatorDelegate* delegate)
25    : controller_(navigation_controller),
26      delegate_(delegate) {
27}
28
29void NavigatorImpl::DidStartProvisionalLoad(
30    RenderFrameHostImpl* render_frame_host,
31    int64 frame_id,
32    int64 parent_frame_id,
33    bool is_main_frame,
34    const GURL& url) {
35  bool is_error_page = (url.spec() == kUnreachableWebDataURL);
36  bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL);
37  GURL validated_url(url);
38  RenderProcessHost* render_process_host = render_frame_host->GetProcess();
39  RenderViewHost::FilterURL(render_process_host, false, &validated_url);
40
41  if (is_main_frame) {
42    // If there is no browser-initiated pending entry for this navigation and it
43    // is not for the error URL, create a pending entry using the current
44    // SiteInstance, and ensure the address bar updates accordingly.  We don't
45    // know the referrer or extra headers at this point, but the referrer will
46    // be set properly upon commit.
47    NavigationEntryImpl* pending_entry =
48        NavigationEntryImpl::FromNavigationEntry(
49            controller_->GetPendingEntry());
50    bool has_browser_initiated_pending_entry = pending_entry &&
51        !pending_entry->is_renderer_initiated();
52    if (!has_browser_initiated_pending_entry && !is_error_page) {
53      NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
54          controller_->CreateNavigationEntry(validated_url,
55                                             content::Referrer(),
56                                             content::PAGE_TRANSITION_LINK,
57                                             true /* is_renderer_initiated */,
58                                             std::string(),
59                                             controller_->GetBrowserContext()));
60      entry->set_site_instance(
61          static_cast<SiteInstanceImpl*>(
62              render_frame_host->render_view_host()->GetSiteInstance()));
63      // TODO(creis): If there's a pending entry already, find a safe way to
64      // update it instead of replacing it and copying over things like this.
65      if (pending_entry) {
66        entry->set_transferred_global_request_id(
67            pending_entry->transferred_global_request_id());
68        entry->set_should_replace_entry(pending_entry->should_replace_entry());
69        entry->set_redirect_chain(pending_entry->redirect_chain());
70      }
71      controller_->SetPendingEntry(entry);
72      if (delegate_)
73        delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL);
74    }
75  }
76
77  if (delegate_) {
78    // Notify the observer about the start of the provisional load.
79    delegate_->DidStartProvisionalLoad(
80        render_frame_host, frame_id, parent_frame_id, is_main_frame,
81        validated_url, is_error_page, is_iframe_srcdoc);
82  }
83}
84
85}  // namespace content
86