Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / extensions / api / web_navigation / frame_navigation_state.h
blob2e4a30096c985bd0603ea12065c95a1a45c3dc95
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_
8 #include <map>
9 #include <set>
11 #include "base/compiler_specific.h"
12 #include "url/gurl.h"
14 namespace content {
15 class RenderFrameHost;
16 class RenderViewHost;
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 {
25 public:
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 navigation in |frame_host| to |url|.
43 void StartTrackingNavigation(content::RenderFrameHost* frame_host,
44 const GURL& url,
45 bool is_error_page,
46 bool is_iframe_srcdoc);
48 // Adds the |frame_host| to the set of RenderFrameHosts associated with the
49 // WebContents this object is tracking. This method and FrameHostDeleted
50 // are used to track the set of current RenderFrameHosts, which is used to
51 // implement the GetFrame and GetAllFrames extension APIs.
52 void FrameHostCreated(content::RenderFrameHost* frame_host);
54 // Removes the |frame_host| from the set of RenderFrameHosts associated with
55 // the WebContents this object is tracking.
56 void FrameHostDeleted(content::RenderFrameHost* frame_host);
58 // Update the URL associated with |frame_host|.
59 void UpdateFrame(content::RenderFrameHost* frame_host, const GURL& url);
61 // Returns true if |frame_host| is a known frame host.
62 bool IsValidFrame(content::RenderFrameHost* frame_host) const;
64 // Returns the URL corresponding to a tracked |frame_host|.
65 // TODO(dcheng): Why is this needed? Can't this information be extracted from
66 // RenderFrameHost?
67 GURL GetUrl(content::RenderFrameHost* frame_host) const;
69 // Marks |frame_host| as in an error state, i.e. the onErrorOccurred event was
70 // fired for it, and no further events should be sent for it.
71 void SetErrorOccurredInFrame(content::RenderFrameHost* frame_host);
73 // True if |frame_host| is marked as being in an error state.
74 bool GetErrorOccurredInFrame(content::RenderFrameHost* frame_host) const;
76 // Marks |frame_host| as having finished its last navigation, i.e. the
77 // onCompleted event was fired for this frame.
78 void SetNavigationCompleted(content::RenderFrameHost* frame_host);
80 // True if |frame_host| is currently not navigating.
81 bool GetNavigationCompleted(content::RenderFrameHost* frame_host) const;
83 // Marks |frame_host| as having finished parsing.
84 void SetParsingFinished(content::RenderFrameHost* frame_host);
86 // True if |frame_host| has finished parsing.
87 bool GetParsingFinished(content::RenderFrameHost* frame_host) const;
89 // Marks |frame_host| as having committed its navigation, i.e. the onCommitted
90 // event was fired for this frame.
91 void SetNavigationCommitted(content::RenderFrameHost* frame_host);
93 // True if |frame_host| has committed its navigation.
94 bool GetNavigationCommitted(content::RenderFrameHost* frame_host) const;
96 // Marks |frame_host| as redirected by the server.
97 void SetIsServerRedirected(content::RenderFrameHost* frame_host);
99 // True if |frame_host| was redirected by the server.
100 bool GetIsServerRedirected(content::RenderFrameHost* frame_host) const;
102 #ifdef UNIT_TEST
103 static void set_allow_extension_scheme(bool allow_extension_scheme) {
104 allow_extension_scheme_ = allow_extension_scheme;
106 #endif
108 private:
109 struct FrameState {
110 FrameState();
112 bool error_occurred; // True if an error has occurred in this frame.
113 bool is_iframe_srcdoc; // True if the frame is displaying its srcdoc.
114 bool is_navigating; // True if there is a navigation going on.
115 bool is_committed; // True if the navigation is already committed.
116 bool is_server_redirected; // True if a server redirect happened.
117 bool is_parsing; // True if the frame is still parsing.
118 GURL url; // URL of this frame.
120 typedef std::map<content::RenderFrameHost*, FrameState> FrameHostToStateMap;
122 // Tracks the state of known frame hosts.
123 FrameHostToStateMap frame_host_state_map_;
125 // Set of all known frame hosts.
126 std::set<content::RenderFrameHost*> frame_hosts_;
128 // If true, also allow events from chrome-extension:// URLs.
129 static bool allow_extension_scheme_;
131 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState);
134 } // namespace extensions
136 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H_