Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: chrome/browser/extensions/api/web_navigation/frame_navigation_state.h

Issue 384993004: Simplify WebNavigationApi by using RenderFrameHost internally. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove troublesome DCHECKs Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/api/web_navigation/frame_navigation_state.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "url/gurl.h" 12 #include "url/gurl.h"
13 13
14 namespace content { 14 namespace content {
15 class RenderFrameHost;
15 class RenderViewHost; 16 class RenderViewHost;
16 } 17 }
17 18
18 namespace extensions { 19 namespace extensions {
19 20
20 // Tracks the navigation state of all frames in a given tab currently known to 21 // Tracks the navigation state of all frame hosts in a given tab currently known
21 // the webNavigation API. It is mainly used to track in which frames an error 22 // to the webNavigation API. It is mainly used to track in which frames an error
22 // occurred so no further events for this frame are being sent. 23 // occurred so no further events for this frame are being sent.
23 class FrameNavigationState { 24 class FrameNavigationState {
24 public: 25 public:
25 // A frame is uniquely identified by its frame ID and the RVH it's in. 26 typedef std::set<content::RenderFrameHost*>::const_iterator const_iterator;
26 struct FrameID {
27 FrameID();
28 FrameID(int64 frame_num, content::RenderViewHost* render_view_host);
29
30 bool operator<(const FrameID& other) const;
31 bool operator==(const FrameID& other) const;
32 bool operator!=(const FrameID& other) const;
33
34 int64 frame_num;
35 content::RenderViewHost* render_view_host;
36 };
37 typedef std::set<FrameID>::const_iterator const_iterator;
38 27
39 FrameNavigationState(); 28 FrameNavigationState();
40 ~FrameNavigationState(); 29 ~FrameNavigationState();
41 30
42 // Use these to iterate over all frame IDs known by this object. 31 // Use these to iterate over all frame hosts known by this object.
43 const_iterator begin() const { return frame_ids_.begin(); } 32 const_iterator begin() const { return frame_hosts_.begin(); }
44 const_iterator end() const { return frame_ids_.end(); } 33 const_iterator end() const { return frame_hosts_.end(); }
45 34
46 // True if navigation events for the given frame can be sent. 35 // True if navigation events for the given frame can be sent.
47 bool CanSendEvents(FrameID frame_id) const; 36 bool CanSendEvents(content::RenderFrameHost* frame_host) const;
48 37
38 // TODO(dcheng): This should be static.
49 // True if in general webNavigation events may be sent for the given URL. 39 // True if in general webNavigation events may be sent for the given URL.
50 bool IsValidUrl(const GURL& url) const; 40 bool IsValidUrl(const GURL& url) const;
51 41
52 // Starts to track a frame identified by its |frame_id| showing the URL |url|. 42 // Starts to track a |frame_host| showing the URL |url|.
53 void TrackFrame(FrameID frame_id, 43 void TrackFrame(content::RenderFrameHost* frame_host,
54 FrameID parent_frame_id,
55 const GURL& url, 44 const GURL& url,
56 bool is_main_frame,
57 bool is_error_page, 45 bool is_error_page,
58 bool is_iframe_srcdoc); 46 bool is_iframe_srcdoc);
59 47
60 // Marks the frame as detached and stops tracking it. 48 // Marks |frame_host| as detached and stops tracking it.
61 void FrameDetached(FrameID frame_id); 49 void FrameDetached(content::RenderFrameHost* frame_host);
62 50
63 // Stops tracking all frames but the frame with |id_to_skip| for a given 51 // Stops tracking all frame hosts but |frame_host_to_skip| in
64 // RenderViewHost. 52 // |render_view_host|.
65 void StopTrackingFramesInRVH(content::RenderViewHost* render_view_host, 53 void StopTrackingFramesInRVH(content::RenderViewHost* render_view_host,
66 FrameID id_to_skip); 54 content::RenderFrameHost* frame_host_to_skip);
67 55
68 // Update the URL associated with a given frame. 56 // Update the URL associated with |frame_host|.
69 void UpdateFrame(FrameID frame_id, const GURL& url); 57 void UpdateFrame(content::RenderFrameHost* frame_host, const GURL& url);
70 58
71 // Returns true if |frame_id| is a known frame. 59 // Returns true if |frame_host| is a known frame host.
72 bool IsValidFrame(FrameID frame_id) const; 60 bool IsValidFrame(content::RenderFrameHost* frame_host) const;
73 61
74 // Returns the URL corresponding to a tracked frame given by its |frame_id|. 62 // Returns the URL corresponding to a tracked |frame_host|.
75 GURL GetUrl(FrameID frame_id) const; 63 // TODO(dcheng): Why is this needed? Can't this information be extracted from
64 // RenderFrameHost?
65 GURL GetUrl(content::RenderFrameHost* frame_host) const;
76 66
77 // True if the frame given by its |frame_id| is a main frame of its tab. 67 // Returns a pointer to the last comitted main frame host.
78 // There might be multiple uncomitted main frames. 68 content::RenderFrameHost* GetLastCommittedMainFrameHost() const;
79 bool IsMainFrame(FrameID frame_id) const;
80 69
81 // Returns the frame ID of the last comitted main frame, or -1 if the frame 70 // Marks |frame_host| as in an error state, i.e. the onErrorOccurred event was
82 // ID is not known. 71 // fired for it, and no further events should be sent for it.
83 FrameID GetMainFrameID() const; 72 void SetErrorOccurredInFrame(content::RenderFrameHost* frame_host);
84 73
85 // Get the parent frame ID (or an invalid ID, if |frame_id| is a main frame). 74 // True if |frame_host| is marked as being in an error state.
86 FrameID GetParentFrameID(FrameID frame_id) const; 75 bool GetErrorOccurredInFrame(content::RenderFrameHost* frame_host) const;
87 76
88 // Marks a frame as in an error state, i.e. the onErrorOccurred event was 77 // Marks |frame_host| as having finished its last navigation, i.e. the
89 // fired for this frame, and no further events should be sent for it. 78 // onCompleted event was fired for this frame.
90 void SetErrorOccurredInFrame(FrameID frame_id); 79 void SetNavigationCompleted(content::RenderFrameHost* frame_host);
91 80
92 // True if the frame is marked as being in an error state. 81 // True if |frame_host| is currently not navigating.
93 bool GetErrorOccurredInFrame(FrameID frame_id) const; 82 bool GetNavigationCompleted(content::RenderFrameHost* frame_host) const;
94 83
95 // Marks a frame as having finished its last navigation, i.e. the onCompleted 84 // Marks |frame_host| as having finished parsing.
85 void SetParsingFinished(content::RenderFrameHost* frame_host);
86
87 // True if |frame_host| has finished parsing.
88 bool GetParsingFinished(content::RenderFrameHost* frame_host) const;
89
90 // Marks |frame_host| as having committed its navigation, i.e. the onCommitted
96 // event was fired for this frame. 91 // event was fired for this frame.
97 void SetNavigationCompleted(FrameID frame_id); 92 void SetNavigationCommitted(content::RenderFrameHost* frame_host);
98 93
99 // True if the frame is currently not navigating. 94 // True if |frame_host| has committed its navigation.
100 bool GetNavigationCompleted(FrameID frame_id) const; 95 bool GetNavigationCommitted(content::RenderFrameHost* frame_host) const;
101 96
102 // Marks a frame as having finished parsing. 97 // Marks |frame_host| as redirected by the server.
103 void SetParsingFinished(FrameID frame_id); 98 void SetIsServerRedirected(content::RenderFrameHost* frame_host);
104 99
105 // True if the frame has finished parsing. 100 // True if |frame_host| was redirected by the server.
106 bool GetParsingFinished(FrameID frame_id) const; 101 bool GetIsServerRedirected(content::RenderFrameHost* frame_host) const;
107
108 // Marks a frame as having committed its navigation, i.e. the onCommitted
109 // event was fired for this frame.
110 void SetNavigationCommitted(FrameID frame_id);
111
112 // True if the frame has committed its navigation.
113 bool GetNavigationCommitted(FrameID frame_id) const;
114
115 // Marks a frame as redirected by the server.
116 void SetIsServerRedirected(FrameID frame_id);
117
118 // True if the frame was redirected by the server.
119 bool GetIsServerRedirected(FrameID frame_id) const;
120 102
121 #ifdef UNIT_TEST 103 #ifdef UNIT_TEST
122 static void set_allow_extension_scheme(bool allow_extension_scheme) { 104 static void set_allow_extension_scheme(bool allow_extension_scheme) {
123 allow_extension_scheme_ = allow_extension_scheme; 105 allow_extension_scheme_ = allow_extension_scheme;
124 } 106 }
125 #endif 107 #endif
126 108
127 private: 109 private:
128 struct FrameState { 110 struct FrameState {
129 FrameState(); 111 FrameState();
130 112
131 bool error_occurred; // True if an error has occurred in this frame. 113 bool error_occurred; // True if an error has occurred in this frame.
132 bool is_main_frame; // True if this is a main frame.
133 bool is_iframe_srcdoc; // True if the frame is displaying its srcdoc. 114 bool is_iframe_srcdoc; // True if the frame is displaying its srcdoc.
134 bool is_navigating; // True if there is a navigation going on. 115 bool is_navigating; // True if there is a navigation going on.
135 bool is_committed; // True if the navigation is already committed. 116 bool is_committed; // True if the navigation is already committed.
136 bool is_server_redirected; // True if a server redirect happened. 117 bool is_server_redirected; // True if a server redirect happened.
137 bool is_parsing; // True if the frame is still parsing. 118 bool is_parsing; // True if the frame is still parsing.
138 int64 parent_frame_num;
139 GURL url; // URL of this frame. 119 GURL url; // URL of this frame.
140 }; 120 };
141 typedef std::map<FrameID, FrameState> FrameIdToStateMap; 121 typedef std::map<content::RenderFrameHost*, FrameState> FrameHostToStateMap;
142 122
143 // Tracks the state of known frames. 123 // Tracks the state of known frame hosts.
144 FrameIdToStateMap frame_state_map_; 124 FrameHostToStateMap frame_host_state_map_;
145 125
146 // Set of all known frames. 126 // Set of all known frame hosts.
147 std::set<FrameID> frame_ids_; 127 std::set<content::RenderFrameHost*> frame_hosts_;
148 128
149 // The id of the last comitted main frame. 129 // The last comitted main frame.
150 FrameID main_frame_id_; 130 content::RenderFrameHost* main_frame_host_;
151 131
152 // If true, also allow events from chrome-extension:// URLs. 132 // If true, also allow events from chrome-extension:// URLs.
153 static bool allow_extension_scheme_; 133 static bool allow_extension_scheme_;
154 134
155 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState); 135 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState);
156 }; 136 };
157 137
158 } // namespace extensions 138 } // namespace extensions
159 139
160 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H _ 140 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H _
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/web_navigation/frame_navigation_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698