'atom/browser/ui/win/notify_icon.h',
'atom/browser/ui/x/x_window_utils.cc',
'atom/browser/ui/x/x_window_utils.h',
- 'atom/browser/web_view/web_view_guest.cc',
- 'atom/browser/web_view/web_view_guest.h',
'atom/browser/web_view/web_view_manager.cc',
'atom/browser/web_view/web_view_manager.h',
'atom/browser/window_list.cc',
params.guest_delegate = this;
storage_.reset(content::WebContents::Create(params));
+ storage_->SetDelegate(this);
Observe(storage_.get());
}
return handled;
}
+void WebContents::RenderViewReady() {
+}
+
void WebContents::WebContentsDestroyed() {
// The RenderViewDeleted was not called when the WebContents is destroyed.
RenderViewDeleted(web_contents()->GetRenderViewHost());
LOG(ERROR) << "WillAttach";
}
+content::WebContents* WebContents::CreateNewGuestWindow(
+ const content::WebContents::CreateParams& create_params) {
+ LOG(ERROR) << "CreateNewGuestWindow";
+ return nullptr;
+}
+
void WebContents::DidAttach() {
LOG(ERROR) << "DidAttach";
}
}
void WebContents::Destroy() {
+ LOG(ERROR) << "Destroy";
if (storage_) {
if (!destruction_callback_.is_null())
destruction_callback_.Run();
#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"
class WebContents : public mate::EventEmitter,
public content::BrowserPluginGuestDelegate,
+ public content::WebContentsDelegate,
public content::WebContentsObserver {
public:
// Create from an existing WebContents.
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);
// 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.
// Returns the browser context singleton.
static AtomBrowserContext* Get();
- AtomURLRequestJobFactory* job_factory() const { return job_factory_; }
-
- protected:
// brightray::URLRequestContextGetter::Delegate:
virtual net::URLRequestJobFactory* CreateURLRequestJobFactory(
content::ProtocolHandlerMap* handlers,
// content::BrowserContext:
virtual content::BrowserPluginGuestManager* GetGuestManager() override;
+ AtomURLRequestJobFactory* job_factory() const { return job_factory_; }
+
private:
// A fake BrowserProcess object that used to feed the source code from chrome.
scoped_ptr<BrowserProcess> fake_browser_process_;
resizable: false,
'auto-hide-menu-bar': true,
'use-content-size': true,
+ 'web-preferences': {
+ 'plugins': true,
+ },
});
mainWindow.loadUrl('file://' + __dirname + '/index.html');
mainWindow.focus();
ipc = require 'ipc'
webContents = require 'web-contents'
+webViewManager = null # Doesn't exist in early initialization.
nextInstanceId = 0
guestInstances = {}
# Create a new guest instance.
createGuest = (embedder, params) ->
+ webViewManager ?= process.atomBinding 'web_view_manager'
+
id = getNextInstanceId embedder
- guestInstances[id] = webContents.create isGuest: true, guestInstanceId: id
+ guestInstances[id] = webContents.create
+ isGuest: true
+ guestInstanceId: id
+ storagePartitionId: params.storagePartitionId
+ webViewManager.addGuest id, embedder, guestInstances[id]
id
# Destroy an existing guest instance.
destroyGuest = (id) ->
+ webViewManager.removeGuest id
guestInstances[id].destroy()
delete guestInstances[id]
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', (event, type, params, requestId) ->
- event.sender.send "ATOM_SHELL_RESPONSE_#{requestId}", createGuest(event.sender)
+ event.sender.send "ATOM_SHELL_RESPONSE_#{requestId}", createGuest(event.sender, params)
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', (event, guestInstanceId) ->
destroyGuest guestInstanceId
+++ /dev/null
-// Copyright (c) 2014 GitHub, Inc. All rights reserved.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#include "atom/browser/web_view/web_view_guest.h"
-
-namespace atom {
-
-
-
-} // namespace atom
+++ /dev/null
-// Copyright (c) 2014 GitHub, Inc. All rights reserved.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#ifndef ATOM_BROWSER_WEB_VIEW_WEB_VIEW_GUEST_H_
-#define ATOM_BROWSER_WEB_VIEW_WEB_VIEW_GUEST_H_
-
-namespace atom {
-
-// A WebViewGuest provides the browser-side implementation of the <webview> API
-// and manages the dispatch of <webview> extension events. WebViewGuest is
-// created on attachment. That is, when a guest WebContents is associated with
-// a particular embedder WebContents. This happens on either initial navigation
-// or through the use of the New Window API, when a new window is attached to
-// a particular <webview>.
-
-} // namespace atom
-
-#endif // ATOM_BROWSER_WEB_VIEW_WEB_VIEW_GUEST_H_
#include "atom/browser/web_view/web_view_manager.h"
-#include "base/logging.h"
+#include "atom/browser/api/atom_api_web_contents.h"
+#include "atom/browser/atom_browser_context.h"
+#include "base/bind.h"
+#include "base/stl_util.h"
+#include "native_mate/dictionary.h"
+#include "native_mate/object_template_builder.h"
+
+#include "atom/common/node_includes.h"
+
+namespace mate {
+
+template<>
+struct Converter<content::WebContents*> {
+ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
+ content::WebContents** out) {
+ atom::api::WebContents* contents;
+ if (!Converter<atom::api::WebContents*>::FromV8(isolate, val, &contents))
+ return false;
+ *out = contents->web_contents();
+ return true;
+ }
+};
+
+} // namespace mate
namespace atom {
WebViewManager::~WebViewManager() {
}
+void WebViewManager::AddGuest(int guest_instance_id,
+ content::WebContents* embedder,
+ content::WebContents* web_contents) {
+ web_contents_map_[guest_instance_id] = {web_contents, embedder};
+}
+
+void WebViewManager::RemoveGuest(int guest_instance_id) {
+ web_contents_map_.erase(guest_instance_id);
+}
+
void WebViewManager::MaybeGetGuestByInstanceIDOrKill(
int guest_instance_id,
int embedder_render_process_id,
const GuestByInstanceIDCallback& callback) {
- LOG(ERROR) << "MaybeGetGuestByInstanceIDOrKill";
- callback.Run(nullptr);
+ if (ContainsKey(web_contents_map_, guest_instance_id))
+ callback.Run(web_contents_map_[guest_instance_id].web_contents);
+ else
+ callback.Run(nullptr);
}
bool WebViewManager::ForEachGuest(content::WebContents* embedder_web_contents,
const GuestCallback& callback) {
- LOG(ERROR) << "ForEachGuest";
+ for (auto& item : web_contents_map_)
+ if (item.second.embedder == embedder_web_contents &&
+ callback.Run(item.second.web_contents))
+ return true;
return false;
}
} // namespace atom
+
+namespace {
+
+void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
+ v8::Handle<v8::Context> context, void* priv) {
+ using atom::WebViewManager;
+ auto manager = static_cast<WebViewManager*>(
+ atom::AtomBrowserContext::Get()->GetGuestManager());
+ mate::Dictionary dict(context->GetIsolate(), exports);
+ dict.SetMethod("addGuest",
+ base::Bind(&WebViewManager::AddGuest,
+ base::Unretained(manager)));
+ dict.SetMethod("removeGuest",
+ base::Bind(&WebViewManager::RemoveGuest,
+ base::Unretained(manager)));
+}
+
+} // namespace
+
+NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_web_view_manager, Initialize)
#ifndef ATOM_BROWSER_WEB_VIEW_WEB_VIEW_MANAGER_H_
#define ATOM_BROWSER_WEB_VIEW_WEB_VIEW_MANAGER_H_
+#include <map>
+
#include "content/public/browser/browser_plugin_guest_manager.h"
namespace content {
explicit WebViewManager(content::BrowserContext* context);
virtual ~WebViewManager();
+ void AddGuest(int guest_instance_id,
+ content::WebContents* embedder,
+ content::WebContents* web_contents);
+ void RemoveGuest(int guest_instance_id);
+
+ protected:
// content::BrowserPluginGuestManager:
virtual void MaybeGetGuestByInstanceIDOrKill(
int guest_instance_id,
const GuestCallback& callback) override;
private:
+ struct WebContentsWithEmbedder {
+ content::WebContents* web_contents; // Weak ref.
+ content::WebContents* embedder;
+ };
+ std::map<int, WebContentsWithEmbedder> web_contents_map_;
+
DISALLOW_COPY_AND_ASSIGN(WebViewManager);
};