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 // Implements the Chrome Extensions WebNavigation API. | 5 // Implements the Chrome Extensions WebNavigation API. |
6 | 6 |
7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" | 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" | 10 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" |
11 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper
s.h" | 11 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper
s.h" |
12 #include "chrome/browser/extensions/event_router.h" | 12 #include "chrome/browser/extensions/event_router.h" |
13 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
14 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/tab_contents/retargeting_details.h" | 16 #include "chrome/browser/tab_contents/retargeting_details.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_iterator.h" | 18 #include "chrome/browser/ui/browser_iterator.h" |
19 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
20 #include "chrome/browser/view_type_utils.h" | |
21 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/common/extensions/api/web_navigation.h" | 21 #include "chrome/common/extensions/api/web_navigation.h" |
23 #include "content/public/browser/navigation_details.h" | 22 #include "content/public/browser/navigation_details.h" |
24 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
26 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
27 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
28 #include "content/public/browser/resource_request_details.h" | 27 #include "content/public/browser/resource_request_details.h" |
29 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
30 #include "content/public/common/url_constants.h" | 29 #include "content/public/common/url_constants.h" |
| 30 #include "extensions/browser/view_type_utils.h" |
31 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
32 | 32 |
33 namespace GetFrame = extensions::api::web_navigation::GetFrame; | 33 namespace GetFrame = extensions::api::web_navigation::GetFrame; |
34 namespace GetAllFrames = extensions::api::web_navigation::GetAllFrames; | 34 namespace GetAllFrames = extensions::api::web_navigation::GetAllFrames; |
35 | 35 |
36 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::WebNavigationTabObserver); | 36 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::WebNavigationTabObserver); |
37 | 37 |
38 namespace extensions { | 38 namespace extensions { |
39 | 39 |
40 namespace helpers = web_navigation_api_helpers; | 40 namespace helpers = web_navigation_api_helpers; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 void WebNavigationEventRouter::TabReplacedAt( | 112 void WebNavigationEventRouter::TabReplacedAt( |
113 TabStripModel* tab_strip_model, | 113 TabStripModel* tab_strip_model, |
114 content::WebContents* old_contents, | 114 content::WebContents* old_contents, |
115 content::WebContents* new_contents, | 115 content::WebContents* new_contents, |
116 int index) { | 116 int index) { |
117 WebNavigationTabObserver* tab_observer = | 117 WebNavigationTabObserver* tab_observer = |
118 WebNavigationTabObserver::Get(old_contents); | 118 WebNavigationTabObserver::Get(old_contents); |
119 if (!tab_observer) { | 119 if (!tab_observer) { |
120 // If you hit this DCHECK(), please add reproduction steps to | 120 // If you hit this DCHECK(), please add reproduction steps to |
121 // http://crbug.com/109464. | 121 // http://crbug.com/109464. |
122 DCHECK(chrome::GetViewType(old_contents) != chrome::VIEW_TYPE_TAB_CONTENTS); | 122 DCHECK(GetViewType(old_contents) != VIEW_TYPE_TAB_CONTENTS); |
123 return; | 123 return; |
124 } | 124 } |
125 const FrameNavigationState& frame_navigation_state = | 125 const FrameNavigationState& frame_navigation_state = |
126 tab_observer->frame_navigation_state(); | 126 tab_observer->frame_navigation_state(); |
127 | 127 |
128 if (!frame_navigation_state.IsValidUrl(old_contents->GetURL()) || | 128 if (!frame_navigation_state.IsValidUrl(old_contents->GetURL()) || |
129 !frame_navigation_state.IsValidUrl(new_contents->GetURL())) | 129 !frame_navigation_state.IsValidUrl(new_contents->GetURL())) |
130 return; | 130 return; |
131 | 131 |
132 helpers::DispatchOnTabReplaced(old_contents, profile_, new_contents); | 132 helpers::DispatchOnTabReplaced(old_contents, profile_, new_contents); |
(...skipping 27 matching lines...) Expand all Loading... |
160 } | 160 } |
161 | 161 |
162 void WebNavigationEventRouter::Retargeting(const RetargetingDetails* details) { | 162 void WebNavigationEventRouter::Retargeting(const RetargetingDetails* details) { |
163 if (details->source_frame_id == 0) | 163 if (details->source_frame_id == 0) |
164 return; | 164 return; |
165 WebNavigationTabObserver* tab_observer = | 165 WebNavigationTabObserver* tab_observer = |
166 WebNavigationTabObserver::Get(details->source_web_contents); | 166 WebNavigationTabObserver::Get(details->source_web_contents); |
167 if (!tab_observer) { | 167 if (!tab_observer) { |
168 // If you hit this DCHECK(), please add reproduction steps to | 168 // If you hit this DCHECK(), please add reproduction steps to |
169 // http://crbug.com/109464. | 169 // http://crbug.com/109464. |
170 DCHECK(chrome::GetViewType(details->source_web_contents) != | 170 DCHECK(GetViewType(details->source_web_contents) != VIEW_TYPE_TAB_CONTENTS); |
171 chrome::VIEW_TYPE_TAB_CONTENTS); | |
172 return; | 171 return; |
173 } | 172 } |
174 const FrameNavigationState& frame_navigation_state = | 173 const FrameNavigationState& frame_navigation_state = |
175 tab_observer->frame_navigation_state(); | 174 tab_observer->frame_navigation_state(); |
176 | 175 |
177 FrameNavigationState::FrameID frame_id( | 176 FrameNavigationState::FrameID frame_id( |
178 details->source_frame_id, | 177 details->source_frame_id, |
179 details->source_web_contents->GetRenderViewHost()); | 178 details->source_web_contents->GetRenderViewHost()); |
180 if (!frame_navigation_state.CanSendEvents(frame_id)) | 179 if (!frame_navigation_state.CanSendEvents(frame_id)) |
181 return; | 180 return; |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 | 814 |
816 static base::LazyInstance<ProfileKeyedAPIFactory<WebNavigationAPI> > | 815 static base::LazyInstance<ProfileKeyedAPIFactory<WebNavigationAPI> > |
817 g_factory = LAZY_INSTANCE_INITIALIZER; | 816 g_factory = LAZY_INSTANCE_INITIALIZER; |
818 | 817 |
819 // static | 818 // static |
820 ProfileKeyedAPIFactory<WebNavigationAPI>* | 819 ProfileKeyedAPIFactory<WebNavigationAPI>* |
821 WebNavigationAPI::GetFactoryInstance() { | 820 WebNavigationAPI::GetFactoryInstance() { |
822 return &g_factory.Get(); | 821 return &g_factory.Get(); |
823 } | 822 } |
824 | 823 |
825 void WebNavigationAPI::OnListenerAdded( | 824 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) { |
826 const extensions::EventListenerInfo& details) { | |
827 web_navigation_event_router_.reset(new WebNavigationEventRouter(profile_)); | 825 web_navigation_event_router_.reset(new WebNavigationEventRouter(profile_)); |
828 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 826 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
829 } | 827 } |
830 | 828 |
831 } // namespace extensions | 829 } // namespace extensions |
OLD | NEW |