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

Side by Side Diff: chrome/browser/extensions/webstore_inline_installer.cc

Issue 2655823002: Include referrer chain with inline install requests. (Closed)
Patch Set: Cleanup. Created 3 years, 10 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) 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>
8
9 #include "base/json/json_writer.h"
7 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/values.h"
12 #include "chrome/browser/extensions/webstore_data_fetcher.h"
8 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser_finder.h" 14 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" 15 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
11 #include "content/public/browser/navigation_details.h" 16 #include "content/public/browser/navigation_details.h"
17 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
13 19
14 using content::WebContents; 20 using content::WebContents;
15 21
16 namespace extensions { 22 namespace extensions {
17 23
18 const char kInvalidWebstoreResponseError[] = 24 const char kInvalidWebstoreResponseError[] =
19 "Invalid Chrome Web Store response."; 25 "Invalid Chrome Web Store response.";
20 const char kNoVerifiedSitesError[] = 26 const char kNoVerifiedSitesError[] =
21 "Inline installs can only be initiated for Chrome Web Store items that " 27 "Inline installs can only be initiated for Chrome Web Store items that "
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 94 }
89 } 95 }
90 if (!requestor_is_ok) { 96 if (!requestor_is_ok) {
91 *error = kNotFromVerifiedSitesError; 97 *error = kNotFromVerifiedSitesError;
92 return false; 98 return false;
93 } 99 }
94 *error = ""; 100 *error = "";
95 return true; 101 return true;
96 } 102 }
97 103
104 std::string WebstoreInlineInstaller::GetJsonPostData() {
105 content::WebContents* web_contents = GetWebContents();
106
107 if (web_contents) {
Devlin 2017/01/30 17:24:48 Can |web_contents| be null? If so, we should mayb
robertshield 2017/01/31 02:48:14 Spelunking a bit: GetWebContents() returns web_con
robertshield 2017/01/31 02:56:27 Actually.. I spelunked some more. Looking at e.g.
108 content::NavigationController& navigation_controller =
109 web_contents->GetController();
110 content::NavigationEntry* navigation_entry =
111 navigation_controller.GetLastCommittedEntry();
112
113 if (navigation_entry) {
114 const std::vector<GURL>& redirect_urls =
115 navigation_entry->GetRedirectChain();
116
117 if (!redirect_urls.empty()) {
118 base::DictionaryValue dictionary;
119 dictionary.SetString("id", id());
120 dictionary.SetString("referrer", requestor_url_.spec());
121 std::unique_ptr<base::ListValue> redirect_chain =
122 base::MakeUnique<base::ListValue>();
123 for (const GURL& url : redirect_urls) {
124 redirect_chain->AppendString(url.spec());
125 }
126 dictionary.Set("redirect_chain", std::move(redirect_chain));
127
128 std::string json;
129 if (base::JSONWriter::Write(dictionary, &json))
Devlin 2017/01/30 17:24:48 Could this fail? If this is just to be cautious,
robertshield 2017/01/31 02:48:14 Actually, Write() always DCHECKs before returning
130 return json;
131 }
132 }
133 }
134
135 return std::string();
136 }
137
98 bool WebstoreInlineInstaller::CheckRequestorAlive() const { 138 bool WebstoreInlineInstaller::CheckRequestorAlive() const {
99 // The frame or tab may have gone away - cancel installation in that case. 139 // The frame or tab may have gone away - cancel installation in that case.
100 return host_ != nullptr && web_contents() != nullptr; 140 return host_ != nullptr && web_contents() != nullptr;
101 } 141 }
102 142
103 const GURL& WebstoreInlineInstaller::GetRequestorURL() const { 143 const GURL& WebstoreInlineInstaller::GetRequestorURL() const {
104 return requestor_url_; 144 return requestor_url_;
105 } 145 }
106 146
107 std::unique_ptr<ExtensionInstallPrompt::Prompt> 147 std::unique_ptr<ExtensionInstallPrompt::Prompt>
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 DLOG(WARNING) << "Could not parse " << verified_site_pattern_spec << 285 DLOG(WARNING) << "Could not parse " << verified_site_pattern_spec <<
246 " as URL pattern " << parse_result; 286 " as URL pattern " << parse_result;
247 return false; 287 return false;
248 } 288 }
249 verified_site_pattern.SetScheme("*"); 289 verified_site_pattern.SetScheme("*");
250 290
251 return verified_site_pattern.MatchesURL(requestor_url); 291 return verified_site_pattern.MatchesURL(requestor_url);
252 } 292 }
253 293
254 } // namespace extensions 294 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698