| 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 "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "content/public/browser/navigation_details.h" |
| 10 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 11 | 12 |
| 12 using content::WebContents; | 13 using content::WebContents; |
| 13 | 14 |
| 14 namespace extensions { | 15 namespace extensions { |
| 15 | 16 |
| 16 const char kInvalidWebstoreResponseError[] = | 17 const char kInvalidWebstoreResponseError[] = |
| 17 "Invalid Chrome Web Store response."; | 18 "Invalid Chrome Web Store response."; |
| 18 const char kNoVerifiedSitesError[] = | 19 const char kNoVerifiedSitesError[] = |
| 19 "Inline installs can only be initiated for Chrome Web Store items that " | 20 "Inline installs can only be initiated for Chrome Web Store items that " |
| 20 "have one or more verified sites."; | 21 "have one or more verified sites."; |
| 21 const char kNotFromVerifiedSitesError[] = | 22 const char kNotFromVerifiedSitesError[] = |
| 22 "Installs can only be initiated by one of the Chrome Web Store item's " | 23 "Installs can only be initiated by one of the Chrome Web Store item's " |
| 23 "verified sites."; | 24 "verified sites."; |
| 24 const char kInlineInstallSupportedError[] = | 25 const char kInlineInstallSupportedError[] = |
| 25 "Inline installation is not supported for this item. The user will be " | 26 "Inline installation is not supported for this item. The user will be " |
| 26 "redirected to the Chrome Web Store."; | 27 "redirected to the Chrome Web Store."; |
| 27 const char kInitiatedFromPopupError[] = | 28 const char kInitiatedFromPopupError[] = |
| 28 "Inline installs can not be initiated from pop-up windows."; | 29 "Inline installs can not be initiated from pop-up windows."; |
| 29 | 30 |
| 30 WebstoreInlineInstaller::WebstoreInlineInstaller( | 31 WebstoreInlineInstaller::WebstoreInlineInstaller( |
| 31 content::WebContents* web_contents, | 32 content::WebContents* web_contents, |
| 33 content::RenderFrameHost* host, |
| 32 const std::string& webstore_item_id, | 34 const std::string& webstore_item_id, |
| 33 const GURL& requestor_url, | 35 const GURL& requestor_url, |
| 34 const Callback& callback) | 36 const Callback& callback) |
| 35 : WebstoreStandaloneInstaller( | 37 : WebstoreStandaloneInstaller( |
| 36 webstore_item_id, | 38 webstore_item_id, |
| 37 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | 39 Profile::FromBrowserContext(web_contents->GetBrowserContext()), |
| 38 callback), | 40 callback), |
| 39 content::WebContentsObserver(web_contents), | 41 content::WebContentsObserver(web_contents), |
| 40 requestor_url_(requestor_url) { | 42 host_(host), |
| 41 } | 43 requestor_url_(requestor_url) {} |
| 42 | 44 |
| 43 WebstoreInlineInstaller::~WebstoreInlineInstaller() {} | 45 WebstoreInlineInstaller::~WebstoreInlineInstaller() {} |
| 44 | 46 |
| 45 // static | 47 // static |
| 46 bool WebstoreInlineInstaller::IsRequestorPermitted( | 48 bool WebstoreInlineInstaller::IsRequestorPermitted( |
| 47 const base::DictionaryValue& webstore_data, | 49 const base::DictionaryValue& webstore_data, |
| 48 const GURL& requestor_url, | 50 const GURL& requestor_url, |
| 49 std::string* error) { | 51 std::string* error) { |
| 50 // Ensure that there is at least one verified site present. | 52 // Ensure that there is at least one verified site present. |
| 51 const bool data_has_single_site = webstore_data.HasKey(kVerifiedSiteKey); | 53 const bool data_has_single_site = webstore_data.HasKey(kVerifiedSiteKey); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 86 } |
| 85 if (!requestor_is_ok) { | 87 if (!requestor_is_ok) { |
| 86 *error = kNotFromVerifiedSitesError; | 88 *error = kNotFromVerifiedSitesError; |
| 87 return false; | 89 return false; |
| 88 } | 90 } |
| 89 *error = ""; | 91 *error = ""; |
| 90 return true; | 92 return true; |
| 91 } | 93 } |
| 92 | 94 |
| 93 bool WebstoreInlineInstaller::CheckRequestorAlive() const { | 95 bool WebstoreInlineInstaller::CheckRequestorAlive() const { |
| 94 // The tab may have gone away - cancel installation in that case. | 96 // The frame or tab may have gone away - cancel installation in that case. |
| 95 return web_contents() != NULL; | 97 return host_ != nullptr && web_contents() != nullptr; |
| 96 } | 98 } |
| 97 | 99 |
| 98 const GURL& WebstoreInlineInstaller::GetRequestorURL() const { | 100 const GURL& WebstoreInlineInstaller::GetRequestorURL() const { |
| 99 return requestor_url_; | 101 return requestor_url_; |
| 100 } | 102 } |
| 101 | 103 |
| 102 scoped_refptr<ExtensionInstallPrompt::Prompt> | 104 scoped_refptr<ExtensionInstallPrompt::Prompt> |
| 103 WebstoreInlineInstaller::CreateInstallPrompt() const { | 105 WebstoreInlineInstaller::CreateInstallPrompt() const { |
| 104 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt( | 106 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt( |
| 105 new ExtensionInstallPrompt::Prompt( | 107 new ExtensionInstallPrompt::Prompt( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 bool WebstoreInlineInstaller::CheckRequestorPermitted( | 171 bool WebstoreInlineInstaller::CheckRequestorPermitted( |
| 170 const base::DictionaryValue& webstore_data, | 172 const base::DictionaryValue& webstore_data, |
| 171 std::string* error) const { | 173 std::string* error) const { |
| 172 return IsRequestorPermitted(webstore_data, requestor_url_, error); | 174 return IsRequestorPermitted(webstore_data, requestor_url_, error); |
| 173 } | 175 } |
| 174 | 176 |
| 175 // | 177 // |
| 176 // Private implementation. | 178 // Private implementation. |
| 177 // | 179 // |
| 178 | 180 |
| 181 void WebstoreInlineInstaller::DidNavigateAnyFrame( |
| 182 content::RenderFrameHost* render_frame_host, |
| 183 const content::LoadCommittedDetails& details, |
| 184 const content::FrameNavigateParams& params) { |
| 185 if (!details.is_in_page && |
| 186 (render_frame_host == host_ || details.is_main_frame)) |
| 187 host_ = nullptr; |
| 188 } |
| 189 |
| 179 void WebstoreInlineInstaller::WebContentsDestroyed() { | 190 void WebstoreInlineInstaller::WebContentsDestroyed() { |
| 180 AbortInstall(); | 191 AbortInstall(); |
| 181 } | 192 } |
| 182 | 193 |
| 183 // static | 194 // static |
| 184 bool WebstoreInlineInstaller::IsRequestorURLInVerifiedSite( | 195 bool WebstoreInlineInstaller::IsRequestorURLInVerifiedSite( |
| 185 const GURL& requestor_url, | 196 const GURL& requestor_url, |
| 186 const std::string& verified_site) { | 197 const std::string& verified_site) { |
| 187 // Turn the verified site into a URL that can be parsed by URLPattern. | 198 // Turn the verified site into a URL that can be parsed by URLPattern. |
| 188 // |verified_site| must follow the format: | 199 // |verified_site| must follow the format: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 DLOG(WARNING) << "Could not parse " << verified_site_pattern_spec << | 235 DLOG(WARNING) << "Could not parse " << verified_site_pattern_spec << |
| 225 " as URL pattern " << parse_result; | 236 " as URL pattern " << parse_result; |
| 226 return false; | 237 return false; |
| 227 } | 238 } |
| 228 verified_site_pattern.SetScheme("*"); | 239 verified_site_pattern.SetScheme("*"); |
| 229 | 240 |
| 230 return verified_site_pattern.MatchesURL(requestor_url); | 241 return verified_site_pattern.MatchesURL(requestor_url); |
| 231 } | 242 } |
| 232 | 243 |
| 233 } // namespace extensions | 244 } // namespace extensions |
| OLD | NEW |