• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 "content/common/page_transition_types.h"
12 #include "googleurl/src/gurl.h"
13 #include "ui/gfx/rect.h"
14 #include "webkit/glue/window_open_disposition.h"
15 
16 class Browser;
17 class Profile;
18 class TabContentsWrapper;
19 
20 namespace 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(&params);
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(&params);
35 //
36 // Opens a popup TabContents:
37 // browser::NavigateParams params(browser, popup_contents);
38 // params.source_contents = source_contents;
39 // browser::Navigate(&params);
40 //
41 // See browser_navigator_browsertest.cc for more examples.
42 //
43 struct 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_ACTIVE 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_ACTIVE 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_ACTIVE.
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   // Determines if and how the target window should be made visible at the end
119   // of the call to Navigate().
120   enum WindowAction {
121     // Do not show or activate the browser window after navigating.
122     NO_ACTION,
123     // Show and activate the browser window after navigating.
124     SHOW_WINDOW,
125     // Show the browser window after navigating but do not activate.
126     SHOW_WINDOW_INACTIVE
127   };
128   // Default is NO_ACTION (don't show or activate the window).
129   // If disposition is NEW_WINDOW or NEW_POPUP, and |window_action| is set to
130   // NO_ACTION, |window_action| will be set to SHOW_WINDOW.
131   WindowAction window_action;
132 
133   // What to do with the path component of the URL for singleton navigations.
134   enum PathBehavior {
135     // Two URLs with differing paths are different.
136     RESPECT,
137     // Ignore path when finding existing tab, navigate to new URL.
138     IGNORE_AND_NAVIGATE,
139     // Ignore path when finding existing tab, don't navigate tab.
140     IGNORE_AND_STAY_PUT,
141   };
142   // Default is RESPECT.
143   PathBehavior path_behavior;
144 
145   // [in]  Specifies a Browser object where the navigation could occur or the
146   //       tab could be added. Navigate() is not obliged to use this Browser if
147   //       it is not compatible with the operation being performed. If NULL,
148   //       |profile| should be specified to find or create a matching Browser.
149   // [out] Specifies the Browser object where the navigation occurred or the
150   //       tab was added. Guaranteed non-NULL unless the disposition did not
151   //       require a navigation, in which case this is set to NULL
152   //       (SUPPRESS_OPEN, SAVE_TO_DISK, IGNORE_ACTION).
153   // Note: If |show_window| is set to false and a new Browser is created by
154   //       Navigate(), the caller is responsible for showing it so that its
155   //       window can assume responsibility for the Browser's lifetime (Browser
156   //       objects are deleted when the user closes a visible browser window).
157   Browser* browser;
158 
159   // If |browser| == NULL, specifies a Profile to use when finding or
160   // creating a Browser.
161   Profile* profile;
162 
163  private:
164   NavigateParams();
165 };
166 
167 // Navigates according to the configuration specified in |params|.
168 void Navigate(NavigateParams* params);
169 
170 }  // namespace browser
171 
172 #endif  // CHROME_BROWSER_UI_BROWSER_NAVIGATOR_H_
173