OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 "chrome/renderer/extensions/dom_activity_logger.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "chrome/common/extensions/extension_messages.h" |
| 9 #include "chrome/renderer/chrome_render_process_observer.h" |
| 10 #include "content/public/renderer/render_thread.h" |
| 11 #include "content/public/renderer/v8_value_converter.h" |
| 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMActivityLogger.
h" |
| 14 #include "v8/include/v8.h" |
| 15 |
| 16 using content::V8ValueConverter; |
| 17 |
| 18 namespace extensions { |
| 19 |
| 20 DOMActivityLogger::DOMActivityLogger(const std::string& extension_id, |
| 21 const GURL& url, |
| 22 const string16& title) |
| 23 : extension_id_(extension_id), url_(url), title_(title) { |
| 24 } |
| 25 |
| 26 void DOMActivityLogger::log( |
| 27 const WebString& api_name, |
| 28 int argc, |
| 29 const v8::Handle<v8::Value> argv[], |
| 30 const WebString& extra_info) { |
| 31 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
| 32 scoped_ptr<ListValue> argv_list_value(new ListValue()); |
| 33 for (int i =0; i < argc; i++) { |
| 34 argv_list_value->Set( |
| 35 i, converter->FromV8Value(argv[i], v8::Context::GetCurrent())); |
| 36 } |
| 37 ExtensionHostMsg_DOMAction_Params params; |
| 38 params.url = url_; |
| 39 params.url_title = title_; |
| 40 params.api_call = api_name.utf8(); |
| 41 params.arguments.Swap(argv_list_value.get()); |
| 42 params.extra = extra_info.utf8(); |
| 43 |
| 44 content::RenderThread::Get()->Send( |
| 45 new ExtensionHostMsg_AddDOMActionToActivityLog(extension_id_, params)); |
| 46 } |
| 47 |
| 48 void DOMActivityLogger::AttachToWorld(int world_id, |
| 49 const std::string& extension_id, |
| 50 const GURL& url, |
| 51 const string16& title) { |
| 52 // Check if extension activity logging is enabled. |
| 53 if (!ChromeRenderProcessObserver::extension_activity_log_enabled()) |
| 54 return; |
| 55 // If there is no logger registered for world_id, construct a new logger |
| 56 // and register it with world_id. |
| 57 if (!WebKit::hasDOMActivityLogger(world_id)) { |
| 58 DOMActivityLogger* logger = new DOMActivityLogger(extension_id, url, title); |
| 59 WebKit::setDOMActivityLogger(world_id, logger); |
| 60 } |
| 61 } |
| 62 |
| 63 } // namespace extensions |
| 64 |
OLD | NEW |