[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / content / renderer / do_not_track_bindings.cc
blob0c2731ba6a8afa2b435529cf9860a75fd641a9f8
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/do_not_track_bindings.h"
7 #include "content/renderer/render_view_impl.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
9 #include "v8/include/v8.h"
11 using WebKit::WebFrame;
13 namespace content {
15 namespace {
17 v8::Handle<v8::Value> GetDoNotTrack(v8::Local<v8::String> property,
18 const v8::AccessorInfo& info) {
19 WebFrame* frame = WebFrame::frameForCurrentContext();
20 if (!frame)
21 return v8::Null();
22 RenderViewImpl* view = RenderViewImpl::FromWebView(frame->view());
23 if (!view)
24 return v8::Null();
25 if (view->enable_do_not_track())
26 return v8::String::New("1");
27 return v8::Null();
30 } // namespace
32 void InjectDoNotTrackBindings(WebFrame* frame) {
33 v8::HandleScope handle_scope;
35 v8::Handle<v8::Context> v8_context = frame->mainWorldScriptContext();
36 if (v8_context.IsEmpty())
37 return;
39 v8::Context::Scope scope(v8_context);
41 v8::Handle<v8::Object> global = v8_context->Global();
42 v8::Handle<v8::Object> navigator =
43 global->Get(v8::String::New("navigator"))->ToObject();
44 if (navigator.IsEmpty())
45 return;
46 navigator->SetAccessor(v8::String::New("doNotTrack"), GetDoNotTrack);
49 } // namespace content