Index: chrome/browser/extensions/webstore_inline_installer.cc |
diff --git a/chrome/browser/extensions/webstore_inline_installer.cc b/chrome/browser/extensions/webstore_inline_installer.cc |
index ad79d091d6e530be10464fce566459d7d0f7efb1..7c5d6f9967922ef07a11e8fdb1f42d60e5bd7adf 100644 |
--- a/chrome/browser/extensions/webstore_inline_installer.cc |
+++ b/chrome/browser/extensions/webstore_inline_installer.cc |
@@ -9,8 +9,11 @@ |
#include "base/json/json_writer.h" |
#include "base/strings/stringprintf.h" |
#include "base/values.h" |
+#include "chrome/browser/browser_process.h" |
#include "chrome/browser/extensions/webstore_data_fetcher.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.h" |
+#include "chrome/browser/safe_browsing/safe_browsing_service.h" |
#include "chrome/browser/ui/browser_finder.h" |
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
#include "content/public/browser/navigation_entry.h" |
@@ -18,6 +21,14 @@ |
#include "content/public/browser/web_contents.h" |
using content::WebContents; |
+using safe_browsing::SafeBrowsingNavigationObserverManager; |
+using safe_browsing::ReferrerChain; |
+ |
+namespace { |
+ |
+// The number of user gestures to trace back for CWS pings. |
+const int kExtensionReferrerUserGestureLimit = 2; |
Devlin
2017/04/13 15:03:07
\n
robertshield
2017/04/21 00:40:41
Done.
|
+} |
namespace extensions { |
@@ -101,36 +112,76 @@ bool WebstoreInlineInstaller::IsRequestorPermitted( |
return true; |
} |
+bool WebstoreInlineInstaller::SafeBrowsingNavigationEventsEnabled() const { |
+ return SafeBrowsingNavigationObserverManager::IsEnabledAndReady( |
+ Profile::FromBrowserContext(web_contents()->GetBrowserContext())); |
+} |
+ |
std::string WebstoreInlineInstaller::GetJsonPostData() { |
// web_contents() might return null during tab destruction. This object would |
// also be destroyed shortly thereafter but check to be on the safe side. |
if (!web_contents()) |
return std::string(); |
- content::NavigationController& navigation_controller = |
- web_contents()->GetController(); |
- content::NavigationEntry* navigation_entry = |
- navigation_controller.GetLastCommittedEntry(); |
- |
- if (navigation_entry) { |
+ std::unique_ptr<base::ListValue> redirect_chain = |
+ base::MakeUnique<base::ListValue>(); |
+ |
+ if (SafeBrowsingNavigationEventsEnabled()) { |
+ // If we have it, use the new referrer checker. |
+ safe_browsing::SafeBrowsingService* safe_browsing_service = |
+ g_browser_process->safe_browsing_service(); |
+ if (!safe_browsing_service) |
Devlin
2017/04/13 15:03:07
Document when this and navigation_observer_manager
robertshield
2017/04/21 00:40:41
Done.
|
+ return std::string(); |
+ |
+ scoped_refptr<SafeBrowsingNavigationObserverManager> |
+ navigation_observer_manager = |
+ safe_browsing_service->navigation_observer_manager(); |
+ if (!navigation_observer_manager) |
+ return std::string(); |
+ |
+ ReferrerChain referrer_chain; |
+ SafeBrowsingNavigationObserverManager::AttributionResult result = |
+ navigation_observer_manager->IdentifyReferrerChainByWebContents( |
+ web_contents(), kExtensionReferrerUserGestureLimit, |
+ &referrer_chain); |
+ if (result != |
+ SafeBrowsingNavigationObserverManager::NAVIGATION_EVENT_NOT_FOUND) { |
+ // For now the CWS post data is JSON encoded. Consider moving it to a |
+ // proto. |
+ for (const auto& referrer_chain_entry : referrer_chain) { |
+ // Referrer chain entries are a list of URLs in reverse chronological |
+ // order, so the final URL is the last thing in the list and the initial |
+ // landing page is the first thing in the list. |
+ // Furthermore each entry may contain a series of server redirects |
+ // stored in the same order. |
+ redirect_chain->AppendString(referrer_chain_entry.url()); |
+ for (const auto& server_side_redirect : |
+ referrer_chain_entry.server_redirect_chain()) { |
+ redirect_chain->AppendString(server_side_redirect.url()); |
+ } |
+ } |
+ } |
+ } else { |
+ content::NavigationController& navigation_controller = |
+ web_contents()->GetController(); |
+ content::NavigationEntry* navigation_entry = |
+ navigation_controller.GetLastCommittedEntry(); |
const std::vector<GURL>& redirect_urls = |
navigation_entry->GetRedirectChain(); |
+ for (const GURL& url : redirect_urls) { |
+ redirect_chain->AppendString(url.spec()); |
+ } |
+ } |
- if (!redirect_urls.empty()) { |
- base::DictionaryValue dictionary; |
- dictionary.SetString("id", id()); |
- dictionary.SetString("referrer", requestor_url_.spec()); |
- std::unique_ptr<base::ListValue> redirect_chain = |
- base::MakeUnique<base::ListValue>(); |
- for (const GURL& url : redirect_urls) { |
- redirect_chain->AppendString(url.spec()); |
- } |
- dictionary.Set("redirect_chain", std::move(redirect_chain)); |
+ if (!redirect_chain->empty()) { |
+ base::DictionaryValue dictionary; |
+ dictionary.SetString("id", id()); |
+ dictionary.SetString("referrer", requestor_url_.spec()); |
+ dictionary.Set("redirect_chain", std::move(redirect_chain)); |
- std::string json; |
- base::JSONWriter::Write(dictionary, &json); |
- return json; |
- } |
+ std::string json; |
+ base::JSONWriter::Write(dictionary, &json); |
+ return json; |
} |
return std::string(); |