page_navigator.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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// PageNavigator defines an interface that can be used to express the user's
6// intention to navigate to a particular URL.  The implementing class should
7// perform the navigation.
8
9#ifndef CONTENT_PUBLIC_BROWSER_PAGE_NAVIGATOR_H_
10#define CONTENT_PUBLIC_BROWSER_PAGE_NAVIGATOR_H_
11
12#include <string>
13
14#include "content/common/content_export.h"
15#include "content/public/browser/global_request_id.h"
16#include "content/public/common/page_transition_types.h"
17#include "content/public/common/referrer.h"
18#include "googleurl/src/gurl.h"
19#include "ui/base/window_open_disposition.h"
20
21namespace content {
22
23class WebContents;
24
25struct CONTENT_EXPORT OpenURLParams {
26  OpenURLParams(const GURL& url,
27                const Referrer& referrer,
28                WindowOpenDisposition disposition,
29                PageTransition transition,
30                bool is_renderer_initiated);
31  OpenURLParams(const GURL& url,
32                const Referrer& referrer,
33                int64 source_frame_id,
34                WindowOpenDisposition disposition,
35                PageTransition transition,
36                bool is_renderer_initiated);
37  ~OpenURLParams();
38
39  // The URL/referrer to be opened.
40  GURL url;
41  Referrer referrer;
42
43  // Extra headers to add to the request for this page.  Headers are
44  // represented as "<name>: <value>" and separated by \r\n.  The entire string
45  // is terminated by \r\n.  May be empty if no extra headers are needed.
46  std::string extra_headers;
47
48  // The source frame id or -1 to indicate the main frame.
49  int64 source_frame_id;
50
51  // The disposition requested by the navigation source.
52  WindowOpenDisposition disposition;
53
54  // The transition type of navigation.
55  PageTransition transition;
56
57  // Whether this navigation is initiated by the renderer process.
58  bool is_renderer_initiated;
59
60  // The override encoding of the URL contents to be opened.
61  std::string override_encoding;
62
63  // Reference to the old request id in case this is a navigation that is being
64  // transferred to a new renderer.
65  GlobalRequestID transferred_global_request_id;
66
67  // Indicates whether this navigation involves a cross-process redirect,
68  // in which case it should replace the current navigation entry.
69  bool is_cross_site_redirect;
70
71 private:
72  OpenURLParams();
73};
74
75class PageNavigator {
76 public:
77  virtual ~PageNavigator() {}
78
79  // Opens a URL with the given disposition.  The transition specifies how this
80  // navigation should be recorded in the history system (for example, typed).
81  // Returns the WebContents the URL is opened in, or NULL if the URL wasn't
82  // opened immediately.
83  virtual WebContents* OpenURL(const OpenURLParams& params) = 0;
84};
85
86}
87
88#endif  // CONTENT_PUBLIC_BROWSER_PAGE_NAVIGATOR_H_
89