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 |
11 #include <map> | 11 #include <map> |
12 #include <set> | 12 #include <set> |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "chrome/browser/extensions/api/web_navigation/frame_navigation_state.h" | 15 #include "chrome/browser/extensions/api/web_navigation/frame_navigation_state.h" |
16 #include "chrome/browser/extensions/chrome_extension_function.h" | 16 #include "chrome/browser/extensions/chrome_extension_function.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser_list_observer.h" | 18 #include "chrome/browser/ui/browser_tab_strip_tracker.h" |
| 19 #include "chrome/browser/ui/browser_tab_strip_tracker_delegate.h" |
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
20 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
22 #include "content/public/browser/web_contents_observer.h" | 23 #include "content/public/browser/web_contents_observer.h" |
23 #include "content/public/browser/web_contents_user_data.h" | 24 #include "content/public/browser/web_contents_user_data.h" |
24 #include "extensions/browser/browser_context_keyed_api_factory.h" | 25 #include "extensions/browser/browser_context_keyed_api_factory.h" |
25 #include "extensions/browser/event_router.h" | 26 #include "extensions/browser/event_router.h" |
26 #include "url/gurl.h" | 27 #include "url/gurl.h" |
27 | 28 |
28 struct RetargetingDetails; | 29 struct RetargetingDetails; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 106 |
106 // Used for tracking registrations to redirect notifications. | 107 // Used for tracking registrations to redirect notifications. |
107 content::NotificationRegistrar registrar_; | 108 content::NotificationRegistrar registrar_; |
108 | 109 |
109 DISALLOW_COPY_AND_ASSIGN(WebNavigationTabObserver); | 110 DISALLOW_COPY_AND_ASSIGN(WebNavigationTabObserver); |
110 }; | 111 }; |
111 | 112 |
112 // Observes navigation notifications and routes them as events to the extension | 113 // Observes navigation notifications and routes them as events to the extension |
113 // system. | 114 // system. |
114 class WebNavigationEventRouter : public TabStripModelObserver, | 115 class WebNavigationEventRouter : public TabStripModelObserver, |
115 public chrome::BrowserListObserver, | 116 public BrowserTabStripTrackerDelegate, |
116 public content::NotificationObserver { | 117 public content::NotificationObserver { |
117 public: | 118 public: |
118 explicit WebNavigationEventRouter(Profile* profile); | 119 explicit WebNavigationEventRouter(Profile* profile); |
119 ~WebNavigationEventRouter() override; | 120 ~WebNavigationEventRouter() override; |
120 | 121 |
121 private: | 122 private: |
122 // Used to cache the information about newly created WebContents objects. | 123 // Used to cache the information about newly created WebContents objects. |
123 struct PendingWebContents{ | 124 struct PendingWebContents{ |
124 PendingWebContents(); | 125 PendingWebContents(); |
125 PendingWebContents(content::WebContents* source_web_contents, | 126 PendingWebContents(content::WebContents* source_web_contents, |
126 content::RenderFrameHost* source_frame_host, | 127 content::RenderFrameHost* source_frame_host, |
127 content::WebContents* target_web_contents, | 128 content::WebContents* target_web_contents, |
128 const GURL& target_url); | 129 const GURL& target_url); |
129 ~PendingWebContents(); | 130 ~PendingWebContents(); |
130 | 131 |
131 content::WebContents* source_web_contents; | 132 content::WebContents* source_web_contents; |
132 content::RenderFrameHost* source_frame_host; | 133 content::RenderFrameHost* source_frame_host; |
133 content::WebContents* target_web_contents; | 134 content::WebContents* target_web_contents; |
134 GURL target_url; | 135 GURL target_url; |
135 }; | 136 }; |
136 | 137 |
| 138 // BrowserTabStripTrackerDelegate implementation. |
| 139 bool ShouldTrackBrowser(Browser* browser) override; |
| 140 |
137 // TabStripModelObserver implementation. | 141 // TabStripModelObserver implementation. |
138 void TabReplacedAt(TabStripModel* tab_strip_model, | 142 void TabReplacedAt(TabStripModel* tab_strip_model, |
139 content::WebContents* old_contents, | 143 content::WebContents* old_contents, |
140 content::WebContents* new_contents, | 144 content::WebContents* new_contents, |
141 int index) override; | 145 int index) override; |
142 | 146 |
143 // chrome::BrowserListObserver implementation. | |
144 void OnBrowserAdded(Browser* browser) override; | |
145 void OnBrowserRemoved(Browser* browser) override; | |
146 | |
147 // content::NotificationObserver implementation. | 147 // content::NotificationObserver implementation. |
148 void Observe(int type, | 148 void Observe(int type, |
149 const content::NotificationSource& source, | 149 const content::NotificationSource& source, |
150 const content::NotificationDetails& details) override; | 150 const content::NotificationDetails& details) override; |
151 | 151 |
152 // Handler for the NOTIFICATION_RETARGETING event. The method takes the | 152 // Handler for the NOTIFICATION_RETARGETING event. The method takes the |
153 // details of such an event and stores them for the later | 153 // details of such an event and stores them for the later |
154 // NOTIFICATION_TAB_ADDED event. | 154 // NOTIFICATION_TAB_ADDED event. |
155 void Retargeting(const RetargetingDetails* details); | 155 void Retargeting(const RetargetingDetails* details); |
156 | 156 |
157 // Handler for the NOTIFICATION_TAB_ADDED event. The method takes the details | 157 // Handler for the NOTIFICATION_TAB_ADDED event. The method takes the details |
158 // of such an event and creates a JSON formated extension event from it. | 158 // of such an event and creates a JSON formated extension event from it. |
159 void TabAdded(content::WebContents* tab); | 159 void TabAdded(content::WebContents* tab); |
160 | 160 |
161 // Handler for NOTIFICATION_WEB_CONTENTS_DESTROYED. If |tab| is in | 161 // Handler for NOTIFICATION_WEB_CONTENTS_DESTROYED. If |tab| is in |
162 // |pending_web_contents_|, it is removed. | 162 // |pending_web_contents_|, it is removed. |
163 void TabDestroyed(content::WebContents* tab); | 163 void TabDestroyed(content::WebContents* tab); |
164 | 164 |
165 // Mapping pointers to WebContents objects to information about how they got | 165 // Mapping pointers to WebContents objects to information about how they got |
166 // created. | 166 // created. |
167 std::map<content::WebContents*, PendingWebContents> pending_web_contents_; | 167 std::map<content::WebContents*, PendingWebContents> pending_web_contents_; |
168 | 168 |
169 // Used for tracking registrations to navigation notifications. | 169 // Used for tracking registrations to navigation notifications. |
170 content::NotificationRegistrar registrar_; | 170 content::NotificationRegistrar registrar_; |
171 | 171 |
172 // The profile that owns us via ExtensionService. | 172 // The profile that owns us via ExtensionService. |
173 Profile* profile_; | 173 Profile* profile_; |
174 | 174 |
| 175 BrowserTabStripTracker browser_tab_strip_tracker_; |
| 176 |
175 DISALLOW_COPY_AND_ASSIGN(WebNavigationEventRouter); | 177 DISALLOW_COPY_AND_ASSIGN(WebNavigationEventRouter); |
176 }; | 178 }; |
177 | 179 |
178 // API function that returns the state of a given frame. | 180 // API function that returns the state of a given frame. |
179 class WebNavigationGetFrameFunction : public ChromeSyncExtensionFunction { | 181 class WebNavigationGetFrameFunction : public ChromeSyncExtensionFunction { |
180 ~WebNavigationGetFrameFunction() override {} | 182 ~WebNavigationGetFrameFunction() override {} |
181 bool RunSync() override; | 183 bool RunSync() override; |
182 DECLARE_EXTENSION_FUNCTION("webNavigation.getFrame", WEBNAVIGATION_GETFRAME) | 184 DECLARE_EXTENSION_FUNCTION("webNavigation.getFrame", WEBNAVIGATION_GETFRAME) |
183 }; | 185 }; |
184 | 186 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 220 |
219 // Created lazily upon OnListenerAdded. | 221 // Created lazily upon OnListenerAdded. |
220 scoped_ptr<WebNavigationEventRouter> web_navigation_event_router_; | 222 scoped_ptr<WebNavigationEventRouter> web_navigation_event_router_; |
221 | 223 |
222 DISALLOW_COPY_AND_ASSIGN(WebNavigationAPI); | 224 DISALLOW_COPY_AND_ASSIGN(WebNavigationAPI); |
223 }; | 225 }; |
224 | 226 |
225 } // namespace extensions | 227 } // namespace extensions |
226 | 228 |
227 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_WEB_NAVIGATION_API_H_ | 229 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_WEB_NAVIGATION_API_H_ |
OLD | NEW |