| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_container_win.h" | 5 #include "chrome/browser/external_tab_container_win.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" |
| 9 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 10 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 14 #include "base/win/win_util.h" | 15 #include "base/win/win_util.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/app/chrome_dll_resource.h" | 17 #include "chrome/app/chrome_dll_resource.h" |
| 17 #include "chrome/browser/automation/automation_provider.h" | 18 #include "chrome/browser/automation/automation_provider.h" |
| 18 #include "chrome/browser/debugger/devtools_toggle_action.h" | 19 #include "chrome/browser/debugger/devtools_toggle_action.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 ExternalTabContainer::ExternalTabContainer( | 96 ExternalTabContainer::ExternalTabContainer( |
| 96 AutomationProvider* automation, AutomationResourceMessageFilter* filter) | 97 AutomationProvider* automation, AutomationResourceMessageFilter* filter) |
| 97 : views::NativeWidgetWin(new views::Widget), | 98 : views::NativeWidgetWin(new views::Widget), |
| 98 automation_(automation), | 99 automation_(automation), |
| 99 tab_contents_container_(NULL), | 100 tab_contents_container_(NULL), |
| 100 tab_handle_(0), | 101 tab_handle_(0), |
| 101 ignore_next_load_notification_(false), | 102 ignore_next_load_notification_(false), |
| 102 automation_resource_message_filter_(filter), | 103 automation_resource_message_filter_(filter), |
| 103 load_requests_via_automation_(false), | 104 load_requests_via_automation_(false), |
| 104 handle_top_level_requests_(false), | 105 handle_top_level_requests_(false), |
| 105 external_method_factory_(this), | 106 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 106 pending_(false), | 107 pending_(false), |
| 107 focus_manager_(NULL), | 108 focus_manager_(NULL), |
| 108 external_tab_view_(NULL), | 109 external_tab_view_(NULL), |
| 109 unload_reply_message_(NULL), | 110 unload_reply_message_(NULL), |
| 110 route_all_top_level_navigations_(false), | 111 route_all_top_level_navigations_(false), |
| 111 is_popup_window_(false) { | 112 is_popup_window_(false) { |
| 112 } | 113 } |
| 113 | 114 |
| 114 ExternalTabContainer::~ExternalTabContainer() { | 115 ExternalTabContainer::~ExternalTabContainer() { |
| 115 Uninitialize(); | 116 Uninitialize(); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, | 192 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
| 192 content::NotificationService::AllSources()); | 193 content::NotificationService::AllSources()); |
| 193 | 194 |
| 194 TabContentsObserver::Observe(tab_contents_->tab_contents()); | 195 TabContentsObserver::Observe(tab_contents_->tab_contents()); |
| 195 | 196 |
| 196 // Start loading initial URL | 197 // Start loading initial URL |
| 197 if (!initial_url.is_empty()) { | 198 if (!initial_url.is_empty()) { |
| 198 // Navigate out of context since we don't have a 'tab_handle_' yet. | 199 // Navigate out of context since we don't have a 'tab_handle_' yet. |
| 199 MessageLoop::current()->PostTask( | 200 MessageLoop::current()->PostTask( |
| 200 FROM_HERE, | 201 FROM_HERE, |
| 201 external_method_factory_.NewRunnableMethod( | 202 base::Bind(&ExternalTabContainer::Navigate, weak_factory_.GetWeakPtr(), |
| 202 &ExternalTabContainer::Navigate, initial_url, referrer)); | 203 initial_url, referrer)); |
| 203 } | 204 } |
| 204 | 205 |
| 205 // We need WS_POPUP to be on the window during initialization, but | 206 // We need WS_POPUP to be on the window during initialization, but |
| 206 // once initialized we apply the requested style which may or may not | 207 // once initialized we apply the requested style which may or may not |
| 207 // include the popup bit. | 208 // include the popup bit. |
| 208 // Note that it's important to do this before we call SetParent since | 209 // Note that it's important to do this before we call SetParent since |
| 209 // during the SetParent call we will otherwise get a WA_ACTIVATE call | 210 // during the SetParent call we will otherwise get a WA_ACTIVATE call |
| 210 // that causes us to steal the current focus. | 211 // that causes us to steal the current focus. |
| 211 SetWindowLong(GWL_STYLE, (GetWindowLong(GWL_STYLE) & ~WS_POPUP) | style); | 212 SetWindowLong(GWL_STYLE, (GetWindowLong(GWL_STYLE) & ~WS_POPUP) | style); |
| 212 | 213 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if (!automation_provider || !filter) { | 256 if (!automation_provider || !filter) { |
| 256 NOTREACHED(); | 257 NOTREACHED(); |
| 257 return false; | 258 return false; |
| 258 } | 259 } |
| 259 | 260 |
| 260 automation_ = automation_provider; | 261 automation_ = automation_provider; |
| 261 automation_resource_message_filter_ = filter; | 262 automation_resource_message_filter_ = filter; |
| 262 // Wait for the automation channel to be initialized before resuming pending | 263 // Wait for the automation channel to be initialized before resuming pending |
| 263 // render views and sending in the navigation state. | 264 // render views and sending in the navigation state. |
| 264 MessageLoop::current()->PostTask( | 265 MessageLoop::current()->PostTask( |
| 265 FROM_HERE, | 266 FROM_HERE, base::Bind(&ExternalTabContainer::OnReinitialize, |
| 266 external_method_factory_.NewRunnableMethod( | 267 weak_factory_.GetWeakPtr())); |
| 267 &ExternalTabContainer::OnReinitialize)); | |
| 268 | 268 |
| 269 if (parent_window) | 269 if (parent_window) |
| 270 SetParent(GetNativeView(), parent_window); | 270 SetParent(GetNativeView(), parent_window); |
| 271 return true; | 271 return true; |
| 272 } | 272 } |
| 273 | 273 |
| 274 void ExternalTabContainer::SetTabHandle(int handle) { | 274 void ExternalTabContainer::SetTabHandle(int handle) { |
| 275 tab_handle_ = handle; | 275 tab_handle_ = handle; |
| 276 } | 276 } |
| 277 | 277 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 | 535 |
| 536 return true; | 536 return true; |
| 537 } | 537 } |
| 538 | 538 |
| 539 bool ExternalTabContainer::CanDownload(TabContents* source, int request_id) { | 539 bool ExternalTabContainer::CanDownload(TabContents* source, int request_id) { |
| 540 if (load_requests_via_automation_) { | 540 if (load_requests_via_automation_) { |
| 541 if (automation_) { | 541 if (automation_) { |
| 542 // In case the host needs to show UI that needs to take the focus. | 542 // In case the host needs to show UI that needs to take the focus. |
| 543 ::AllowSetForegroundWindow(ASFW_ANY); | 543 ::AllowSetForegroundWindow(ASFW_ANY); |
| 544 | 544 |
| 545 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 545 BrowserThread::PostTask( |
| 546 NewRunnableMethod(automation_resource_message_filter_.get(), | 546 BrowserThread::IO, FROM_HERE, |
| 547 base::IgnoreReturn<bool>(base::Bind( |
| 547 &AutomationResourceMessageFilter::SendDownloadRequestToHost, | 548 &AutomationResourceMessageFilter::SendDownloadRequestToHost, |
| 548 0, tab_handle_, request_id)); | 549 automation_resource_message_filter_.get(), 0, tab_handle_, |
| 550 request_id))); |
| 549 } | 551 } |
| 550 } else { | 552 } else { |
| 551 DLOG(WARNING) << "Downloads are only supported with host browser network " | 553 DLOG(WARNING) << "Downloads are only supported with host browser network " |
| 552 "stack enabled."; | 554 "stack enabled."; |
| 553 } | 555 } |
| 554 | 556 |
| 555 // Never allow downloads. | 557 // Never allow downloads. |
| 556 return false; | 558 return false; |
| 557 } | 559 } |
| 558 | 560 |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 if (params.disposition == CURRENT_TAB) { | 1177 if (params.disposition == CURRENT_TAB) { |
| 1176 DCHECK(route_all_top_level_navigations_); | 1178 DCHECK(route_all_top_level_navigations_); |
| 1177 forward_params.disposition = NEW_FOREGROUND_TAB; | 1179 forward_params.disposition = NEW_FOREGROUND_TAB; |
| 1178 } | 1180 } |
| 1179 TabContents* new_contents = | 1181 TabContents* new_contents = |
| 1180 ExternalTabContainer::OpenURLFromTab(source, forward_params); | 1182 ExternalTabContainer::OpenURLFromTab(source, forward_params); |
| 1181 // support only one navigation for a dummy tab before it is killed. | 1183 // support only one navigation for a dummy tab before it is killed. |
| 1182 ::DestroyWindow(GetNativeView()); | 1184 ::DestroyWindow(GetNativeView()); |
| 1183 return new_contents; | 1185 return new_contents; |
| 1184 } | 1186 } |
| OLD | NEW |