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