Commit 620d5de5 authored by fsamuel@chromium.org's avatar fsamuel@chromium.org

Browser Plugin: <webview> should inherit partition attribute of opener on attachment.

BUG=140316
Test=Updated WebViewTest.NewWindow

Review URL: https://chromiumcodereview.appspot.com/13032003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192646 0039d316-1c4b-4281-b951-d872f2087c98
parent 9bc3f245
...@@ -16,12 +16,15 @@ embedder.setUp = function(config) { ...@@ -16,12 +16,15 @@ embedder.setUp = function(config) {
}; };
/** @private */ /** @private */
embedder.setUpGuest_ = function() { embedder.setUpGuest_ = function(partitionName) {
document.querySelector('#webview-tag-container').innerHTML = document.querySelector('#webview-tag-container').innerHTML =
'<webview style="width: 100px; height: 100px;"' + '<webview style="width: 100px; height: 100px;"' +
' src="' + embedder.guestURL + '"' + ' src="' + embedder.guestURL + '"' +
'></webview>'; '></webview>';
var webview = document.querySelector('webview'); var webview = document.querySelector('webview');
if (partitionName) {
webview.partition = partitionName;
}
if (!webview) { if (!webview) {
chrome.test.fail('No <webview> element created'); chrome.test.fail('No <webview> element created');
} }
...@@ -48,7 +51,8 @@ embedder.setUpFrameNameRequest_ = function(webview, testName) { ...@@ -48,7 +51,8 @@ embedder.setUpFrameNameRequest_ = function(webview, testName) {
}; };
/** @private */ /** @private */
embedder.requestFrameName_ = function(webview, testName, expectedFrameName) { embedder.requestFrameName_ =
function(webview, openerwebview, testName, expectedFrameName) {
var onPostMessageReceived = function(e) { var onPostMessageReceived = function(e) {
var data = JSON.parse(e.data); var data = JSON.parse(e.data);
if (data[0] == 'get-frame-name') { if (data[0] == 'get-frame-name') {
...@@ -58,6 +62,7 @@ embedder.requestFrameName_ = function(webview, testName, expectedFrameName) { ...@@ -58,6 +62,7 @@ embedder.requestFrameName_ = function(webview, testName, expectedFrameName) {
var frameName = data[2]; var frameName = data[2];
chrome.test.assertEq(expectedFrameName, frameName); chrome.test.assertEq(expectedFrameName, frameName);
chrome.test.assertEq(expectedFrameName, webview.name); chrome.test.assertEq(expectedFrameName, webview.name);
chrome.test.assertEq(openerwebview.partition, webview.partition);
chrome.test.succeed(); chrome.test.succeed();
} }
}; };
...@@ -76,9 +81,12 @@ embedder.assertCorrectEvent_ = function(e) { ...@@ -76,9 +81,12 @@ embedder.assertCorrectEvent_ = function(e) {
// The embedder has to initiate a post message so that the guest can get a // The embedder has to initiate a post message so that the guest can get a
// reference to embedder to send the reply back. // reference to embedder to send the reply back.
var testNewWindow = var testNewWindow = function(testName,
function(testName, webViewName, guestName, expectedFrameName) { webViewName,
var webview = embedder.setUpGuest_(); guestName,
partitionName,
expectedFrameName) {
var webview = embedder.setUpGuest_(partitionName);
var onNewWindow = function(e) { var onNewWindow = function(e) {
chrome.test.log('Embedder notified on newwindow'); chrome.test.log('Embedder notified on newwindow');
...@@ -97,7 +105,8 @@ var testNewWindow = ...@@ -97,7 +105,8 @@ var testNewWindow =
var newwebview = w.document.querySelector('webview'); var newwebview = w.document.querySelector('webview');
newwebview.name = webViewName; newwebview.name = webViewName;
embedder.setUpFrameNameRequest_(newwebview, testName); embedder.setUpFrameNameRequest_(newwebview, testName);
embedder.requestFrameName_(newwebview, testName, expectedFrameName); embedder.requestFrameName_(
newwebview, webview, testName, expectedFrameName);
try { try {
e.window.attach(newwebview); e.window.attach(newwebview);
} catch (e) { } catch (e) {
...@@ -117,25 +126,29 @@ embedder.tests.testNewWindowNameTakesPrecedence = ...@@ -117,25 +126,29 @@ embedder.tests.testNewWindowNameTakesPrecedence =
function testNewWindowNameTakesPrecedence() { function testNewWindowNameTakesPrecedence() {
var webViewName = 'foo'; var webViewName = 'foo';
var guestName = 'bar'; var guestName = 'bar';
var partitionName = 'foobar';
var expectedName = guestName; var expectedName = guestName;
testNewWindow('testNewWindowNameTakesPrecedence', testNewWindow('testNewWindowNameTakesPrecedence',
webViewName, guestName, expectedName); webViewName, guestName, partitionName, expectedName);
}; };
embedder.tests.testWebViewNameTakesPrecedence = embedder.tests.testWebViewNameTakesPrecedence =
function testWebViewNameTakesPrecedence() { function testWebViewNameTakesPrecedence() {
var webViewName = 'foo'; var webViewName = 'foo';
var guestName = ''; var guestName = '';
var partitionName = 'persist:foobar';
var expectedName = webViewName; var expectedName = webViewName;
testNewWindow('testWebViewNameTakesPrecedence', testNewWindow('testWebViewNameTakesPrecedence',
webViewName, guestName, expectedName); webViewName, guestName, partitionName, expectedName);
}; };
embedder.tests.testNoName = function testNoName() { embedder.tests.testNoName = function testNoName() {
var webViewName = ''; var webViewName = '';
var guestName = ''; var guestName = '';
var partitionName = '';
var expectedName = ''; var expectedName = '';
testNewWindow('testNoName', webViewName, guestName, expectedName); testNewWindow('testNoName',
webViewName, guestName, partitionName, expectedName);
}; };
onload = function() { onload = function() {
......
...@@ -745,11 +745,17 @@ void BrowserPluginGuest::Attach( ...@@ -745,11 +745,17 @@ void BrowserPluginGuest::Attach(
GetWebContents()->GetRenderViewHost())->Init(); GetWebContents()->GetRenderViewHost())->Init();
} }
// Inform the embedder BrowserPlugin of the attached guest. // Inform the embedder of the guest's information.
if (!name_.empty()) { // We pull the partition information from the site's URL, which is of the form
// guest://site/{persist}?{partition_name}.
const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL();
BrowserPluginMsg_Attach_ACK_Params ack_params;
ack_params.storage_partition_id = site_url.query();
ack_params.persist_storage =
site_url.path().find("persist") != std::string::npos;
ack_params.name = name_;
SendMessageToEmbedder( SendMessageToEmbedder(
new BrowserPluginMsg_UpdatedName(instance_id_, name_)); new BrowserPluginMsg_Attach_ACK(instance_id_, ack_params));
}
} }
void BrowserPluginGuest::OnCompositorFrameACK( void BrowserPluginGuest::OnCompositorFrameACK(
......
...@@ -72,6 +72,12 @@ IPC_STRUCT_BEGIN(BrowserPluginHostMsg_CreateGuest_Params) ...@@ -72,6 +72,12 @@ IPC_STRUCT_BEGIN(BrowserPluginHostMsg_CreateGuest_Params)
resize_guest_params) resize_guest_params)
IPC_STRUCT_END() IPC_STRUCT_END()
IPC_STRUCT_BEGIN(BrowserPluginMsg_Attach_ACK_Params)
IPC_STRUCT_MEMBER(std::string, storage_partition_id)
IPC_STRUCT_MEMBER(bool, persist_storage)
IPC_STRUCT_MEMBER(std::string, name)
IPC_STRUCT_END()
IPC_STRUCT_BEGIN(BrowserPluginMsg_LoadCommit_Params) IPC_STRUCT_BEGIN(BrowserPluginMsg_LoadCommit_Params)
// The current URL of the guest. // The current URL of the guest.
IPC_STRUCT_MEMBER(GURL, url) IPC_STRUCT_MEMBER(GURL, url)
...@@ -299,6 +305,14 @@ IPC_MESSAGE_ROUTED2(BrowserPluginMsg_AllocateInstanceID_ACK, ...@@ -299,6 +305,14 @@ IPC_MESSAGE_ROUTED2(BrowserPluginMsg_AllocateInstanceID_ACK,
int /* request_id */, int /* request_id */,
int /* instance_id */) int /* instance_id */)
// This message is sent in response to a completed attachment of a guest
// to a BrowserPlugin. This message carries information about the guest
// that is used to update the attributes of the browser plugin.
IPC_MESSAGE_CONTROL2(BrowserPluginMsg_Attach_ACK,
int /* instance_id */,
BrowserPluginMsg_Attach_ACK_Params /* params */)
// Once the swapped out guest RenderView has been created in the embedder render // Once the swapped out guest RenderView has been created in the embedder render
// process, the browser process informs the embedder of its routing ID. // process, the browser process informs the embedder of its routing ID.
IPC_MESSAGE_CONTROL2(BrowserPluginMsg_GuestContentWindowReady, IPC_MESSAGE_CONTROL2(BrowserPluginMsg_GuestContentWindowReady,
......
...@@ -141,7 +141,7 @@ BrowserPlugin::BrowserPlugin( ...@@ -141,7 +141,7 @@ BrowserPlugin::BrowserPlugin(
plugin_focused_(false), plugin_focused_(false),
visible_(true), visible_(true),
size_changed_in_flight_(false), size_changed_in_flight_(false),
allocate_instance_id_sent_(false), before_first_navigation_(true),
browser_plugin_manager_(render_view->browser_plugin_manager()), browser_plugin_manager_(render_view->browser_plugin_manager()),
current_nav_entry_index_(0), current_nav_entry_index_(0),
nav_entry_count_(0), nav_entry_count_(0),
...@@ -174,6 +174,7 @@ bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { ...@@ -174,6 +174,7 @@ bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) {
bool handled = true; bool handled = true;
IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message)
IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus)
IPC_MESSAGE_HANDLER(BrowserPluginMsg_Attach_ACK, OnAttachACK)
IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped)
IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped, IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped,
OnCompositorFrameSwapped(message)) OnCompositorFrameSwapped(message))
...@@ -336,16 +337,16 @@ bool BrowserPlugin::ParseSrcAttribute(std::string* error_message) { ...@@ -336,16 +337,16 @@ bool BrowserPlugin::ParseSrcAttribute(std::string* error_message) {
if (!HasGuest()) { if (!HasGuest()) {
// On initial navigation, we request an instance ID from the browser // On initial navigation, we request an instance ID from the browser
// process. We essentially ignore all subsequent calls to SetSrcAttribute // process. We essentially ignore all subsequent calls to SetSrcAttribute
// until we receive an instance ID. |allocate_instance_id_sent_| // until we receive an instance ID. |before_first_navigation_|
// prevents BrowserPlugin from allocating more than one instance ID. // prevents BrowserPlugin from allocating more than one instance ID.
// Upon receiving an instance ID from the browser process, we continue // Upon receiving an instance ID from the browser process, we continue
// the process of navigation by populating the // the process of navigation by populating the
// BrowserPluginHostMsg_CreateGuest_Params with the current state of // BrowserPluginHostMsg_CreateGuest_Params with the current state of
// BrowserPlugin and sending a BrowserPluginHostMsg_CreateGuest to the // BrowserPlugin and sending a BrowserPluginHostMsg_CreateGuest to the
// browser process in order to create a new guest. // browser process in order to create a new guest.
if (!allocate_instance_id_sent_) { if (before_first_navigation_) {
browser_plugin_manager()->AllocateInstanceID(this); browser_plugin_manager()->AllocateInstanceID(this);
allocate_instance_id_sent_ = true; before_first_navigation_ = false;
} }
return true; return true;
} }
...@@ -424,6 +425,7 @@ bool BrowserPlugin::UsesPendingDamageBuffer( ...@@ -424,6 +425,7 @@ bool BrowserPlugin::UsesPendingDamageBuffer(
void BrowserPlugin::SetInstanceID(int instance_id, bool new_guest) { void BrowserPlugin::SetInstanceID(int instance_id, bool new_guest) {
CHECK(instance_id != browser_plugin::kInstanceIDNone); CHECK(instance_id != browser_plugin::kInstanceIDNone);
before_first_navigation_ = false;
instance_id_ = instance_id; instance_id_ = instance_id;
browser_plugin_manager()->AddBrowserPlugin(instance_id, this); browser_plugin_manager()->AddBrowserPlugin(instance_id, this);
...@@ -460,6 +462,20 @@ void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { ...@@ -460,6 +462,20 @@ void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) {
render_view_->GetWebView()->advanceFocus(reverse); render_view_->GetWebView()->advanceFocus(reverse);
} }
void BrowserPlugin::OnAttachACK(
int instance_id,
const BrowserPluginMsg_Attach_ACK_Params& params) {
// Update BrowserPlugin attributes to match the state of the guest.
if (!params.name.empty())
OnUpdatedName(instance_id, params.name);
if (!params.storage_partition_id.empty()) {
std::string partition_name =
(params.persist_storage ? browser_plugin::kPersistPrefix : "") +
params.storage_partition_id;
UpdateDOMAttribute(browser_plugin::kAttributePartition, partition_name);
}
}
void BrowserPlugin::OnBuffersSwapped(int instance_id, void BrowserPlugin::OnBuffersSwapped(int instance_id,
const gfx::Size& size, const gfx::Size& size,
std::string mailbox_name, std::string mailbox_name,
...@@ -850,7 +866,7 @@ bool BrowserPlugin::CanGoForward() const { ...@@ -850,7 +866,7 @@ bool BrowserPlugin::CanGoForward() const {
} }
bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) { bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) {
if (allocate_instance_id_sent_) { if (!before_first_navigation_) {
*error_message = browser_plugin::kErrorAlreadyNavigated; *error_message = browser_plugin::kErrorAlreadyNavigated;
return false; return false;
} }
...@@ -1245,6 +1261,7 @@ bool BrowserPlugin::ShouldForwardToBrowserPlugin( ...@@ -1245,6 +1261,7 @@ bool BrowserPlugin::ShouldForwardToBrowserPlugin(
const IPC::Message& message) { const IPC::Message& message) {
switch (message.type()) { switch (message.type()) {
case BrowserPluginMsg_AdvanceFocus::ID: case BrowserPluginMsg_AdvanceFocus::ID:
case BrowserPluginMsg_Attach_ACK::ID:
case BrowserPluginMsg_BuffersSwapped::ID: case BrowserPluginMsg_BuffersSwapped::ID:
case BrowserPluginMsg_CompositorFrameSwapped::ID: case BrowserPluginMsg_CompositorFrameSwapped::ID:
case BrowserPluginMsg_GuestContentWindowReady::ID: case BrowserPluginMsg_GuestContentWindowReady::ID:
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
struct BrowserPluginHostMsg_AutoSize_Params; struct BrowserPluginHostMsg_AutoSize_Params;
struct BrowserPluginHostMsg_ResizeGuest_Params; struct BrowserPluginHostMsg_ResizeGuest_Params;
struct BrowserPluginMsg_Attach_ACK_Params;
struct BrowserPluginMsg_LoadCommit_Params; struct BrowserPluginMsg_LoadCommit_Params;
struct BrowserPluginMsg_UpdateRect_Params; struct BrowserPluginMsg_UpdateRect_Params;
...@@ -323,6 +324,8 @@ class CONTENT_EXPORT BrowserPlugin : ...@@ -323,6 +324,8 @@ class CONTENT_EXPORT BrowserPlugin :
// IPC message handlers. // IPC message handlers.
// Please keep in alphabetical order. // Please keep in alphabetical order.
void OnAdvanceFocus(int instance_id, bool reverse); void OnAdvanceFocus(int instance_id, bool reverse);
void OnAttachACK(int instance_id,
const BrowserPluginMsg_Attach_ACK_Params& ack_params);
void OnBuffersSwapped(int instance_id, void OnBuffersSwapped(int instance_id,
const gfx::Size& size, const gfx::Size& size,
std::string mailbox_name, std::string mailbox_name,
...@@ -392,7 +395,7 @@ class CONTENT_EXPORT BrowserPlugin : ...@@ -392,7 +395,7 @@ class CONTENT_EXPORT BrowserPlugin :
gfx::Size last_view_size_; gfx::Size last_view_size_;
bool size_changed_in_flight_; bool size_changed_in_flight_;
bool allocate_instance_id_sent_; bool before_first_navigation_;
// Each permission request item in the map is a pair of request id and // Each permission request item in the map is a pair of request id and
// permission type. // permission type.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment