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