diff options
author | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-09 02:49:25 +0000 |
---|---|---|
committer | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-09 02:49:25 +0000 |
commit | 25bcc8ff25d5b94b84782783fc762a635d7b23d6 (patch) | |
tree | bc9236fdd4d639736778720bd5c468d03c6d03e6 /content/browser | |
parent | 726ecd2526de747aa613daa6dffe4f2524bb6de8 (diff) | |
download | chromium_src-25bcc8ff25d5b94b84782783fc762a635d7b23d6.zip chromium_src-25bcc8ff25d5b94b84782783fc762a635d7b23d6.tar.gz chromium_src-25bcc8ff25d5b94b84782783fc762a635d7b23d6.tar.bz2 |
<webview>: Add name attribute
This change requires this WebKit patch: https://bugs.webkit.org/show_bug.cgi?id=104404
This change enables access to the guest's window's name attribute from the embedder <webview>. It also enables changes to the window name attribute from the embedder WebContents.
BUG=140316
Test=BrowserPluginHostTest.ChangeWindowName
Review URL: https://codereview.chromium.org/11554030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175681 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
5 files changed, 78 insertions, 6 deletions
diff --git a/content/browser/browser_plugin/browser_plugin_embedder.cc b/content/browser/browser_plugin/browser_plugin_embedder.cc index 16ad747..130fe5b 100644 --- a/content/browser/browser_plugin/browser_plugin_embedder.cc +++ b/content/browser/browser_plugin/browser_plugin_embedder.cc @@ -279,6 +279,7 @@ bool BrowserPluginEmbedder::ShouldForwardToBrowserPluginGuest( case BrowserPluginHostMsg_ResizeGuest::ID: case BrowserPluginHostMsg_SetAutoSize::ID: case BrowserPluginHostMsg_SetFocus::ID: + case BrowserPluginHostMsg_SetName::ID: case BrowserPluginHostMsg_SetVisibility::ID: case BrowserPluginHostMsg_Stop::ID: case BrowserPluginHostMsg_TerminateGuest::ID: diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc index a5eec10..83208891 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.cc +++ b/content/browser/browser_plugin/browser_plugin_guest.cc @@ -56,6 +56,7 @@ BrowserPluginGuest::BrowserPluginGuest( base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), focused_(params.focused), visible_(params.visible), + name_(params.name), auto_size_enabled_(params.auto_size_params.enable), max_auto_size_(params.auto_size_params.max_size), min_auto_size_(params.auto_size_params.min_size) { @@ -75,6 +76,7 @@ bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize) IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) + IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetName, OnSetName) IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Stop, OnStop) IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_TerminateGuest, OnTerminateGuest) @@ -321,12 +323,13 @@ void BrowserPluginGuest::RenderViewReady() { // here (see http://crbug.com/158151). Send(new ViewMsg_SetFocus(routing_id(), focused_)); UpdateVisibility(); - if (auto_size_enabled_) { - web_contents()->GetRenderViewHost()->EnableAutoResize( - min_auto_size_, max_auto_size_); - } else { - web_contents()->GetRenderViewHost()->DisableAutoResize(damage_view_size_); - } + RenderViewHost* rvh = web_contents()->GetRenderViewHost(); + if (auto_size_enabled_) + rvh->EnableAutoResize(min_auto_size_, max_auto_size_); + else + rvh->DisableAutoResize(damage_view_size_); + + rvh->Send(new ViewMsg_SetName(rvh->GetRoutingID(), name_)); } void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { @@ -367,6 +370,7 @@ bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) + IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -466,6 +470,15 @@ void BrowserPluginGuest::OnSetFocus(int instance_id, bool focused) { Send(new ViewMsg_SetFocus(routing_id(), focused)); } +void BrowserPluginGuest::OnSetName(int instance_id, const std::string& name) { + if (name == name_) + return; + name_ = name; + web_contents()->GetRenderViewHost()->Send(new ViewMsg_SetName( + web_contents()->GetRenderViewHost()->GetRoutingID(), + name)); +} + void BrowserPluginGuest::OnSetSize( int instance_id, const BrowserPluginHostMsg_AutoSize_Params& auto_size_params, @@ -607,6 +620,19 @@ void BrowserPluginGuest::OnUpdateDragCursor( view->UpdateDragCursor(operation); } +void BrowserPluginGuest::OnUpdateFrameName(int frame_id, + bool is_top_level, + const std::string& name) { + if (!is_top_level) + return; + + name_ = name; + SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( + embedder_routing_id(), + instance_id_, + name)); +} + void BrowserPluginGuest::OnUpdateRect( const ViewHostMsg_UpdateRect_Params& params) { diff --git a/content/browser/browser_plugin/browser_plugin_guest.h b/content/browser/browser_plugin/browser_plugin_guest.h index e16696c..a3bf19b 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.h +++ b/content/browser/browser_plugin/browser_plugin_guest.h @@ -219,6 +219,9 @@ class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver, const BrowserPluginHostMsg_ResizeGuest_Params& params); // Overriden in tests. virtual void OnSetFocus(int instance_id, bool focused); + // Sets the name of the guest so that other guests in the same partition can + // access it. + void OnSetName(int instance_id, const std::string& name); // Updates the size state of the guest. void OnSetSize( int instance_id, @@ -269,6 +272,9 @@ class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver, // Overriden in tests. virtual void OnTakeFocus(bool reverse); void OnUpdateDragCursor(WebKit::WebDragOperation operation); + void OnUpdateFrameName(int frame_id, + bool is_top_level, + const std::string& name); void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params); // Static factory instance (always NULL for non-test). @@ -290,6 +296,7 @@ class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver, base::TimeDelta guest_hang_timeout_; bool focused_; bool visible_; + std::string name_; bool auto_size_enabled_; gfx::Size max_auto_size_; gfx::Size min_auto_size_; diff --git a/content/browser/browser_plugin/browser_plugin_guest_helper.cc b/content/browser/browser_plugin/browser_plugin_guest_helper.cc index 85c6a1a..5a9d6e0 100644 --- a/content/browser/browser_plugin/browser_plugin_guest_helper.cc +++ b/content/browser/browser_plugin/browser_plugin_guest_helper.cc @@ -41,6 +41,7 @@ bool BrowserPluginGuestHelper::ShouldForwardToBrowserPluginGuest( #endif case ViewHostMsg_ShowWidget::ID: case ViewHostMsg_TakeFocus::ID: + case ViewHostMsg_UpdateFrameName::ID: case ViewHostMsg_UpdateRect::ID: return true; default: diff --git a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc index 5dc3de4..742a31a 100644 --- a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc +++ b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc @@ -1242,4 +1242,41 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, GetRenderViewHostAtPositionTest) { test_embedder()->last_rvh_at_position_response()); } +IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ChangeWindowName) { + const char kEmbedderURL[] = "files/browser_plugin_naming_embedder.html"; + const char* kGuestURL = "files/browser_plugin_naming_guest.html"; + StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); + + RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( + test_embedder()->web_contents()->GetRenderViewHost()); + { + // Open a channel with the guest, wait until it replies, + // then verify that the plugin's name has been updated. + const string16 expected_title = ASCIIToUTF16("guest"); + content::TitleWatcher title_watcher(test_embedder()->web_contents(), + expected_title); + ExecuteSyncJSFunction(rvh, "OpenCommChannel();"); + string16 actual_title = title_watcher.WaitAndGetTitle(); + EXPECT_EQ(expected_title, actual_title); + + scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(string16(), + ASCIIToUTF16("document.getElementById('plugin').name"))); + std::string result; + EXPECT_TRUE(value->GetAsString(&result)); + EXPECT_EQ("guest", result); + } + { + // Set the plugin's name and verify that the window.name of the guest + // has been updated. + const string16 expected_title = ASCIIToUTF16("foobar"); + content::TitleWatcher title_watcher(test_embedder()->web_contents(), + expected_title); + ExecuteSyncJSFunction(rvh, + "document.getElementById('plugin').name = 'foobar';"); + string16 actual_title = title_watcher.WaitAndGetTitle(); + EXPECT_EQ(expected_title, actual_title); + + } +} + } // namespace content |