guest_delegate_->SetSize(params);
}
-void WebContents::SetAllowTransparency(bool allow) {
- if (guest_delegate_)
- guest_delegate_->SetAllowTransparency(allow);
-}
-
bool WebContents::IsGuest() const {
return type_ == WEB_VIEW;
}
&WebContents::BeginFrameSubscription)
.SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription)
.SetMethod("setSize", &WebContents::SetSize)
- .SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
.SetMethod("isGuest", &WebContents::IsGuest)
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
.SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)
// Methods for creating <webview>.
void SetSize(const SetSizeParams& params);
- void SetAllowTransparency(bool allow);
bool IsGuest() const;
// Callback triggered on permission response.
#include "atom/browser/web_view_guest_delegate.h"
#include "atom/browser/api/atom_api_web_contents.h"
+#include "atom/common/api/api_messages.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "content/public/browser/guest_host.h"
#include "content/public/browser/render_frame_host.h"
} // namespace
WebViewGuestDelegate::WebViewGuestDelegate()
- : guest_opaque_(true),
- guest_host_(nullptr),
+ : guest_host_(nullptr),
auto_size_enabled_(false),
is_full_page_plugin_(false),
api_web_contents_(nullptr) {
auto_size_enabled_ = enable_auto_size;
}
-void WebViewGuestDelegate::SetAllowTransparency(bool allow) {
- if (guest_opaque_ != allow)
- return;
-
- auto render_view_host = web_contents()->GetRenderViewHost();
- guest_opaque_ = !allow;
- if (!render_view_host->GetWidget()->GetView())
- return;
-
- if (guest_opaque_) {
- render_view_host->GetWidget()->GetView()->SetBackgroundColorToDefault();
- } else {
- render_view_host->GetWidget()->GetView()->SetBackgroundColor(
- SK_ColorTRANSPARENT);
- }
-}
-
void WebViewGuestDelegate::HandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) {
}
void WebViewGuestDelegate::RenderViewReady() {
- // We don't want to accidentally set the opacity of an interstitial page.
- // WebContents::GetRenderWidgetHostView will return the RWHV of an
- // interstitial page if one is showing at this time. We only want opacity
- // to apply to web pages.
- auto render_view_host_view =
- web_contents()->GetRenderViewHost()->GetWidget()->GetView();
- if (guest_opaque_)
- render_view_host_view->SetBackgroundColorToDefault();
- else
- render_view_host_view->SetBackgroundColor(SK_ColorTRANSPARENT);
+ // Set default UA-dependent background as transparent.
+ api_web_contents_->Send(new AtomViewMsg_SetTransparentBackground(
+ api_web_contents_->routing_id()));
}
void WebViewGuestDelegate::DidCommitProvisionalLoadForFrame(
// and normal sizes.
void SetSize(const SetSizeParams& params);
- // Sets the transparency of the guest.
- void SetAllowTransparency(bool allow);
-
// Transfer the keyboard event to embedder.
void HandleKeyboardEvent(content::WebContents* source,
const content::NativeWebKeyboardEvent& event);
// Returns the default size of the guestview.
gfx::Size GetDefaultSize() const;
- // Stores whether the contents of the guest can be transparent.
- bool guest_opaque_;
-
// The WebContents that attaches this guest view.
content::WebContents* embedder_web_contents_;
// Sent by the renderer when the draggable regions are updated.
IPC_MESSAGE_ROUTED1(AtomViewHostMsg_UpdateDraggableRegions,
std::vector<atom::DraggableRegion> /* regions */)
+
+IPC_MESSAGE_ROUTED0(AtomViewMsg_SetTransparentBackground)
#include "ipc/ipc_message_macros.h"
#include "net/base/net_module.h"
#include "net/grit/net_resources.h"
+#include "third_party/skia/include/core/SkColor.h"
#include "third_party/WebKit/public/web/WebDraggableRegion.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFrame.h"
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(AtomRenderViewObserver, message)
IPC_MESSAGE_HANDLER(AtomViewMsg_Message, OnBrowserMessage)
+ IPC_MESSAGE_HANDLER(AtomViewMsg_SetTransparentBackground,
+ OnSetTransparentBackground)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
}
}
+void AtomRenderViewObserver::OnSetTransparentBackground() {
+ if (!render_view()->GetWebView())
+ return;
+ render_view()->GetWebView()->setBaseBackgroundColor(SK_ColorTRANSPARENT);
+}
+
} // namespace atom
void OnBrowserMessage(const base::string16& channel,
const base::ListValue& args);
+ void OnSetTransparentBackground();
// Weak reference to renderer client.
AtomRendererClient* renderer_client_;
}
this.loadURL(params.src, opts);
}
- if (params.allowtransparency != null) {
- this.setAllowTransparency(params.allowtransparency);
- }
return guest.allowPopups = params.allowpopups;
});
return (ref1 = guestInstances[id]) != null ? ref1.guest.setSize(params) : void 0;
});
-ipcMain.on('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', function(event, id, allowtransparency) {
- var ref1;
- return (ref1 = guestInstances[id]) != null ? ref1.guest.setAllowTransparency(allowtransparency) : void 0;
-});
-
// Returns WebContents from its guest id.
exports.getGuest = function(id) {
var ref1;
setSize: function(guestInstanceId, params) {
return ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', guestInstanceId, params);
},
- setAllowTransparency: function(guestInstanceId, allowtransparency) {
- return ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', guestInstanceId, allowtransparency);
- }
};
}
}
-// Attribute that specifies whether transparency is allowed in the webview.
-class AllowTransparencyAttribute extends BooleanAttribute {
- constructor(webViewImpl) {
- super(webViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, webViewImpl);
- }
-
- handleMutation() {
- if (!this.webViewImpl.guestInstanceId) {
- return;
- }
- return guestViewInternal.setAllowTransparency(this.webViewImpl.guestInstanceId, this.getValue());
- }
-}
-
// Attribute used to define the demension limits of autosizing.
class AutosizeDimensionAttribute extends WebViewAttribute {
constructor(name, webViewImpl) {
// Sets up all of the webview attributes.
WebViewImpl.prototype.setupWebViewAttributes = function() {
this.attributes = {};
- this.attributes[webViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY] = new AllowTransparencyAttribute(this);
this.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE] = new AutosizeAttribute(this);
this.attributes[webViewConstants.ATTRIBUTE_PARTITION] = new PartitionAttribute(this);
this.attributes[webViewConstants.ATTRIBUTE_SRC] = new SrcAttribute(this);
module.exports = {
// Attributes.
- ATTRIBUTE_ALLOWTRANSPARENCY: 'allowtransparency',
ATTRIBUTE_AUTOSIZE: 'autosize',
ATTRIBUTE_MAXHEIGHT: 'maxheight',
ATTRIBUTE_MAXWIDTH: 'maxwidth',