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

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

Issue 2655823002: Include referrer chain with inline install requests. (Closed)
Patch Set: Add missing comment. 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 // 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.
107 if (!web_contents())
108 return std::string();
109
110 content::NavigationController& navigation_controller =
111 web_contents()->GetController();
112 content::NavigationEntry* navigation_entry =
113 navigation_controller.GetLastCommittedEntry();
114
115 if (navigation_entry) {
116 const std::vector<GURL>& redirect_urls =
117 navigation_entry->GetRedirectChain();
118
119 if (!redirect_urls.empty()) {
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 }
134 }
135
136 return std::string();
137 }
138
98 bool WebstoreInlineInstaller::CheckRequestorAlive() const { 139 bool WebstoreInlineInstaller::CheckRequestorAlive() const {
99 // The frame or tab may have gone away - cancel installation in that case. 140 // The frame or tab may have gone away - cancel installation in that case.
100 return host_ != nullptr && web_contents() != nullptr; 141 return host_ != nullptr && web_contents() != nullptr;
101 } 142 }
102 143
103 const GURL& WebstoreInlineInstaller::GetRequestorURL() const { 144 const GURL& WebstoreInlineInstaller::GetRequestorURL() const {
104 return requestor_url_; 145 return requestor_url_;
105 } 146 }
106 147
107 std::unique_ptr<ExtensionInstallPrompt::Prompt> 148 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 << 286 DLOG(WARNING) << "Could not parse " << verified_site_pattern_spec <<
246 " as URL pattern " << parse_result; 287 " as URL pattern " << parse_result;
247 return false; 288 return false;
248 } 289 }
249 verified_site_pattern.SetScheme("*"); 290 verified_site_pattern.SetScheme("*");
250 291
251 return verified_site_pattern.MatchesURL(requestor_url); 292 return verified_site_pattern.MatchesURL(requestor_url);
252 } 293 }
253 294
254 } // namespace extensions 295 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698