OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "public/web/WebDOMActivityLogger.h" | |
32 | |
33 #include <memory> | |
34 #include "bindings/core/v8/V8BindingForCore.h" | |
35 #include "bindings/core/v8/V8DOMActivityLogger.h" | |
36 #include "core/dom/Document.h" | |
37 #include "core/frame/LocalDOMWindow.h" | |
38 #include "platform/wtf/PassRefPtr.h" | |
39 #include "platform/wtf/PtrUtil.h" | |
40 #include "platform/wtf/text/WTFString.h" | |
41 | |
42 namespace blink { | |
43 | |
44 class DOMActivityLoggerContainer : public V8DOMActivityLogger { | |
45 public: | |
46 explicit DOMActivityLoggerContainer( | |
47 std::unique_ptr<WebDOMActivityLogger> logger) | |
48 : dom_activity_logger_(std::move(logger)) {} | |
49 | |
50 void LogGetter(const String& api_name) override { | |
51 dom_activity_logger_->LogGetter(WebString(api_name), GetURL(), GetTitle()); | |
52 } | |
53 | |
54 void LogSetter(const String& api_name, | |
55 const v8::Local<v8::Value>& new_value) override { | |
56 dom_activity_logger_->LogSetter(WebString(api_name), new_value, GetURL(), | |
57 GetTitle()); | |
58 } | |
59 | |
60 void LogMethod(const String& api_name, | |
61 int argc, | |
62 const v8::Local<v8::Value>* argv) override { | |
63 dom_activity_logger_->LogMethod(WebString(api_name), argc, argv, GetURL(), | |
64 GetTitle()); | |
65 } | |
66 | |
67 void LogEvent(const String& event_name, | |
68 int argc, | |
69 const String* argv) override { | |
70 Vector<WebString> web_string_argv; | |
71 for (int i = 0; i < argc; i++) | |
72 web_string_argv.push_back(argv[i]); | |
73 dom_activity_logger_->LogEvent(WebString(event_name), argc, | |
74 web_string_argv.data(), GetURL(), | |
75 GetTitle()); | |
76 } | |
77 | |
78 private: | |
79 WebURL GetURL() { | |
80 if (Document* document = | |
81 CurrentDOMWindow(v8::Isolate::GetCurrent())->document()) | |
82 return WebURL(document->Url()); | |
83 return WebURL(); | |
84 } | |
85 | |
86 WebString GetTitle() { | |
87 if (Document* document = | |
88 CurrentDOMWindow(v8::Isolate::GetCurrent())->document()) | |
89 return WebString(document->title()); | |
90 return WebString(); | |
91 } | |
92 | |
93 std::unique_ptr<WebDOMActivityLogger> dom_activity_logger_; | |
94 }; | |
95 | |
96 bool HasDOMActivityLogger(int world_id, const WebString& extension_id) { | |
97 return V8DOMActivityLogger::ActivityLogger(world_id, extension_id); | |
98 } | |
99 | |
100 void SetDOMActivityLogger(int world_id, | |
101 const WebString& extension_id, | |
102 WebDOMActivityLogger* logger) { | |
103 DCHECK(logger); | |
104 V8DOMActivityLogger::SetActivityLogger( | |
105 world_id, extension_id, | |
106 WTF::WrapUnique(new DOMActivityLoggerContainer(WTF::WrapUnique(logger)))); | |
107 } | |
108 | |
109 } // namespace blink | |
OLD | NEW |