browser_navigator.h revision 201ade2fbba22bfb27ae029f4d23fca6ded109a0
1// Copyright (c) 2010 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#pragma once 8 9#include <string> 10 11#include "chrome/common/page_transition_types.h" 12#include "gfx/rect.h" 13#include "googleurl/src/gurl.h" 14#include "webkit/glue/window_open_disposition.h" 15 16class Browser; 17class Profile; 18class TabContentsWrapper; 19 20namespace browser { 21 22// Parameters that tell Navigate() what to do. 23// 24// Some basic examples: 25// 26// Simple Navigate to URL in current tab: 27// browser::NavigateParams params(browser, GURL("http://www.google.com/"), 28// PageTransition::LINK); 29// browser::Navigate(¶ms); 30// 31// Open bookmark in new background tab: 32// browser::NavigateParams params(browser, url, PageTransition::AUTO_BOOKMARK); 33// params.disposition = NEW_BACKGROUND_TAB; 34// browser::Navigate(¶ms); 35// 36// Opens a popup TabContents: 37// browser::NavigateParams params(browser, popup_contents); 38// params.source_contents = source_contents; 39// browser::Navigate(¶ms); 40// 41// See browser_navigator_browsertest.cc for more examples. 42// 43struct NavigateParams { 44 NavigateParams(Browser* browser, 45 const GURL& a_url, 46 PageTransition::Type a_transition); 47 NavigateParams(Browser* browser, TabContentsWrapper* a_target_contents); 48 ~NavigateParams(); 49 50 // The URL/referrer to be loaded. Ignored if |target_contents| is non-NULL. 51 GURL url; 52 GURL referrer; 53 54 // [in] A TabContents to be navigated or inserted into the target Browser's 55 // tabstrip. If NULL, |url| or the homepage will be used instead. When 56 // non-NULL, Navigate() assumes it has already been navigated to its 57 // intended destination and will not load any URL in it (i.e. |url| is 58 // ignored). 59 // Default is NULL. 60 // [out] The TabContents in which the navigation occurred or that was 61 // inserted. Guaranteed non-NULL except for note below: 62 // Note: If this field is set to NULL by the caller and Navigate() creates 63 // a new TabContents, this field will remain NULL and the TabContents 64 // deleted if the TabContents it created is not added to a TabStripModel 65 // before Navigate() returns. 66 TabContentsWrapper* target_contents; 67 68 // [in] The TabContents that initiated the Navigate() request if such context 69 // is necessary. Default is NULL, i.e. no context. 70 // [out] If NULL, this value will be set to the selected TabContents in the 71 // originating browser prior to the operation performed by Navigate(). 72 // However, if the originating page is from a different profile (e.g. an 73 // OFF_THE_RECORD page originating from a non-OTR window), then 74 // |source_contents| is reset to NULL. 75 TabContentsWrapper* source_contents; 76 77 // The disposition requested by the navigation source. Default is 78 // CURRENT_TAB. What follows is a set of coercions that happen to this value 79 // when other factors are at play: 80 // 81 // [in]: Condition: [out]: 82 // NEW_BACKGROUND_TAB target browser tabstrip is empty NEW_FOREGROUND_TAB 83 // CURRENT_TAB " " " NEW_FOREGROUND_TAB 84 // OFF_THE_RECORD target browser profile is incog. NEW_FOREGROUND_TAB 85 // 86 // If disposition is NEW_BACKGROUND_TAB, TabStripModel::ADD_SELECTED is 87 // removed from |tabstrip_add_types| automatically. 88 // If disposition is one of NEW_WINDOW, NEW_POPUP, NEW_FOREGROUND_TAB or 89 // SINGLETON_TAB, then TabStripModel::ADD_SELECTED is automatically added to 90 // |tabstrip_add_types|. 91 WindowOpenDisposition disposition; 92 93 // The transition type of the navigation. Default is PageTransition::LINK 94 // when target_contents is specified in the constructor. 95 PageTransition::Type transition; 96 97 // The index the caller would like the tab to be positioned at in the 98 // TabStrip. The actual index will be determined by the TabHandler in 99 // accordance with |add_types|. Defaults to -1 (allows the TabHandler to 100 // decide). 101 int tabstrip_index; 102 103 // A bitmask of values defined in TabStripModel::AddTabTypes. Helps 104 // determine where to insert a new tab and whether or not it should be 105 // selected, among other properties. Default is ADD_SELECTED. 106 int tabstrip_add_types; 107 108 // If non-empty, the new tab is an app tab. 109 std::string extension_app_id; 110 111 // If non-empty, specifies the desired initial position and size of the 112 // window if |disposition| == NEW_POPUP. 113 // TODO(beng): Figure out if this can be used to create Browser windows 114 // for other callsites that use set_override_bounds, or 115 // remove this comment. 116 gfx::Rect window_bounds; 117 118 // True if the target window should be made visible at the end of the call 119 // to Navigate(). This activates the window if it was already visible. 120 // Default is false. 121 // If disposition is NEW_WINDOW or NEW_POPUP, |show_window| is set to true 122 // automatically. 123 bool show_window; 124 125 // True if the paths of the target content's URL and |url| should be ignored 126 // when locating a singleton tab. 127 bool ignore_path; 128 129 // [in] Specifies a Browser object where the navigation could occur or the 130 // tab could be added. Navigate() is not obliged to use this Browser if 131 // it is not compatible with the operation being performed. If NULL, 132 // |profile| should be specified to find or create a matching Browser. 133 // [out] Specifies the Browser object where the navigation occurred or the 134 // tab was added. Guaranteed non-NULL unless the disposition did not 135 // require a navigation, in which case this is set to NULL 136 // (SUPPRESS_OPEN, SAVE_TO_DISK, IGNORE_ACTION). 137 // Note: If |show_window| is set to false and a new Browser is created by 138 // Navigate(), the caller is responsible for showing it so that its 139 // window can assume responsibility for the Browser's lifetime (Browser 140 // objects are deleted when the user closes a visible browser window). 141 Browser* browser; 142 143 // If |browser| == NULL, specifies a Profile to use when finding or 144 // creating a Browser. 145 Profile* profile; 146 147 private: 148 NavigateParams(); 149}; 150 151// Navigates according to the configuration specified in |params|. 152void Navigate(NavigateParams* params); 153 154} // namespace browser 155 156#endif // CHROME_BROWSER_UI_BROWSER_NAVIGATOR_H_ 157