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 #include "chrome/browser/external_tab/external_tab_container_win.h" | 5 #include "chrome/browser/external_tab/external_tab_container_win.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 tab_container = reinterpret_cast<ExternalTabContainer*>( | 348 tab_container = reinterpret_cast<ExternalTabContainer*>( |
349 ViewProp::GetValue(native_window, kWindowObjectKey)); | 349 ViewProp::GetValue(native_window, kWindowObjectKey)); |
350 } | 350 } |
351 return tab_container; | 351 return tab_container; |
352 } | 352 } |
353 //////////////////////////////////////////////////////////////////////////////// | 353 //////////////////////////////////////////////////////////////////////////////// |
354 // ExternalTabContainer, content::WebContentsDelegate implementation: | 354 // ExternalTabContainer, content::WebContentsDelegate implementation: |
355 | 355 |
356 WebContents* ExternalTabContainer::OpenURLFromTab(WebContents* source, | 356 WebContents* ExternalTabContainer::OpenURLFromTab(WebContents* source, |
357 const OpenURLParams& params) { | 357 const OpenURLParams& params) { |
358 if (pending()) { | 358 GURL referrer_url = GURL(WebSecurityPolicy::generateReferrerHeader( |
359 pending_open_url_requests_.push_back(params); | 359 params.referrer.policy, |
360 return NULL; | 360 params.url, |
| 361 WebString::fromUTF8(params.referrer.url.spec())).utf8()); |
| 362 content::Referrer referrer = content::Referrer(referrer_url, |
| 363 params.referrer.policy); |
| 364 return OpenUrlInExtenalHost(source, params.url, params.disposition, referrer); |
| 365 } |
| 366 |
| 367 bool ExternalTabContainer::ShouldIgnoreNavigation( |
| 368 WebContents* source, |
| 369 const GURL& url, |
| 370 const content::Referrer& referrer, |
| 371 WindowOpenDisposition disposition, |
| 372 bool is_content_initiated, |
| 373 content::PageTransition transition_type) { |
| 374 |
| 375 if (is_content_initiated) { |
| 376 OpenUrlInExtenalHost(source, url, disposition, referrer); |
| 377 return true; |
361 } | 378 } |
362 | 379 return false; |
363 switch (params.disposition) { | |
364 case CURRENT_TAB: | |
365 case SINGLETON_TAB: | |
366 case NEW_FOREGROUND_TAB: | |
367 case NEW_BACKGROUND_TAB: | |
368 case NEW_POPUP: | |
369 case NEW_WINDOW: | |
370 case SAVE_TO_DISK: | |
371 if (automation_) { | |
372 GURL referrer = GURL(WebSecurityPolicy::generateReferrerHeader( | |
373 params.referrer.policy, | |
374 params.url, | |
375 WebString::fromUTF8(params.referrer.url.spec())).utf8()); | |
376 automation_->Send(new AutomationMsg_OpenURL(tab_handle_, | |
377 params.url, | |
378 referrer, | |
379 params.disposition)); | |
380 // TODO(ananta) | |
381 // We should populate other fields in the | |
382 // ViewHostMsg_FrameNavigate_Params structure. Another option could be | |
383 // to refactor the UpdateHistoryForNavigation function in TabContents. | |
384 content::FrameNavigateParams nav_params; | |
385 nav_params.referrer = content::Referrer(referrer, | |
386 params.referrer.policy); | |
387 nav_params.url = params.url; | |
388 nav_params.page_id = -1; | |
389 nav_params.transition = content::PAGE_TRANSITION_LINK; | |
390 | |
391 content::LoadCommittedDetails details; | |
392 details.did_replace_entry = false; | |
393 | |
394 scoped_refptr<history::HistoryAddPageArgs> add_page_args( | |
395 tab_contents_->history_tab_helper()-> | |
396 CreateHistoryAddPageArgs(params.url, details, nav_params)); | |
397 tab_contents_->history_tab_helper()-> | |
398 UpdateHistoryForNavigation(add_page_args); | |
399 | |
400 return tab_contents_->web_contents(); | |
401 } | |
402 break; | |
403 default: | |
404 NOTREACHED(); | |
405 break; | |
406 } | |
407 | |
408 return NULL; | |
409 } | 380 } |
410 | 381 |
411 void ExternalTabContainer::NavigationStateChanged(const WebContents* source, | 382 void ExternalTabContainer::NavigationStateChanged(const WebContents* source, |
412 unsigned changed_flags) { | 383 unsigned changed_flags) { |
413 if (automation_) { | 384 if (automation_) { |
414 NavigationInfo nav_info; | 385 NavigationInfo nav_info; |
415 if (InitNavigationInfo(&nav_info, content::NAVIGATION_TYPE_NAV_IGNORE, 0)) | 386 if (InitNavigationInfo(&nav_info, content::NAVIGATION_TYPE_NAV_IGNORE, 0)) |
416 automation_->Send(new AutomationMsg_NavigationStateChanged( | 387 automation_->Send(new AutomationMsg_NavigationStateChanged( |
417 tab_handle_, changed_flags, nav_info)); | 388 tab_handle_, changed_flags, nav_info)); |
418 } | 389 } |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 ServicePendingOpenURLRequests(); | 1114 ServicePendingOpenURLRequests(); |
1144 } | 1115 } |
1145 | 1116 |
1146 void ExternalTabContainer::ServicePendingOpenURLRequests() { | 1117 void ExternalTabContainer::ServicePendingOpenURLRequests() { |
1147 DCHECK(pending()); | 1118 DCHECK(pending()); |
1148 | 1119 |
1149 set_pending(false); | 1120 set_pending(false); |
1150 | 1121 |
1151 for (size_t index = 0; index < pending_open_url_requests_.size(); | 1122 for (size_t index = 0; index < pending_open_url_requests_.size(); |
1152 ++index) { | 1123 ++index) { |
1153 const OpenURLParams& url_request = pending_open_url_requests_[index]; | 1124 const PendingOpenUrlRequest& url_request = |
1154 OpenURLFromTab(web_contents(), url_request); | 1125 pending_open_url_requests_[index]; |
| 1126 OpenUrlInExtenalHost(web_contents(), url_request.url, |
| 1127 url_request.disposition, url_request.referrer); |
1155 } | 1128 } |
1156 pending_open_url_requests_.clear(); | 1129 pending_open_url_requests_.clear(); |
1157 } | 1130 } |
1158 | 1131 |
1159 void ExternalTabContainer::SetupExternalTabView() { | 1132 void ExternalTabContainer::SetupExternalTabView() { |
1160 // Create a TabContentsContainer to handle focus cycling using Tab and | 1133 // Create a TabContentsContainer to handle focus cycling using Tab and |
1161 // Shift-Tab. | 1134 // Shift-Tab. |
1162 tab_contents_container_ = new TabContentsContainer; | 1135 tab_contents_container_ = new TabContentsContainer; |
1163 | 1136 |
1164 // The views created here will be destroyed when the ExternalTabContainer | 1137 // The views created here will be destroyed when the ExternalTabContainer |
(...skipping 17 matching lines...) Expand all Loading... |
1182 | 1155 |
1183 layout->StartRow(0, 0); | 1156 layout->StartRow(0, 0); |
1184 layout->AddView(info_bar_container); | 1157 layout->AddView(info_bar_container); |
1185 layout->StartRow(1, 0); | 1158 layout->StartRow(1, 0); |
1186 layout->AddView(tab_contents_container_); | 1159 layout->AddView(tab_contents_container_); |
1187 GetWidget()->SetContentsView(external_tab_view_); | 1160 GetWidget()->SetContentsView(external_tab_view_); |
1188 // Note that SetTabContents must be called after AddChildView is called | 1161 // Note that SetTabContents must be called after AddChildView is called |
1189 tab_contents_container_->ChangeWebContents(web_contents()); | 1162 tab_contents_container_->ChangeWebContents(web_contents()); |
1190 } | 1163 } |
1191 | 1164 |
| 1165 content::WebContents* ExternalTabContainer::OpenUrlInExtenalHost( |
| 1166 content::WebContents* source, |
| 1167 const GURL& url, |
| 1168 WindowOpenDisposition disposition, |
| 1169 const content::Referrer& referrer) { |
| 1170 |
| 1171 if (pending()) { |
| 1172 PendingOpenUrlRequest pending_request; |
| 1173 pending_request.url = url; |
| 1174 pending_request.disposition = disposition; |
| 1175 pending_request.referrer = referrer; |
| 1176 pending_open_url_requests_.push_back(pending_request); |
| 1177 return NULL; |
| 1178 } |
| 1179 |
| 1180 switch (disposition) { |
| 1181 case CURRENT_TAB: |
| 1182 case SINGLETON_TAB: |
| 1183 case NEW_FOREGROUND_TAB: |
| 1184 case NEW_BACKGROUND_TAB: |
| 1185 case NEW_POPUP: |
| 1186 case NEW_WINDOW: |
| 1187 case SAVE_TO_DISK: |
| 1188 if (automation_) { |
| 1189 automation_->Send(new AutomationMsg_OpenURL(tab_handle_, |
| 1190 url, |
| 1191 referrer.url, |
| 1192 disposition)); |
| 1193 // TODO(ananta) |
| 1194 // We should populate other fields in the |
| 1195 // ViewHostMsg_FrameNavigate_Params structure. Another option could be |
| 1196 // to refactor the UpdateHistoryForNavigation function in TabContents. |
| 1197 content::FrameNavigateParams nav_params; |
| 1198 nav_params.referrer = referrer; |
| 1199 nav_params.url = url; |
| 1200 nav_params.page_id = -1; |
| 1201 nav_params.transition = content::PAGE_TRANSITION_LINK; |
| 1202 |
| 1203 content::LoadCommittedDetails details; |
| 1204 details.did_replace_entry = false; |
| 1205 |
| 1206 scoped_refptr<history::HistoryAddPageArgs> add_page_args( |
| 1207 tab_contents_->history_tab_helper()-> |
| 1208 CreateHistoryAddPageArgs(url, details, nav_params)); |
| 1209 tab_contents_->history_tab_helper()-> |
| 1210 UpdateHistoryForNavigation(add_page_args); |
| 1211 |
| 1212 return tab_contents_->web_contents(); |
| 1213 } |
| 1214 break; |
| 1215 default: |
| 1216 NOTREACHED(); |
| 1217 break; |
| 1218 } |
| 1219 |
| 1220 return NULL; |
| 1221 } |
| 1222 |
1192 TemporaryPopupExternalTabContainer::TemporaryPopupExternalTabContainer( | 1223 TemporaryPopupExternalTabContainer::TemporaryPopupExternalTabContainer( |
1193 AutomationProvider* automation, | 1224 AutomationProvider* automation, |
1194 AutomationResourceMessageFilter* filter) | 1225 AutomationResourceMessageFilter* filter) |
1195 : ExternalTabContainer(automation, filter) { | 1226 : ExternalTabContainer(automation, filter) { |
1196 } | 1227 } |
1197 | 1228 |
1198 TemporaryPopupExternalTabContainer::~TemporaryPopupExternalTabContainer() { | 1229 TemporaryPopupExternalTabContainer::~TemporaryPopupExternalTabContainer() { |
1199 DVLOG(1) << __FUNCTION__; | 1230 DVLOG(1) << __FUNCTION__; |
1200 } | 1231 } |
1201 | 1232 |
1202 WebContents* TemporaryPopupExternalTabContainer::OpenURLFromTab( | 1233 WebContents* TemporaryPopupExternalTabContainer::OpenURLFromTab( |
1203 WebContents* source, | 1234 WebContents* source, |
1204 const OpenURLParams& params) { | 1235 const OpenURLParams& params) { |
1205 if (!automation_) | 1236 if (!automation_) |
1206 return NULL; | 1237 return NULL; |
1207 | 1238 |
1208 OpenURLParams forward_params = params; | 1239 OpenURLParams forward_params = params; |
1209 if (params.disposition == CURRENT_TAB) { | 1240 if (params.disposition == CURRENT_TAB) { |
1210 DCHECK(route_all_top_level_navigations_); | 1241 DCHECK(route_all_top_level_navigations_); |
1211 forward_params.disposition = NEW_FOREGROUND_TAB; | 1242 forward_params.disposition = NEW_FOREGROUND_TAB; |
1212 } | 1243 } |
1213 WebContents* new_contents = | 1244 WebContents* new_contents = |
1214 ExternalTabContainer::OpenURLFromTab(source, forward_params); | 1245 ExternalTabContainer::OpenURLFromTab(source, forward_params); |
1215 // support only one navigation for a dummy tab before it is killed. | 1246 // support only one navigation for a dummy tab before it is killed. |
1216 ::DestroyWindow(GetNativeView()); | 1247 ::DestroyWindow(GetNativeView()); |
1217 return new_contents; | 1248 return new_contents; |
1218 } | 1249 } |
OLD | NEW |