Register guest web view

This commit is contained in:
Cheng Zhao 2014-10-23 23:08:48 +08:00
parent 81599f1535
commit dacbf7a042
10 changed files with 126 additions and 56 deletions

View file

@ -44,6 +44,7 @@ WebContents::WebContents(const mate::Dictionary& options)
params.guest_delegate = this;
storage_.reset(content::WebContents::Create(params));
storage_->SetDelegate(this);
Observe(storage_.get());
}
@ -94,6 +95,9 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) {
return handled;
}
void WebContents::RenderViewReady() {
}
void WebContents::WebContentsDestroyed() {
// The RenderViewDeleted was not called when the WebContents is destroyed.
RenderViewDeleted(web_contents()->GetRenderViewHost());
@ -105,6 +109,12 @@ void WebContents::WillAttach(content::WebContents* embedder_web_contents,
LOG(ERROR) << "WillAttach";
}
content::WebContents* WebContents::CreateNewGuestWindow(
const content::WebContents::CreateParams& create_params) {
LOG(ERROR) << "CreateNewGuestWindow";
return nullptr;
}
void WebContents::DidAttach() {
LOG(ERROR) << "DidAttach";
}
@ -137,6 +147,7 @@ void WebContents::RegisterDestructionCallback(
}
void WebContents::Destroy() {
LOG(ERROR) << "Destroy";
if (storage_) {
if (!destruction_callback_.is_null())
destruction_callback_.Run();

View file

@ -7,6 +7,7 @@
#include "atom/browser/api/event_emitter.h"
#include "content/public/browser/browser_plugin_guest_delegate.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "native_mate/handle.h"
@ -20,6 +21,7 @@ namespace api {
class WebContents : public mate::EventEmitter,
public content::BrowserPluginGuestDelegate,
public content::WebContentsDelegate,
public content::WebContentsObserver {
public:
// Create from an existing WebContents.
@ -54,6 +56,10 @@ class WebContents : public mate::EventEmitter,
bool SendIPCMessage(const base::string16& channel,
const base::ListValue& args);
content::WebContents* web_contents() const {
return content::WebContentsObserver::web_contents();
}
protected:
explicit WebContents(content::WebContents* web_contents);
explicit WebContents(const mate::Dictionary& options);
@ -61,35 +67,38 @@ class WebContents : public mate::EventEmitter,
// mate::Wrappable:
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate) OVERRIDE;
v8::Isolate* isolate) override;
// content::WebContentsObserver:
virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE;
virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
virtual void RenderViewDeleted(content::RenderViewHost*) override;
virtual void RenderProcessGone(base::TerminationStatus status) override;
virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) OVERRIDE;
const GURL& validated_url) override;
virtual void DidStartLoading(
content::RenderViewHost* render_view_host) OVERRIDE;
content::RenderViewHost* render_view_host) override;
virtual void DidStopLoading(
content::RenderViewHost* render_view_host) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void WebContentsDestroyed() OVERRIDE;
content::RenderViewHost* render_view_host) override;
virtual bool OnMessageReceived(const IPC::Message& message) override;
virtual void RenderViewReady() override;
virtual void WebContentsDestroyed() override;
// content::BrowserPluginGuestDelegate:
virtual void WillAttach(content::WebContents* embedder_web_contents,
const base::DictionaryValue& extra_params) final;
virtual void DidAttach() final;
virtual int GetGuestInstanceID() const final;
const base::DictionaryValue& extra_params) override;
virtual content::WebContents* CreateNewGuestWindow(
const content::WebContents::CreateParams& create_params) override;
virtual void DidAttach() override;
virtual int GetGuestInstanceID() const override;
virtual void ElementSizeChanged(const gfx::Size& old_size,
const gfx::Size& new_size) final;
const gfx::Size& new_size) override;
virtual void GuestSizeChanged(const gfx::Size& old_size,
const gfx::Size& new_size) final;
const gfx::Size& new_size) override;
virtual void RequestPointerLockPermission(
bool user_gesture,
bool last_unlocked_by_target,
const base::Callback<void(bool)>& callback) final;
const base::Callback<void(bool)>& callback) override;
virtual void RegisterDestructionCallback(
const DestructionCallback& callback) final;
const DestructionCallback& callback) override;
private:
// Called when received a message from renderer.