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 | |
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
16 files changed, 261 insertions, 10 deletions
diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js index 4577b53..f52429a 100644 --- a/chrome/renderer/resources/extensions/web_view.js +++ b/chrome/renderer/resources/extensions/web_view.js @@ -9,7 +9,7 @@ var watchForTag = require("tagWatcher").watchForTag; -var WEB_VIEW_ATTRIBUTES = ['src', 'partition']; +var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition']; // All exposed api methods for <webview>, these are forwarded to the browser // plugin. @@ -117,6 +117,11 @@ function WebView(node) { * @private */ WebView.prototype.handleMutation_ = function(mutation) { + // This observer monitors mutations to attributes of the <webview> and + // updates the BrowserPlugin properties accordingly. In turn, updating + // a BrowserPlugin property will update the corresponding BrowserPlugin + // attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more + // details. this.objectNode_[mutation.attributeName] = this.node_.getAttribute(mutation.attributeName); }; @@ -125,8 +130,17 @@ WebView.prototype.handleMutation_ = function(mutation) { * @private */ WebView.prototype.handleObjectMutation_ = function(mutation) { - this.node_.setAttribute(mutation.attributeName, - this.objectNode_.getAttribute(mutation.attributeName)); + // This observer monitors mutations to attributes of the BrowserPlugin and + // updates the <webview> attributes accordingly. + if (!this.objectNode_.hasAttribute(mutation.attributeName)) { + // If an attribute is removed from the BrowserPlugin, then remove it + // from the <webview> as well. + this.node_.removeAttribute(mutation.attributeName); + } else { + // Update the <webview> attribute to match the BrowserPlugin attribute. + this.node_.setAttribute(mutation.attributeName, + this.objectNode_.getAttribute(mutation.attributeName)); + } }; /** 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 diff --git a/content/common/browser_plugin_messages.h b/content/common/browser_plugin_messages.h index e412277..13f0ea8 100644 --- a/content/common/browser_plugin_messages.h +++ b/content/common/browser_plugin_messages.h @@ -55,6 +55,7 @@ IPC_STRUCT_BEGIN(BrowserPluginHostMsg_CreateGuest_Params) IPC_STRUCT_MEMBER(bool, persist_storage) IPC_STRUCT_MEMBER(bool, focused) IPC_STRUCT_MEMBER(bool, visible) + IPC_STRUCT_MEMBER(std::string, name) IPC_STRUCT_MEMBER(BrowserPluginHostMsg_AutoSize_Params, auto_size_params) IPC_STRUCT_MEMBER(BrowserPluginHostMsg_ResizeGuest_Params, resize_guest_params) @@ -214,6 +215,11 @@ IPC_MESSAGE_ROUTED3(BrowserPluginHostMsg_PluginAtPositionResponse, int /* request_id */, gfx::Point /* position */) +// Sets the name of the guest window to the provided |name|. +IPC_MESSAGE_ROUTED2(BrowserPluginHostMsg_SetName, + int /* instance_id */, + std::string /* name */) + // ----------------------------------------------------------------------------- // These messages are from the guest renderer to the browser process @@ -319,6 +325,11 @@ IPC_MESSAGE_ROUTED2(BrowserPluginMsg_PluginAtPositionRequest, int /* request_id */, gfx::Point /* position */) +// Informs BrowserPlugin of a new name set for the top-level guest frame. +IPC_MESSAGE_ROUTED2(BrowserPluginMsg_UpdatedName, + int /* instance_id */, + std::string /* name */) + // Guest renders into an FBO with textures provided by the embedder. // When HW accelerated buffers are swapped in the guest, the message // is forwarded to the embedder to notify it of a new texture diff --git a/content/common/view_messages.h b/content/common/view_messages.h index 74f3a3c..ffdda9b 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -693,6 +693,10 @@ IPC_STRUCT_END() // Messages sent from the browser to the renderer. +// Set the top-level frame to the provided name. +IPC_MESSAGE_ROUTED1(ViewMsg_SetName, + std::string /* frame_name */) + // Sent to the RenderView when a new tab is swapped into an existing // tab and the histories need to be merged. The existing tab has a history of // |merged_history_length| which precedes the history of the new tab. All @@ -2051,6 +2055,12 @@ IPC_MESSAGE_ROUTED3(ViewHostMsg_UpdateZoomLimits, IPC_MESSAGE_CONTROL1(ViewHostMsg_SuddenTerminationChanged, bool /* enabled */) +// Informs the browser of updated frame names. +IPC_MESSAGE_ROUTED3(ViewHostMsg_UpdateFrameName, + int /* frame_id */, + bool /* is_top_level */, + std::string /* name */) + #if defined(OS_MACOSX) // Request that the browser load a font into shared memory for us. IPC_SYNC_MESSAGE_CONTROL1_3(ViewHostMsg_LoadFont, diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc index eacc7f6..557d82f 100644 --- a/content/renderer/browser_plugin/browser_plugin.cc +++ b/content/renderer/browser_plugin/browser_plugin.cc @@ -60,6 +60,7 @@ const char kEventUnresponsive[] = "unresponsive"; // Parameters/properties on events. const char kIsTopLevel[] = "isTopLevel"; +const char kName[] = "name"; const char kNewURL[] = "newUrl"; const char kNewHeight[] = "newHeight"; const char kNewWidth[] = "newWidth"; @@ -156,9 +157,10 @@ bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect) IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart) IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStop, OnLoadStop) + IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, OnShouldAcceptTouchEvents) - IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) + IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdatedName, OnUpdatedName) IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -186,6 +188,21 @@ void BrowserPlugin::UpdateDOMAttribute( } } +void BrowserPlugin::SetNameAttribute(const std::string& name) { + if (name_ == name) + return; + + name_ = name; + if (!navigate_src_sent_) + return; + + browser_plugin_manager()->Send( + new BrowserPluginHostMsg_SetName( + render_view_routing_id_, + instance_id_, + name)); +} + bool BrowserPlugin::SetSrcAttribute(const std::string& src, std::string* error_message) { if (!valid_partition_id_) { @@ -205,6 +222,7 @@ bool BrowserPlugin::SetSrcAttribute(const std::string& src, create_guest_params.persist_storage = persist_storage_; create_guest_params.focused = ShouldGuestBeFocused(); create_guest_params.visible = visible_; + create_guest_params.name = name_; GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, &create_guest_params.resize_guest_params); browser_plugin_manager()->Send( @@ -406,6 +424,11 @@ void BrowserPlugin::OnShouldAcceptTouchEvents(int instance_id, bool accept) { } } +void BrowserPlugin::OnUpdatedName(int instance_id, const std::string& name) { + name_ = name; + UpdateDOMAttribute(kName, name); +} + void BrowserPlugin::OnUpdateRect( int instance_id, const BrowserPluginMsg_UpdateRect_Params& params) { diff --git a/content/renderer/browser_plugin/browser_plugin.h b/content/renderer/browser_plugin/browser_plugin.h index 0eeb8f9..80f2c6b 100644 --- a/content/renderer/browser_plugin/browser_plugin.h +++ b/content/renderer/browser_plugin/browser_plugin.h @@ -41,6 +41,10 @@ class CONTENT_EXPORT BrowserPlugin : void UpdateDOMAttribute(const std::string& attribute_name, const std::string& attribute_value); + // Get the name attribute value. + std::string name_attribute() const { return name_; } + // Set the name attribute value. + void SetNameAttribute(const std::string& name); // Get the src attribute value of the BrowserPlugin instance. std::string src_attribute() const { return src_; } // Set the src attribute value of the BrowserPlugin instance. @@ -260,6 +264,7 @@ class CONTENT_EXPORT BrowserPlugin : void OnLoadStop(int instance_id); void OnSetCursor(int instance_id, const WebCursor& cursor); void OnShouldAcceptTouchEvents(int instance_id, bool accept); + void OnUpdatedName(int instance_id, const std::string& name); void OnUpdateRect(int instance_id, const BrowserPluginMsg_UpdateRect_Params& params); @@ -299,6 +304,7 @@ class CONTENT_EXPORT BrowserPlugin : // Tracks the visibility of the browser plugin regardless of the whole // embedder RenderView's visibility. bool visible_; + std::string name_; WebCursor cursor_; diff --git a/content/renderer/browser_plugin/browser_plugin_bindings.cc b/content/renderer/browser_plugin/browser_plugin_bindings.cc index 2bf0387..a6cfb39 100644 --- a/content/renderer/browser_plugin/browser_plugin_bindings.cc +++ b/content/renderer/browser_plugin/browser_plugin_bindings.cc @@ -54,6 +54,7 @@ const char kAttributeMaxHeight[] = "maxHeight"; const char kAttributeMaxWidth[] = "maxWidth"; const char kAttributeMinHeight[] = "minHeight"; const char kAttributeMinWidth[] = "minWidth"; +const char kAttributeName[] = "name"; const char kAttributePartition[] = "partition"; const char kAttributeSrc[] = "src"; @@ -576,6 +577,33 @@ class BrowserPluginPropertyBindingMinWidth DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); }; +class BrowserPluginPropertyBindingName + : public BrowserPluginPropertyBinding { + public: + BrowserPluginPropertyBindingName() : + BrowserPluginPropertyBinding(kAttributeName) { + } + virtual bool GetProperty(BrowserPluginBindings* bindings, + NPVariant* result) OVERRIDE { + std::string name = bindings->instance()->name_attribute(); + return StringToNPVariant(name, result); + return true; + } + virtual bool SetProperty(BrowserPluginBindings* bindings, + NPObject* np_obj, + const NPVariant* variant) OVERRIDE { + std::string name = StringFromNPVariant(*variant); + bindings->instance()->SetNameAttribute(name); + return true; + } + virtual std::string GetDOMAttributeValue( + BrowserPlugin* browser_plugin) OVERRIDE { + return browser_plugin->name_attribute(); + } + private: + DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingName); +}; + class BrowserPluginPropertyBindingPartition : public BrowserPluginPropertyBinding { public: @@ -672,6 +700,7 @@ BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance) property_bindings_.push_back(new BrowserPluginPropertyBindingMaxWidth); property_bindings_.push_back(new BrowserPluginPropertyBindingMinHeight); property_bindings_.push_back(new BrowserPluginPropertyBindingMinWidth); + property_bindings_.push_back(new BrowserPluginPropertyBindingName); property_bindings_.push_back(new BrowserPluginPropertyBindingPartition); property_bindings_.push_back(new BrowserPluginPropertyBindingSrc); } diff --git a/content/renderer/browser_plugin/browser_plugin_manager_impl.cc b/content/renderer/browser_plugin/browser_plugin_manager_impl.cc index 55286e45..74a566df6 100644 --- a/content/renderer/browser_plugin/browser_plugin_manager_impl.cc +++ b/content/renderer/browser_plugin/browser_plugin_manager_impl.cc @@ -100,6 +100,7 @@ bool BrowserPluginManagerImpl::ShouldForwardToBrowserPlugin( case BrowserPluginMsg_LoadStop::ID: case BrowserPluginMsg_SetCursor::ID: case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: + case BrowserPluginMsg_UpdatedName::ID: case BrowserPluginMsg_UpdateRect::ID: return true; default: diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 1dcfe80..c0f21d3 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -964,6 +964,7 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) + IPC_MESSAGE_HANDLER(ViewMsg_SetName, OnSetName) IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) IPC_MESSAGE_HANDLER(ViewMsg_Unselect, OnUnselect) IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets, @@ -1386,6 +1387,13 @@ void RenderViewImpl::OnDelete() { webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete")); } +void RenderViewImpl::OnSetName(const std::string& name) { + if (!webview()) + return; + + webview()->mainFrame()->setName(WebString::fromUTF8(name)); +} + void RenderViewImpl::OnSelectAll() { if (!webview()) return; @@ -2730,6 +2738,14 @@ void RenderViewImpl::willClose(WebFrame* frame) { FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame)); } +void RenderViewImpl::didChangeName(WebFrame* frame, + const WebString& name) { + Send(new ViewHostMsg_UpdateFrameName(routing_id_, + frame->identifier(), + !frame->parent(), + UTF16ToUTF8(name))); +} + void RenderViewImpl::loadURLExternally( WebFrame* frame, const WebURLRequest& request, WebNavigationPolicy policy) { diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h index 1079af74..17c96f7 100644 --- a/content/renderer/render_view_impl.h +++ b/content/renderer/render_view_impl.h @@ -536,6 +536,8 @@ class CONTENT_EXPORT RenderViewImpl virtual void didDisownOpener(WebKit::WebFrame* frame); virtual void frameDetached(WebKit::WebFrame* frame); virtual void willClose(WebKit::WebFrame* frame); + virtual void didChangeName(WebKit::WebFrame* frame, + const WebKit::WebString& name); virtual void loadURLExternally(WebKit::WebFrame* frame, const WebKit::WebURLRequest& request, WebKit::WebNavigationPolicy policy); @@ -923,6 +925,7 @@ class CONTENT_EXPORT RenderViewImpl void OnCustomContextMenuAction(const CustomContextMenuContext& custom_context, unsigned action); void OnDelete(); + void OnSetName(const std::string& name); void OnDeterminePageLanguage(); void OnDisableScrollbarsForSmallWindows( const gfx::Size& disable_scrollbars_size_limit); diff --git a/content/test/data/browser_plugin_naming_embedder.html b/content/test/data/browser_plugin_naming_embedder.html new file mode 100644 index 0000000..7d6e1a6 --- /dev/null +++ b/content/test/data/browser_plugin_naming_embedder.html @@ -0,0 +1,37 @@ +<html> + <body> + <object id="plugin" + type="application/browser-plugin" + width="640" + height="480"></object> + <script> + var loadstop = false; + var requestCommChannel = false; + function SetSrc(src) { + var plugin = document.getElementById('plugin'); + plugin.src = src; + } + // Open a two-way communication channel with the guest. + function OpenCommChannel() { + if (!loadstop) { + requestCommChannel = true; + return; + } + var plugin = document.getElementById('plugin'); + plugin.contentWindow.frames.postMessage('test', '*'); + } + + // Establish a two-way channel with the guest. + window.addEventListener('message', function(e) { + document.title = event.data; + }); + var plugin = document.getElementById('plugin'); + plugin.addEventListener('-internal-loadstop', function(e) { + loadstop = true; + if (requestCommChannel) { + plugin.contentWindow.frames.postMessage('test', '*'); + } + }); + </script> + </body> +</html> diff --git a/content/test/data/browser_plugin_naming_guest.html b/content/test/data/browser_plugin_naming_guest.html new file mode 100644 index 0000000..5b2b8a3 --- /dev/null +++ b/content/test/data/browser_plugin_naming_guest.html @@ -0,0 +1,29 @@ +<html> + <body> + <script> + var embedder = null; + var lastName = ''; + function SetWindowName(name) { + window.name = name; + lastName = name; + embedder.postMessage(name, '*'); + } + + function pollName() { + if (window.name != lastName) { + lastName = window.name; + // Signal the embedder with the new window name. + embedder.postMessage(lastName, '*'); + setTimeout(pollName, 100); + } + } + + window.addEventListener('message', function(e) { + console.log('test'); + embedder = e.source; + SetWindowName('guest'); + setTimeout(pollName, 100); + }); + </script> + </body> +</html> |