diff options
author | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-14 22:39:01 +0000 |
---|---|---|
committer | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-14 22:39:01 +0000 |
commit | a50a4905eba14504880c53952c37d5a6081cb1ef (patch) | |
tree | 8eaa81c77e66ecc26195124cdc3471501804e6f0 /chrome | |
parent | 1c13aa8dc0a48cdbcfb76a3ed91d096a7f768946 (diff) | |
download | chromium_src-a50a4905eba14504880c53952c37d5a6081cb1ef.zip chromium_src-a50a4905eba14504880c53952c37d5a6081cb1ef.tar.gz chromium_src-a50a4905eba14504880c53952c37d5a6081cb1ef.tar.bz2 |
Added support in the ExternalTabContainer for handling the NEW_FOREGROUND_TAB and NEW_BACKGROUND_TAB dispositions in its implementation of TabContents::AddNewContents. These dispositions are handled by creating a new ExternalTabContainer instance, attaching it to the automation provider and sending off the AutomationMsg_AttachExternalTab IPC to the automation client requesting it to attach to the newly created tab.
This fixes bug http://b/issue?id=2050347
Bug=2050347
Review URL: http://codereview.chromium.org/164530
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23483 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 23 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.h | 3 | ||||
-rw-r--r-- | chrome/browser/external_tab_container.cc | 64 | ||||
-rw-r--r-- | chrome/browser/external_tab_container.h | 10 | ||||
-rw-r--r-- | chrome/test/automation/automation_messages_internal.h | 7 |
5 files changed, 90 insertions, 17 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 5cbecf8..2e6a186 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -2390,10 +2390,11 @@ void AutomationProvider::CreateExternalTab( profile_->GetOffTheRecordProfile() : profile_; external_tab_container->Init(profile, settings.parent, settings.dimensions, settings.style, settings.load_requests_via_automation, - settings.handle_top_level_requests); - TabContents* tab_contents = external_tab_container->tab_contents(); - if (tab_contents) { - *tab_handle = tab_tracker_->Add(&tab_contents->controller()); + settings.handle_top_level_requests, NULL); + + if (AddExternalTab(external_tab_container)) { + TabContents* tab_contents = external_tab_container->tab_contents(); + *tab_handle = external_tab_container->tab_handle(); external_tab_container->set_tab_handle(*tab_handle); *tab_container_window = external_tab_container->GetNativeView(); *tab_window = tab_contents->GetNativeView(); @@ -2401,6 +2402,20 @@ void AutomationProvider::CreateExternalTab( delete external_tab_container; } } + +bool AutomationProvider::AddExternalTab(ExternalTabContainer* external_tab) { + DCHECK(external_tab != NULL); + + TabContents* tab_contents = external_tab->tab_contents(); + if (tab_contents) { + int tab_handle = tab_tracker_->Add(&tab_contents->controller()); + external_tab->set_tab_handle(tab_handle); + return true; + } + + return false; +} + #endif void AutomationProvider::NavigateInExternalTab( diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index 55735b6..bdd1c87 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -134,6 +134,9 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, return reply_message; } + // Adds the external tab passed in to the tab tracker. + bool AddExternalTab(ExternalTabContainer* external_tab); + private: // IPC Message callbacks. void CloseBrowser(int handle, IPC::Message* reply_message); diff --git a/chrome/browser/external_tab_container.cc b/chrome/browser/external_tab_container.cc index fb593c8..69df25e 100644 --- a/chrome/browser/external_tab_container.cc +++ b/chrome/browser/external_tab_container.cc @@ -35,7 +35,8 @@ ExternalTabContainer::ExternalTabContainer( tab_handle_(0), ignore_next_load_notification_(false), automation_resource_message_filter_(filter), - load_requests_via_automation_(false) { + load_requests_via_automation_(false), + handle_top_level_requests_(false) { } ExternalTabContainer::~ExternalTabContainer() { @@ -47,13 +48,15 @@ bool ExternalTabContainer::Init(Profile* profile, const gfx::Rect& bounds, DWORD style, bool load_requests_via_automation, - bool handle_top_level_requests) { + bool handle_top_level_requests, + TabContents* existing_contents) { if (IsWindow()) { NOTREACHED(); return false; } load_requests_via_automation_ = load_requests_via_automation; + handle_top_level_requests_ = handle_top_level_requests; set_window_style(WS_POPUP | WS_CLIPCHILDREN); views::WidgetWin::Init(NULL, bounds); @@ -82,12 +85,19 @@ bool ExternalTabContainer::Init(Profile* profile, profile = automation_profile_.get(); } - tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL); + if (existing_contents) + tab_contents_ = existing_contents; + else + tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL); + tab_contents_->set_delegate(this); tab_contents_->GetMutableRendererPrefs()->browser_handles_top_level_requests = handle_top_level_requests; - tab_contents_->render_view_host()->AllowBindings( - BindingsPolicy::EXTERNAL_HOST); + + if (!existing_contents) { + tab_contents_->render_view_host()->AllowBindings( + BindingsPolicy::EXTERNAL_HOST); + } // Create a TabContentsContainer to handle focus cycling using Tab and // Shift-Tab. @@ -208,13 +218,43 @@ void ExternalTabContainer::AddNewContents(TabContents* source, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture) { - if (disposition == NEW_POPUP || disposition == NEW_WINDOW || - disposition == NEW_FOREGROUND_TAB) { - Browser::BuildPopupWindowHelper(source, new_contents, initial_pos, - Browser::TYPE_POPUP, - tab_contents_->profile(), true); - } else { - NOTREACHED(); + switch (disposition) { + case NEW_POPUP: + case NEW_WINDOW: { + Browser::BuildPopupWindowHelper(source, new_contents, initial_pos, + Browser::TYPE_POPUP, + tab_contents_->profile(), true); + break; + } + + case NEW_FOREGROUND_TAB: + case NEW_BACKGROUND_TAB: { + DCHECK(automation_ != NULL); + + ExternalTabContainer* new_container = + new ExternalTabContainer(automation_, + automation_resource_message_filter_); + bool result = new_container->Init(automation_profile_.get(), + NULL, + initial_pos, + WS_CHILD, + load_requests_via_automation_, + handle_top_level_requests_, + new_contents); + DCHECK(result); + result = automation_->AddExternalTab(new_container); + DCHECK(result); + + automation_->Send(new AutomationMsg_AttachExternalTab( + 0, tab_handle_, new_container->tab_handle(), + new_container->GetNativeView(), new_contents->GetNativeView(), + disposition)); + break; + } + + default: + NOTREACHED(); + break; } } diff --git a/chrome/browser/external_tab_container.h b/chrome/browser/external_tab_container.h index cfee279..f51761a 100644 --- a/chrome/browser/external_tab_container.h +++ b/chrome/browser/external_tab_container.h @@ -42,12 +42,17 @@ class ExternalTabContainer : public TabContentsDelegate, automation_profile_->set_tab_handle(handle); } + int tab_handle() const { + return tab_handle_; + } + bool Init(Profile* profile, HWND parent, const gfx::Rect& bounds, DWORD style, bool load_requests_via_automation, - bool handle_top_level_requests); + bool handle_top_level_requests, + TabContents* existing_tab_contents); // This is invoked when the external host reflects back to us a keyboard // message it did not process @@ -160,6 +165,9 @@ class ExternalTabContainer : public TabContentsDelegate, // If all the url requests for this tab are to be loaded via automation. bool load_requests_via_automation_; + // whether top level URL requests are to be handled by the automation client. + bool handle_top_level_requests_; + // Scoped browser object for this ExternalTabContainer instance. scoped_ptr<Browser> browser_; diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h index 46bb160..cb7d769 100644 --- a/chrome/test/automation/automation_messages_internal.h +++ b/chrome/test/automation/automation_messages_internal.h @@ -993,6 +993,13 @@ IPC_BEGIN_MESSAGES(Automation) IPC_SYNC_MESSAGE_ROUTED0_1(AutomationMsg_GetFilteredInetHitCount, int /* hit_count */) + IPC_MESSAGE_ROUTED5(AutomationMsg_AttachExternalTab, + int /* tab_handle */, + int /* existing_tab_handle */, + gfx::NativeWindow /* Tab container window */, + gfx::NativeWindow /* Tab window */, + int /* disposition */) + #if defined(OS_LINUX) || defined(OS_MACOSX) // See previous definition of this message for explanation of why it is // defined twice. |