Home | History | Annotate | Download | only in extensions
      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 #ifndef CHROME_RENDERER_EXTENSIONS_DOM_ACTIVITY_LOGGER_H_
      6 #define CHROME_RENDERER_EXTENSIONS_DOM_ACTIVITY_LOGGER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/strings/string_piece.h"
     11 #include "third_party/WebKit/public/platform/WebString.h"
     12 #include "third_party/WebKit/public/web/WebDOMActivityLogger.h"
     13 #include "url/gurl.h"
     14 #include "v8/include/v8.h"
     15 
     16 using WebKit::WebString;
     17 
     18 // Used to log DOM API calls from within WebKit. The events are sent via IPC to
     19 // extensions::ActivityLog for recording and display.
     20 namespace extensions {
     21 
     22 class DOMActivityLogger: public WebKit::WebDOMActivityLogger {
     23  public:
     24   static const int kMainWorldId = 0;
     25   DOMActivityLogger(const std::string& extension_id,
     26                     const GURL& url,
     27                     const string16& title);
     28 
     29   // Marshalls the arguments into an ExtensionHostMsg_DOMAction_Params
     30   // and sends it over to the browser (via IPC) for appending it to the
     31   // extension activity log.
     32   // (Overrides the log method in WebKit::WebDOMActivityLogger)
     33   virtual void log(const WebString& api_name,
     34                    int argc,
     35                    const v8::Handle<v8::Value> argv[],
     36                    const WebString& call_type);
     37 
     38   // If extension activity logging is enabled then check (using the
     39   // WebKit API) if there is no logger attached to the world corresponding
     40   // to world_id, and if so, construct a new logger and attach it.
     41   // worl_id = 0 indicates the main world.
     42   static void AttachToWorld(int world_id,
     43                             const std::string& extension_id,
     44                             const GURL& url,
     45                             const string16& title);
     46 
     47  private:
     48   std::string extension_id_;
     49   GURL url_;
     50   string16 title_;
     51 
     52   DISALLOW_COPY_AND_ASSIGN(DOMActivityLogger);
     53 };
     54 
     55 }  // namespace extensions
     56 
     57 #endif  // CHROME_RENDERER_EXTENSIONS_DOM_ACTIVITY_LOGGER_H_
     58 
     59