Commit 1d139b20 authored by fsamuel's avatar fsamuel Committed by Commit bot

GuestView: Lazily push attributes to the browser process on attach

Only push attributes to the browser process on attach that have changed
since create.

This CL also allows partial changes to autosize parameters.

BUG=471402

Review URL: https://codereview.chromium.org/1033373003

Cr-Commit-Position: refs/heads/master@{#322683}
parent ac201157
...@@ -785,21 +785,21 @@ double GuestViewBase::GetEmbedderZoomFactor() { ...@@ -785,21 +785,21 @@ double GuestViewBase::GetEmbedderZoomFactor() {
void GuestViewBase::SetUpSizing(const base::DictionaryValue& params) { void GuestViewBase::SetUpSizing(const base::DictionaryValue& params) {
// Read the autosize parameters passed in from the embedder. // Read the autosize parameters passed in from the embedder.
bool auto_size_enabled = false; bool auto_size_enabled = auto_size_enabled_;
params.GetBoolean(guestview::kAttributeAutoSize, &auto_size_enabled); params.GetBoolean(guestview::kAttributeAutoSize, &auto_size_enabled);
int max_height = 0; int max_height = max_auto_size_.height();
int max_width = 0; int max_width = max_auto_size_.width();
params.GetInteger(guestview::kAttributeMaxHeight, &max_height); params.GetInteger(guestview::kAttributeMaxHeight, &max_height);
params.GetInteger(guestview::kAttributeMaxWidth, &max_width); params.GetInteger(guestview::kAttributeMaxWidth, &max_width);
int min_height = 0; int min_height = min_auto_size_.height();
int min_width = 0; int min_width = min_auto_size_.width();
params.GetInteger(guestview::kAttributeMinHeight, &min_height); params.GetInteger(guestview::kAttributeMinHeight, &min_height);
params.GetInteger(guestview::kAttributeMinWidth, &min_width); params.GetInteger(guestview::kAttributeMinWidth, &min_width);
int normal_height = 0; int normal_height = normal_size_.height();
int normal_width = 0; int normal_width = normal_size_.width();
if (is_full_page_plugin()) { if (is_full_page_plugin()) {
// The initial size of a full page plugin should be set to fill the // The initial size of a full page plugin should be set to fill the
// owner's visible viewport. // owner's visible viewport.
......
...@@ -9,9 +9,10 @@ ...@@ -9,9 +9,10 @@
// Default implementation of a GuestView attribute. // Default implementation of a GuestView attribute.
function Attribute(name, view) { function Attribute(name, view) {
this.dirty = false;
this.ignoreMutation = false;
this.name = name; this.name = name;
this.view = view; this.view = view;
this.ignoreMutation = false;
this.defineProperty(); this.defineProperty();
} }
...@@ -21,6 +22,15 @@ Attribute.prototype.getValue = function() { ...@@ -21,6 +22,15 @@ Attribute.prototype.getValue = function() {
return this.view.element.getAttribute(this.name) || ''; return this.view.element.getAttribute(this.name) || '';
}; };
// Retrieves and returns the attribute's value if it has been dirtied since
// the last time this method was called. Returns null otherwise.
Attribute.prototype.getValueIfDirty = function() {
if (!this.dirty)
return null;
this.dirty = false;
return this.getValue();
};
// Sets the attribute's value. // Sets the attribute's value.
Attribute.prototype.setValue = function(value) { Attribute.prototype.setValue = function(value) {
this.view.element.setAttribute(this.name, value || ''); this.view.element.setAttribute(this.name, value || '');
...@@ -51,6 +61,7 @@ Attribute.prototype.maybeHandleMutation = function(oldValue, newValue) { ...@@ -51,6 +61,7 @@ Attribute.prototype.maybeHandleMutation = function(oldValue, newValue) {
if (this.ignoreMutation) if (this.ignoreMutation)
return; return;
this.dirty = true;
this.handleMutation(oldValue, newValue); this.handleMutation(oldValue, newValue);
}; };
......
...@@ -55,6 +55,10 @@ WebViewImpl.setupElement = function(proto) { ...@@ -55,6 +55,10 @@ WebViewImpl.setupElement = function(proto) {
// Initiates navigation once the <webview> element is attached to the DOM. // Initiates navigation once the <webview> element is attached to the DOM.
WebViewImpl.prototype.onElementAttached = function() { WebViewImpl.prototype.onElementAttached = function() {
// Mark all attributes as dirty on attachment.
for (var i in this.attributes) {
this.attributes[i].dirty = true;
}
for (var i in this.attributes) { for (var i in this.attributes) {
this.attributes[i].attach(); this.attributes[i].attach();
} }
...@@ -63,6 +67,9 @@ WebViewImpl.prototype.onElementAttached = function() { ...@@ -63,6 +67,9 @@ WebViewImpl.prototype.onElementAttached = function() {
// Resets some state upon detaching <webview> element from the DOM. // Resets some state upon detaching <webview> element from the DOM.
WebViewImpl.prototype.onElementDetached = function() { WebViewImpl.prototype.onElementDetached = function() {
this.guest.destroy(); this.guest.destroy();
for (var i in this.attributes) {
this.attributes[i].dirty = false;
}
for (var i in this.attributes) { for (var i in this.attributes) {
this.attributes[i].detach(); this.attributes[i].detach();
} }
...@@ -167,7 +174,9 @@ WebViewImpl.prototype.onAttach = function(storagePartitionId) { ...@@ -167,7 +174,9 @@ WebViewImpl.prototype.onAttach = function(storagePartitionId) {
WebViewImpl.prototype.buildContainerParams = function() { WebViewImpl.prototype.buildContainerParams = function() {
var params = { 'userAgentOverride': this.userAgentOverride }; var params = { 'userAgentOverride': this.userAgentOverride };
for (var i in this.attributes) { for (var i in this.attributes) {
params[i] = this.attributes[i].getValue(); var value = this.attributes[i].getValueIfDirty();
if (value)
params[i] = value;
} }
return params; return params;
}; };
......
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