Make it possible to only set preferences for BrowserWindow
This commit is contained in:
parent
4fb9e20c33
commit
7eab259d92
4 changed files with 30 additions and 8 deletions
|
@ -4,8 +4,12 @@
|
||||||
|
|
||||||
#include "atom/browser/api/atom_api_render_process_preferences.h"
|
#include "atom/browser/api/atom_api_render_process_preferences.h"
|
||||||
|
|
||||||
|
#include "atom/browser/atom_browser_client.h"
|
||||||
|
#include "atom/browser/native_window.h"
|
||||||
|
#include "atom/browser/window_list.h"
|
||||||
#include "atom/common/native_mate_converters/value_converter.h"
|
#include "atom/common/native_mate_converters/value_converter.h"
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
|
#include "content/public/browser/render_process_host.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
|
|
||||||
|
@ -16,6 +20,16 @@ namespace api {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool IsBrowserWindow(content::RenderProcessHost* process) {
|
bool IsBrowserWindow(content::RenderProcessHost* process) {
|
||||||
|
content::WebContents* web_contents =
|
||||||
|
static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())->
|
||||||
|
GetWebContentsFromProcessID(process->GetID());
|
||||||
|
if (!web_contents)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
NativeWindow* window = NativeWindow::FromWebContents(web_contents);
|
||||||
|
if (!window)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,17 @@ AtomBrowserClient::AtomBrowserClient() : delegate_(nullptr) {
|
||||||
AtomBrowserClient::~AtomBrowserClient() {
|
AtomBrowserClient::~AtomBrowserClient() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content::WebContents* AtomBrowserClient::GetWebContentsFromProcessID(
|
||||||
|
int process_id) {
|
||||||
|
// If the process is a pending process, we should use the old one.
|
||||||
|
if (ContainsKey(pending_processes_, process_id))
|
||||||
|
process_id = pending_processes_[process_id];
|
||||||
|
|
||||||
|
// Certain render process will be created with no associated render view,
|
||||||
|
// for example: ServiceWorker.
|
||||||
|
return WebContentsPreferences::GetWebContentsFromProcessID(process_id);
|
||||||
|
}
|
||||||
|
|
||||||
void AtomBrowserClient::RenderProcessWillLaunch(
|
void AtomBrowserClient::RenderProcessWillLaunch(
|
||||||
content::RenderProcessHost* host) {
|
content::RenderProcessHost* host) {
|
||||||
int process_id = host->GetID();
|
int process_id = host->GetID();
|
||||||
|
@ -172,14 +183,7 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// If the process is a pending process, we should use the old one.
|
content::WebContents* web_contents = GetWebContentsFromProcessID(process_id);
|
||||||
if (ContainsKey(pending_processes_, process_id))
|
|
||||||
process_id = pending_processes_[process_id];
|
|
||||||
|
|
||||||
// Certain render process will be created with no associated render view,
|
|
||||||
// for example: ServiceWorker.
|
|
||||||
content::WebContents* web_contents =
|
|
||||||
WebContentsPreferences::GetWebContentsFromProcessID(process_id);
|
|
||||||
if (!web_contents)
|
if (!web_contents)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,9 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
||||||
using Delegate = content::ContentBrowserClient;
|
using Delegate = content::ContentBrowserClient;
|
||||||
void set_delegate(Delegate* delegate) { delegate_ = delegate; }
|
void set_delegate(Delegate* delegate) { delegate_ = delegate; }
|
||||||
|
|
||||||
|
// Returns the WebContents for pending render processes.
|
||||||
|
content::WebContents* GetWebContentsFromProcessID(int process_id);
|
||||||
|
|
||||||
// Don't force renderer process to restart for once.
|
// Don't force renderer process to restart for once.
|
||||||
static void SuppressRendererProcessRestartForOnce();
|
static void SuppressRendererProcessRestartForOnce();
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ class WebContentsPreferences
|
||||||
: public content::WebContentsUserData<WebContentsPreferences> {
|
: public content::WebContentsUserData<WebContentsPreferences> {
|
||||||
public:
|
public:
|
||||||
// Get WebContents according to process ID.
|
// Get WebContents according to process ID.
|
||||||
|
// FIXME(zcbenz): This method does not belong here.
|
||||||
static content::WebContents* GetWebContentsFromProcessID(int process_id);
|
static content::WebContents* GetWebContentsFromProcessID(int process_id);
|
||||||
|
|
||||||
// Append command paramters according to |web_contents|'s preferences.
|
// Append command paramters according to |web_contents|'s preferences.
|
||||||
|
|
Loading…
Reference in a new issue