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