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

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"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 Action::InjectionType Action::DidInjectAd( 154 Action::InjectionType Action::DidInjectAd(
155 rappor::RapporService* rappor_service) const { 155 rappor::RapporService* rappor_service) const {
156 MaybeUploadUrl(rappor_service); 156 MaybeUploadUrl(rappor_service);
157 157
158 // Currently, we do not have the list of ad networks, so we exit immediately 158 // 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). 159 // with NO_AD_INJECTION (unless the database has been set by a test).
160 if (!AdNetworkDatabase::Get()) 160 if (!AdNetworkDatabase::Get())
161 return NO_AD_INJECTION; 161 return NO_AD_INJECTION;
162 162
163 if (api_name_ == ad_injection_constants::kHtmlIframeSrcApiName || 163 if (api_name_ == ad_injection_constants::kHtmlIframeSrcApiName ||
164 api_name_ == ad_injection_constants::kHtmlEmbedSrcApiName) { 164 api_name_ == ad_injection_constants::kHtmlEmbedSrcApiName ||
165 api_name_ == ad_injection_constants::kHtmlAnchorHrefApiName) {
165 return CheckSrcModification(); 166 return CheckSrcModification();
166 } else if (EndsWith(api_name_, 167 } else if (EndsWith(api_name_,
167 ad_injection_constants::kAppendChildApiSuffix, 168 ad_injection_constants::kAppendChildApiSuffix,
168 true /* case senstive */)) { 169 true /* case senstive */)) {
169 return CheckAppendChild(); 170 return CheckAppendChild();
170 } 171 }
171 172
172 return NO_AD_INJECTION; 173 return NO_AD_INJECTION;
173 } 174 }
174 175
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 if (!can_inject_ads) 412 if (!can_inject_ads)
412 return; 413 return;
413 414
414 // Record the URL - an ad *may* have been injected. 415 // Record the URL - an ad *may* have been injected.
415 rappor_service->RecordSample(kExtensionAdInjectionRapporMetricName, 416 rappor_service->RecordSample(kExtensionAdInjectionRapporMetricName,
416 rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, 417 rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
417 host); 418 host);
418 } 419 }
419 420
420 Action::InjectionType Action::CheckSrcModification() const { 421 Action::InjectionType Action::CheckSrcModification() const {
421 bool injected_ad = arg_url_.is_valid() && 422 const AdNetworkDatabase* database = AdNetworkDatabase::Get();
422 !arg_url_.is_empty() && 423
423 AdNetworkDatabase::Get()->IsAdNetwork(arg_url_); 424 bool arg_url_valid = arg_url_.is_valid() && !arg_url_.is_empty();
424 return injected_ad ? INJECTION_NEW_AD : NO_AD_INJECTION; 425
426 GURL prev_url;
427 std::string prev_url_string;
428 if (args_.get() && args_->GetString(1u, &prev_url_string))
429 prev_url = GURL(prev_url_string);
430
431 bool prev_url_valid = prev_url.is_valid() && !prev_url.is_empty();
432
433 bool injected_ad = arg_url_valid && database->IsAdNetwork(arg_url_);
434 bool replaced_ad = prev_url_valid && database->IsAdNetwork(prev_url);
435
436 if (injected_ad && replaced_ad)
437 return INJECTION_REPLACED_AD;
438 if (injected_ad)
439 return INJECTION_NEW_AD;
440 if (replaced_ad)
441 return INJECTION_REMOVED_AD;
442
443 // If the extension replaced a valid URL with another valid URL for an iframe,
444 // embed, href, etc, then chances are it's ad injection (as there are few
445 // legitimate use cases for this). Log it as a likely one, which also helps
446 // us determine the effectiveness of our IsAdNetwork() recognition.
447 if (arg_url_valid && prev_url_valid)
448 return INJECTION_LIKELY_REPLACED_AD;
449
450 return NO_AD_INJECTION;
425 } 451 }
426 452
427 Action::InjectionType Action::CheckAppendChild() const { 453 Action::InjectionType Action::CheckAppendChild() const {
428 const base::DictionaryValue* child = NULL; 454 const base::DictionaryValue* child = NULL;
429 if (!args_->GetDictionary(0u, &child)) 455 if (!args_->GetDictionary(0u, &child))
430 return NO_AD_INJECTION; 456 return NO_AD_INJECTION;
431 457
432 return CheckDomObject(child); 458 return CheckDomObject(child);
433 } 459 }
434 460
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 std::string rhs_other = ActivityLogPolicy::Util::Serialize(rhs->other()); 516 std::string rhs_other = ActivityLogPolicy::Util::Serialize(rhs->other());
491 if (lhs_other != rhs_other) 517 if (lhs_other != rhs_other)
492 return lhs_other < rhs_other; 518 return lhs_other < rhs_other;
493 } 519 }
494 520
495 // All fields compare as equal if this point is reached. 521 // All fields compare as equal if this point is reached.
496 return false; 522 return false;
497 } 523 }
498 524
499 } // namespace extensions 525 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698