From 993f66bd02cefc74e413ac5b160aabf361a0c2d8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 24 Oct 2014 16:09:18 +0800 Subject: [PATCH] Fix initializing webview --- atom/browser/api/atom_api_web_contents.cc | 12 +++++++++++- atom/browser/api/atom_api_web_contents.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 490ec66c18..b2a0eef6cd 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -14,6 +14,7 @@ #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" +#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/web_contents.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" @@ -39,7 +40,7 @@ WebContents::WebContents(content::WebContents* web_contents) WebContents::WebContents(const mate::Dictionary& options) : guest_instance_id_(-1), auto_size_enabled_(false) { - options.Get("guestInstances", &guest_instance_id_); + options.Get("guestInstanceId", &guest_instance_id_); content::WebContents::CreateParams params(AtomBrowserContext::Get()); bool is_guest; @@ -99,6 +100,15 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) { } void WebContents::RenderViewReady() { + if (!is_guest()) + return; + + content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); + if (auto_size_enabled_) { + rvh->EnableAutoResize(min_auto_size_, max_auto_size_); + } else { + rvh->DisableAutoResize(element_size_); + } } void WebContents::WebContentsDestroyed() { diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index a0e47a6006..ee2fcc784d 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -61,6 +61,9 @@ class WebContents : public mate::EventEmitter, const gfx::Size& min_size, const gfx::Size& max_size); + // Returns whether this is a guest view. + bool is_guest() const { return guest_instance_id_ != -1; } + // Returns whether this guest has an associated embedder. bool attached() const { return !!embedder_web_contents_; }