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 and the render process ID. |
| 22 // We use the render process ID instead of e.g. a pointer to the RVH so we |
| 23 // don't depend on the lifetime of the RVH. |
| 24 struct FrameID { |
| 25 FrameID(); |
| 26 FrameID(int64 frame_num, int render_process_id); |
| 27 |
| 28 bool IsValid() const; |
| 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 int render_process_id; |
| 36 }; |
| 37 typedef std::set<FrameID>::const_iterator const_iterator; |
22 | 38 |
23 FrameNavigationState(); | 39 FrameNavigationState(); |
24 ~FrameNavigationState(); | 40 ~FrameNavigationState(); |
25 | 41 |
26 // Use these to iterate over all frame IDs known by this object. | 42 // Use these to iterate over all frame IDs known by this object. |
27 const_iterator begin() const { return frame_ids_.begin(); } | 43 const_iterator begin() const { return frame_ids_.begin(); } |
28 const_iterator end() const { return frame_ids_.end(); } | 44 const_iterator end() const { return frame_ids_.end(); } |
29 | 45 |
30 // True if navigation events for the given frame can be sent. | 46 // True if navigation events for the given frame can be sent. |
31 bool CanSendEvents(int64 frame_id) const; | 47 bool CanSendEvents(FrameID frame_id) const; |
32 | 48 |
33 // True if in general webNavigation events may be sent for the given URL. | 49 // True if in general webNavigation events may be sent for the given URL. |
34 bool IsValidUrl(const GURL& url) const; | 50 bool IsValidUrl(const GURL& url) const; |
35 | 51 |
36 // Starts to track a frame identified by its |frame_id| showing the URL |url|. | 52 // Starts to track a frame identified by its |frame_id| showing the URL |url|. |
37 void TrackFrame(int64 frame_id, | 53 void TrackFrame(FrameID frame_id, |
38 const GURL& url, | 54 const GURL& url, |
39 bool is_main_frame, | 55 bool is_main_frame, |
40 bool is_error_page); | 56 bool is_error_page); |
41 | 57 |
42 // Update the URL associated with a given frame. | 58 // Update the URL associated with a given frame. |
43 void UpdateFrame(int64 frame_id, const GURL& url); | 59 void UpdateFrame(FrameID frame_id, const GURL& url); |
44 | 60 |
45 // Returns true if |frame_id| is a known frame. | 61 // Returns true if |frame_id| is a known frame. |
46 bool IsValidFrame(int64 frame_id) const; | 62 bool IsValidFrame(FrameID frame_id) const; |
47 | 63 |
48 // Returns the URL corresponding to a tracked frame given by its |frame_id|. | 64 // Returns the URL corresponding to a tracked frame given by its |frame_id|. |
49 GURL GetUrl(int64 frame_id) const; | 65 GURL GetUrl(FrameID frame_id) const; |
50 | 66 |
51 // True if the frame given by its |frame_id| is the main frame of its tab. | 67 // True if the frame given by its |frame_id| is the main frame of its tab. |
52 bool IsMainFrame(int64 frame_id) const; | 68 bool IsMainFrame(FrameID frame_id) const; |
53 | 69 |
54 // Returns the frame ID of the main frame, or -1 if the frame ID is not | 70 // Returns the frame ID of the main frame, or -1 if the frame ID is not |
55 // known. | 71 // known. |
56 int64 GetMainFrameID() const; | 72 FrameID GetMainFrameID() const; |
57 | 73 |
58 // Marks a frame as in an error state, i.e. the onErrorOccurred event was | 74 // 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. | 75 // fired for this frame, and no further events should be sent for it. |
60 void SetErrorOccurredInFrame(int64 frame_id); | 76 void SetErrorOccurredInFrame(FrameID frame_id); |
61 | 77 |
62 // True if the frame is marked as being in an error state. | 78 // True if the frame is marked as being in an error state. |
63 bool GetErrorOccurredInFrame(int64 frame_id) const; | 79 bool GetErrorOccurredInFrame(FrameID frame_id) const; |
64 | 80 |
65 // Marks a frame as having finished its last navigation, i.e. the onCompleted | 81 // Marks a frame as having finished its last navigation, i.e. the onCompleted |
66 // event was fired for this frame. | 82 // event was fired for this frame. |
67 void SetNavigationCompleted(int64 frame_id); | 83 void SetNavigationCompleted(FrameID frame_id); |
68 | 84 |
69 // True if the frame is currently not navigating. | 85 // True if the frame is currently not navigating. |
70 bool GetNavigationCompleted(int64 frame_id) const; | 86 bool GetNavigationCompleted(FrameID frame_id) const; |
71 | 87 |
72 // Marks a frame as having committed its navigation, i.e. the onCommitted | 88 // Marks a frame as having committed its navigation, i.e. the onCommitted |
73 // event was fired for this frame. | 89 // event was fired for this frame. |
74 void SetNavigationCommitted(int64 frame_id); | 90 void SetNavigationCommitted(FrameID frame_id); |
75 | 91 |
76 // True if the frame has committed its navigation. | 92 // True if the frame has committed its navigation. |
77 bool GetNavigationCommitted(int64 frame_id) const; | 93 bool GetNavigationCommitted(FrameID frame_id) const; |
78 | 94 |
79 // Marks a frame as redirected by the server. | 95 // Marks a frame as redirected by the server. |
80 void SetIsServerRedirected(int64 frame_id); | 96 void SetIsServerRedirected(FrameID frame_id); |
81 | 97 |
82 // True if the frame was redirected by the server. | 98 // True if the frame was redirected by the server. |
83 bool GetIsServerRedirected(int64 frame_id) const; | 99 bool GetIsServerRedirected(FrameID frame_id) const; |
84 | 100 |
85 #ifdef UNIT_TEST | 101 #ifdef UNIT_TEST |
86 static void set_allow_extension_scheme(bool allow_extension_scheme) { | 102 static void set_allow_extension_scheme(bool allow_extension_scheme) { |
87 allow_extension_scheme_ = allow_extension_scheme; | 103 allow_extension_scheme_ = allow_extension_scheme; |
88 } | 104 } |
89 #endif | 105 #endif |
90 | 106 |
91 private: | 107 private: |
92 struct FrameState { | 108 struct FrameState { |
93 bool error_occurred; // True if an error has occurred in this frame. | 109 bool error_occurred; // True if an error has occurred in this frame. |
94 bool is_main_frame; // True if this is a main frame. | 110 bool is_main_frame; // True if this is a main frame. |
95 bool is_navigating; // True if there is a navigation going on. | 111 bool is_navigating; // True if there is a navigation going on. |
96 bool is_committed; // True if the navigation is already committed. | 112 bool is_committed; // True if the navigation is already committed. |
97 bool is_server_redirected; // True if a server redirect happened. | 113 bool is_server_redirected; // True if a server redirect happened. |
98 GURL url; // URL of this frame. | 114 GURL url; // URL of this frame. |
99 }; | 115 }; |
100 typedef std::map<int64, FrameState> FrameIdToStateMap; | 116 typedef std::map<FrameID, FrameState> FrameIdToStateMap; |
101 | 117 |
102 // Tracks the state of known frames. | 118 // Tracks the state of known frames. |
103 FrameIdToStateMap frame_state_map_; | 119 FrameIdToStateMap frame_state_map_; |
104 | 120 |
105 // Set of all known frames. | 121 // Set of all known frames. |
106 std::set<int64> frame_ids_; | 122 std::set<FrameID> frame_ids_; |
107 | 123 |
108 // The current main frame. | 124 // The current main frame. |
109 int64 main_frame_id_; | 125 FrameID main_frame_id_; |
110 | 126 |
111 // If true, also allow events from chrome-extension:// URLs. | 127 // If true, also allow events from chrome-extension:// URLs. |
112 static bool allow_extension_scheme_; | 128 static bool allow_extension_scheme_; |
113 | 129 |
114 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState); | 130 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState); |
115 }; | 131 }; |
116 | 132 |
117 } // namespace extensions | 133 } // namespace extensions |
118 | 134 |
119 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H
_ | 135 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H
_ |
OLD | NEW |