summaryrefslogtreecommitdiffstats
path: root/webkit/tools/test_shell/temp/navigation_entry.h
blob: c40eb5be7b8594cc3eb54a7c52722bccaea01516 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//    * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//    * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//    * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef WEBKIT_TOOLS_TEST_SHELL_TEMP_NAVIGATION_ENTRY_H__
#define WEBKIT_TOOLS_TEST_SHELL_TEMP_NAVIGATION_ENTRY_H__

#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "webkit/tools/test_shell/temp/page_transition_types.h"
#include "googleurl/src/gurl.h"

////////////////////////////////////////////////////////////////////////////////
//
// NavigationEntry class
//
// A NavigationEntry is a data structure that captures all the information
// required to recreate a browsing state. This includes some opaque binary
// state as provided by the TabContents as well as some clear text title and
// uri which is used for our user interface.
//
////////////////////////////////////////////////////////////////////////////////
class NavigationEntry {
 public:
  // Create a new NavigationEntry.
  explicit NavigationEntry(TabContentsType type)
      : type_(type),
        page_id_(-1),
        transition_(PageTransition::LINK) {
  }

  NavigationEntry(TabContentsType type,
                  int page_id,
                  const GURL& url,
                  const std::wstring& title,
                  PageTransition::Type transition)
      : type_(type),
        page_id_(page_id),
        url_(url),
        title_(title),
        transition_(transition) {
  }

  // virtual to allow test_shell to extend the class.
  virtual ~NavigationEntry() {
  }

  // Return the TabContents type required to display this entry. Immutable
  // because a tab can never change its type.
  TabContentsType GetType() const { return type_; }

  // Set / Get the URI
  void SetURL(const GURL& url) { url_ = url; }
  const GURL& GetURL() const { return url_; }

  void SetDisplayURL(const GURL& url) {
    if (url == url_) {
      display_url_ = GURL::EmptyGURL();
    } else {
      display_url_ = url;
    }
  }

  bool HasDisplayURL() { return !display_url_.is_empty(); }

  const GURL& GetDisplayURL() const {
    if (display_url_.is_empty()) {
      return url_;
    } else {
      return display_url_;
    }
  }

  // Set / Get the title
  void SetTitle(const std::wstring& a_title) { title_ = a_title; }
  const std::wstring& GetTitle() const { return title_; }

  // Set / Get opaque state.
  // WARNING: This state is saved to the database and used to restore previous
  // states. If you use write a custom TabContents and provide your own
  // state make sure you have the ability to modify the format in the future
  // while being able to deal with older versions.
  void SetContentState(const std::string& state) { state_ = state; }
  const std::string& GetContentState() const { return state_; }

  // Get the page id corresponding to the tab's state.
  void SetPageID(int page_id) { page_id_ = page_id; }
  int32 GetPageID() const { return page_id_; }

  // The transition type indicates what the user did to move to this page from
  // the previous page.
  void SetTransition(PageTransition::Type transition) {
    transition_ = transition;
  }
  PageTransition::Type GetTransition() const { return transition_; }

  // Set / Get favicon URL.
  void SetFavIconURL(const GURL& url) { fav_icon_url_ = url; }
  const GURL& GetFavIconURL() const { return fav_icon_url_; }

  // This is the URL the user typed in. This may be invalid.
  void SetUserTypedURL(const GURL& url) { user_typed_url_ = url; }
  const GURL& GetUserTypedURL() const { return user_typed_url_; }

  // If the user typed url is valid it is returned, otherwise url is returned.
  const GURL& GetUserTypedURLOrURL() const {
    return user_typed_url_.is_valid() ? user_typed_url_ : url_;
  }

 private:
  TabContentsType type_;

  // Describes the current page that the tab represents. This is not relevant
  // for all tab contents types.
  int32 page_id_;

  GURL url_;
  // The URL the user typed in.
  GURL user_typed_url_;
  std::wstring title_;
  GURL fav_icon_url_;
  GURL display_url_;

  std::string state_;

  PageTransition::Type transition_;
};

#endif  //  WEBKIT_TOOLS_TEST_SHELL_TEMP_NAVIGATION_ENTRY_H__