Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / browser_navigator.h
blob07754c72fa0450c5d7f1a801949f1b867697ca71
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_BROWSER_NAVIGATOR_H_
6 #define CHROME_BROWSER_UI_BROWSER_NAVIGATOR_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/ref_counted_memory.h"
12 #include "chrome/browser/ui/host_desktop.h"
13 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/global_request_id.h"
15 #include "content/public/browser/page_navigator.h"
16 #include "content/public/browser/site_instance.h"
17 #include "content/public/common/referrer.h"
18 #include "ui/base/page_transition_types.h"
19 #include "ui/base/window_open_disposition.h"
20 #include "ui/gfx/geometry/rect.h"
21 #include "url/gurl.h"
23 class Browser;
24 class Profile;
26 namespace content {
27 class WebContents;
30 namespace chrome {
32 // Parameters that tell Navigate() what to do.
34 // Some basic examples:
36 // Simple Navigate to URL in current tab:
37 // chrome::NavigateParams params(browser, GURL("http://www.google.com/"),
38 // ui::PAGE_TRANSITION_LINK);
39 // chrome::Navigate(&params);
41 // Open bookmark in new background tab:
42 // chrome::NavigateParams params(browser, url,
43 // ui::PAGE_TRANSITION_AUTO_BOOKMARK);
44 // params.disposition = NEW_BACKGROUND_TAB;
45 // chrome::Navigate(&params);
47 // Opens a popup WebContents:
48 // chrome::NavigateParams params(browser, popup_contents);
49 // params.source_contents = source_contents;
50 // chrome::Navigate(&params);
52 // See browser_navigator_browsertest.cc for more examples.
54 struct NavigateParams {
55 NavigateParams(Browser* browser,
56 const GURL& a_url,
57 ui::PageTransition a_transition);
58 NavigateParams(Browser* browser,
59 content::WebContents* a_target_contents);
60 NavigateParams(Profile* profile,
61 const GURL& a_url,
62 ui::PageTransition a_transition);
63 ~NavigateParams();
65 // The URL/referrer to be loaded. Ignored if |target_contents| is non-NULL.
66 GURL url;
67 content::Referrer referrer;
69 // The browser-global ID of the frame to navigate, or -1 for the main frame.
70 int frame_tree_node_id;
72 // Any redirect URLs that occurred for this navigation before |url|.
73 // Usually empty.
74 std::vector<GURL> redirect_chain;
76 // Indicates whether this navigation will be sent using POST.
77 // The POST method is limited support for basic POST data by leveraging
78 // NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST.
79 // It is not for things like file uploads.
80 bool uses_post;
82 // The post data when the navigation uses POST.
83 scoped_refptr<base::RefCountedMemory> browser_initiated_post_data;
85 // Extra headers to add to the request for this page. Headers are
86 // represented as "<name>: <value>" and separated by \r\n. The entire string
87 // is terminated by \r\n. May be empty if no extra headers are needed.
88 std::string extra_headers;
90 // [in] A WebContents to be navigated or inserted into the target
91 // Browser's tabstrip. If NULL, |url| or the homepage will be used
92 // instead. When non-NULL, Navigate() assumes it has already been
93 // navigated to its intended destination and will not load any URL in it
94 // (i.e. |url| is ignored).
95 // Default is NULL.
96 // [out] The WebContents in which the navigation occurred or that was
97 // inserted. Guaranteed non-NULL except for note below:
98 // Note: If this field is set to NULL by the caller and Navigate() creates
99 // a new WebContents, this field will remain NULL and the
100 // WebContents deleted if the WebContents it created is
101 // not added to a TabStripModel before Navigate() returns.
102 content::WebContents* target_contents;
104 // [in] The WebContents that initiated the Navigate() request if such
105 // context is necessary. Default is NULL, i.e. no context.
106 // [out] If NULL, this value will be set to the selected WebContents in
107 // the originating browser prior to the operation performed by
108 // Navigate(). However, if the originating page is from a different
109 // profile (e.g. an OFF_THE_RECORD page originating from a non-OTR
110 // window), then |source_contents| is reset to NULL.
111 content::WebContents* source_contents;
113 // The disposition requested by the navigation source. Default is
114 // CURRENT_TAB. What follows is a set of coercions that happen to this value
115 // when other factors are at play:
117 // [in]: Condition: [out]:
118 // NEW_BACKGROUND_TAB target browser tabstrip is empty NEW_FOREGROUND_TAB
119 // CURRENT_TAB " " " NEW_FOREGROUND_TAB
120 // OFF_THE_RECORD target browser profile is incog. NEW_FOREGROUND_TAB
122 // If disposition is NEW_BACKGROUND_TAB, TabStripModel::ADD_ACTIVE is
123 // removed from |tabstrip_add_types| automatically.
124 // If disposition is one of NEW_WINDOW, NEW_POPUP, NEW_FOREGROUND_TAB or
125 // SINGLETON_TAB, then TabStripModel::ADD_ACTIVE is automatically added to
126 // |tabstrip_add_types|.
127 WindowOpenDisposition disposition;
129 // Sets browser->is_trusted_source. Default is false.
130 bool trusted_source;
132 // The transition type of the navigation. Default is
133 // ui::PAGE_TRANSITION_LINK when target_contents is specified in the
134 // constructor.
135 ui::PageTransition transition;
137 // Whether this navigation was initiated by the renderer process. Default is
138 // false.
139 bool is_renderer_initiated;
141 // The index the caller would like the tab to be positioned at in the
142 // TabStrip. The actual index will be determined by the TabHandler in
143 // accordance with |add_types|. Defaults to -1 (allows the TabHandler to
144 // decide).
145 int tabstrip_index;
147 // A bitmask of values defined in TabStripModel::AddTabTypes. Helps
148 // determine where to insert a new tab and whether or not it should be
149 // selected, among other properties. Default is ADD_ACTIVE.
150 int tabstrip_add_types;
152 // If non-empty, the new tab is an app tab.
153 std::string extension_app_id;
155 // If non-empty, specifies the desired initial position and size of the
156 // window if |disposition| == NEW_POPUP.
157 // TODO(beng): Figure out if this can be used to create Browser windows
158 // for other callsites that use set_override_bounds, or
159 // remove this comment.
160 gfx::Rect window_bounds;
162 // Determines if and how the target window should be made visible at the end
163 // of the call to Navigate().
164 enum WindowAction {
165 // Do not show or activate the browser window after navigating.
166 NO_ACTION,
167 // Show and activate the browser window after navigating.
168 SHOW_WINDOW,
169 // Show the browser window after navigating but do not activate.
170 SHOW_WINDOW_INACTIVE
172 // Default is NO_ACTION (don't show or activate the window).
173 // If disposition is NEW_WINDOW or NEW_POPUP, and |window_action| is set to
174 // NO_ACTION, |window_action| will be set to SHOW_WINDOW.
175 WindowAction window_action;
177 // If false then the navigation was not initiated by a user gesture.
178 // Default is true.
179 bool user_gesture;
181 // What to do with the path component of the URL for singleton navigations.
182 enum PathBehavior {
183 // Two URLs with differing paths are different.
184 RESPECT,
185 // Ignore path when finding existing tab, navigate to new URL.
186 IGNORE_AND_NAVIGATE,
187 // Ignore path when finding existing tab, don't navigate tab.
188 IGNORE_AND_STAY_PUT,
190 // Default is RESPECT.
191 PathBehavior path_behavior;
193 // What to do with the ref component of the URL for singleton navigations.
194 enum RefBehavior {
195 // Two URLs with differing refs are same.
196 IGNORE_REF,
197 // Two URLs with differing refs are different.
198 RESPECT_REF,
200 // Default is IGNORE.
201 RefBehavior ref_behavior;
203 // [in] Specifies a Browser object where the navigation could occur or the
204 // tab could be added. Navigate() is not obliged to use this Browser if
205 // it is not compatible with the operation being performed. This can be
206 // NULL, in which case |initiating_profile| must be provided.
207 // [out] Specifies the Browser object where the navigation occurred or the
208 // tab was added. Guaranteed non-NULL unless the disposition did not
209 // require a navigation, in which case this is set to NULL
210 // (SUPPRESS_OPEN, SAVE_TO_DISK, IGNORE_ACTION).
211 // Note: If |show_window| is set to false and a new Browser is created by
212 // Navigate(), the caller is responsible for showing it so that its
213 // window can assume responsibility for the Browser's lifetime (Browser
214 // objects are deleted when the user closes a visible browser window).
215 Browser* browser;
217 // The profile that is initiating the navigation. If there is a non-NULL
218 // browser passed in via |browser|, it's profile will be used instead.
219 Profile* initiating_profile;
221 // Refers to a navigation that was parked in the browser in order to be
222 // transferred to another RVH. Only used in case of a redirection of a request
223 // to a different site that created a new RVH.
224 content::GlobalRequestID transferred_global_request_id;
226 // Refers to which desktop this navigation should occur on. May be passed
227 // explicitly or inferred from an existing Browser instance.
228 chrome::HostDesktopType host_desktop_type;
230 // Indicates whether this navigation should replace the current
231 // navigation entry.
232 bool should_replace_current_entry;
234 // Indicates whether |target_contents| is being created with a window.opener.
235 bool created_with_opener;
237 // SiteInstance of the frame that initiated the navigation or null if we
238 // don't know it. This should be assigned from the OpenURLParams of the
239 // WebContentsDelegate::OpenURLFromTab implementation and is used to determine
240 // the SiteInstance that will be used for the resulting frame in the case of
241 // an about:blank or a data url navigation.
242 scoped_refptr<content::SiteInstance> source_site_instance;
244 private:
245 NavigateParams();
248 // Copies fields from |params| struct to |nav_params| struct.
249 void FillNavigateParamsFromOpenURLParams(chrome::NavigateParams* nav_params,
250 const content::OpenURLParams& params);
252 // Navigates according to the configuration specified in |params|.
253 void Navigate(NavigateParams* params);
255 // Returns true if the url is allowed to open in incognito window.
256 bool IsURLAllowedInIncognito(const GURL& url,
257 content::BrowserContext* browser_context);
259 } // namespace chrome
261 #endif // CHROME_BROWSER_UI_BROWSER_NAVIGATOR_H_