Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/extensions/api/web_navigation/frame_navigation_state.h

Issue 10835033: Only delete old frames when a new main frame navigation commits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 content {
15 class RenderViewHost;
16 }
17
14 namespace extensions { 18 namespace extensions {
15 19
16 // Tracks the navigation state of all frames in a given tab currently known to 20 // 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 21 // 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. 22 // occurred so no further events for this frame are being sent.
19 class FrameNavigationState { 23 class FrameNavigationState {
20 public: 24 public:
21 // A frame is uniquely identified by its frame ID and the render process ID. 25 // A frame is uniquely identified by its frame ID and the RVH it's in.
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 { 26 struct FrameID {
25 FrameID(); 27 FrameID();
26 FrameID(int64 frame_num, int render_process_id); 28 FrameID(int64 frame_num, content::RenderViewHost* render_view_host);
27 29
28 bool IsValid() const; 30 bool IsValid() const;
29 31
30 bool operator<(const FrameID& other) const; 32 bool operator<(const FrameID& other) const;
31 bool operator==(const FrameID& other) const; 33 bool operator==(const FrameID& other) const;
32 bool operator!=(const FrameID& other) const; 34 bool operator!=(const FrameID& other) const;
33 35
34 int64 frame_num; 36 int64 frame_num;
35 int render_process_id; 37 content::RenderViewHost* render_view_host;
Matt Perry 2012/07/30 11:52:43 Is render_view_host guaranteed to outlive a FrameI
jochen (gone - plz use gerrit) 2012/07/30 15:33:18 Done.
36 }; 38 };
37 typedef std::set<FrameID>::const_iterator const_iterator; 39 typedef std::set<FrameID>::const_iterator const_iterator;
38 40
39 FrameNavigationState(); 41 FrameNavigationState();
40 ~FrameNavigationState(); 42 ~FrameNavigationState();
41 43
42 // Use these to iterate over all frame IDs known by this object. 44 // Use these to iterate over all frame IDs known by this object.
43 const_iterator begin() const { return frame_ids_.begin(); } 45 const_iterator begin() const { return frame_ids_.begin(); }
44 const_iterator end() const { return frame_ids_.end(); } 46 const_iterator end() const { return frame_ids_.end(); }
45 47
46 // True if navigation events for the given frame can be sent. 48 // True if navigation events for the given frame can be sent.
47 bool CanSendEvents(FrameID frame_id) const; 49 bool CanSendEvents(FrameID frame_id) const;
48 50
49 // True if in general webNavigation events may be sent for the given URL. 51 // True if in general webNavigation events may be sent for the given URL.
50 bool IsValidUrl(const GURL& url) const; 52 bool IsValidUrl(const GURL& url) const;
51 53
52 // Starts to track a frame identified by its |frame_id| showing the URL |url|. 54 // Starts to track a frame identified by its |frame_id| showing the URL |url|.
53 void TrackFrame(FrameID frame_id, 55 void TrackFrame(FrameID frame_id,
54 const GURL& url, 56 const GURL& url,
55 bool is_main_frame, 57 bool is_main_frame,
56 bool is_error_page); 58 bool is_error_page);
57 59
60 // Stops tracking all frames for a given RenderViewHost.
61 void StopTrackingFramesInRVH(content::RenderViewHost* render_view_host);
62
58 // Update the URL associated with a given frame. 63 // Update the URL associated with a given frame.
59 void UpdateFrame(FrameID frame_id, const GURL& url); 64 void UpdateFrame(FrameID frame_id, const GURL& url);
60 65
61 // Returns true if |frame_id| is a known frame. 66 // Returns true if |frame_id| is a known frame.
62 bool IsValidFrame(FrameID frame_id) const; 67 bool IsValidFrame(FrameID frame_id) const;
63 68
64 // Returns the URL corresponding to a tracked frame given by its |frame_id|. 69 // Returns the URL corresponding to a tracked frame given by its |frame_id|.
65 GURL GetUrl(FrameID frame_id) const; 70 GURL GetUrl(FrameID frame_id) const;
66 71
67 // True if the frame given by its |frame_id| is the main frame of its tab. 72 // True if the frame given by its |frame_id| is a main frame of its tab.
73 // There might be multiple uncomitted main frames.
68 bool IsMainFrame(FrameID frame_id) const; 74 bool IsMainFrame(FrameID frame_id) const;
69 75
70 // Returns the frame ID of the main frame, or -1 if the frame ID is not 76 // Returns the frame ID of the last comitted main frame, or -1 if the frame
71 // known. 77 // ID is not known.
72 FrameID GetMainFrameID() const; 78 FrameID GetMainFrameID() const;
73 79
74 // Marks a frame as in an error state, i.e. the onErrorOccurred event was 80 // Marks a frame as in an error state, i.e. the onErrorOccurred event was
75 // fired for this frame, and no further events should be sent for it. 81 // fired for this frame, and no further events should be sent for it.
76 void SetErrorOccurredInFrame(FrameID frame_id); 82 void SetErrorOccurredInFrame(FrameID frame_id);
77 83
78 // True if the frame is marked as being in an error state. 84 // True if the frame is marked as being in an error state.
79 bool GetErrorOccurredInFrame(FrameID frame_id) const; 85 bool GetErrorOccurredInFrame(FrameID frame_id) const;
80 86
81 // Marks a frame as having finished its last navigation, i.e. the onCompleted 87 // Marks a frame as having finished its last navigation, i.e. the onCompleted
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 GURL url; // URL of this frame. 120 GURL url; // URL of this frame.
115 }; 121 };
116 typedef std::map<FrameID, FrameState> FrameIdToStateMap; 122 typedef std::map<FrameID, FrameState> FrameIdToStateMap;
117 123
118 // Tracks the state of known frames. 124 // Tracks the state of known frames.
119 FrameIdToStateMap frame_state_map_; 125 FrameIdToStateMap frame_state_map_;
120 126
121 // Set of all known frames. 127 // Set of all known frames.
122 std::set<FrameID> frame_ids_; 128 std::set<FrameID> frame_ids_;
123 129
124 // The current main frame. 130 // The id of the last comitted main frame.
125 FrameID main_frame_id_; 131 FrameID main_frame_id_;
126 132
127 // If true, also allow events from chrome-extension:// URLs. 133 // If true, also allow events from chrome-extension:// URLs.
128 static bool allow_extension_scheme_; 134 static bool allow_extension_scheme_;
129 135
130 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState); 136 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState);
131 }; 137 };
132 138
133 } // namespace extensions 139 } // namespace extensions
134 140
135 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H _ 141 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698