OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/automation/automation_provider.h" | 5 #include "chrome/browser/automation/automation_provider.h" |
6 | 6 |
7 #include "chrome/browser/automation/ui_controls.h" | 7 #include "chrome/browser/automation/ui_controls.h" |
8 #include "chrome/browser/browser_window.h" | 8 #include "chrome/browser/browser_window.h" |
9 #include "chrome/browser/external_tab_container.h" | 9 #include "chrome/browser/external_tab_container.h" |
10 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 328 } |
329 } | 329 } |
330 | 330 |
331 void AutomationProvider::CreateExternalTab( | 331 void AutomationProvider::CreateExternalTab( |
332 const IPC::ExternalTabSettings& settings, | 332 const IPC::ExternalTabSettings& settings, |
333 gfx::NativeWindow* tab_container_window, gfx::NativeWindow* tab_window, | 333 gfx::NativeWindow* tab_container_window, gfx::NativeWindow* tab_window, |
334 int* tab_handle) { | 334 int* tab_handle) { |
335 *tab_handle = 0; | 335 *tab_handle = 0; |
336 *tab_container_window = NULL; | 336 *tab_container_window = NULL; |
337 *tab_window = NULL; | 337 *tab_window = NULL; |
338 ExternalTabContainer* external_tab_container = | 338 scoped_refptr<ExternalTabContainer> external_tab_container = |
339 new ExternalTabContainer(this, automation_resource_message_filter_); | 339 new ExternalTabContainer(this, automation_resource_message_filter_); |
| 340 |
340 Profile* profile = settings.is_off_the_record ? | 341 Profile* profile = settings.is_off_the_record ? |
341 profile_->GetOffTheRecordProfile() : profile_; | 342 profile_->GetOffTheRecordProfile() : profile_; |
| 343 |
| 344 // When the ExternalTabContainer window is created we grab a reference on it |
| 345 // which is released when the window is destroyed. |
342 external_tab_container->Init(profile, settings.parent, settings.dimensions, | 346 external_tab_container->Init(profile, settings.parent, settings.dimensions, |
343 settings.style, settings.load_requests_via_automation, | 347 settings.style, settings.load_requests_via_automation, |
344 settings.handle_top_level_requests, NULL); | 348 settings.handle_top_level_requests, NULL); |
345 | 349 |
346 if (AddExternalTab(external_tab_container)) { | 350 if (AddExternalTab(external_tab_container)) { |
347 TabContents* tab_contents = external_tab_container->tab_contents(); | 351 TabContents* tab_contents = external_tab_container->tab_contents(); |
348 *tab_handle = external_tab_container->tab_handle(); | 352 *tab_handle = external_tab_container->tab_handle(); |
349 external_tab_container->set_tab_handle(*tab_handle); | 353 external_tab_container->set_tab_handle(*tab_handle); |
350 *tab_container_window = external_tab_container->GetNativeView(); | 354 *tab_container_window = external_tab_container->GetNativeView(); |
351 *tab_window = tab_contents->GetNativeView(); | 355 *tab_window = tab_contents->GetNativeView(); |
352 } else { | 356 } else { |
353 delete external_tab_container; | 357 external_tab_container->Uninitialize(); |
354 } | 358 } |
355 } | 359 } |
356 | 360 |
357 bool AutomationProvider::AddExternalTab(ExternalTabContainer* external_tab) { | 361 bool AutomationProvider::AddExternalTab(ExternalTabContainer* external_tab) { |
358 DCHECK(external_tab != NULL); | 362 DCHECK(external_tab != NULL); |
359 | 363 |
360 TabContents* tab_contents = external_tab->tab_contents(); | 364 TabContents* tab_contents = external_tab->tab_contents(); |
361 if (tab_contents) { | 365 if (tab_contents) { |
362 int tab_handle = tab_tracker_->Add(&tab_contents->controller()); | 366 int tab_handle = tab_tracker_->Add(&tab_contents->controller()); |
363 external_tab->set_tab_handle(tab_handle); | 367 external_tab->set_tab_handle(tab_handle); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 | 448 |
445 TabContents* tab_contents = tab->tab_contents(); | 449 TabContents* tab_contents = tab->tab_contents(); |
446 if (!tab_contents || !tab_contents->delegate()) { | 450 if (!tab_contents || !tab_contents->delegate()) { |
447 NOTREACHED(); | 451 NOTREACHED(); |
448 return; | 452 return; |
449 } | 453 } |
450 | 454 |
451 tab_contents->delegate()->ExecuteContextMenuCommand(command); | 455 tab_contents->delegate()->ExecuteContextMenuCommand(command); |
452 } | 456 } |
453 } | 457 } |
| 458 |
| 459 void AutomationProvider::ConnectExternalTab( |
| 460 intptr_t cookie, |
| 461 gfx::NativeWindow* tab_container_window, |
| 462 gfx::NativeWindow* tab_window, |
| 463 int* tab_handle) { |
| 464 *tab_handle = 0; |
| 465 *tab_container_window = NULL; |
| 466 *tab_window = NULL; |
| 467 |
| 468 scoped_refptr<ExternalTabContainer> external_tab_container = |
| 469 ExternalTabContainer::RemovePendingTab(cookie); |
| 470 if (!external_tab_container.get()) { |
| 471 NOTREACHED(); |
| 472 return; |
| 473 } |
| 474 |
| 475 if (AddExternalTab(external_tab_container)) { |
| 476 external_tab_container->Reinitialize(this, |
| 477 automation_resource_message_filter_); |
| 478 TabContents* tab_contents = external_tab_container->tab_contents(); |
| 479 *tab_handle = external_tab_container->tab_handle(); |
| 480 external_tab_container->set_tab_handle(*tab_handle); |
| 481 *tab_container_window = external_tab_container->GetNativeView(); |
| 482 *tab_window = tab_contents->GetNativeView(); |
| 483 } else { |
| 484 external_tab_container->Uninitialize(); |
| 485 } |
| 486 } |
| 487 |
OLD | NEW |