Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/webstore_inline_installer.h" | 5 #include "chrome/browser/extensions/webstore_inline_installer.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/browser_process.h" | |
| 12 #include "chrome/browser/extensions/webstore_data_fetcher.h" | 13 #include "chrome/browser/extensions/webstore_data_fetcher.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h" | |
| 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
| 14 #include "chrome/browser/ui/browser_finder.h" | 17 #include "chrome/browser/ui/browser_finder.h" |
| 15 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 18 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 16 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
| 17 #include "content/public/browser/navigation_handle.h" | 20 #include "content/public/browser/navigation_handle.h" |
| 18 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 19 | 22 |
| 23 | |
| 20 using content::WebContents; | 24 using content::WebContents; |
| 25 using safe_browsing::SafeBrowsingNavigationObserverManager; | |
| 26 using safe_browsing::ReferrerChain; | |
| 27 | |
| 28 namespace { | |
| 29 | |
| 30 // The number of user gestures to trace back for CWS pings. | |
| 31 const int kExtensionReferrerUserGestureLimit = 2; | |
| 32 | |
| 33 } | |
| 21 | 34 |
| 22 namespace extensions { | 35 namespace extensions { |
| 23 | 36 |
| 24 const char kInvalidWebstoreResponseError[] = | 37 const char kInvalidWebstoreResponseError[] = |
| 25 "Invalid Chrome Web Store response."; | 38 "Invalid Chrome Web Store response."; |
| 26 const char kNoVerifiedSitesError[] = | 39 const char kNoVerifiedSitesError[] = |
| 27 "Inline installs can only be initiated for Chrome Web Store items that " | 40 "Inline installs can only be initiated for Chrome Web Store items that " |
| 28 "have one or more verified sites."; | 41 "have one or more verified sites."; |
| 29 const char kNotFromVerifiedSitesError[] = | 42 const char kNotFromVerifiedSitesError[] = |
| 30 "Installs can only be initiated by one of the Chrome Web Store item's " | 43 "Installs can only be initiated by one of the Chrome Web Store item's " |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 *error = ""; | 113 *error = ""; |
| 101 return true; | 114 return true; |
| 102 } | 115 } |
| 103 | 116 |
| 104 std::string WebstoreInlineInstaller::GetJsonPostData() { | 117 std::string WebstoreInlineInstaller::GetJsonPostData() { |
| 105 // web_contents() might return null during tab destruction. This object would | 118 // web_contents() might return null during tab destruction. This object would |
| 106 // also be destroyed shortly thereafter but check to be on the safe side. | 119 // also be destroyed shortly thereafter but check to be on the safe side. |
| 107 if (!web_contents()) | 120 if (!web_contents()) |
| 108 return std::string(); | 121 return std::string(); |
| 109 | 122 |
| 110 content::NavigationController& navigation_controller = | 123 std::unique_ptr<base::ListValue> redirect_chain = |
| 111 web_contents()->GetController(); | 124 base::MakeUnique<base::ListValue>(); |
| 112 content::NavigationEntry* navigation_entry = | |
| 113 navigation_controller.GetLastCommittedEntry(); | |
| 114 | 125 |
| 115 if (navigation_entry) { | 126 if (true || |
| 127 !SafeBrowsingNavigationObserverManager::IsEnabledAndReady( | |
| 128 Profile::FromBrowserContext(web_contents()->GetBrowserContext()))) { | |
| 129 // If we have it, use the new referrer checker. | |
| 130 safe_browsing::SafeBrowsingService* safe_browsing_service = | |
| 131 g_browser_process->safe_browsing_service(); | |
| 132 if (!safe_browsing_service) | |
| 133 return std::string(); | |
| 134 | |
| 135 scoped_refptr<SafeBrowsingNavigationObserverManager> | |
| 136 navigation_observer_manager = | |
| 137 safe_browsing_service->navigation_observer_manager(); | |
| 138 if (!navigation_observer_manager) | |
| 139 return std::string(); | |
| 140 | |
| 141 ReferrerChain referrer_chain; | |
| 142 SafeBrowsingNavigationObserverManager::AttributionResult result = | |
| 143 navigation_observer_manager->IdentifyReferrerChainByDownloadWebContent( | |
|
Jialiu Lin
2017/03/31 19:17:52
FYI, I updated the function name to IdentifyReferr
| |
| 144 web_contents(), | |
| 145 kExtensionReferrerUserGestureLimit, | |
| 146 &referrer_chain); | |
| 147 if (result != | |
| 148 SafeBrowsingNavigationObserverManager::NAVIGATION_EVENT_NOT_FOUND) { | |
| 149 | |
| 150 // For now the CWS post data is JSON encoded. Consider moving it to a | |
| 151 // proto. | |
| 152 for (const auto& referrer_chain_entry : referrer_chain) { | |
| 153 // Referrer chain entries are a list of URLs in reverse chronological | |
| 154 // order, so the final URL is the last thing in the list and the initial | |
| 155 // landing page is the first thing in the list. | |
| 156 // Furthermore each entry may contain a series of server redirects | |
| 157 // stored in the same order. | |
| 158 redirect_chain->AppendString(referrer_chain_entry.url()); | |
| 159 for (const auto& server_side_redirect : | |
| 160 referrer_chain_entry.server_redirect_chain()) { | |
| 161 redirect_chain->AppendString(server_side_redirect.url()); | |
| 162 } | |
| 163 } | |
| 164 } | |
| 165 } else { | |
| 166 content::NavigationController& navigation_controller = | |
| 167 web_contents()->GetController(); | |
| 168 content::NavigationEntry* navigation_entry = | |
| 169 navigation_controller.GetLastCommittedEntry(); | |
| 116 const std::vector<GURL>& redirect_urls = | 170 const std::vector<GURL>& redirect_urls = |
| 117 navigation_entry->GetRedirectChain(); | 171 navigation_entry->GetRedirectChain(); |
| 118 | 172 for (const GURL& url : redirect_urls) { |
| 119 if (!redirect_urls.empty()) { | 173 redirect_chain->AppendString(url.spec()); |
| 120 base::DictionaryValue dictionary; | |
| 121 dictionary.SetString("id", id()); | |
| 122 dictionary.SetString("referrer", requestor_url_.spec()); | |
| 123 std::unique_ptr<base::ListValue> redirect_chain = | |
| 124 base::MakeUnique<base::ListValue>(); | |
| 125 for (const GURL& url : redirect_urls) { | |
| 126 redirect_chain->AppendString(url.spec()); | |
| 127 } | |
| 128 dictionary.Set("redirect_chain", std::move(redirect_chain)); | |
| 129 | |
| 130 std::string json; | |
| 131 base::JSONWriter::Write(dictionary, &json); | |
| 132 return json; | |
| 133 } | 174 } |
| 134 } | 175 } |
| 135 | 176 |
| 177 if (!redirect_chain->empty()) { | |
| 178 base::DictionaryValue dictionary; | |
| 179 dictionary.SetString("id", id()); | |
| 180 dictionary.SetString("referrer", requestor_url_.spec()); | |
| 181 dictionary.Set("redirect_chain", std::move(redirect_chain)); | |
| 182 | |
| 183 std::string json; | |
| 184 base::JSONWriter::Write(dictionary, &json); | |
| 185 return json; | |
| 186 } | |
| 187 | |
| 136 return std::string(); | 188 return std::string(); |
| 137 } | 189 } |
| 138 | 190 |
| 139 bool WebstoreInlineInstaller::CheckRequestorAlive() const { | 191 bool WebstoreInlineInstaller::CheckRequestorAlive() const { |
| 140 // The frame or tab may have gone away - cancel installation in that case. | 192 // The frame or tab may have gone away - cancel installation in that case. |
| 141 return host_ != nullptr && web_contents() != nullptr && | 193 return host_ != nullptr && web_contents() != nullptr && |
| 142 chrome::FindBrowserWithWebContents(web_contents()) != nullptr; | 194 chrome::FindBrowserWithWebContents(web_contents()) != nullptr; |
| 143 } | 195 } |
| 144 | 196 |
| 145 const GURL& WebstoreInlineInstaller::GetRequestorURL() const { | 197 const GURL& WebstoreInlineInstaller::GetRequestorURL() const { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 DLOG(WARNING) << "Could not parse " << verified_site_pattern_spec << | 340 DLOG(WARNING) << "Could not parse " << verified_site_pattern_spec << |
| 289 " as URL pattern " << parse_result; | 341 " as URL pattern " << parse_result; |
| 290 return false; | 342 return false; |
| 291 } | 343 } |
| 292 verified_site_pattern.SetScheme("*"); | 344 verified_site_pattern.SetScheme("*"); |
| 293 | 345 |
| 294 return verified_site_pattern.MatchesURL(requestor_url); | 346 return verified_site_pattern.MatchesURL(requestor_url); |
| 295 } | 347 } |
| 296 | 348 |
| 297 } // namespace extensions | 349 } // namespace extensions |
| OLD | NEW |