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 "common/options_switches.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/site_instance.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "webkit/common/webpreferences.h"
|
||||
|
||||
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() {
|
||||
|
@ -56,6 +74,9 @@ bool AtomBrowserClient::ShouldSwapProcessesForNavigation(
|
|||
content::SiteInstance* site_instance,
|
||||
const GURL& current_url,
|
||||
const GURL& new_url) {
|
||||
if (site_instance->HasProcess())
|
||||
dying_render_process_ = site_instance->GetProcess();
|
||||
|
||||
// Restart renderer process for all navigations.
|
||||
return true;
|
||||
}
|
||||
|
@ -63,18 +84,30 @@ bool AtomBrowserClient::ShouldSwapProcessesForNavigation(
|
|||
void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||
CommandLine* command_line,
|
||||
int child_process_id) {
|
||||
// Append --node-integration to renderer process.
|
||||
WindowList* list = WindowList::GetInstance();
|
||||
for (WindowList::const_iterator iter = list->begin(); iter != list->end();
|
||||
++iter) {
|
||||
NativeWindow* window = *iter;
|
||||
int id = window->GetWebContents()->GetRenderProcessHost()->GetID();
|
||||
if (id == child_process_id) {
|
||||
command_line->AppendSwitchASCII(switches::kNodeIntegration,
|
||||
window->node_integration());
|
||||
return;
|
||||
}
|
||||
NativeWindow* window = NULL;
|
||||
|
||||
// Find the owner of this child process.
|
||||
WindowList::const_iterator iter = std::find_if(
|
||||
list->begin(), list->end(), FindByProcessId(child_process_id));
|
||||
if (iter != list->end())
|
||||
window = *iter;
|
||||
|
||||
// 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(
|
||||
|
|
|
@ -32,6 +32,9 @@ class AtomBrowserClient : public brightray::BrowserClient {
|
|||
virtual brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
||||
const content::MainFunctionParams&) OVERRIDE;
|
||||
|
||||
// The render process which would be swapped out soon.
|
||||
content::RenderProcessHost* dying_render_process_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomBrowserClient);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue