Fix loss of --node-integration token after refresh.
This commit is contained in:
parent
ec00da416f
commit
61b69a4e8a
2 changed files with 47 additions and 11 deletions
|
@ -12,12 +12,30 @@
|
||||||
#include "browser/window_list.h"
|
#include "browser/window_list.h"
|
||||||
#include "common/options_switches.h"
|
#include "common/options_switches.h"
|
||||||
#include "content/public/browser/render_process_host.h"
|
#include "content/public/browser/render_process_host.h"
|
||||||
|
#include "content/public/browser/site_instance.h"
|
||||||
#include "content/public/browser/web_contents.h"
|
#include "content/public/browser/web_contents.h"
|
||||||
#include "webkit/common/webpreferences.h"
|
#include "webkit/common/webpreferences.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
AtomBrowserClient::AtomBrowserClient() {
|
namespace {
|
||||||
|
|
||||||
|
struct FindByProcessId {
|
||||||
|
FindByProcessId(int child_process_id) : child_process_id_(child_process_id) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator() (NativeWindow* const window) {
|
||||||
|
int id = window->GetWebContents()->GetRenderProcessHost()->GetID();
|
||||||
|
return id == child_process_id_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int child_process_id_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
AtomBrowserClient::AtomBrowserClient()
|
||||||
|
: dying_render_process_(NULL) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AtomBrowserClient::~AtomBrowserClient() {
|
AtomBrowserClient::~AtomBrowserClient() {
|
||||||
|
@ -56,6 +74,9 @@ bool AtomBrowserClient::ShouldSwapProcessesForNavigation(
|
||||||
content::SiteInstance* site_instance,
|
content::SiteInstance* site_instance,
|
||||||
const GURL& current_url,
|
const GURL& current_url,
|
||||||
const GURL& new_url) {
|
const GURL& new_url) {
|
||||||
|
if (site_instance->HasProcess())
|
||||||
|
dying_render_process_ = site_instance->GetProcess();
|
||||||
|
|
||||||
// Restart renderer process for all navigations.
|
// Restart renderer process for all navigations.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -63,18 +84,30 @@ bool AtomBrowserClient::ShouldSwapProcessesForNavigation(
|
||||||
void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
CommandLine* command_line,
|
CommandLine* command_line,
|
||||||
int child_process_id) {
|
int child_process_id) {
|
||||||
// Append --node-integration to renderer process.
|
|
||||||
WindowList* list = WindowList::GetInstance();
|
WindowList* list = WindowList::GetInstance();
|
||||||
for (WindowList::const_iterator iter = list->begin(); iter != list->end();
|
NativeWindow* window = NULL;
|
||||||
++iter) {
|
|
||||||
NativeWindow* window = *iter;
|
// Find the owner of this child process.
|
||||||
int id = window->GetWebContents()->GetRenderProcessHost()->GetID();
|
WindowList::const_iterator iter = std::find_if(
|
||||||
if (id == child_process_id) {
|
list->begin(), list->end(), FindByProcessId(child_process_id));
|
||||||
command_line->AppendSwitchASCII(switches::kNodeIntegration,
|
if (iter != list->end())
|
||||||
window->node_integration());
|
window = *iter;
|
||||||
return;
|
|
||||||
}
|
// If the render process is a newly started one, which means the window still
|
||||||
|
// uses the old going-to-be-swapped render process, then we try to find the
|
||||||
|
// window from the swapped render process.
|
||||||
|
if (window == NULL && dying_render_process_ != NULL) {
|
||||||
|
child_process_id = dying_render_process_->GetID();
|
||||||
|
WindowList::const_iterator iter = std::find_if(
|
||||||
|
list->begin(), list->end(), FindByProcessId(child_process_id));
|
||||||
|
if (iter != list->end())
|
||||||
|
window = *iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Append --node-integration to renderer process.
|
||||||
|
if (window != NULL)
|
||||||
|
command_line->AppendSwitchASCII(switches::kNodeIntegration,
|
||||||
|
window->node_integration());
|
||||||
}
|
}
|
||||||
|
|
||||||
brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
|
brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
|
||||||
|
|
|
@ -32,6 +32,9 @@ class AtomBrowserClient : public brightray::BrowserClient {
|
||||||
virtual brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
virtual brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
||||||
const content::MainFunctionParams&) OVERRIDE;
|
const content::MainFunctionParams&) OVERRIDE;
|
||||||
|
|
||||||
|
// The render process which would be swapped out soon.
|
||||||
|
content::RenderProcessHost* dying_render_process_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(AtomBrowserClient);
|
DISALLOW_COPY_AND_ASSIGN(AtomBrowserClient);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue