2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-10-22 14:55:13 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-02-04 23:17:28 +00:00
|
|
|
#ifndef ATOM_BROWSER_WEB_VIEW_MANAGER_H_
|
|
|
|
#define ATOM_BROWSER_WEB_VIEW_MANAGER_H_
|
2014-10-22 14:55:13 +00:00
|
|
|
|
2014-10-23 15:08:48 +00:00
|
|
|
#include <map>
|
|
|
|
|
2015-02-04 22:58:03 +00:00
|
|
|
#include "base/files/file_path.h"
|
2015-09-03 00:47:58 +00:00
|
|
|
#include "base/supports_user_data.h"
|
2015-02-04 22:58:03 +00:00
|
|
|
#include "base/synchronization/lock.h"
|
2014-10-22 14:55:13 +00:00
|
|
|
#include "content/public/browser/browser_plugin_guest_manager.h"
|
2015-08-06 15:01:05 +00:00
|
|
|
#include "content/public/browser/site_instance.h"
|
2014-10-22 14:55:13 +00:00
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class BrowserContext;
|
2015-02-04 23:08:29 +00:00
|
|
|
class RenderProcessHost;
|
2014-10-22 14:55:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
class WebViewManager : public content::BrowserPluginGuestManager {
|
|
|
|
public:
|
2015-02-04 22:58:03 +00:00
|
|
|
struct WebViewInfo {
|
|
|
|
int guest_instance_id;
|
|
|
|
content::WebContents* embedder;
|
2014-12-09 22:38:43 +00:00
|
|
|
bool node_integration;
|
|
|
|
bool plugins;
|
2014-12-18 00:32:25 +00:00
|
|
|
bool disable_web_security;
|
2015-02-04 22:58:03 +00:00
|
|
|
base::FilePath preload_script;
|
2015-08-06 15:01:05 +00:00
|
|
|
GURL partition_id;
|
2014-12-09 22:38:43 +00:00
|
|
|
};
|
|
|
|
|
2015-09-03 00:47:58 +00:00
|
|
|
class WebViewInfoUserData : public base::SupportsUserData::Data {
|
|
|
|
public:
|
|
|
|
explicit WebViewInfoUserData(WebViewInfo info)
|
|
|
|
: web_view_info_(info) {}
|
|
|
|
~WebViewInfoUserData() override {}
|
|
|
|
|
|
|
|
WebViewInfo& web_view_info() { return web_view_info_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
WebViewInfo web_view_info_;
|
|
|
|
};
|
2015-04-26 07:30:31 +00:00
|
|
|
|
2015-02-04 23:08:29 +00:00
|
|
|
explicit WebViewManager(content::BrowserContext* context);
|
|
|
|
virtual ~WebViewManager();
|
|
|
|
|
2014-10-23 15:08:48 +00:00
|
|
|
void AddGuest(int guest_instance_id,
|
2014-12-09 22:38:43 +00:00
|
|
|
int element_instance_id,
|
2014-10-23 15:08:48 +00:00
|
|
|
content::WebContents* embedder,
|
2015-09-03 00:47:58 +00:00
|
|
|
content::WebContents* web_contents);
|
2014-10-23 15:08:48 +00:00
|
|
|
void RemoveGuest(int guest_instance_id);
|
|
|
|
|
|
|
|
protected:
|
2014-10-22 14:55:13 +00:00
|
|
|
// content::BrowserPluginGuestManager:
|
2015-04-21 10:56:08 +00:00
|
|
|
content::WebContents* GetGuestByInstanceID(int owner_process_id,
|
|
|
|
int element_instance_id) override;
|
2014-12-09 22:38:43 +00:00
|
|
|
bool ForEachGuest(content::WebContents* embedder,
|
2014-12-07 15:43:26 +00:00
|
|
|
const GuestCallback& callback) override;
|
2014-10-22 14:55:13 +00:00
|
|
|
|
|
|
|
private:
|
2014-10-23 15:08:48 +00:00
|
|
|
struct WebContentsWithEmbedder {
|
2015-02-04 23:28:26 +00:00
|
|
|
content::WebContents* web_contents;
|
2014-10-23 15:08:48 +00:00
|
|
|
content::WebContents* embedder;
|
|
|
|
};
|
2015-02-04 23:28:26 +00:00
|
|
|
// guest_instance_id => (web_contents, embedder)
|
2015-08-06 15:01:05 +00:00
|
|
|
std::map<int, WebContentsWithEmbedder> web_contents_embedder_map_;
|
2014-10-23 15:08:48 +00:00
|
|
|
|
2014-12-09 22:38:43 +00:00
|
|
|
struct ElementInstanceKey {
|
2015-04-21 10:56:08 +00:00
|
|
|
int embedder_process_id;
|
2014-12-09 22:38:43 +00:00
|
|
|
int element_instance_id;
|
|
|
|
|
2015-04-21 10:56:08 +00:00
|
|
|
ElementInstanceKey(int embedder_process_id, int element_instance_id)
|
|
|
|
: embedder_process_id(embedder_process_id),
|
2014-12-09 22:38:43 +00:00
|
|
|
element_instance_id(element_instance_id) {}
|
|
|
|
|
|
|
|
bool operator<(const ElementInstanceKey& other) const {
|
2015-04-21 10:56:08 +00:00
|
|
|
if (embedder_process_id != other.embedder_process_id)
|
|
|
|
return embedder_process_id < other.embedder_process_id;
|
2014-12-09 22:38:43 +00:00
|
|
|
return element_instance_id < other.element_instance_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const ElementInstanceKey& other) const {
|
2015-04-21 10:56:08 +00:00
|
|
|
return (embedder_process_id == other.embedder_process_id) &&
|
2014-12-09 22:38:43 +00:00
|
|
|
(element_instance_id == other.element_instance_id);
|
|
|
|
}
|
|
|
|
};
|
2015-04-21 10:56:08 +00:00
|
|
|
// (embedder_process_id, element_instance_id) => guest_instance_id
|
2014-12-09 22:38:43 +00:00
|
|
|
std::map<ElementInstanceKey, int> element_instance_id_to_guest_map_;
|
|
|
|
|
2015-02-04 22:58:03 +00:00
|
|
|
base::Lock lock_;
|
|
|
|
|
2014-10-22 14:55:13 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebViewManager);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
2015-02-04 23:17:28 +00:00
|
|
|
#endif // ATOM_BROWSER_WEB_VIEW_MANAGER_H_
|