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 // Defines the Chrome Extensions WebNavigation API functions for observing and | 5 // Defines the Chrome Extensions WebNavigation API functions for observing and |
6 // intercepting navigation events, as specified in the extension JSON API. | 6 // intercepting navigation events, as specified in the extension JSON API. |
7 | 7 |
8 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_WEB_NAVIGATION_API_H_ | 8 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_WEB_NAVIGATION_API_H_ |
9 #define CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_WEB_NAVIGATION_API_H_ | 9 #define CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_WEB_NAVIGATION_API_H_ |
10 | 10 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 // Observes navigation notifications and routes them as events to the extension | 104 // Observes navigation notifications and routes them as events to the extension |
105 // system. | 105 // system. |
106 class WebNavigationEventRouter : public TabStripModelObserver, | 106 class WebNavigationEventRouter : public TabStripModelObserver, |
107 public BrowserTabStripTrackerDelegate, | 107 public BrowserTabStripTrackerDelegate, |
108 public content::NotificationObserver { | 108 public content::NotificationObserver { |
109 public: | 109 public: |
110 explicit WebNavigationEventRouter(Profile* profile); | 110 explicit WebNavigationEventRouter(Profile* profile); |
111 ~WebNavigationEventRouter() override; | 111 ~WebNavigationEventRouter() override; |
112 | 112 |
113 private: | 113 // Handler for the NOTIFICATION_RETARGETING event. The method takes the |
| 114 // details of such an event and stores them for the later |
| 115 // NOTIFICATION_TAB_ADDED event. |
| 116 void Retargeting(const RetargetingDetails* details); |
| 117 |
114 // Used to cache the information about newly created WebContents objects. | 118 // Used to cache the information about newly created WebContents objects. |
115 struct PendingWebContents{ | 119 struct PendingWebContents{ |
116 PendingWebContents(); | 120 PendingWebContents(); |
117 PendingWebContents(content::WebContents* source_web_contents, | 121 PendingWebContents(content::WebContents* source_web_contents, |
118 content::RenderFrameHost* source_frame_host, | 122 content::RenderFrameHost* source_frame_host, |
119 content::WebContents* target_web_contents, | 123 content::WebContents* target_web_contents, |
120 const GURL& target_url); | 124 const GURL& target_url); |
121 ~PendingWebContents(); | 125 ~PendingWebContents(); |
122 | 126 |
123 content::WebContents* source_web_contents; | 127 content::WebContents* source_web_contents; |
124 content::RenderFrameHost* source_frame_host; | 128 content::RenderFrameHost* source_frame_host; |
125 content::WebContents* target_web_contents; | 129 content::WebContents* target_web_contents; |
126 GURL target_url; | 130 GURL target_url; |
127 }; | 131 }; |
128 | 132 |
| 133 private: |
129 // BrowserTabStripTrackerDelegate implementation. | 134 // BrowserTabStripTrackerDelegate implementation. |
130 bool ShouldTrackBrowser(Browser* browser) override; | 135 bool ShouldTrackBrowser(Browser* browser) override; |
131 | 136 |
132 // TabStripModelObserver implementation. | 137 // TabStripModelObserver implementation. |
133 void TabReplacedAt(TabStripModel* tab_strip_model, | 138 void TabReplacedAt(TabStripModel* tab_strip_model, |
134 content::WebContents* old_contents, | 139 content::WebContents* old_contents, |
135 content::WebContents* new_contents, | 140 content::WebContents* new_contents, |
136 int index) override; | 141 int index) override; |
137 | 142 |
138 // content::NotificationObserver implementation. | 143 // content::NotificationObserver implementation. |
139 void Observe(int type, | 144 void Observe(int type, |
140 const content::NotificationSource& source, | 145 const content::NotificationSource& source, |
141 const content::NotificationDetails& details) override; | 146 const content::NotificationDetails& details) override; |
142 | 147 |
143 // Handler for the NOTIFICATION_RETARGETING event. The method takes the | |
144 // details of such an event and stores them for the later | |
145 // NOTIFICATION_TAB_ADDED event. | |
146 void Retargeting(const RetargetingDetails* details); | |
147 | |
148 // Handler for the NOTIFICATION_TAB_ADDED event. The method takes the details | 148 // Handler for the NOTIFICATION_TAB_ADDED event. The method takes the details |
149 // of such an event and creates a JSON formated extension event from it. | 149 // of such an event and creates a JSON formated extension event from it. |
150 void TabAdded(content::WebContents* tab); | 150 void TabAdded(content::WebContents* tab); |
151 | 151 |
152 // Handler for NOTIFICATION_WEB_CONTENTS_DESTROYED. If |tab| is in | 152 // Handler for NOTIFICATION_WEB_CONTENTS_DESTROYED. If |tab| is in |
153 // |pending_web_contents_|, it is removed. | 153 // |pending_web_contents_|, it is removed. |
154 void TabDestroyed(content::WebContents* tab); | 154 void TabDestroyed(content::WebContents* tab); |
155 | 155 |
156 // Mapping pointers to WebContents objects to information about how they got | 156 // Mapping pointers to WebContents objects to information about how they got |
157 // created. | 157 // created. |
158 std::map<content::WebContents*, PendingWebContents> pending_web_contents_; | |
159 | 158 |
160 // Used for tracking registrations to navigation notifications. | 159 // Used for tracking registrations to navigation notifications. |
161 content::NotificationRegistrar registrar_; | 160 content::NotificationRegistrar registrar_; |
162 | 161 |
163 // The profile that owns us via ExtensionService. | 162 // The profile that owns us via ExtensionService. |
164 Profile* profile_; | 163 Profile* profile_; |
165 | 164 |
166 BrowserTabStripTracker browser_tab_strip_tracker_; | 165 BrowserTabStripTracker browser_tab_strip_tracker_; |
167 | 166 |
168 DISALLOW_COPY_AND_ASSIGN(WebNavigationEventRouter); | 167 DISALLOW_COPY_AND_ASSIGN(WebNavigationEventRouter); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 210 |
212 // Created lazily upon OnListenerAdded. | 211 // Created lazily upon OnListenerAdded. |
213 std::unique_ptr<WebNavigationEventRouter> web_navigation_event_router_; | 212 std::unique_ptr<WebNavigationEventRouter> web_navigation_event_router_; |
214 | 213 |
215 DISALLOW_COPY_AND_ASSIGN(WebNavigationAPI); | 214 DISALLOW_COPY_AND_ASSIGN(WebNavigationAPI); |
216 }; | 215 }; |
217 | 216 |
218 } // namespace extensions | 217 } // namespace extensions |
219 | 218 |
220 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_WEB_NAVIGATION_API_H_ | 219 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_WEB_NAVIGATION_API_H_ |
OLD | NEW |