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 // True if in general webNavigation events may be sent for the given URL.
32 static bool IsValidUrl(const GURL
& url
);
34 // Use these to iterate over all frame hosts known by this object.
35 const_iterator
begin() const { return frame_hosts_
.begin(); }
36 const_iterator
end() const { return frame_hosts_
.end(); }
38 // True if navigation events for the given frame can be sent.
39 bool CanSendEvents(content::RenderFrameHost
* frame_host
) const;
41 // Starts to track a navigation in |frame_host| to |url|.
42 void StartTrackingNavigation(content::RenderFrameHost
* frame_host
,
45 bool is_iframe_srcdoc
);
47 // Adds the |frame_host| to the set of RenderFrameHosts associated with the
48 // WebContents this object is tracking. This method and FrameHostDeleted
49 // are used to track the set of current RenderFrameHosts, which is used to
50 // implement the GetFrame and GetAllFrames extension APIs.
51 void FrameHostCreated(content::RenderFrameHost
* frame_host
);
53 // Removes the |frame_host| from the set of RenderFrameHosts associated with
54 // the WebContents this object is tracking.
55 void FrameHostDeleted(content::RenderFrameHost
* frame_host
);
57 // Update the URL associated with |frame_host|.
58 void UpdateFrame(content::RenderFrameHost
* frame_host
, const GURL
& url
);
60 // Returns true if |frame_host| is a known frame host.
61 bool IsValidFrame(content::RenderFrameHost
* frame_host
) const;
63 // Returns the URL corresponding to a tracked |frame_host|.
64 // TODO(dcheng): Why is this needed? Can't this information be extracted from
66 GURL
GetUrl(content::RenderFrameHost
* frame_host
) const;
68 // Marks |frame_host| as in an error state, i.e. the onErrorOccurred event was
69 // fired for it, and no further events should be sent for it.
70 void SetErrorOccurredInFrame(content::RenderFrameHost
* frame_host
);
72 // True if |frame_host| is marked as being in an error state.
73 bool GetErrorOccurredInFrame(content::RenderFrameHost
* frame_host
) const;
75 // Marks |frame_host| as having finished its last navigation, i.e. the
76 // onCompleted event was fired for this frame.
77 void SetNavigationCompleted(content::RenderFrameHost
* frame_host
);
79 // True if |frame_host| is currently not navigating.
80 bool GetNavigationCompleted(content::RenderFrameHost
* frame_host
) const;
82 // Marks |frame_host| as having finished parsing.
83 void SetParsingFinished(content::RenderFrameHost
* frame_host
);
85 // True if |frame_host| has finished parsing.
86 bool GetParsingFinished(content::RenderFrameHost
* frame_host
) const;
88 // Marks |frame_host| as having committed its navigation, i.e. the onCommitted
89 // event was fired for this frame.
90 void SetNavigationCommitted(content::RenderFrameHost
* frame_host
);
92 // True if |frame_host| has committed its navigation.
93 bool GetNavigationCommitted(content::RenderFrameHost
* frame_host
) const;
95 // Marks |frame_host| as redirected by the server.
96 void SetIsServerRedirected(content::RenderFrameHost
* frame_host
);
98 // True if |frame_host| was redirected by the server.
99 bool GetIsServerRedirected(content::RenderFrameHost
* frame_host
) const;
102 static void set_allow_extension_scheme(bool allow_extension_scheme
) {
103 allow_extension_scheme_
= allow_extension_scheme
;
111 bool error_occurred
; // True if an error has occurred in this frame.
112 bool is_iframe_srcdoc
; // True if the frame is displaying its srcdoc.
113 bool is_navigating
; // True if there is a navigation going on.
114 bool is_committed
; // True if the navigation is already committed.
115 bool is_server_redirected
; // True if a server redirect happened.
116 bool is_parsing
; // True if the frame is still parsing.
117 GURL url
; // URL of this frame.
119 typedef std::map
<content::RenderFrameHost
*, FrameState
> FrameHostToStateMap
;
121 // Tracks the state of known frame hosts.
122 FrameHostToStateMap frame_host_state_map_
;
124 // Set of all known frame hosts.
125 std::set
<content::RenderFrameHost
*> frame_hosts_
;
127 // If true, also allow events from chrome-extension:// URLs.
128 static bool allow_extension_scheme_
;
130 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState
);
133 } // namespace extensions
135 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H_