OLD | NEW |
---|---|
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 "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
13 | 13 |
14 namespace extensions { | 14 namespace extensions { |
15 | 15 |
16 // Tracks the navigation state of all frames in a given tab currently known to | 16 // Tracks the navigation state of all frames in a given tab currently known to |
17 // the webNavigation API. It is mainly used to track in which frames an error | 17 // the webNavigation API. It is mainly used to track in which frames an error |
18 // occurred so no further events for this frame are being sent. | 18 // occurred so no further events for this frame are being sent. |
19 class FrameNavigationState { | 19 class FrameNavigationState { |
20 public: | 20 public: |
21 typedef std::set<int64>::const_iterator const_iterator; | 21 // A frame is uniquely identified by its frame ID (int64) and the render |
22 // process ID (int). We use the render process ID instead of e.g. a pointer | |
23 // to the RVH so we don't depend on the lifetime of the RVH. | |
24 typedef std::pair<int64, int> FrameID; | |
Matt Perry
2012/07/23 21:28:10
How much more work would it be to define your own
jochen (gone - plz use gerrit)
2012/07/23 22:04:05
not too much. I'd have to specialize the std::less
Matt Perry
2012/07/23 22:31:29
Yeah I think that's worth it. Or maybe just define
| |
25 typedef std::set<FrameID>::const_iterator const_iterator; | |
26 | |
27 static FrameID kInvalidFrameID; | |
22 | 28 |
23 FrameNavigationState(); | 29 FrameNavigationState(); |
24 ~FrameNavigationState(); | 30 ~FrameNavigationState(); |
25 | 31 |
26 // Use these to iterate over all frame IDs known by this object. | 32 // Use these to iterate over all frame IDs known by this object. |
27 const_iterator begin() const { return frame_ids_.begin(); } | 33 const_iterator begin() const { return frame_ids_.begin(); } |
28 const_iterator end() const { return frame_ids_.end(); } | 34 const_iterator end() const { return frame_ids_.end(); } |
29 | 35 |
30 // True if navigation events for the given frame can be sent. | 36 // True if navigation events for the given frame can be sent. |
31 bool CanSendEvents(int64 frame_id) const; | 37 bool CanSendEvents(FrameID frame_id) const; |
32 | 38 |
33 // 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. |
34 bool IsValidUrl(const GURL& url) const; | 40 bool IsValidUrl(const GURL& url) const; |
35 | 41 |
36 // Starts to track a frame identified by its |frame_id| showing the URL |url|. | 42 // Starts to track a frame identified by its |frame_id| showing the URL |url|. |
37 void TrackFrame(int64 frame_id, | 43 void TrackFrame(FrameID frame_id, |
38 const GURL& url, | 44 const GURL& url, |
39 bool is_main_frame, | 45 bool is_main_frame, |
40 bool is_error_page); | 46 bool is_error_page); |
41 | 47 |
42 // Update the URL associated with a given frame. | 48 // Update the URL associated with a given frame. |
43 void UpdateFrame(int64 frame_id, const GURL& url); | 49 void UpdateFrame(FrameID frame_id, const GURL& url); |
44 | 50 |
45 // Returns true if |frame_id| is a known frame. | 51 // Returns true if |frame_id| is a known frame. |
46 bool IsValidFrame(int64 frame_id) const; | 52 bool IsValidFrame(FrameID frame_id) const; |
47 | 53 |
48 // Returns the URL corresponding to a tracked frame given by its |frame_id|. | 54 // Returns the URL corresponding to a tracked frame given by its |frame_id|. |
49 GURL GetUrl(int64 frame_id) const; | 55 GURL GetUrl(FrameID frame_id) const; |
50 | 56 |
51 // True if the frame given by its |frame_id| is the main frame of its tab. | 57 // True if the frame given by its |frame_id| is the main frame of its tab. |
52 bool IsMainFrame(int64 frame_id) const; | 58 bool IsMainFrame(FrameID frame_id) const; |
53 | 59 |
54 // Returns the frame ID of the main frame, or -1 if the frame ID is not | 60 // Returns the frame ID of the main frame, or -1 if the frame ID is not |
55 // known. | 61 // known. |
56 int64 GetMainFrameID() const; | 62 FrameID GetMainFrameID() const; |
57 | 63 |
58 // Marks a frame as in an error state, i.e. the onErrorOccurred event was | 64 // Marks a frame as in an error state, i.e. the onErrorOccurred event was |
59 // fired for this frame, and no further events should be sent for it. | 65 // fired for this frame, and no further events should be sent for it. |
60 void SetErrorOccurredInFrame(int64 frame_id); | 66 void SetErrorOccurredInFrame(FrameID frame_id); |
61 | 67 |
62 // True if the frame is marked as being in an error state. | 68 // True if the frame is marked as being in an error state. |
63 bool GetErrorOccurredInFrame(int64 frame_id) const; | 69 bool GetErrorOccurredInFrame(FrameID frame_id) const; |
64 | 70 |
65 // Marks a frame as having finished its last navigation, i.e. the onCompleted | 71 // Marks a frame as having finished its last navigation, i.e. the onCompleted |
66 // event was fired for this frame. | 72 // event was fired for this frame. |
67 void SetNavigationCompleted(int64 frame_id); | 73 void SetNavigationCompleted(FrameID frame_id); |
68 | 74 |
69 // True if the frame is currently not navigating. | 75 // True if the frame is currently not navigating. |
70 bool GetNavigationCompleted(int64 frame_id) const; | 76 bool GetNavigationCompleted(FrameID frame_id) const; |
71 | 77 |
72 // Marks a frame as having committed its navigation, i.e. the onCommitted | 78 // Marks a frame as having committed its navigation, i.e. the onCommitted |
73 // event was fired for this frame. | 79 // event was fired for this frame. |
74 void SetNavigationCommitted(int64 frame_id); | 80 void SetNavigationCommitted(FrameID frame_id); |
75 | 81 |
76 // True if the frame has committed its navigation. | 82 // True if the frame has committed its navigation. |
77 bool GetNavigationCommitted(int64 frame_id) const; | 83 bool GetNavigationCommitted(FrameID frame_id) const; |
78 | 84 |
79 // Marks a frame as redirected by the server. | 85 // Marks a frame as redirected by the server. |
80 void SetIsServerRedirected(int64 frame_id); | 86 void SetIsServerRedirected(FrameID frame_id); |
81 | 87 |
82 // True if the frame was redirected by the server. | 88 // True if the frame was redirected by the server. |
83 bool GetIsServerRedirected(int64 frame_id) const; | 89 bool GetIsServerRedirected(FrameID frame_id) const; |
84 | 90 |
85 #ifdef UNIT_TEST | 91 #ifdef UNIT_TEST |
86 static void set_allow_extension_scheme(bool allow_extension_scheme) { | 92 static void set_allow_extension_scheme(bool allow_extension_scheme) { |
87 allow_extension_scheme_ = allow_extension_scheme; | 93 allow_extension_scheme_ = allow_extension_scheme; |
88 } | 94 } |
89 #endif | 95 #endif |
90 | 96 |
91 private: | 97 private: |
92 struct FrameState { | 98 struct FrameState { |
93 bool error_occurred; // True if an error has occurred in this frame. | 99 bool error_occurred; // True if an error has occurred in this frame. |
94 bool is_main_frame; // True if this is a main frame. | 100 bool is_main_frame; // True if this is a main frame. |
95 bool is_navigating; // True if there is a navigation going on. | 101 bool is_navigating; // True if there is a navigation going on. |
96 bool is_committed; // True if the navigation is already committed. | 102 bool is_committed; // True if the navigation is already committed. |
97 bool is_server_redirected; // True if a server redirect happened. | 103 bool is_server_redirected; // True if a server redirect happened. |
98 GURL url; // URL of this frame. | 104 GURL url; // URL of this frame. |
99 }; | 105 }; |
100 typedef std::map<int64, FrameState> FrameIdToStateMap; | 106 typedef std::map<FrameID, FrameState> FrameIdToStateMap; |
101 | 107 |
102 // Tracks the state of known frames. | 108 // Tracks the state of known frames. |
103 FrameIdToStateMap frame_state_map_; | 109 FrameIdToStateMap frame_state_map_; |
104 | 110 |
105 // Set of all known frames. | 111 // Set of all known frames. |
106 std::set<int64> frame_ids_; | 112 std::set<FrameID> frame_ids_; |
107 | 113 |
108 // The current main frame. | 114 // The current main frame. |
109 int64 main_frame_id_; | 115 FrameID main_frame_id_; |
110 | 116 |
111 // If true, also allow events from chrome-extension:// URLs. | 117 // If true, also allow events from chrome-extension:// URLs. |
112 static bool allow_extension_scheme_; | 118 static bool allow_extension_scheme_; |
113 | 119 |
114 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState); | 120 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState); |
115 }; | 121 }; |
116 | 122 |
117 } // namespace extensions | 123 } // namespace extensions |
118 | 124 |
119 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H _ | 125 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H _ |
OLD | NEW |