page_navigator.h revision a36e5920737c6adbddd3e43b760e5de8431db6e0
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 "base/memory/ref_counted.h"
15#include "base/memory/ref_counted_memory.h"
16#include "content/common/content_export.h"
17#include "content/public/browser/global_request_id.h"
18#include "content/public/common/page_transition_types.h"
19#include "content/public/common/referrer.h"
20#include "ui/base/window_open_disposition.h"
21#include "url/gurl.h"
22
23namespace content {
24
25class WebContents;
26
27struct CONTENT_EXPORT OpenURLParams {
28  OpenURLParams(const GURL& url,
29                const Referrer& referrer,
30                WindowOpenDisposition disposition,
31                PageTransition transition,
32                bool is_renderer_initiated);
33  OpenURLParams(const GURL& url,
34                const Referrer& referrer,
35                int64 source_frame_id,
36                WindowOpenDisposition disposition,
37                PageTransition transition,
38                bool is_renderer_initiated);
39  ~OpenURLParams();
40
41  // The URL/referrer to be opened.
42  GURL url;
43  Referrer referrer;
44
45  // Indicates whether this navigation will be sent using POST.
46  // The POST method is limited support for basic POST data by leveraging
47  // NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST.
48  // It is not for things like file uploads.
49  bool uses_post;
50
51  // The post data when the navigation uses POST.
52  scoped_refptr<base::RefCountedMemory> browser_initiated_post_data;
53
54  // Extra headers to add to the request for this page.  Headers are
55  // represented as "<name>: <value>" and separated by \r\n.  The entire string
56  // is terminated by \r\n.  May be empty if no extra headers are needed.
57  std::string extra_headers;
58
59  // The source frame id or -1 to indicate the main frame.
60  int64 source_frame_id;
61
62  // The disposition requested by the navigation source.
63  WindowOpenDisposition disposition;
64
65  // The transition type of navigation.
66  PageTransition transition;
67
68  // Whether this navigation is initiated by the renderer process.
69  bool is_renderer_initiated;
70
71  // The override encoding of the URL contents to be opened.
72  std::string override_encoding;
73
74  // Reference to the old request id in case this is a navigation that is being
75  // transferred to a new renderer.
76  GlobalRequestID transferred_global_request_id;
77
78  // Indicates whether this navigation should replace the current
79  // navigation entry.
80  bool should_replace_current_entry;
81
82  // Indicates whether this navigation was triggered while processing a user
83  // gesture if the navigation was initiated by the renderer.
84  bool user_gesture;
85
86 private:
87  OpenURLParams();
88};
89
90class PageNavigator {
91 public:
92  virtual ~PageNavigator() {}
93
94  // Opens a URL with the given disposition.  The transition specifies how this
95  // navigation should be recorded in the history system (for example, typed).
96  // Returns the WebContents the URL is opened in, or NULL if the URL wasn't
97  // opened immediately.
98  virtual WebContents* OpenURL(const OpenURLParams& params) = 0;
99};
100
101}  // namespace content
102
103#endif  // CONTENT_PUBLIC_BROWSER_PAGE_NAVIGATOR_H_
104