diff --git a/atom.gyp b/atom.gyp index 0f69b18f41e5..12d1bb1eb142 100644 --- a/atom.gyp +++ b/atom.gyp @@ -29,6 +29,7 @@ 'atom/browser/api/lib/tray.coffee', 'atom/browser/api/lib/web-contents.coffee', 'atom/browser/lib/chrome-extension.coffee', + 'atom/browser/lib/guest-view-manager.coffee', 'atom/browser/lib/init.coffee', 'atom/browser/lib/objects-registry.coffee', 'atom/browser/lib/rpc-server.coffee', @@ -41,6 +42,7 @@ 'atom/common/lib/init.coffee', 'atom/common/lib/asar.coffee', 'atom/renderer/lib/chrome-api.coffee', + 'atom/renderer/lib/guest-view-internal.coffee', 'atom/renderer/lib/init.coffee', 'atom/renderer/lib/inspector.coffee', 'atom/renderer/lib/override.coffee', diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 9978e92d6cf3..62f4bacd2f6e 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -30,10 +30,14 @@ v8::Persistent template_; } // namespace WebContents::WebContents(content::WebContents* web_contents) - : content::WebContentsObserver(web_contents) { + : content::WebContentsObserver(web_contents), + guest_instance_id_(-1) { } -WebContents::WebContents(const mate::Dictionary& options) { +WebContents::WebContents(const mate::Dictionary& options) + : guest_instance_id_(-1) { + options.Get("guestInstances", &guest_instance_id_); + content::WebContents::CreateParams params(AtomBrowserContext::Get()); bool is_guest; if (options.Get("isGuest", &is_guest) && is_guest) @@ -44,6 +48,7 @@ WebContents::WebContents(const mate::Dictionary& options) { } WebContents::~WebContents() { + Destroy(); } void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) { @@ -95,8 +100,47 @@ void WebContents::WebContentsDestroyed() { Emit("destroyed"); } +void WebContents::WillAttach(content::WebContents* embedder_web_contents, + const base::DictionaryValue& extra_params) { + LOG(ERROR) << "WillAttach"; +} + +void WebContents::DidAttach() { + LOG(ERROR) << "DidAttach"; +} + +int WebContents::GetGuestInstanceID() const { + return guest_instance_id_; +} + +void WebContents::ElementSizeChanged(const gfx::Size& old_size, + const gfx::Size& new_size) { + LOG(ERROR) << "ElementSizeChanged"; +} + +void WebContents::GuestSizeChanged(const gfx::Size& old_size, + const gfx::Size& new_size) { + LOG(ERROR) << "GuestSizeChanged"; +} + +void WebContents::RequestPointerLockPermission( + bool user_gesture, + bool last_unlocked_by_target, + const base::Callback& callback) { + callback.Run(true); +} + +void WebContents::RegisterDestructionCallback( + const DestructionCallback& callback) { + LOG(ERROR) << "RegisterDestructionCallback"; + destruction_callback_ = callback; +} + void WebContents::Destroy() { if (storage_) { + if (!destruction_callback_.is_null()) + destruction_callback_.Run(); + Observe(nullptr); storage_.reset(); } diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 4e119768960c..7734fee18a89 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -59,11 +59,11 @@ class WebContents : public mate::EventEmitter, explicit WebContents(const mate::Dictionary& options); ~WebContents(); - // mate::Wrappable implementations: + // mate::Wrappable: virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder( v8::Isolate* isolate) OVERRIDE; - // content::WebContentsObserver implementations: + // content::WebContentsObserver: virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE; virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host, @@ -75,6 +75,22 @@ class WebContents : public mate::EventEmitter, virtual bool OnMessageReceived(const IPC::Message& message) 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; + virtual void ElementSizeChanged(const gfx::Size& old_size, + const gfx::Size& new_size) final; + virtual void GuestSizeChanged(const gfx::Size& old_size, + const gfx::Size& new_size) final; + virtual void RequestPointerLockPermission( + bool user_gesture, + bool last_unlocked_by_target, + const base::Callback& callback) final; + virtual void RegisterDestructionCallback( + const DestructionCallback& callback) final; + private: // Called when received a message from renderer. void OnRendererMessage(const base::string16& channel, @@ -85,6 +101,11 @@ class WebContents : public mate::EventEmitter, const base::ListValue& args, IPC::Message* message); + // Unique ID for a guest WebContents. + int guest_instance_id_; + + DestructionCallback destruction_callback_; + // Stores the WebContents that managed by this class. scoped_ptr storage_; diff --git a/atom/browser/default_app/index.html b/atom/browser/default_app/index.html index 810f11f18476..0d9c59a857fe 100644 --- a/atom/browser/default_app/index.html +++ b/atom/browser/default_app/index.html @@ -56,7 +56,7 @@ - +