| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/renderer/dom_activity_logger.h" | 5 #include "extensions/renderer/dom_activity_logger.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "content/public/child/v8_value_converter.h" | 9 #include "content/public/child/v8_value_converter.h" |
| 10 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 namespace extensions { | 21 namespace extensions { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Converts the given |v8_value| and appends it to the given |list|, if the | 25 // Converts the given |v8_value| and appends it to the given |list|, if the |
| 26 // conversion succeeds. | 26 // conversion succeeds. |
| 27 void AppendV8Value(const std::string& api_name, | 27 void AppendV8Value(const std::string& api_name, |
| 28 const v8::Local<v8::Value>& v8_value, | 28 const v8::Local<v8::Value>& v8_value, |
| 29 base::ListValue* list) { | 29 base::ListValue* list) { |
| 30 DCHECK(list); | 30 DCHECK(list); |
| 31 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 31 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
| 32 ActivityLogConverterStrategy strategy; | 32 ActivityLogConverterStrategy strategy; |
| 33 converter->SetFunctionAllowed(true); | 33 converter->SetFunctionAllowed(true); |
| 34 converter->SetStrategy(&strategy); | 34 converter->SetStrategy(&strategy); |
| 35 scoped_ptr<base::Value> value(converter->FromV8Value( | 35 std::unique_ptr<base::Value> value(converter->FromV8Value( |
| 36 v8_value, v8::Isolate::GetCurrent()->GetCurrentContext())); | 36 v8_value, v8::Isolate::GetCurrent()->GetCurrentContext())); |
| 37 | 37 |
| 38 if (value.get()) | 38 if (value.get()) |
| 39 list->Append(value.release()); | 39 list->Append(value.release()); |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 DOMActivityLogger::DOMActivityLogger(const std::string& extension_id) | 44 DOMActivityLogger::DOMActivityLogger(const std::string& extension_id) |
| 45 : extension_id_(extension_id) { | 45 : extension_id_(extension_id) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 56 DOMActivityLogger* logger = new DOMActivityLogger(extension_id); | 56 DOMActivityLogger* logger = new DOMActivityLogger(extension_id); |
| 57 blink::setDOMActivityLogger(world_id, | 57 blink::setDOMActivityLogger(world_id, |
| 58 WebString::fromUTF8(extension_id), | 58 WebString::fromUTF8(extension_id), |
| 59 logger); | 59 logger); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 void DOMActivityLogger::logGetter(const WebString& api_name, | 63 void DOMActivityLogger::logGetter(const WebString& api_name, |
| 64 const WebURL& url, | 64 const WebURL& url, |
| 65 const WebString& title) { | 65 const WebString& title) { |
| 66 SendDomActionMessage(api_name.utf8(), | 66 SendDomActionMessage(api_name.utf8(), url, title, DomActionType::GETTER, |
| 67 url, | 67 std::unique_ptr<base::ListValue>(new base::ListValue())); |
| 68 title, | |
| 69 DomActionType::GETTER, | |
| 70 scoped_ptr<base::ListValue>(new base::ListValue())); | |
| 71 } | 68 } |
| 72 | 69 |
| 73 void DOMActivityLogger::logSetter(const WebString& api_name, | 70 void DOMActivityLogger::logSetter(const WebString& api_name, |
| 74 const v8::Local<v8::Value>& new_value, | 71 const v8::Local<v8::Value>& new_value, |
| 75 const WebURL& url, | 72 const WebURL& url, |
| 76 const WebString& title) { | 73 const WebString& title) { |
| 77 logSetter(api_name, new_value, v8::Local<v8::Value>(), url, title); | 74 logSetter(api_name, new_value, v8::Local<v8::Value>(), url, title); |
| 78 } | 75 } |
| 79 | 76 |
| 80 void DOMActivityLogger::logSetter(const WebString& api_name, | 77 void DOMActivityLogger::logSetter(const WebString& api_name, |
| 81 const v8::Local<v8::Value>& new_value, | 78 const v8::Local<v8::Value>& new_value, |
| 82 const v8::Local<v8::Value>& old_value, | 79 const v8::Local<v8::Value>& old_value, |
| 83 const WebURL& url, | 80 const WebURL& url, |
| 84 const WebString& title) { | 81 const WebString& title) { |
| 85 scoped_ptr<base::ListValue> args(new base::ListValue); | 82 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 86 std::string api_name_utf8 = api_name.utf8(); | 83 std::string api_name_utf8 = api_name.utf8(); |
| 87 AppendV8Value(api_name_utf8, new_value, args.get()); | 84 AppendV8Value(api_name_utf8, new_value, args.get()); |
| 88 if (!old_value.IsEmpty()) | 85 if (!old_value.IsEmpty()) |
| 89 AppendV8Value(api_name_utf8, old_value, args.get()); | 86 AppendV8Value(api_name_utf8, old_value, args.get()); |
| 90 SendDomActionMessage(api_name_utf8, url, title, DomActionType::SETTER, | 87 SendDomActionMessage(api_name_utf8, url, title, DomActionType::SETTER, |
| 91 std::move(args)); | 88 std::move(args)); |
| 92 } | 89 } |
| 93 | 90 |
| 94 void DOMActivityLogger::logMethod(const WebString& api_name, | 91 void DOMActivityLogger::logMethod(const WebString& api_name, |
| 95 int argc, | 92 int argc, |
| 96 const v8::Local<v8::Value>* argv, | 93 const v8::Local<v8::Value>* argv, |
| 97 const WebURL& url, | 94 const WebURL& url, |
| 98 const WebString& title) { | 95 const WebString& title) { |
| 99 scoped_ptr<base::ListValue> args(new base::ListValue); | 96 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 100 std::string api_name_utf8 = api_name.utf8(); | 97 std::string api_name_utf8 = api_name.utf8(); |
| 101 for (int i = 0; i < argc; ++i) | 98 for (int i = 0; i < argc; ++i) |
| 102 AppendV8Value(api_name_utf8, argv[i], args.get()); | 99 AppendV8Value(api_name_utf8, argv[i], args.get()); |
| 103 SendDomActionMessage(api_name_utf8, url, title, DomActionType::METHOD, | 100 SendDomActionMessage(api_name_utf8, url, title, DomActionType::METHOD, |
| 104 std::move(args)); | 101 std::move(args)); |
| 105 } | 102 } |
| 106 | 103 |
| 107 void DOMActivityLogger::logEvent(const WebString& event_name, | 104 void DOMActivityLogger::logEvent(const WebString& event_name, |
| 108 int argc, | 105 int argc, |
| 109 const WebString* argv, | 106 const WebString* argv, |
| 110 const WebURL& url, | 107 const WebURL& url, |
| 111 const WebString& title) { | 108 const WebString& title) { |
| 112 scoped_ptr<base::ListValue> args(new base::ListValue); | 109 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 113 std::string event_name_utf8 = event_name.utf8(); | 110 std::string event_name_utf8 = event_name.utf8(); |
| 114 for (int i = 0; i < argc; ++i) | 111 for (int i = 0; i < argc; ++i) |
| 115 args->Append(new base::StringValue(argv[i])); | 112 args->Append(new base::StringValue(argv[i])); |
| 116 SendDomActionMessage(event_name_utf8, url, title, DomActionType::METHOD, | 113 SendDomActionMessage(event_name_utf8, url, title, DomActionType::METHOD, |
| 117 std::move(args)); | 114 std::move(args)); |
| 118 } | 115 } |
| 119 | 116 |
| 120 void DOMActivityLogger::SendDomActionMessage(const std::string& api_call, | 117 void DOMActivityLogger::SendDomActionMessage( |
| 121 const GURL& url, | 118 const std::string& api_call, |
| 122 const base::string16& url_title, | 119 const GURL& url, |
| 123 DomActionType::Type call_type, | 120 const base::string16& url_title, |
| 124 scoped_ptr<base::ListValue> args) { | 121 DomActionType::Type call_type, |
| 122 std::unique_ptr<base::ListValue> args) { |
| 125 ExtensionHostMsg_DOMAction_Params params; | 123 ExtensionHostMsg_DOMAction_Params params; |
| 126 params.api_call = api_call; | 124 params.api_call = api_call; |
| 127 params.url = url; | 125 params.url = url; |
| 128 params.url_title = url_title; | 126 params.url_title = url_title; |
| 129 params.call_type = call_type; | 127 params.call_type = call_type; |
| 130 params.arguments.Swap(args.get()); | 128 params.arguments.Swap(args.get()); |
| 131 content::RenderThread::Get()->Send( | 129 content::RenderThread::Get()->Send( |
| 132 new ExtensionHostMsg_AddDOMActionToActivityLog(extension_id_, params)); | 130 new ExtensionHostMsg_AddDOMActionToActivityLog(extension_id_, params)); |
| 133 } | 131 } |
| 134 | 132 |
| 135 } // namespace extensions | 133 } // namespace extensions |
| OLD | NEW |