Remove the WebViewRendererState class
This commit is contained in:
parent
aa49e4790f
commit
502c0f0df7
7 changed files with 68 additions and 142 deletions
2
atom.gyp
2
atom.gyp
|
@ -192,8 +192,6 @@
|
||||||
'atom/browser/ui/x/x_window_utils.h',
|
'atom/browser/ui/x/x_window_utils.h',
|
||||||
'atom/browser/web_view/web_view_manager.cc',
|
'atom/browser/web_view/web_view_manager.cc',
|
||||||
'atom/browser/web_view/web_view_manager.h',
|
'atom/browser/web_view/web_view_manager.h',
|
||||||
'atom/browser/web_view/web_view_renderer_state.cc',
|
|
||||||
'atom/browser/web_view/web_view_renderer_state.h',
|
|
||||||
'atom/browser/web_dialog_helper.cc',
|
'atom/browser/web_dialog_helper.cc',
|
||||||
'atom/browser/web_dialog_helper.h',
|
'atom/browser/web_dialog_helper.h',
|
||||||
'atom/browser/window_list.cc',
|
'atom/browser/window_list.cc',
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "atom/browser/atom_browser_context.h"
|
#include "atom/browser/atom_browser_context.h"
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
#include "atom/browser/web_dialog_helper.h"
|
#include "atom/browser/web_dialog_helper.h"
|
||||||
#include "atom/browser/web_view/web_view_renderer_state.h"
|
#include "atom/browser/web_view/web_view_manager.h"
|
||||||
#include "atom/common/api/api_messages.h"
|
#include "atom/common/api/api_messages.h"
|
||||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||||
|
@ -39,9 +39,10 @@ v8::Persistent<v8::ObjectTemplate> template_;
|
||||||
|
|
||||||
// Get the window that has the |guest| embedded.
|
// Get the window that has the |guest| embedded.
|
||||||
NativeWindow* GetWindowFromGuest(const content::WebContents* guest) {
|
NativeWindow* GetWindowFromGuest(const content::WebContents* guest) {
|
||||||
|
auto manager = AtomBrowserContext::Get()->GetGuestManager();
|
||||||
int guest_process_id = guest->GetRenderProcessHost()->GetID();
|
int guest_process_id = guest->GetRenderProcessHost()->GetID();
|
||||||
WebViewRendererState::WebViewInfo info;
|
WebViewManager::WebViewInfo info;
|
||||||
if (!WebViewRendererState::GetInstance()->GetInfo(guest_process_id, &info))
|
if (!static_cast<WebViewManager*>(manager)->GetInfo(guest_process_id, &info))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return NativeWindow::FromRenderView(
|
return NativeWindow::FromRenderView(
|
||||||
info.embedder->GetRenderProcessHost()->GetID(),
|
info.embedder->GetRenderProcessHost()->GetID(),
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "atom/browser/atom_browser_main_parts.h"
|
#include "atom/browser/atom_browser_main_parts.h"
|
||||||
#include "atom/browser/atom_speech_recognition_manager_delegate.h"
|
#include "atom/browser/atom_speech_recognition_manager_delegate.h"
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
#include "atom/browser/web_view/web_view_renderer_state.h"
|
#include "atom/browser/web_view/web_view_manager.h"
|
||||||
#include "atom/browser/window_list.h"
|
#include "atom/browser/window_list.h"
|
||||||
#include "atom/common/options_switches.h"
|
#include "atom/common/options_switches.h"
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
|
@ -44,6 +44,19 @@ struct FindByProcessId {
|
||||||
int child_process_id_;
|
int child_process_id_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool GetWebViewInfo(content::RenderProcessHost* host,
|
||||||
|
WebViewManager::WebViewInfo* info) {
|
||||||
|
if (!host)
|
||||||
|
return false;
|
||||||
|
auto context = host->GetBrowserContext();
|
||||||
|
if (!context)
|
||||||
|
return false;
|
||||||
|
auto manager = context->GetGuestManager();
|
||||||
|
if (!manager)
|
||||||
|
return false;
|
||||||
|
return static_cast<WebViewManager*>(manager)->GetInfo(host->GetID(), info);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
AtomBrowserClient::AtomBrowserClient()
|
AtomBrowserClient::AtomBrowserClient()
|
||||||
|
@ -97,9 +110,8 @@ void AtomBrowserClient::OverrideWebkitPrefs(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Custom preferences of guest page.
|
// Custom preferences of guest page.
|
||||||
int guest_process_id = render_view_host->GetProcess()->GetID();
|
WebViewManager::WebViewInfo info;
|
||||||
WebViewRendererState::WebViewInfo info;
|
if (GetWebViewInfo(render_view_host->GetProcess(), &info)) {
|
||||||
if (WebViewRendererState::GetInstance()->GetInfo(guest_process_id, &info)) {
|
|
||||||
prefs->web_security_enabled = !info.disable_web_security;
|
prefs->web_security_enabled = !info.disable_web_security;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -154,8 +166,9 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
window->AppendExtraCommandLineSwitches(command_line, child_process_id);
|
window->AppendExtraCommandLineSwitches(command_line, child_process_id);
|
||||||
} else {
|
} else {
|
||||||
// Append commnad line arguments for guest web view.
|
// Append commnad line arguments for guest web view.
|
||||||
WebViewRendererState::WebViewInfo info;
|
auto child_process = content::RenderProcessHost::FromID(child_process_id);
|
||||||
if (WebViewRendererState::GetInstance()->GetInfo(child_process_id, &info)) {
|
WebViewManager::WebViewInfo info;
|
||||||
|
if (GetWebViewInfo(child_process, &info)) {
|
||||||
command_line->AppendSwitchASCII(
|
command_line->AppendSwitchASCII(
|
||||||
switches::kGuestInstanceID,
|
switches::kGuestInstanceID,
|
||||||
base::IntToString(info.guest_instance_id));
|
base::IntToString(info.guest_instance_id));
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#include "atom/browser/api/atom_api_web_contents.h"
|
#include "atom/browser/api/atom_api_web_contents.h"
|
||||||
#include "atom/browser/atom_browser_context.h"
|
#include "atom/browser/atom_browser_context.h"
|
||||||
#include "atom/browser/web_view/web_view_renderer_state.h"
|
|
||||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "base/stl_util.h"
|
#include "base/stl_util.h"
|
||||||
|
@ -32,15 +31,20 @@ struct Converter<content::WebContents*> {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Converter<atom::WebViewManager::WebViewOptions> {
|
struct Converter<atom::WebViewManager::WebViewInfo> {
|
||||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||||
atom::WebViewManager::WebViewOptions* out) {
|
atom::WebViewManager::WebViewInfo* out) {
|
||||||
Dictionary options;
|
Dictionary options;
|
||||||
if (!ConvertFromV8(isolate, val, &options))
|
if (!ConvertFromV8(isolate, val, &options))
|
||||||
return false;
|
return false;
|
||||||
return options.Get("nodeIntegration", &(out->node_integration)) &&
|
|
||||||
|
GURL preload_url;
|
||||||
|
if (!options.Get("preloadUrl", &preload_url))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return net::FileURLToFilePath(preload_url, &(out->preload_script)) &&
|
||||||
|
options.Get("nodeIntegration", &(out->node_integration)) &&
|
||||||
options.Get("plugins", &(out->plugins)) &&
|
options.Get("plugins", &(out->plugins)) &&
|
||||||
options.Get("preloadUrl", &(out->preload_url)) &&
|
|
||||||
options.Get("disableWebSecurity", &(out->disable_web_security));
|
options.Get("disableWebSecurity", &(out->disable_web_security));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -59,20 +63,14 @@ void WebViewManager::AddGuest(int guest_instance_id,
|
||||||
int element_instance_id,
|
int element_instance_id,
|
||||||
content::WebContents* embedder,
|
content::WebContents* embedder,
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
const WebViewOptions& options) {
|
WebViewInfo info) {
|
||||||
|
base::AutoLock auto_lock(lock_);
|
||||||
web_contents_map_[guest_instance_id] = { web_contents, embedder };
|
web_contents_map_[guest_instance_id] = { web_contents, embedder };
|
||||||
|
|
||||||
WebViewRendererState::WebViewInfo web_view_info = {
|
int guest_process_id = web_contents->GetRenderProcessHost()->GetID();
|
||||||
guest_instance_id,
|
info.guest_instance_id = guest_instance_id;
|
||||||
embedder,
|
info.embedder = embedder;
|
||||||
options.node_integration,
|
webview_info_map_[guest_process_id] = info;
|
||||||
options.plugins,
|
|
||||||
options.disable_web_security,
|
|
||||||
};
|
|
||||||
net::FileURLToFilePath(options.preload_url, &web_view_info.preload_script);
|
|
||||||
WebViewRendererState::GetInstance()->AddGuest(
|
|
||||||
web_contents->GetRenderProcessHost()->GetID(),
|
|
||||||
web_view_info);
|
|
||||||
|
|
||||||
// Map the element in embedder to guest.
|
// Map the element in embedder to guest.
|
||||||
ElementInstanceKey key(embedder, element_instance_id);
|
ElementInstanceKey key(embedder, element_instance_id);
|
||||||
|
@ -80,16 +78,17 @@ void WebViewManager::AddGuest(int guest_instance_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebViewManager::RemoveGuest(int guest_instance_id) {
|
void WebViewManager::RemoveGuest(int guest_instance_id) {
|
||||||
|
base::AutoLock auto_lock(lock_);
|
||||||
if (!ContainsKey(web_contents_map_, guest_instance_id)) {
|
if (!ContainsKey(web_contents_map_, guest_instance_id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto web_contents = web_contents_map_[guest_instance_id].web_contents;
|
auto web_contents = web_contents_map_[guest_instance_id].web_contents;
|
||||||
WebViewRendererState::GetInstance()->RemoveGuest(
|
|
||||||
web_contents->GetRenderProcessHost()->GetID());
|
|
||||||
|
|
||||||
web_contents_map_.erase(guest_instance_id);
|
web_contents_map_.erase(guest_instance_id);
|
||||||
|
|
||||||
|
int guest_process_id = web_contents->GetRenderProcessHost()->GetID();
|
||||||
|
webview_info_map_.erase(guest_process_id);
|
||||||
|
|
||||||
// Remove the record of element in embedder too.
|
// Remove the record of element in embedder too.
|
||||||
for (const auto& element : element_instance_id_to_guest_map_)
|
for (const auto& element : element_instance_id_to_guest_map_)
|
||||||
if (element.second == guest_instance_id) {
|
if (element.second == guest_instance_id) {
|
||||||
|
@ -98,6 +97,16 @@ void WebViewManager::RemoveGuest(int guest_instance_id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WebViewManager::GetInfo(int guest_process_id, WebViewInfo* webview_info) {
|
||||||
|
base::AutoLock auto_lock(lock_);
|
||||||
|
WebViewInfoMap::iterator iter = webview_info_map_.find(guest_process_id);
|
||||||
|
if (iter != webview_info_map_.end()) {
|
||||||
|
*webview_info = iter->second;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
content::WebContents* WebViewManager::GetGuestByInstanceID(
|
content::WebContents* WebViewManager::GetGuestByInstanceID(
|
||||||
content::WebContents* embedder,
|
content::WebContents* embedder,
|
||||||
int element_instance_id) {
|
int element_instance_id) {
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "base/files/file_path.h"
|
||||||
|
#include "base/synchronization/lock.h"
|
||||||
#include "content/public/browser/browser_plugin_guest_manager.h"
|
#include "content/public/browser/browser_plugin_guest_manager.h"
|
||||||
#include "url/gurl.h"
|
#include "url/gurl.h"
|
||||||
|
|
||||||
|
@ -21,20 +23,26 @@ class WebViewManager : public content::BrowserPluginGuestManager {
|
||||||
explicit WebViewManager(content::BrowserContext* context);
|
explicit WebViewManager(content::BrowserContext* context);
|
||||||
virtual ~WebViewManager();
|
virtual ~WebViewManager();
|
||||||
|
|
||||||
struct WebViewOptions {
|
struct WebViewInfo {
|
||||||
|
int guest_instance_id;
|
||||||
|
content::WebContents* embedder;
|
||||||
bool node_integration;
|
bool node_integration;
|
||||||
bool plugins;
|
bool plugins;
|
||||||
bool disable_web_security;
|
bool disable_web_security;
|
||||||
GURL preload_url;
|
base::FilePath preload_script;
|
||||||
};
|
};
|
||||||
|
|
||||||
void AddGuest(int guest_instance_id,
|
void AddGuest(int guest_instance_id,
|
||||||
int element_instance_id,
|
int element_instance_id,
|
||||||
content::WebContents* embedder,
|
content::WebContents* embedder,
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
const WebViewOptions& options);
|
WebViewInfo info);
|
||||||
void RemoveGuest(int guest_instance_id);
|
void RemoveGuest(int guest_instance_id);
|
||||||
|
|
||||||
|
// Looks up the information for the embedder <webview> for a given render
|
||||||
|
// view, if one exists. Called on the IO thread.
|
||||||
|
bool GetInfo(int guest_process_id, WebViewInfo* webview_info);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// content::BrowserPluginGuestManager:
|
// content::BrowserPluginGuestManager:
|
||||||
content::WebContents* GetGuestByInstanceID(
|
content::WebContents* GetGuestByInstanceID(
|
||||||
|
@ -76,6 +84,11 @@ class WebViewManager : public content::BrowserPluginGuestManager {
|
||||||
};
|
};
|
||||||
std::map<ElementInstanceKey, int> element_instance_id_to_guest_map_;
|
std::map<ElementInstanceKey, int> element_instance_id_to_guest_map_;
|
||||||
|
|
||||||
|
typedef std::map<int, WebViewInfo> WebViewInfoMap;
|
||||||
|
WebViewInfoMap webview_info_map_;
|
||||||
|
|
||||||
|
base::Lock lock_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(WebViewManager);
|
DISALLOW_COPY_AND_ASSIGN(WebViewManager);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
// Copyright (c) 2014 GitHub, Inc.
|
|
||||||
// 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_renderer_state.h"
|
|
||||||
|
|
||||||
#include "content/public/browser/browser_thread.h"
|
|
||||||
|
|
||||||
namespace atom {
|
|
||||||
|
|
||||||
// static
|
|
||||||
WebViewRendererState* WebViewRendererState::GetInstance() {
|
|
||||||
return Singleton<WebViewRendererState>::get();
|
|
||||||
}
|
|
||||||
|
|
||||||
WebViewRendererState::WebViewRendererState() {
|
|
||||||
}
|
|
||||||
|
|
||||||
WebViewRendererState::~WebViewRendererState() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebViewRendererState::AddGuest(int guest_process_id,
|
|
||||||
const WebViewInfo& webview_info) {
|
|
||||||
base::AutoLock auto_lock(lock_);
|
|
||||||
webview_info_map_[guest_process_id] = webview_info;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebViewRendererState::RemoveGuest(int guest_process_id) {
|
|
||||||
base::AutoLock auto_lock(lock_);
|
|
||||||
webview_info_map_.erase(guest_process_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WebViewRendererState::GetInfo(int guest_process_id,
|
|
||||||
WebViewInfo* webview_info) {
|
|
||||||
base::AutoLock auto_lock(lock_);
|
|
||||||
WebViewInfoMap::iterator iter = webview_info_map_.find(guest_process_id);
|
|
||||||
if (iter != webview_info_map_.end()) {
|
|
||||||
*webview_info = iter->second;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace atom
|
|
|
@ -1,64 +0,0 @@
|
||||||
// Copyright (c) 2014 GitHub, Inc.
|
|
||||||
// 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_RENDERER_STATE_H_
|
|
||||||
#define ATOM_BROWSER_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "base/files/file_path.h"
|
|
||||||
#include "base/memory/singleton.h"
|
|
||||||
#include "base/synchronization/lock.h"
|
|
||||||
|
|
||||||
namespace content {
|
|
||||||
class WebContents;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace atom {
|
|
||||||
|
|
||||||
class WebViewManager;
|
|
||||||
|
|
||||||
// This class keeps track of <webview> renderer state for use on the IO thread.
|
|
||||||
// All methods should be called on the IO thread.
|
|
||||||
class WebViewRendererState {
|
|
||||||
public:
|
|
||||||
struct WebViewInfo {
|
|
||||||
int guest_instance_id;
|
|
||||||
content::WebContents* embedder;
|
|
||||||
bool node_integration;
|
|
||||||
bool plugins;
|
|
||||||
bool disable_web_security;
|
|
||||||
base::FilePath preload_script;
|
|
||||||
};
|
|
||||||
|
|
||||||
static WebViewRendererState* GetInstance();
|
|
||||||
|
|
||||||
// Looks up the information for the embedder <webview> for a given render
|
|
||||||
// view, if one exists. Called on the IO thread.
|
|
||||||
bool GetInfo(int guest_process_id, WebViewInfo* webview_info);
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class WebViewManager;
|
|
||||||
friend struct DefaultSingletonTraits<WebViewRendererState>;
|
|
||||||
|
|
||||||
typedef std::map<int, WebViewInfo> WebViewInfoMap;
|
|
||||||
|
|
||||||
WebViewRendererState();
|
|
||||||
~WebViewRendererState();
|
|
||||||
|
|
||||||
// Adds or removes a <webview> guest render process from the set.
|
|
||||||
void AddGuest(int render_process_id, const WebViewInfo& webview_info);
|
|
||||||
void RemoveGuest(int render_process_id);
|
|
||||||
|
|
||||||
WebViewInfoMap webview_info_map_;
|
|
||||||
base::Lock lock_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(WebViewRendererState);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace atom
|
|
||||||
|
|
||||||
#endif // ATOM_BROWSER_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_
|
|
Loading…
Reference in a new issue