Chromium Code Reviews| 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 "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 class RenderFrameHost; | 16 class RenderFrameHost; |
| 17 class RenderViewHost; | 17 class RenderViewHost; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 // Tracks the navigation state of all frame hosts in a given tab currently known | 22 // Tracks the navigation state of all frame hosts in a given tab currently known |
| 23 // to the webNavigation API. It is mainly used to track in which frames an error | 23 // to the webNavigation API. It is mainly used to track in which frames an error |
| 24 // occurred so no further events for this frame are being sent. | 24 // occurred so no further events for this frame are being sent. |
| 25 class FrameNavigationState { | 25 class FrameNavigationState { |
|
nasko
2016/02/05 17:49:30
I renamed this into FrameLoadingState in my big CL
| |
| 26 public: | 26 public: |
| 27 typedef std::set<content::RenderFrameHost*>::const_iterator const_iterator; | 27 typedef std::set<content::RenderFrameHost*>::const_iterator const_iterator; |
| 28 | 28 |
| 29 FrameNavigationState(); | 29 FrameNavigationState(); |
| 30 ~FrameNavigationState(); | 30 ~FrameNavigationState(); |
| 31 | 31 |
| 32 // True if in general webNavigation events may be sent for the given URL. | 32 // True if in general webNavigation events may be sent for the given URL. |
| 33 static bool IsValidUrl(const GURL& url); | 33 static bool IsValidUrl(const GURL& url); |
| 34 | 34 |
| 35 // Use these to iterate over all frame hosts known by this object. | 35 // Use these to iterate over all frame hosts known by this object. |
| 36 const_iterator begin() const { return frame_hosts_.begin(); } | 36 const_iterator begin() const { return frame_hosts_.begin(); } |
| 37 const_iterator end() const { return frame_hosts_.end(); } | 37 const_iterator end() const { return frame_hosts_.end(); } |
| 38 | 38 |
| 39 // True if navigation events for the given frame can be sent. | 39 // True if navigation events for the given frame can be sent. |
| 40 bool CanSendEvents(content::RenderFrameHost* frame_host) const; | 40 bool CanSendEvents(content::RenderFrameHost* frame_host) const; |
| 41 | 41 |
| 42 // Starts to track a navigation in |frame_host| to |url|. | 42 // Starts to track a navigation in |frame_host| to |url|. |
| 43 void StartTrackingNavigation(content::RenderFrameHost* frame_host, | 43 void StartTrackingDocumentLoad(content::RenderFrameHost* frame_host, |
| 44 const GURL& url, | 44 const GURL& url, |
| 45 bool is_error_page, | 45 bool is_same_page, |
| 46 bool is_iframe_srcdoc); | 46 bool is_error_page, |
| 47 bool is_iframe_srcdoc); | |
| 47 | 48 |
| 48 // Adds the |frame_host| to the set of RenderFrameHosts associated with the | 49 // Adds the |frame_host| to the set of RenderFrameHosts associated with the |
| 49 // WebContents this object is tracking. This method and FrameHostDeleted | 50 // WebContents this object is tracking. This method and FrameHostDeleted |
| 50 // are used to track the set of current RenderFrameHosts, which is used to | 51 // are used to track the set of current RenderFrameHosts, which is used to |
| 51 // implement the GetFrame and GetAllFrames extension APIs. | 52 // implement the GetFrame and GetAllFrames extension APIs. |
| 52 void FrameHostCreated(content::RenderFrameHost* frame_host); | 53 void FrameHostCreated(content::RenderFrameHost* frame_host); |
| 53 | 54 |
| 54 // Removes the |frame_host| from the set of RenderFrameHosts associated with | 55 // Removes the |frame_host| from the set of RenderFrameHosts associated with |
| 55 // the WebContents this object is tracking. | 56 // the WebContents this object is tracking. |
| 56 void FrameHostDeleted(content::RenderFrameHost* frame_host); | 57 void FrameHostDeleted(content::RenderFrameHost* frame_host); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 79 | 80 |
| 80 // True if |frame_host| is currently not navigating. | 81 // True if |frame_host| is currently not navigating. |
| 81 bool GetNavigationCompleted(content::RenderFrameHost* frame_host) const; | 82 bool GetNavigationCompleted(content::RenderFrameHost* frame_host) const; |
| 82 | 83 |
| 83 // Marks |frame_host| as having finished parsing. | 84 // Marks |frame_host| as having finished parsing. |
| 84 void SetParsingFinished(content::RenderFrameHost* frame_host); | 85 void SetParsingFinished(content::RenderFrameHost* frame_host); |
| 85 | 86 |
| 86 // True if |frame_host| has finished parsing. | 87 // True if |frame_host| has finished parsing. |
| 87 bool GetParsingFinished(content::RenderFrameHost* frame_host) const; | 88 bool GetParsingFinished(content::RenderFrameHost* frame_host) const; |
| 88 | 89 |
| 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); | |
| 92 | |
| 93 // True if |frame_host| has committed its navigation. | |
| 94 bool GetNavigationCommitted(content::RenderFrameHost* frame_host) const; | |
| 95 | |
| 96 // Marks |frame_host| as redirected by the server. | |
| 97 void SetIsServerRedirected(content::RenderFrameHost* frame_host); | |
| 98 | |
| 99 // True if |frame_host| was redirected by the server. | |
| 100 bool GetIsServerRedirected(content::RenderFrameHost* frame_host) const; | |
| 101 | |
| 102 #ifdef UNIT_TEST | 90 #ifdef UNIT_TEST |
| 103 static void set_allow_extension_scheme(bool allow_extension_scheme) { | 91 static void set_allow_extension_scheme(bool allow_extension_scheme) { |
| 104 allow_extension_scheme_ = allow_extension_scheme; | 92 allow_extension_scheme_ = allow_extension_scheme; |
| 105 } | 93 } |
| 106 #endif | 94 #endif |
| 107 | 95 |
| 108 private: | 96 private: |
| 109 struct FrameState { | 97 struct FrameState { |
| 110 FrameState(); | 98 FrameState(); |
| 111 | 99 |
| 112 bool error_occurred; // True if an error has occurred in this frame. | 100 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. | 101 bool is_iframe_srcdoc; // True if the frame is displaying its srcdoc. |
| 114 bool is_navigating; // True if there is a navigation going on. | 102 bool is_loading; // True if there is a navigation going on. |
|
Devlin
2016/02/05 18:30:28
this comment is weird, given that this is set to t
nasko
2016/02/05 23:41:22
In general, the model we want to move to is have c
| |
| 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. | 103 bool is_parsing; // True if the frame is still parsing. |
| 118 GURL url; // URL of this frame. | 104 GURL url; // URL of this frame. |
| 119 }; | 105 }; |
| 120 typedef std::map<content::RenderFrameHost*, FrameState> FrameHostToStateMap; | 106 typedef std::map<content::RenderFrameHost*, FrameState> FrameHostToStateMap; |
| 121 | 107 |
| 122 // Tracks the state of known frame hosts. | 108 // Tracks the state of known frame hosts. |
| 123 FrameHostToStateMap frame_host_state_map_; | 109 FrameHostToStateMap frame_host_state_map_; |
| 124 | 110 |
| 125 // Set of all known frame hosts. | 111 // Set of all known frame hosts. |
| 126 std::set<content::RenderFrameHost*> frame_hosts_; | 112 std::set<content::RenderFrameHost*> frame_hosts_; |
| 127 | 113 |
| 128 // If true, also allow events from chrome-extension:// URLs. | 114 // If true, also allow events from chrome-extension:// URLs. |
| 129 static bool allow_extension_scheme_; | 115 static bool allow_extension_scheme_; |
| 130 | 116 |
| 131 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState); | 117 DISALLOW_COPY_AND_ASSIGN(FrameNavigationState); |
| 132 }; | 118 }; |
| 133 | 119 |
| 134 } // namespace extensions | 120 } // namespace extensions |
| 135 | 121 |
| 136 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H _ | 122 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_FRAME_NAVIGATION_STATE_H _ |
| OLD | NEW |