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) {
};
/** @private */
embedder.setUpGuest_ = function() {
embedder.setUpGuest_ = function(partitionName) {
document.querySelector('#webview-tag-container').innerHTML =
'<webview style="width: 100px; height: 100px;"' +
' src="' + embedder.guestURL + '"' +
'></webview>';
var webview = document.querySelector('webview');
if (partitionName) {
webview.partition = partitionName;
}
if (!webview) {
chrome.test.fail('No <webview> element created');
}
......@@ -48,7 +51,8 @@ embedder.setUpFrameNameRequest_ = function(webview, testName) {
};
/** @private */
embedder.requestFrameName_ = function(webview, testName, expectedFrameName) {
embedder.requestFrameName_ =
function(webview, openerwebview, testName, expectedFrameName) {
var onPostMessageReceived = function(e) {
var data = JSON.parse(e.data);
if (data[0] == 'get-frame-name') {
......@@ -58,6 +62,7 @@ embedder.requestFrameName_ = function(webview, testName, expectedFrameName) {
var frameName = data[2];
chrome.test.assertEq(expectedFrameName, frameName);
chrome.test.assertEq(expectedFrameName, webview.name);
chrome.test.assertEq(openerwebview.partition, webview.partition);
chrome.test.succeed();
}
};
......@@ -76,9 +81,12 @@ embedder.assertCorrectEvent_ = function(e) {
// The embedder has to initiate a post message so that the guest can get a
// reference to embedder to send the reply back.
var testNewWindow =
function(testName, webViewName, guestName, expectedFrameName) {
var webview = embedder.setUpGuest_();
var testNewWindow = function(testName,
webViewName,
guestName,
partitionName,
expectedFrameName) {
var webview = embedder.setUpGuest_(partitionName);
var onNewWindow = function(e) {
chrome.test.log('Embedder notified on newwindow');
......@@ -97,7 +105,8 @@ var testNewWindow =
var newwebview = w.document.querySelector('webview');
newwebview.name = webViewName;
embedder.setUpFrameNameRequest_(newwebview, testName);
embedder.requestFrameName_(newwebview, testName, expectedFrameName);
embedder.requestFrameName_(
newwebview, webview, testName, expectedFrameName);
try {
e.window.attach(newwebview);
} catch (e) {
......@@ -117,25 +126,29 @@ embedder.tests.testNewWindowNameTakesPrecedence =
function testNewWindowNameTakesPrecedence() {
var webViewName = 'foo';
var guestName = 'bar';
var partitionName = 'foobar';
var expectedName = guestName;
testNewWindow('testNewWindowNameTakesPrecedence',
webViewName, guestName, expectedName);
webViewName, guestName, partitionName, expectedName);
};
embedder.tests.testWebViewNameTakesPrecedence =
function testWebViewNameTakesPrecedence() {
var webViewName = 'foo';
var guestName = '';
var partitionName = 'persist:foobar';
var expectedName = webViewName;
testNewWindow('testWebViewNameTakesPrecedence',
webViewName, guestName, expectedName);
webViewName, guestName, partitionName, expectedName);
};
embedder.tests.testNoName = function testNoName() {
var webViewName = '';
var guestName = '';
var partitionName = '';
var expectedName = '';
testNewWindow('testNoName', webViewName, guestName, expectedName);
testNewWindow('testNoName',
webViewName, guestName, partitionName, expectedName);
};
onload = function() {
......
......@@ -745,11 +745,17 @@ void BrowserPluginGuest::Attach(
GetWebContents()->GetRenderViewHost())->Init();
}
// Inform the embedder BrowserPlugin of the attached guest.
if (!name_.empty()) {
SendMessageToEmbedder(
new BrowserPluginMsg_UpdatedName(instance_id_, name_));
}
// Inform the embedder of the guest's information.
// 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(
new BrowserPluginMsg_Attach_ACK(instance_id_, ack_params));
}
void BrowserPluginGuest::OnCompositorFrameACK(
......
......@@ -72,6 +72,12 @@ IPC_STRUCT_BEGIN(BrowserPluginHostMsg_CreateGuest_Params)
resize_guest_params)
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)
// The current URL of the guest.
IPC_STRUCT_MEMBER(GURL, url)
......@@ -299,6 +305,14 @@ IPC_MESSAGE_ROUTED2(BrowserPluginMsg_AllocateInstanceID_ACK,
int /* request_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
// process, the browser process informs the embedder of its routing ID.
IPC_MESSAGE_CONTROL2(BrowserPluginMsg_GuestContentWindowReady,
......
......@@ -141,7 +141,7 @@ BrowserPlugin::BrowserPlugin(
plugin_focused_(false),
visible_(true),
size_changed_in_flight_(false),
allocate_instance_id_sent_(false),
before_first_navigation_(true),
browser_plugin_manager_(render_view->browser_plugin_manager()),
current_nav_entry_index_(0),
nav_entry_count_(0),
......@@ -174,6 +174,7 @@ bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message)
IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus)
IPC_MESSAGE_HANDLER(BrowserPluginMsg_Attach_ACK, OnAttachACK)
IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped)
IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped,
OnCompositorFrameSwapped(message))
......@@ -336,16 +337,16 @@ bool BrowserPlugin::ParseSrcAttribute(std::string* error_message) {
if (!HasGuest()) {
// On initial navigation, we request an instance ID from the browser
// 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.
// Upon receiving an instance ID from the browser process, we continue
// the process of navigation by populating the
// BrowserPluginHostMsg_CreateGuest_Params with the current state of
// BrowserPlugin and sending a BrowserPluginHostMsg_CreateGuest to the
// browser process in order to create a new guest.
if (!allocate_instance_id_sent_) {
if (before_first_navigation_) {
browser_plugin_manager()->AllocateInstanceID(this);
allocate_instance_id_sent_ = true;
before_first_navigation_ = false;
}
return true;
}
......@@ -424,6 +425,7 @@ bool BrowserPlugin::UsesPendingDamageBuffer(
void BrowserPlugin::SetInstanceID(int instance_id, bool new_guest) {
CHECK(instance_id != browser_plugin::kInstanceIDNone);
before_first_navigation_ = false;
instance_id_ = instance_id;
browser_plugin_manager()->AddBrowserPlugin(instance_id, this);
......@@ -460,6 +462,20 @@ void BrowserPlugin::OnAdvanceFocus(int instance_id, bool 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,
const gfx::Size& size,
std::string mailbox_name,
......@@ -850,7 +866,7 @@ bool BrowserPlugin::CanGoForward() const {
}
bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) {
if (allocate_instance_id_sent_) {
if (!before_first_navigation_) {
*error_message = browser_plugin::kErrorAlreadyNavigated;
return false;
}
......@@ -1245,6 +1261,7 @@ bool BrowserPlugin::ShouldForwardToBrowserPlugin(
const IPC::Message& message) {
switch (message.type()) {
case BrowserPluginMsg_AdvanceFocus::ID:
case BrowserPluginMsg_Attach_ACK::ID:
case BrowserPluginMsg_BuffersSwapped::ID:
case BrowserPluginMsg_CompositorFrameSwapped::ID:
case BrowserPluginMsg_GuestContentWindowReady::ID:
......
......@@ -23,6 +23,7 @@
struct BrowserPluginHostMsg_AutoSize_Params;
struct BrowserPluginHostMsg_ResizeGuest_Params;
struct BrowserPluginMsg_Attach_ACK_Params;
struct BrowserPluginMsg_LoadCommit_Params;
struct BrowserPluginMsg_UpdateRect_Params;
......@@ -323,6 +324,8 @@ class CONTENT_EXPORT BrowserPlugin :
// IPC message handlers.
// Please keep in alphabetical order.
void OnAdvanceFocus(int instance_id, bool reverse);
void OnAttachACK(int instance_id,
const BrowserPluginMsg_Attach_ACK_Params& ack_params);
void OnBuffersSwapped(int instance_id,
const gfx::Size& size,
std::string mailbox_name,
......@@ -392,7 +395,7 @@ class CONTENT_EXPORT BrowserPlugin :
gfx::Size last_view_size_;
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
// 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