OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "content/renderer/do_not_track_bindings.h" |
| 6 |
| 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" |
| 10 |
| 11 using WebKit::WebFrame; |
| 12 |
| 13 namespace { |
| 14 |
| 15 v8::Handle<v8::Value> GetDoNotTrack(v8::Local<v8::String> property, |
| 16 const v8::AccessorInfo& info) { |
| 17 WebFrame* frame = WebFrame::frameForCurrentContext(); |
| 18 if (!frame) |
| 19 return v8::Null(); |
| 20 RenderViewImpl* view = RenderViewImpl::FromWebView(frame->view()); |
| 21 if (!view) |
| 22 return v8::Null(); |
| 23 if (view->enable_do_not_track()) |
| 24 return v8::String::New("1"); |
| 25 return v8::Null(); |
| 26 } |
| 27 |
| 28 } // namespace |
| 29 |
| 30 namespace content { |
| 31 |
| 32 void InjectDoNotTrackBindings(WebFrame* frame) { |
| 33 v8::HandleScope handle_scope; |
| 34 |
| 35 v8::Handle<v8::Context> v8_context = frame->mainWorldScriptContext(); |
| 36 if (v8_context.IsEmpty()) |
| 37 return; |
| 38 |
| 39 v8::Context::Scope scope(v8_context); |
| 40 |
| 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); |
| 47 } |
| 48 |
| 49 } // namespace content |
OLD | NEW |