Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Side by Side Diff: chrome/browser/extensions/activity_log/activity_actions.cc

Issue 270623005: Update ActivityLog detection to use previous values, hrefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/extensions/activity_log/activity_actions.h" 5 #include "chrome/browser/extensions/activity_log/activity_actions.h"
6 6
7 #include <algorithm> // for std::find. 7 #include <algorithm> // for std::find.
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/format_macros.h" 11 #include "base/format_macros.h"
12 #include "base/json/json_string_value_serializer.h" 12 #include "base/json/json_string_value_serializer.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" 20 #include "chrome/browser/extensions/activity_log/activity_action_constants.h"
21 #include "chrome/browser/extensions/activity_log/ad_network_database.h" 21 #include "chrome/browser/extensions/activity_log/ad_network_database.h"
22 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" 22 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h"
23 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
25 #include "components/rappor/rappor_service.h" 25 #include "components/rappor/rappor_service.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "extensions/common/ad_injection_constants.h" 27 #include "extensions/common/ad_injection_constants.h"
28 #include "extensions/common/constants.h"
28 #include "extensions/common/dom_action_types.h" 29 #include "extensions/common/dom_action_types.h"
29 #include "sql/statement.h" 30 #include "sql/statement.h"
30 #include "url/gurl.h" 31 #include "url/gurl.h"
31 32
32 namespace constants = activity_log_constants; 33 namespace constants = activity_log_constants;
33 34
34 namespace extensions { 35 namespace extensions {
35 36
36 namespace { 37 namespace {
37 38
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 object->GetString(keys::kType, &type); 85 object->GetString(keys::kType, &type);
85 86
86 std::string url_key; 87 std::string url_key;
87 if (IsSrcElement(type)) 88 if (IsSrcElement(type))
88 url_key = keys::kSrc; 89 url_key = keys::kSrc;
89 else if (IsHrefElement(type)) 90 else if (IsHrefElement(type))
90 url_key = keys::kHref; 91 url_key = keys::kHref;
91 92
92 if (!url_key.empty()) { 93 if (!url_key.empty()) {
93 std::string url; 94 std::string url;
94 if (object->GetString(url_key, &url) && 95 if (object->GetString(url_key, &url)) {
95 AdNetworkDatabase::Get()->IsAdNetwork(GURL(url))) { 96 GURL gurl(url);
96 return Action::INJECTION_NEW_AD; 97 if (AdNetworkDatabase::Get()->IsAdNetwork(gurl))
98 return Action::INJECTION_NEW_AD;
99 // If the extension injected an URL which is not local to itself, there is
100 // a good chance it could be a new ad, and our database missed it.
101 // This could be noisier than other metrics, because there are perfectly
102 // acceptable uses for this, like "Show my mail".
103 if (gurl.is_valid() &&
104 !gurl.is_empty() &&
105 !gurl.SchemeIs(kExtensionScheme)) {
106 return Action::INJECTION_LIKELY_NEW_AD;
107 }
97 } 108 }
98 } 109 }
99 110
100 const base::ListValue* children = NULL; 111 const base::ListValue* children = NULL;
101 if (object->GetList(keys::kChildren, &children)) { 112 if (object->GetList(keys::kChildren, &children)) {
102 const base::DictionaryValue* child = NULL; 113 const base::DictionaryValue* child = NULL;
103 for (size_t i = 0; 114 for (size_t i = 0;
104 i < children->GetSize() && 115 i < children->GetSize() &&
105 i < ad_injection_constants::kMaximumChildrenToCheck; 116 i < ad_injection_constants::kMaximumChildrenToCheck;
106 ++i) { 117 ++i) {
107 if (children->GetDictionary(i, &child) && CheckDomObject(child)) 118 if (children->GetDictionary(i, &child)) {
108 return Action::INJECTION_NEW_AD; 119 Action::InjectionType type = CheckDomObject(child);
120 if (type != Action::NO_AD_INJECTION)
121 return type;
122 }
109 } 123 }
110 } 124 }
111 125
112 return Action::NO_AD_INJECTION; 126 return Action::NO_AD_INJECTION;
113 } 127 }
114 128
115 } // namespace 129 } // namespace
116 130
117 using api::activity_log_private::ExtensionActivity; 131 using api::activity_log_private::ExtensionActivity;
118 132
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 Action::InjectionType Action::DidInjectAd( 168 Action::InjectionType Action::DidInjectAd(
155 rappor::RapporService* rappor_service) const { 169 rappor::RapporService* rappor_service) const {
156 MaybeUploadUrl(rappor_service); 170 MaybeUploadUrl(rappor_service);
157 171
158 // Currently, we do not have the list of ad networks, so we exit immediately 172 // Currently, we do not have the list of ad networks, so we exit immediately
159 // with NO_AD_INJECTION (unless the database has been set by a test). 173 // with NO_AD_INJECTION (unless the database has been set by a test).
160 if (!AdNetworkDatabase::Get()) 174 if (!AdNetworkDatabase::Get())
161 return NO_AD_INJECTION; 175 return NO_AD_INJECTION;
162 176
163 if (api_name_ == ad_injection_constants::kHtmlIframeSrcApiName || 177 if (api_name_ == ad_injection_constants::kHtmlIframeSrcApiName ||
164 api_name_ == ad_injection_constants::kHtmlEmbedSrcApiName) { 178 api_name_ == ad_injection_constants::kHtmlEmbedSrcApiName ||
179 api_name_ == ad_injection_constants::kHtmlAnchorHrefApiName) {
165 return CheckSrcModification(); 180 return CheckSrcModification();
166 } else if (EndsWith(api_name_, 181 } else if (EndsWith(api_name_,
167 ad_injection_constants::kAppendChildApiSuffix, 182 ad_injection_constants::kAppendChildApiSuffix,
168 true /* case senstive */)) { 183 true /* case senstive */)) {
169 return CheckAppendChild(); 184 return CheckAppendChild();
170 } 185 }
171 186
172 return NO_AD_INJECTION; 187 return NO_AD_INJECTION;
173 } 188 }
174 189
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 if (!can_inject_ads) 426 if (!can_inject_ads)
412 return; 427 return;
413 428
414 // Record the URL - an ad *may* have been injected. 429 // Record the URL - an ad *may* have been injected.
415 rappor_service->RecordSample(kExtensionAdInjectionRapporMetricName, 430 rappor_service->RecordSample(kExtensionAdInjectionRapporMetricName,
416 rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, 431 rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
417 host); 432 host);
418 } 433 }
419 434
420 Action::InjectionType Action::CheckSrcModification() const { 435 Action::InjectionType Action::CheckSrcModification() const {
421 bool injected_ad = arg_url_.is_valid() && 436 const AdNetworkDatabase* database = AdNetworkDatabase::Get();
422 !arg_url_.is_empty() && 437
423 AdNetworkDatabase::Get()->IsAdNetwork(arg_url_); 438 bool arg_url_valid = arg_url_.is_valid() && !arg_url_.is_empty();
424 return injected_ad ? INJECTION_NEW_AD : NO_AD_INJECTION; 439
440 GURL prev_url;
441 std::string prev_url_string;
442 if (args_.get() && args_->GetString(1u, &prev_url_string))
443 prev_url = GURL(prev_url_string);
444
445 bool prev_url_valid = prev_url.is_valid() && !prev_url.is_empty();
446
447 bool injected_ad = arg_url_valid && database->IsAdNetwork(arg_url_);
448 bool replaced_ad = prev_url_valid && database->IsAdNetwork(prev_url);
449
450 if (injected_ad && replaced_ad)
451 return INJECTION_REPLACED_AD;
452 if (injected_ad)
453 return INJECTION_NEW_AD;
454 if (replaced_ad)
455 return INJECTION_REMOVED_AD;
456
457 // If the extension modified the URL with an external, valid URL then there's
458 // a good chance it's ad injection. Log it as a likely one, which also helps
459 // us determine the effectiveness of our IsAdNetwork() recognition.
460 if (arg_url_valid && !arg_url_.SchemeIs(kExtensionScheme)) {
461 if (prev_url_valid)
462 return INJECTION_LIKELY_REPLACED_AD;
463 return INJECTION_LIKELY_NEW_AD;
464 }
465
466 return NO_AD_INJECTION;
425 } 467 }
426 468
427 Action::InjectionType Action::CheckAppendChild() const { 469 Action::InjectionType Action::CheckAppendChild() const {
428 const base::DictionaryValue* child = NULL; 470 const base::DictionaryValue* child = NULL;
429 if (!args_->GetDictionary(0u, &child)) 471 if (!args_->GetDictionary(0u, &child))
430 return NO_AD_INJECTION; 472 return NO_AD_INJECTION;
431 473
432 return CheckDomObject(child); 474 return CheckDomObject(child);
433 } 475 }
434 476
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 std::string rhs_other = ActivityLogPolicy::Util::Serialize(rhs->other()); 532 std::string rhs_other = ActivityLogPolicy::Util::Serialize(rhs->other());
491 if (lhs_other != rhs_other) 533 if (lhs_other != rhs_other)
492 return lhs_other < rhs_other; 534 return lhs_other < rhs_other;
493 } 535 }
494 536
495 // All fields compare as equal if this point is reached. 537 // All fields compare as equal if this point is reached.
496 return false; 538 return false;
497 } 539 }
498 540
499 } // namespace extensions 541 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/activity_log/activity_actions.h ('k') | chrome/browser/extensions/activity_log/activity_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698