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
;
17 v8::Handle
<v8::Value
> GetDoNotTrack(v8::Local
<v8::String
> property
,
18 const v8::AccessorInfo
& info
) {
19 WebFrame
* frame
= WebFrame::frameForCurrentContext();
22 RenderViewImpl
* view
= RenderViewImpl::FromWebView(frame
->view());
25 if (view
->enable_do_not_track())
26 return v8::String::New("1");
32 void InjectDoNotTrackBindings(WebFrame
* frame
) {
33 v8::HandleScope handle_scope
;
35 v8::Handle
<v8::Context
> v8_context
= frame
->mainWorldScriptContext();
36 if (v8_context
.IsEmpty())
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())
46 navigator
->SetAccessor(v8::String::New("doNotTrack"), GetDoNotTrack
);
49 } // namespace content