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> | |
| 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 Loading... | |
| 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 void WebstoreInlineInstaller::StartWebstoreDataRequest( | |
|
Devlin
2017/01/27 20:31:34
In the original version of this patch, this used a
robertshield
2017/01/28 03:58:48
Good idea! That's a lot cleaner and makes deriving
| |
| 105 WebstoreDataFetcher* fetcher, | |
| 106 const std::vector<GURL> redirect_list) { | |
| 107 if (!redirect_list.empty()) { | |
| 108 base::DictionaryValue dictionary; | |
| 109 dictionary.SetString("id", id()); | |
| 110 dictionary.SetString("referrer", requestor_url_.spec()); | |
| 111 std::unique_ptr<base::ListValue> redirect_chain = | |
| 112 base::MakeUnique<base::ListValue>(); | |
| 113 for (const GURL& url : redirect_list) { | |
|
Devlin
2017/01/27 20:31:34
Are we worried at all about the size of the redire
robertshield
2017/01/28 03:58:48
Good question, I'm not really sure. A estimate of
| |
| 114 redirect_chain->AppendString(url.spec()); | |
| 115 } | |
| 116 dictionary.Set("redirect_chain", std::move(redirect_chain)); | |
| 117 | |
| 118 std::unique_ptr<std::string> json = base::MakeUnique<std::string>(); | |
| 119 base::JSONWriter::Write(dictionary, json.get()); | |
| 120 fetcher->SetJsonPostData(std::move(json)); | |
| 121 } | |
| 122 fetcher->Start(); | |
| 123 } | |
| 124 | |
| 125 void WebstoreInlineInstaller::OnBeforeWebstoreDataRequest( | |
| 126 WebstoreDataFetcher* fetcher) { | |
| 127 content::WebContents* web_contents = GetWebContents(); | |
| 128 | |
| 129 std::vector<GURL> redirect_chain; | |
| 130 if (web_contents) { | |
| 131 content::NavigationController& navigation_controller = | |
| 132 web_contents->GetController(); | |
| 133 content::NavigationEntry* navigation_entry = | |
| 134 navigation_controller.GetLastCommittedEntry(); | |
| 135 if (navigation_entry) { | |
| 136 const std::vector<GURL>& temp_redirects = | |
| 137 navigation_entry->GetRedirectChain(); | |
| 138 redirect_chain.assign(temp_redirects.begin(), temp_redirects.end()); | |
| 139 } | |
| 140 } | |
| 141 StartWebstoreDataRequest(fetcher, redirect_chain); | |
| 142 } | |
| 143 | |
| 98 bool WebstoreInlineInstaller::CheckRequestorAlive() const { | 144 bool WebstoreInlineInstaller::CheckRequestorAlive() const { |
| 99 // The frame or tab may have gone away - cancel installation in that case. | 145 // The frame or tab may have gone away - cancel installation in that case. |
| 100 return host_ != nullptr && web_contents() != nullptr; | 146 return host_ != nullptr && web_contents() != nullptr; |
| 101 } | 147 } |
| 102 | 148 |
| 103 const GURL& WebstoreInlineInstaller::GetRequestorURL() const { | 149 const GURL& WebstoreInlineInstaller::GetRequestorURL() const { |
| 104 return requestor_url_; | 150 return requestor_url_; |
| 105 } | 151 } |
| 106 | 152 |
| 107 std::unique_ptr<ExtensionInstallPrompt::Prompt> | 153 std::unique_ptr<ExtensionInstallPrompt::Prompt> |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 DLOG(WARNING) << "Could not parse " << verified_site_pattern_spec << | 291 DLOG(WARNING) << "Could not parse " << verified_site_pattern_spec << |
| 246 " as URL pattern " << parse_result; | 292 " as URL pattern " << parse_result; |
| 247 return false; | 293 return false; |
| 248 } | 294 } |
| 249 verified_site_pattern.SetScheme("*"); | 295 verified_site_pattern.SetScheme("*"); |
| 250 | 296 |
| 251 return verified_site_pattern.MatchesURL(requestor_url); | 297 return verified_site_pattern.MatchesURL(requestor_url); |
| 252 } | 298 } |
| 253 | 299 |
| 254 } // namespace extensions | 300 } // namespace extensions |
| OLD | NEW |