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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H_
11 #include "base/compiler_specific.h"
15 class RenderFrameHost
;
19 namespace extensions
{
21 // Tracks the navigation state of all frame hosts in a given tab currently known
22 // to the webNavigation API. It is mainly used to track in which frames an error
23 // occurred so no further events for this frame are being sent.
24 class FrameNavigationState
{
26 typedef std::set
<content::RenderFrameHost
*>::const_iterator const_iterator
;
28 FrameNavigationState();
29 ~FrameNavigationState();
31 // Use these to iterate over all frame hosts known by this object.
32 const_iterator
begin() const { return frame_hosts_
.begin(); }
33 const_iterator
end() const { return frame_hosts_
.end(); }
35 // True if navigation events for the given frame can be sent.
36 bool CanSendEvents(content::RenderFrameHost
* frame_host
) const;
38 // TODO(dcheng): This should be static.
39 // True if in general webNavigation events may be sent for the given URL.
40 bool IsValidUrl(const GURL
& url
) const;
42 // Starts to track a |frame_host| showing the URL |url|.
43 void TrackFrame(content::RenderFrameHost
* frame_host
,
46 bool is_iframe_srcdoc
);
48 // Marks |frame_host| as detached and stops tracking it.
49 void FrameDetached(content::RenderFrameHost
* frame_host
);
51 // Stops tracking all frame hosts but |frame_host_to_skip| in
52 // |render_view_host|.
53 void StopTrackingFramesInRVH(content::RenderViewHost
* render_view_host
,
54 content::RenderFrameHost
* frame_host_to_skip
);
56 // Update the URL associated with |frame_host|.
57 void UpdateFrame(content::RenderFrameHost
* frame_host
, const GURL
& url
);
59 // Returns true if |frame_host| is a known frame host.
60 bool IsValidFrame(content::RenderFrameHost
* frame_host
) const;
62 // Returns the URL corresponding to a tracked |frame_host|.
63 // TODO(dcheng): Why is this needed? Can't this information be extracted from
65 GURL
GetUrl(content::RenderFrameHost
* frame_host
) const;
67 // Returns a pointer to the last comitted main frame host.
68 content::RenderFrameHost
* GetLastCommittedMainFrameHost() const;
70 // Marks |frame_host| as in an error state, i.e. the onErrorOccurred event was
71 // fired for it, and no further events should be sent for it.
72 void SetErrorOccurredInFrame(content::RenderFrameHost
* frame_host
);
74 // True if |frame_host| is marked as being in an error state.
75 bool GetErrorOccurredInFrame(content::RenderFrameHost
* frame_host
) const;
77 // Marks |frame_host| as having finished its last navigation, i.e. the
78 // onCompleted event was fired for this frame.
79 void SetNavigationCompleted(content::RenderFrameHost
* frame_host
);
81 // True if |frame_host| is currently not navigating.
82 bool GetNavigationCompleted(content::RenderFrameHost
* frame_host
) const;
84 // Marks |frame_host| as having finished parsing.
85 void SetParsingFinished(content::RenderFrameHost
* frame_host
);
87 // True if |frame_host| has finished parsing.
88 bool GetParsingFinished(content::RenderFrameHost
* frame_host
) const;
90 // Marks |frame_host| as having committed its navigation, i.e. the onCommitted
91 // event was fired for this frame.
92 void SetNavigationCommitted(content::RenderFrameHost
* frame_host
);
94 // True if |frame_host| has committed its navigation.
95 bool GetNavigationCommitted(content::RenderFrameHost
* frame_host
) const;
97 // Marks |frame_host| as redirected by the server.
98 void SetIsServerRedirected(content::RenderFrameHost
* frame_host
);
100 // True if |frame_host| was redirected by the server.
101 bool GetIsServerRedirected(content::RenderFrameHost
* frame_host
) const;
104 static void set_allow_extension_scheme(bool allow_extension_scheme
) {
105 allow_extension_scheme_
= allow_extension_scheme
;
113 bool error_occurred
; // True if an error has occurred in this frame.
114 bool is_iframe_srcdoc
; // True if the frame is displaying its srcdoc.
115 bool is_navigating
; // True if there is a navigation going on.
116 bool is_committed
; // True if the navigation is already committed.
117 bool is_server_redirected
; // True if a server redirect happened.
118 bool is_parsing
; // True if the frame is still parsing.
119 GURL url
; // URL of this frame.
121 typedef std::map
<content::RenderFrameHost
*, FrameState
> FrameHostToStateMap
;
123 // Tracks the state of known frame hosts.
124 FrameHostToStateMap frame_host_state_map_
;
126 // Set of all known frame hosts.
127 std::set
<content::RenderFrameHost
*> frame_hosts_
;
129 // The last comitted main frame.
130 content::RenderFrameHost
* main_frame_host_
;
132 // If true, also allow events from chrome-extension:// URLs.
133 static bool allow_extension_scheme_
;
135 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState
);
138 } // namespace extensions
140 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H_