Add iframe-security support.
This commit is contained in:
parent
a0b15661ed
commit
d4929de33c
3 changed files with 51 additions and 2 deletions
|
@ -6,23 +6,39 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "common/node_bindings.h"
|
||||
#include "common/options_switches.h"
|
||||
#include "renderer/api/atom_renderer_bindings.h"
|
||||
#include "renderer/atom_render_view_observer.h"
|
||||
#include "third_party/WebKit/public/web/WebFrame.h"
|
||||
|
||||
#include "common/v8/node_common.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
AtomRendererClient::AtomRendererClient()
|
||||
: node_bindings_(NodeBindings::Create(false)),
|
||||
atom_bindings_(new AtomRendererBindings) {
|
||||
: iframe_security_(FULL) {
|
||||
std::string security = CommandLine::ForCurrentProcess()->
|
||||
GetSwitchValueASCII(switches::kIframeSecurity);
|
||||
if (security == "manual")
|
||||
iframe_security_ = MANUAL;
|
||||
else if (security == "none")
|
||||
iframe_security_ = NONE;
|
||||
|
||||
if (IsNodeBindingEnabled()) {
|
||||
node_bindings_.reset(NodeBindings::Create(false));
|
||||
atom_bindings_.reset(new AtomRendererBindings);
|
||||
}
|
||||
}
|
||||
|
||||
AtomRendererClient::~AtomRendererClient() {
|
||||
}
|
||||
|
||||
void AtomRendererClient::RenderThreadStarted() {
|
||||
if (!IsNodeBindingEnabled())
|
||||
return;
|
||||
|
||||
node_bindings_->Initialize();
|
||||
node_bindings_->PrepareMessageLoop();
|
||||
|
||||
|
@ -43,6 +59,9 @@ void AtomRendererClient::DidCreateScriptContext(WebKit::WebFrame* frame,
|
|||
v8::Handle<v8::Context> context,
|
||||
int extension_group,
|
||||
int world_id) {
|
||||
if (!IsNodeBindingEnabled(frame))
|
||||
return;
|
||||
|
||||
v8::Context::Scope scope(context);
|
||||
|
||||
// Check the existance of process object to prevent duplicate initialization.
|
||||
|
@ -70,6 +89,9 @@ void AtomRendererClient::WillReleaseScriptContext(
|
|||
WebKit::WebFrame* frame,
|
||||
v8::Handle<v8::Context> context,
|
||||
int world_id) {
|
||||
if (!IsNodeBindingEnabled(frame))
|
||||
return;
|
||||
|
||||
node::Environment* env = node::Environment::GetCurrent(context);
|
||||
if (env == NULL) {
|
||||
LOG(ERROR) << "Encounter a non-node context when releasing script context";
|
||||
|
@ -108,4 +130,15 @@ bool AtomRendererClient::ShouldFork(WebKit::WebFrame* frame,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool AtomRendererClient::IsNodeBindingEnabled(WebKit::WebFrame* frame) {
|
||||
if (iframe_security_ == FULL)
|
||||
return false;
|
||||
else if (iframe_security_ == MANUAL &&
|
||||
frame != NULL &&
|
||||
frame->uniqueName().utf8().find("-enable-node") == std::string::npos)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue