1// Copyright 2014 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#ifndef EXTENSIONS_RENDERER_DOM_ACTIVITY_LOGGER_H_ 6#define EXTENSIONS_RENDERER_DOM_ACTIVITY_LOGGER_H_ 7 8#include <string> 9 10#include "base/macros.h" 11#include "extensions/common/dom_action_types.h" 12#include "third_party/WebKit/public/web/WebDOMActivityLogger.h" 13#include "v8/include/v8.h" 14 15namespace base { 16class ListValue; 17} 18 19namespace blink { 20class WebString; 21class WebURL; 22} 23 24namespace content { 25class V8ValueConverter; 26} 27 28namespace extensions { 29 30// Used to log DOM API calls from within WebKit. The events are sent via IPC to 31// extensions::ActivityLog for recording and display. 32class DOMActivityLogger: public blink::WebDOMActivityLogger { 33 public: 34 static const int kMainWorldId = 0; 35 explicit DOMActivityLogger(const std::string& extension_id); 36 virtual ~DOMActivityLogger(); 37 38 // Check (using the WebKit API) if there is no logger attached to the world 39 // corresponding to world_id, and if so, construct a new logger and attach it. 40 // world_id = 0 indicates the main world. 41 static void AttachToWorld(int world_id, 42 const std::string& extension_id); 43 44 private: 45 // blink::WebDOMActivityLogger implementation. 46 // Marshals the arguments into an ExtensionHostMsg_DOMAction_Params and sends 47 // it over to the browser (via IPC) for appending it to the extension activity 48 // log. 49 // These methods don't have the OVERRIDE keyword due to the complexities it 50 // introduces when changes blink apis. 51 virtual void logGetter(const blink::WebString& api_name, 52 const blink::WebURL& url, 53 const blink::WebString& title); 54 virtual void logSetter(const blink::WebString& api_name, 55 const v8::Handle<v8::Value>& new_value, 56 const blink::WebURL& url, 57 const blink::WebString& title); 58 virtual void logSetter(const blink::WebString& api_name, 59 const v8::Handle<v8::Value>& new_value, 60 const v8::Handle<v8::Value>& old_value, 61 const blink::WebURL& url, 62 const blink::WebString& title); 63 virtual void logMethod(const blink::WebString& api_name, 64 int argc, 65 const v8::Handle<v8::Value>* argv, 66 const blink::WebURL& url, 67 const blink::WebString& title); 68 virtual void logEvent(const blink::WebString& event_name, 69 int argc, 70 const blink::WebString* argv, 71 const blink::WebURL& url, 72 const blink::WebString& title); 73 74 // Helper function to actually send the message across IPC. 75 void SendDomActionMessage(const std::string& api_call, 76 const GURL& url, 77 const base::string16& url_title, 78 DomActionType::Type call_type, 79 scoped_ptr<base::ListValue> args); 80 81 // The id of the extension with which this logger is associated. 82 std::string extension_id_; 83 84 DISALLOW_COPY_AND_ASSIGN(DOMActivityLogger); 85}; 86 87} // namespace extensions 88 89#endif // EXTENSIONS_RENDERER_DOM_ACTIVITY_LOGGER_H_ 90 91