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 "base/macros.h" | 15 #include "base/macros.h" |
16 #include "chrome/browser/extensions/api/web_navigation/frame_navigation_state.h" | 16 #include "chrome/browser/extensions/api/web_navigation/frame_navigation_state.h" |
17 #include "chrome/browser/extensions/chrome_extension_function.h" | 17 #include "chrome/browser/extensions/chrome_extension_function.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/browser_tab_strip_tracker.h" | 19 #include "chrome/browser/ui/browser_tab_strip_tracker.h" |
20 #include "chrome/browser/ui/browser_tab_strip_tracker_delegate.h" | 20 #include "chrome/browser/ui/browser_tab_strip_tracker_delegate.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
23 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
24 #include "content/public/browser/web_contents_observer.h" | 24 #include "content/public/browser/web_contents_observer.h" |
25 #include "content/public/browser/web_contents_user_data.h" | 25 #include "content/public/browser/web_contents_user_data.h" |
26 #include "extensions/browser/browser_context_keyed_api_factory.h" | 26 #include "extensions/browser/browser_context_keyed_api_factory.h" |
27 #include "extensions/browser/event_router.h" | 27 #include "extensions/browser/event_router.h" |
28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
29 | 29 |
30 struct RetargetingDetails; | |
31 | |
32 namespace extensions { | 30 namespace extensions { |
33 | 31 |
34 // Tab contents observer that forwards navigation events to the event router. | 32 // Tab contents observer that forwards navigation events to the event router. |
35 class WebNavigationTabObserver | 33 class WebNavigationTabObserver |
36 : public content::WebContentsObserver, | 34 : public content::WebContentsObserver, |
37 public content::WebContentsUserData<WebNavigationTabObserver> { | 35 public content::WebContentsUserData<WebNavigationTabObserver> { |
38 public: | 36 public: |
39 ~WebNavigationTabObserver() override; | 37 ~WebNavigationTabObserver() override; |
40 | 38 |
41 // Returns the object for the given |web_contents|. | 39 // Returns the object for the given |web_contents|. |
(...skipping 20 matching lines...) Expand all Loading... |
62 const GURL& validated_url, | 60 const GURL& validated_url, |
63 int error_code, | 61 int error_code, |
64 const base::string16& error_description, | 62 const base::string16& error_description, |
65 bool was_ignored_by_handler) override; | 63 bool was_ignored_by_handler) override; |
66 void DidOpenRequestedURL(content::WebContents* new_contents, | 64 void DidOpenRequestedURL(content::WebContents* new_contents, |
67 content::RenderFrameHost* source_render_frame_host, | 65 content::RenderFrameHost* source_render_frame_host, |
68 const GURL& url, | 66 const GURL& url, |
69 const content::Referrer& referrer, | 67 const content::Referrer& referrer, |
70 WindowOpenDisposition disposition, | 68 WindowOpenDisposition disposition, |
71 ui::PageTransition transition, | 69 ui::PageTransition transition, |
72 bool started_from_context_menu) override; | 70 bool started_from_context_menu, |
| 71 bool renderer_initiated) override; |
73 void WebContentsDestroyed() override; | 72 void WebContentsDestroyed() override; |
74 | 73 |
75 // This method dispatches the already created onBeforeNavigate event. | 74 // This method dispatches the already created onBeforeNavigate event. |
76 void DispatchCachedOnBeforeNavigate(); | 75 void DispatchCachedOnBeforeNavigate(); |
77 | 76 |
78 private: | 77 private: |
79 explicit WebNavigationTabObserver(content::WebContents* web_contents); | 78 explicit WebNavigationTabObserver(content::WebContents* web_contents); |
80 friend class content::WebContentsUserData<WebNavigationTabObserver>; | 79 friend class content::WebContentsUserData<WebNavigationTabObserver>; |
81 | 80 |
82 void HandleCommit(content::NavigationHandle* navigation_handle); | 81 void HandleCommit(content::NavigationHandle* navigation_handle); |
(...skipping 29 matching lines...) Expand all Loading... |
112 | 111 |
113 // Observes navigation notifications and routes them as events to the extension | 112 // Observes navigation notifications and routes them as events to the extension |
114 // system. | 113 // system. |
115 class WebNavigationEventRouter : public TabStripModelObserver, | 114 class WebNavigationEventRouter : public TabStripModelObserver, |
116 public BrowserTabStripTrackerDelegate, | 115 public BrowserTabStripTrackerDelegate, |
117 public content::NotificationObserver { | 116 public content::NotificationObserver { |
118 public: | 117 public: |
119 explicit WebNavigationEventRouter(Profile* profile); | 118 explicit WebNavigationEventRouter(Profile* profile); |
120 ~WebNavigationEventRouter() override; | 119 ~WebNavigationEventRouter() override; |
121 | 120 |
| 121 // Router level handler for the creation of WebContents. Stores information |
| 122 // about the newly created WebContents. This information is later used when |
| 123 // the WebContents for the tab is added to the tabstrip and we receive the |
| 124 // TAB_ADDED notification. |
| 125 void RecordNewWebContents(content::WebContents* source_web_contents, |
| 126 int source_render_process_id, |
| 127 int source_render_frame_id, |
| 128 GURL target_url, |
| 129 content::WebContents* target_web_contents, |
| 130 bool not_yet_in_tabstrip); |
| 131 |
122 private: | 132 private: |
123 // Used to cache the information about newly created WebContents objects. | 133 // Used to cache the information about newly created WebContents objects. |
124 struct PendingWebContents{ | 134 struct PendingWebContents{ |
125 PendingWebContents(); | 135 PendingWebContents(); |
126 PendingWebContents(content::WebContents* source_web_contents, | 136 PendingWebContents(content::WebContents* source_web_contents, |
127 content::RenderFrameHost* source_frame_host, | 137 content::RenderFrameHost* source_frame_host, |
128 content::WebContents* target_web_contents, | 138 content::WebContents* target_web_contents, |
129 const GURL& target_url); | 139 const GURL& target_url); |
130 ~PendingWebContents(); | 140 ~PendingWebContents(); |
131 | 141 |
(...skipping 10 matching lines...) Expand all Loading... |
142 void TabReplacedAt(TabStripModel* tab_strip_model, | 152 void TabReplacedAt(TabStripModel* tab_strip_model, |
143 content::WebContents* old_contents, | 153 content::WebContents* old_contents, |
144 content::WebContents* new_contents, | 154 content::WebContents* new_contents, |
145 int index) override; | 155 int index) override; |
146 | 156 |
147 // content::NotificationObserver implementation. | 157 // content::NotificationObserver implementation. |
148 void Observe(int type, | 158 void Observe(int type, |
149 const content::NotificationSource& source, | 159 const content::NotificationSource& source, |
150 const content::NotificationDetails& details) override; | 160 const content::NotificationDetails& details) override; |
151 | 161 |
152 // Handler for the NOTIFICATION_RETARGETING event. The method takes the | |
153 // details of such an event and stores them for the later | |
154 // NOTIFICATION_TAB_ADDED event. | |
155 void Retargeting(const RetargetingDetails* details); | |
156 | |
157 // Handler for the NOTIFICATION_TAB_ADDED event. The method takes the details | 162 // 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. | 163 // of such an event and creates a JSON formated extension event from it. |
159 void TabAdded(content::WebContents* tab); | 164 void TabAdded(content::WebContents* tab); |
160 | 165 |
161 // Handler for NOTIFICATION_WEB_CONTENTS_DESTROYED. If |tab| is in | 166 // Handler for NOTIFICATION_WEB_CONTENTS_DESTROYED. If |tab| is in |
162 // |pending_web_contents_|, it is removed. | 167 // |pending_web_contents_|, it is removed. |
163 void TabDestroyed(content::WebContents* tab); | 168 void TabDestroyed(content::WebContents* tab); |
164 | 169 |
165 // Mapping pointers to WebContents objects to information about how they got | 170 // Mapping pointers to WebContents objects to information about how they got |
166 // created. | 171 // created. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 void Shutdown() override; | 207 void Shutdown() override; |
203 | 208 |
204 // BrowserContextKeyedAPI implementation. | 209 // BrowserContextKeyedAPI implementation. |
205 static BrowserContextKeyedAPIFactory<WebNavigationAPI>* GetFactoryInstance(); | 210 static BrowserContextKeyedAPIFactory<WebNavigationAPI>* GetFactoryInstance(); |
206 | 211 |
207 // EventRouter::Observer implementation. | 212 // EventRouter::Observer implementation. |
208 void OnListenerAdded(const extensions::EventListenerInfo& details) override; | 213 void OnListenerAdded(const extensions::EventListenerInfo& details) override; |
209 | 214 |
210 private: | 215 private: |
211 friend class BrowserContextKeyedAPIFactory<WebNavigationAPI>; | 216 friend class BrowserContextKeyedAPIFactory<WebNavigationAPI>; |
| 217 friend class WebNavigationTabObserver; |
212 | 218 |
213 content::BrowserContext* browser_context_; | 219 content::BrowserContext* browser_context_; |
214 | 220 |
215 // BrowserContextKeyedAPI implementation. | 221 // BrowserContextKeyedAPI implementation. |
216 static const char* service_name() { | 222 static const char* service_name() { |
217 return "WebNavigationAPI"; | 223 return "WebNavigationAPI"; |
218 } | 224 } |
| 225 static const bool kServiceRedirectedInIncognito = true; |
219 static const bool kServiceIsNULLWhileTesting = true; | 226 static const bool kServiceIsNULLWhileTesting = true; |
220 | 227 |
221 // Created lazily upon OnListenerAdded. | 228 // Created lazily upon OnListenerAdded. |
222 std::unique_ptr<WebNavigationEventRouter> web_navigation_event_router_; | 229 std::unique_ptr<WebNavigationEventRouter> web_navigation_event_router_; |
223 | 230 |
224 DISALLOW_COPY_AND_ASSIGN(WebNavigationAPI); | 231 DISALLOW_COPY_AND_ASSIGN(WebNavigationAPI); |
225 }; | 232 }; |
226 | 233 |
227 } // namespace extensions | 234 } // namespace extensions |
228 | 235 |
229 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_WEB_NAVIGATION_API_H_ | 236 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_NAVIGATION_WEB_NAVIGATION_API_H_ |
OLD | NEW |