Add ICU message format support
[chromium-blink-merge.git] / content / renderer / history_entry.h
blob627419b6678152738138c6ba3af87f45bee2163f
1 // Copyright 2014 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.
5 /*
6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
8 * (http://www.torchmobile.com/)
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
20 * its contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #ifndef CONTENT_RENDERER_HISTORY_ENTRY_H_
36 #define CONTENT_RENDERER_HISTORY_ENTRY_H_
38 #include "base/containers/hash_tables.h"
39 #include "base/memory/scoped_ptr.h"
40 #include "base/memory/scoped_vector.h"
41 #include "base/memory/weak_ptr.h"
42 #include "content/common/content_export.h"
43 #include "third_party/WebKit/public/platform/WebURLRequest.h"
44 #include "third_party/WebKit/public/web/WebHistoryItem.h"
46 namespace blink {
47 class WebFrame;
50 namespace content {
51 class RenderFrameImpl;
52 class RenderViewImpl;
54 const int kInvalidFrameRoutingID = -1;
56 class CONTENT_EXPORT HistoryEntry {
57 public:
58 class HistoryNode {
59 public:
60 HistoryNode(const base::WeakPtr<HistoryEntry>& entry,
61 const blink::WebHistoryItem& item);
62 ~HistoryNode();
64 HistoryNode* AddChild(const blink::WebHistoryItem& item);
65 HistoryNode* AddChild();
66 HistoryNode* CloneAndReplace(const base::WeakPtr<HistoryEntry>& new_entry,
67 const blink::WebHistoryItem& new_item,
68 bool clone_children_of_target,
69 RenderFrameImpl* target_frame,
70 RenderFrameImpl* current_frame);
71 blink::WebHistoryItem& item() { return item_; }
72 void set_item(const blink::WebHistoryItem& item);
73 std::vector<HistoryNode*>& children() const { return children_->get(); }
74 void RemoveChildren();
76 private:
77 // When a HistoryEntry is destroyed, it takes all its HistoryNodes with it.
78 // Use a WeakPtr to ensure that HistoryNodes don't try to illegally access
79 // a dying HistoryEntry, or do unnecessary work when the whole entry is
80 // being destroyed.
81 base::WeakPtr<HistoryEntry> entry_;
82 scoped_ptr<ScopedVector<HistoryNode> > children_;
83 blink::WebHistoryItem item_;
84 // We need to track multiple names because the name of a frame can change
85 // over its lifetime. This allows us to clean up all of the names this node
86 // has ever known by when it is destroyed.
87 std::vector<std::string> unique_names_;
90 HistoryEntry(const blink::WebHistoryItem& root);
91 HistoryEntry();
92 ~HistoryEntry();
94 HistoryEntry* CloneAndReplace(const blink::WebHistoryItem& newItem,
95 bool clone_children_of_target,
96 RenderFrameImpl* target_frame,
97 RenderViewImpl* render_view);
99 HistoryNode* GetHistoryNodeForFrame(RenderFrameImpl* frame);
100 blink::WebHistoryItem GetItemForFrame(RenderFrameImpl* frame);
101 const blink::WebHistoryItem& root() const { return root_->item(); }
102 HistoryNode* root_history_node() const { return root_.get(); }
104 private:
105 scoped_ptr<HistoryNode> root_;
107 typedef base::hash_map<std::string, HistoryNode*> UniqueNamesToItems;
108 UniqueNamesToItems unique_names_to_items_;
110 base::WeakPtrFactory<HistoryEntry> weak_ptr_factory_;
113 } // namespace content
115 #endif // CONTENT_RENDERER_HISTORY_ENTRY_H_