From 534c66c7338db94220b0f5995b299415d99e918e Mon Sep 17 00:00:00 2001 From: "rafaelw@chromium.org" Date: Wed, 28 Apr 2010 22:53:11 +0000 Subject: This is the second side of a multi-sided webkit patch that will allow experimental window.open feature strings to be captured and passed to the client. It should wait for: https://bugs.webkit.org/show_bug.cgi?id=38013 to land. This is required because this patch needs to use the WebWindowFeature binding struct in WebKit. Once this is landed, a webkit patch to change the call signature for WebViewClient::createView to include the WebWindowFeatures will be submitted (and after that another chromium patch to remove the old call signature). This patch implements old and new WebViewClient::createView signatures, and additionally passes the vector all the way to RenderViewHostDelegateHelper who will eventually use it to observe the 'background' feature. BUG=41275 TEST=all tests should pass Review URL: http://codereview.chromium.org/1758004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45877 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/extensions/extension_host.cc | 7 ++-- chrome/browser/extensions/extension_host.h | 4 ++- chrome/browser/notifications/balloon_host.cc | 7 ++-- chrome/browser/notifications/balloon_host.h | 4 ++- chrome/browser/renderer_host/render_view_host.cc | 6 ++-- chrome/browser/renderer_host/render_view_host.h | 4 ++- .../renderer_host/render_view_host_delegate.h | 8 ++++- .../browser/renderer_host/render_widget_helper.cc | 20 +++++++---- .../browser/renderer_host/render_widget_helper.h | 5 ++- .../renderer_host/resource_message_filter.cc | 7 ++-- .../renderer_host/resource_message_filter.h | 2 ++ chrome/browser/tab_contents/interstitial_page.cc | 7 ++-- .../render_view_host_delegate_helper.cc | 3 +- .../render_view_host_delegate_helper.h | 13 ++++--- chrome/browser/tab_contents/tab_contents_view.cc | 9 +++-- chrome/browser/tab_contents/tab_contents_view.h | 4 ++- chrome/chrome_common.gypi | 2 ++ chrome/common/render_messages.h | 24 ++++++++++++- chrome/common/render_messages_internal.h | 15 ++++---- chrome/common/window_container_type.cc | 41 ++++++++++++++++++++++ chrome/common/window_container_type.h | 35 ++++++++++++++++++ chrome/renderer/render_view.cc | 22 +++++++++--- chrome/renderer/render_view.h | 6 ++++ 23 files changed, 212 insertions(+), 43 deletions(-) create mode 100644 chrome/common/window_container_type.cc create mode 100644 chrome/common/window_container_type.h (limited to 'chrome') diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index 234e352..1d7de596 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -544,10 +544,13 @@ RenderViewHostDelegate::View* ExtensionHost::GetViewDelegate() { return this; } -void ExtensionHost::CreateNewWindow(int route_id) { +void ExtensionHost::CreateNewWindow( + int route_id, + WindowContainerType window_container_type) { delegate_view_helper_.CreateNewWindow( route_id, render_view_host()->process()->profile(), - site_instance(), DOMUIFactory::GetDOMUIType(url_), NULL); + site_instance(), DOMUIFactory::GetDOMUIType(url_), NULL, + window_container_type); } void ExtensionHost::CreateNewWidget(int route_id, diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index da3cdd0..39d2f8b 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -142,7 +142,9 @@ class ExtensionHost : public RenderViewHostDelegate, virtual RendererPreferences GetRendererPrefs(Profile* profile) const; // RenderViewHostDelegate::View - virtual void CreateNewWindow(int route_id); + virtual void CreateNewWindow( + int route_id, + WindowContainerType window_container_type); virtual void CreateNewWidget(int route_id, WebKit::WebPopupType popup_type); virtual void ShowCreatedWindow(int route_id, WindowOpenDisposition disposition, diff --git a/chrome/browser/notifications/balloon_host.cc b/chrome/browser/notifications/balloon_host.cc index d1786d9..9499f4f 100644 --- a/chrome/browser/notifications/balloon_host.cc +++ b/chrome/browser/notifications/balloon_host.cc @@ -86,10 +86,13 @@ void BalloonHost::ProcessDOMUIMessage(const std::string& message, // RenderViewHostDelegate::View methods implemented to allow links to // open pages in new tabs. -void BalloonHost::CreateNewWindow(int route_id) { +void BalloonHost::CreateNewWindow( + int route_id, + WindowContainerType window_container_type) { delegate_view_helper_.CreateNewWindow( route_id, balloon_->profile(), site_instance_.get(), - DOMUIFactory::GetDOMUIType(balloon_->notification().content_url()), NULL); + DOMUIFactory::GetDOMUIType(balloon_->notification().content_url()), NULL, + window_container_type); } void BalloonHost::ShowCreatedWindow(int route_id, diff --git a/chrome/browser/notifications/balloon_host.h b/chrome/browser/notifications/balloon_host.h index 4c4aad8..4aabe39 100644 --- a/chrome/browser/notifications/balloon_host.h +++ b/chrome/browser/notifications/balloon_host.h @@ -78,7 +78,9 @@ class BalloonHost : public RenderViewHostDelegate, // RenderViewHostDelegate::View methods. Only the ones for opening new // windows are currently implemented. - virtual void CreateNewWindow(int route_id); + virtual void CreateNewWindow( + int route_id, + WindowContainerType window_container_type); virtual void CreateNewWidget(int route_id, WebKit::WebPopupType popup_type) {} virtual void ShowCreatedWindow(int route_id, WindowOpenDisposition disposition, diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 1cd72fe..0cca1a9 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -848,12 +848,14 @@ void RenderViewHost::Shutdown() { RenderWidgetHost::Shutdown(); } -void RenderViewHost::CreateNewWindow(int route_id) { +void RenderViewHost::CreateNewWindow( + int route_id, + WindowContainerType window_container_type) { RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); if (!view) return; - view->CreateNewWindow(route_id); + view->CreateNewWindow(route_id, window_container_type); } void RenderViewHost::CreateNewWidget(int route_id, diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 61f8208..b384d6d 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -15,6 +15,7 @@ #include "chrome/common/page_zoom.h" #include "chrome/common/translate_errors.h" #include "chrome/common/view_types.h" +#include "chrome/common/window_container_type.h" #include "net/base/load_states.h" #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" @@ -418,7 +419,8 @@ class RenderViewHost : public RenderWidgetHost { virtual gfx::Rect GetRootWindowResizerRect() const; // Creates a new RenderView with the given route id. - void CreateNewWindow(int route_id); + void CreateNewWindow(int route_id, + WindowContainerType window_container_type); // Creates a new RenderWidget with the given route id. |popup_type| indicates // if this widget is a popup and what kind of popup it is (select, autofill). diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index 40a7745..233099c 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -13,6 +13,7 @@ #include "chrome/common/content_settings_types.h" #include "chrome/common/translate_errors.h" #include "chrome/common/view_types.h" +#include "chrome/common/window_container_type.h" #include "net/base/load_states.h" #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" #include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h" @@ -88,12 +89,17 @@ class RenderViewHostDelegate { // The page is trying to open a new page (e.g. a popup window). The // window should be created associated with the given route, but it should // not be shown yet. That should happen in response to ShowCreatedWindow. + // |window_container_type| describes the type of RenderViewHost container + // that is requested -- in particular, the window.open call may have + // specified 'background' and 'persistent' in the feature string. // // Note: this is not called "CreateWindow" because that will clash with // the Windows function which is actually a #define. // // NOTE: this takes ownership of @modal_dialog_event - virtual void CreateNewWindow(int route_id) = 0; + virtual void CreateNewWindow( + int route_id, + WindowContainerType window_container_type) = 0; // The page is trying to open a new widget (e.g. a select popup). The // widget should be created associated with the given route, but it should diff --git a/chrome/browser/renderer_host/render_widget_helper.cc b/chrome/browser/renderer_host/render_widget_helper.cc index 5c379e7..2c3b6f4 100644 --- a/chrome/browser/renderer_host/render_widget_helper.cc +++ b/chrome/browser/renderer_host/render_widget_helper.cc @@ -199,10 +199,12 @@ void RenderWidgetHelper::OnCrossSiteClosePageACK( resource_dispatcher_host_->OnClosePageACK(params); } -void RenderWidgetHelper::CreateNewWindow(int opener_id, - bool user_gesture, - base::ProcessHandle render_process, - int* route_id) { +void RenderWidgetHelper::CreateNewWindow( + int opener_id, + bool user_gesture, + WindowContainerType window_container_type, + base::ProcessHandle render_process, + int* route_id) { *route_id = GetNextRoutingID(); // Block resource requests until the view is created, since the HWND might be // needed if a response ends up creating a plugin. @@ -212,13 +214,17 @@ void RenderWidgetHelper::CreateNewWindow(int opener_id, ChromeThread::PostTask( ChromeThread::UI, FROM_HERE, NewRunnableMethod( - this, &RenderWidgetHelper::OnCreateWindowOnUI, opener_id, *route_id)); + this, &RenderWidgetHelper::OnCreateWindowOnUI, opener_id, *route_id, + window_container_type)); } -void RenderWidgetHelper::OnCreateWindowOnUI(int opener_id, int route_id) { +void RenderWidgetHelper::OnCreateWindowOnUI( + int opener_id, + int route_id, + WindowContainerType window_container_type) { RenderViewHost* host = RenderViewHost::FromID(render_process_id_, opener_id); if (host) - host->CreateNewWindow(route_id); + host->CreateNewWindow(route_id, window_container_type); ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, diff --git a/chrome/browser/renderer_host/render_widget_helper.h b/chrome/browser/renderer_host/render_widget_helper.h index 33ca744..f942903 100644 --- a/chrome/browser/renderer_host/render_widget_helper.h +++ b/chrome/browser/renderer_host/render_widget_helper.h @@ -14,6 +14,7 @@ #include "base/ref_counted.h" #include "base/lock.h" #include "base/waitable_event.h" +#include "chrome/common/window_container_type.h" #include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h" namespace IPC { @@ -121,6 +122,7 @@ class RenderWidgetHelper void CreateNewWindow(int opener_id, bool user_gesture, + WindowContainerType window_container_type, base::ProcessHandle render_process, int* route_id); void CreateNewWidget(int opener_id, @@ -161,7 +163,8 @@ class RenderWidgetHelper // Called on the UI thread to finish creating a window. void OnCreateWindowOnUI(int opener_id, - int route_id); + int route_id, + WindowContainerType window_container_type); // Called on the IO thread after a window was created on the UI thread. void OnCreateWindowOnIO(int route_id); diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index 7ef3f8e..0ef86ea 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -598,12 +598,15 @@ URLRequestContext* ResourceMessageFilter::GetRequestContext( } void ResourceMessageFilter::OnMsgCreateWindow( - int opener_id, bool user_gesture, int64 session_storage_namespace_id, - int* route_id, int64* cloned_session_storage_namespace_id) { + int opener_id, bool user_gesture, + WindowContainerType window_container_type, + int64 session_storage_namespace_id, int* route_id, + int64* cloned_session_storage_namespace_id) { *cloned_session_storage_namespace_id = dom_storage_dispatcher_host_-> CloneSessionStorage(session_storage_namespace_id); render_widget_helper_->CreateNewWindow(opener_id, user_gesture, + window_container_type, handle(), route_id); } diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 5013257..e16edc8 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -27,6 +27,7 @@ #include "chrome/common/nacl_types.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/render_messages.h" +#include "chrome/common/window_container_type.h" #include "gfx/native_widget_types.h" #include "gfx/rect.h" #include "ipc/ipc_channel_proxy.h" @@ -132,6 +133,7 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, virtual ~ResourceMessageFilter(); void OnMsgCreateWindow(int opener_id, bool user_gesture, + WindowContainerType window_container_type, int64 session_storage_namespace_id, int* route_id, int64* cloned_session_storage_namespace_id); void OnMsgCreateWidget(int opener_id, diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc index 14eb26b..d22aead 100644 --- a/chrome/browser/tab_contents/interstitial_page.cc +++ b/chrome/browser/tab_contents/interstitial_page.cc @@ -86,7 +86,9 @@ class InterstitialPage::InterstitialPageRVHViewDelegate explicit InterstitialPageRVHViewDelegate(InterstitialPage* page); // RenderViewHostDelegate::View implementation: - virtual void CreateNewWindow(int route_id); + virtual void CreateNewWindow( + int route_id, + WindowContainerType window_container_type); virtual void CreateNewWidget(int route_id, WebKit::WebPopupType popup_type); virtual void ShowCreatedWindow(int route_id, @@ -557,7 +559,8 @@ InterstitialPage::InterstitialPageRVHViewDelegate:: } void InterstitialPage::InterstitialPageRVHViewDelegate::CreateNewWindow( - int route_id) { + int route_id, + WindowContainerType window_container_type) { NOTREACHED() << "InterstitialPage does not support showing popups yet."; } diff --git a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc index e8591fd..5fe2208 100644 --- a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc +++ b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc @@ -26,7 +26,8 @@ TabContents* RenderViewHostDelegateViewHelper::CreateNewWindow( Profile* profile, SiteInstance* site, DOMUITypeID domui_type, - TabContents* old_tab_contents) { + TabContents* old_tab_contents, + WindowContainerType window_container_type) { // Create the new web contents. This will automatically create the new // TabContentsView. In the future, we may want to create the view separately. TabContents* new_contents = diff --git a/chrome/browser/tab_contents/render_view_host_delegate_helper.h b/chrome/browser/tab_contents/render_view_host_delegate_helper.h index 42052b9..351e036 100644 --- a/chrome/browser/tab_contents/render_view_host_delegate_helper.h +++ b/chrome/browser/tab_contents/render_view_host_delegate_helper.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "base/waitable_event.h" #include "chrome/browser/dom_ui/dom_ui_factory.h" +#include "chrome/common/window_container_type.h" #include "gfx/rect.h" #include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h" #include "webkit/glue/webpreferences.h" @@ -31,11 +32,13 @@ class RenderViewHostDelegateViewHelper { public: RenderViewHostDelegateViewHelper() {} - virtual TabContents* CreateNewWindow(int route_id, - Profile* profile, - SiteInstance* site, - DOMUITypeID domui_type, - TabContents* old_tab_contents); + virtual TabContents* CreateNewWindow( + int route_id, + Profile* profile, + SiteInstance* site, + DOMUITypeID domui_type, + TabContents* old_tab_contents, + WindowContainerType window_container_type); virtual RenderWidgetHostView* CreateNewWidget(int route_id, WebKit::WebPopupType popup_type, RenderProcessHost* process); diff --git a/chrome/browser/tab_contents/tab_contents_view.cc b/chrome/browser/tab_contents/tab_contents_view.cc index bce9a50..b6d45a0 100644 --- a/chrome/browser/tab_contents/tab_contents_view.cc +++ b/chrome/browser/tab_contents/tab_contents_view.cc @@ -30,10 +30,13 @@ void TabContentsView::UpdatePreferredSize(const gfx::Size& pref_size) { preferred_width_ = pref_size.width(); } -void TabContentsView::CreateNewWindow(int route_id) { - TabContents* new_contents = delegate_view_helper_.CreateNewWindow( +void TabContentsView::CreateNewWindow( + int route_id, + WindowContainerType window_container_type) { + TabContents* new_contents = delegate_view_helper_.CreateNewWindow( route_id, tab_contents_->profile(), tab_contents_->GetSiteInstance(), - DOMUIFactory::GetDOMUIType(tab_contents_->GetURL()), tab_contents_); + DOMUIFactory::GetDOMUIType(tab_contents_->GetURL()), tab_contents_, + window_container_type); if (tab_contents_->delegate()) tab_contents_->delegate()->TabContentsCreated(new_contents); diff --git a/chrome/browser/tab_contents/tab_contents_view.h b/chrome/browser/tab_contents/tab_contents_view.h index 48c1558..e9e26b3 100644 --- a/chrome/browser/tab_contents/tab_contents_view.h +++ b/chrome/browser/tab_contents/tab_contents_view.h @@ -179,7 +179,9 @@ class TabContentsView : public RenderViewHostDelegate::View { // We implement these functions on RenderViewHostDelegate::View directly and // do some book-keeping associated with the request. The request is then // forwarded to *Internal which does platform-specific work. - virtual void CreateNewWindow(int route_id); + virtual void CreateNewWindow( + int route_id, + WindowContainerType window_container_type); virtual void CreateNewWidget(int route_id, WebKit::WebPopupType popup_type); virtual void ShowCreatedWindow(int route_id, WindowOpenDisposition disposition, diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index d169a5a..668af2d 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -262,6 +262,8 @@ 'common/webkit_param_traits.h', 'common/webmessageportchannel_impl.cc', 'common/webmessageportchannel_impl.h', + 'common/window_container_type.cc', + 'common/window_container_type.h', 'common/worker_messages.h', 'common/worker_messages_internal.h', 'common/worker_thread_ticker.cc', diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index db6dfe5..359fa30 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -30,6 +30,7 @@ #include "chrome/common/translate_errors.h" #include "chrome/common/view_types.h" #include "chrome/common/webkit_param_traits.h" +#include "chrome/common/window_container_type.h" #include "gfx/native_widget_types.h" #include "googleurl/src/gurl.h" #include "ipc/ipc_message_utils.h" @@ -2608,7 +2609,7 @@ struct ParamTraits { GURL origin; std::vector paths; bool success = - ReadParam(m, iter, &origin) && + ReadParam(m, iter, &origin) && ReadParam(m, iter, &paths); if (!success) return false; @@ -2637,6 +2638,27 @@ struct ParamTraits { } }; +template <> +struct ParamTraits { + typedef WindowContainerType param_type; + static void Write(Message* m, const param_type& p) { + int val = static_cast(p); + WriteParam(m, val); + } + static bool Read(const Message* m, void** iter, param_type* p) { + int val = 0; + if (!ReadParam(m, iter, &val) || + val < WINDOW_CONTAINER_TYPE_NORMAL || + val >= WINDOW_CONTAINER_TYPE_MAX_VALUE) + return false; + *p = static_cast(val); + return true; + } + static void Log(const param_type& p, std::wstring* l) { + LogParam(p, l); + } +}; + } // namespace IPC diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 314c933..60c4cab 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -24,6 +24,7 @@ #include "chrome/common/notification_type.h" #include "chrome/common/page_zoom.h" #include "chrome/common/translate_errors.h" +#include "chrome/common/window_container_type.h" #include "gfx/rect.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message.h" @@ -952,12 +953,14 @@ IPC_BEGIN_MESSAGES(ViewHost) // Sent by the renderer when it is creating a new window. The browser creates // a tab for it and responds with a ViewMsg_CreatingNew_ACK. If route_id is // MSG_ROUTING_NONE, the view couldn't be created. - IPC_SYNC_MESSAGE_CONTROL3_2(ViewHostMsg_CreateWindow, - int /* opener_id */, - bool /* user_gesture */, - int64 /* session_storage_namespace_id */, - int /* route_id */, - int64 /* cloned_session_storage_namespace_id */) + IPC_SYNC_MESSAGE_CONTROL4_2( + ViewHostMsg_CreateWindow, + int /* opener_id */, + bool /* user_gesture */, + WindowContainerType /* window_container_type */, + int64 /* session_storage_namespace_id */, + int /* route_id */, + int64 /* cloned_session_storage_namespace_id */) // Similar to ViewHostMsg_CreateWindow, except used for sub-widgets, like //