| 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" |
| 13 #include "chrome/browser/history/history_service_factory.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 16 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 17 #include "components/history/core/browser/history_service.h" |
| 11 #include "content/public/browser/navigation_details.h" | 18 #include "content/public/browser/navigation_details.h" |
| 12 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 13 | 20 |
| 14 using content::WebContents; | 21 using content::WebContents; |
| 15 | 22 |
| 16 namespace extensions { | 23 namespace extensions { |
| 17 | 24 |
| 18 const char kInvalidWebstoreResponseError[] = | 25 const char kInvalidWebstoreResponseError[] = |
| 19 "Invalid Chrome Web Store response."; | 26 "Invalid Chrome Web Store response."; |
| 20 const char kNoVerifiedSitesError[] = | 27 const char kNoVerifiedSitesError[] = |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 95 } |
| 89 } | 96 } |
| 90 if (!requestor_is_ok) { | 97 if (!requestor_is_ok) { |
| 91 *error = kNotFromVerifiedSitesError; | 98 *error = kNotFromVerifiedSitesError; |
| 92 return false; | 99 return false; |
| 93 } | 100 } |
| 94 *error = ""; | 101 *error = ""; |
| 95 return true; | 102 return true; |
| 96 } | 103 } |
| 97 | 104 |
| 105 void WebstoreInlineInstaller::StartWebstoreDataRequest( |
| 106 WebstoreDataFetcher* fetcher, const history::RedirectList* redirect_list) { |
| 107 if (redirect_list) { |
| 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) { |
| 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 if (web_contents) { |
| 129 history::HistoryService* history = HistoryServiceFactory::GetForProfile( |
| 130 profile(), ServiceAccessType::EXPLICIT_ACCESS); |
| 131 if (history) { |
| 132 history->QueryRedirectsTo( |
| 133 requestor_url_, |
| 134 base::Bind(&WebstoreInlineInstaller::StartWebstoreDataRequest, |
| 135 this, |
| 136 base::Unretained(fetcher)), |
| 137 &request_tracker_); |
| 138 return; |
| 139 } |
| 140 } |
| 141 StartWebstoreDataRequest(fetcher, nullptr); |
| 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 |