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

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

Issue 9269020: Handle paths and ports in verified domains in inline install. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test. Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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 <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/extensions/crx_installer.h" 13 #include "chrome/browser/extensions/crx_installer.h"
14 #include "chrome/browser/extensions/extension_install_dialog.h" 14 #include "chrome/browser/extensions/extension_install_dialog.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/chrome_utility_messages.h" 17 #include "chrome/common/chrome_utility_messages.h"
18 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/extensions/extension_constants.h" 19 #include "chrome/common/extensions/extension_constants.h"
20 #include "chrome/common/extensions/url_pattern.h" 20 #include "chrome/common/extensions/url_pattern.h"
21 #include "chrome/common/url_constants.h"
21 #include "content/browser/utility_process_host.h" 22 #include "content/browser/utility_process_host.h"
22 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
23 #include "content/public/common/url_fetcher.h" 24 #include "content/public/common/url_fetcher.h"
24 #include "net/base/escape.h" 25 #include "net/base/escape.h"
25 #include "net/base/load_flags.h" 26 #include "net/base/load_flags.h"
26 #include "net/url_request/url_request_status.h" 27 #include "net/url_request/url_request_status.h"
27 28
28 using content::BrowserThread; 29 using content::BrowserThread;
29 using content::OpenURLParams; 30 using content::OpenURLParams;
30 using content::WebContents; 31 using content::WebContents;
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 icon_url = GURL(extension_urls::GetWebstoreLaunchURL()).Resolve( 288 icon_url = GURL(extension_urls::GetWebstoreLaunchURL()).Resolve(
288 icon_url_string); 289 icon_url_string);
289 if (!icon_url.is_valid()) { 290 if (!icon_url.is_valid()) {
290 CompleteInstall(kInvalidWebstoreResponseError); 291 CompleteInstall(kInvalidWebstoreResponseError);
291 return; 292 return;
292 } 293 }
293 } 294 }
294 295
295 // Verified site is required 296 // Verified site is required
296 if (webstore_data->HasKey(kVerifiedSiteKey)) { 297 if (webstore_data->HasKey(kVerifiedSiteKey)) {
297 std::string verified_site_domain; 298 std::string verified_site;
298 if (!webstore_data->GetString(kVerifiedSiteKey, &verified_site_domain)) { 299 if (!webstore_data->GetString(kVerifiedSiteKey, &verified_site)) {
299 CompleteInstall(kInvalidWebstoreResponseError); 300 CompleteInstall(kInvalidWebstoreResponseError);
300 return; 301 return;
301 } 302 }
302 303
303 URLPattern verified_site_pattern(URLPattern::SCHEME_ALL); 304 if (!IsRequestorUrlInVerifiedSite(requestor_url_, verified_site)) {
304 verified_site_pattern.SetScheme("*");
305 verified_site_pattern.SetHost(verified_site_domain);
306 verified_site_pattern.SetMatchSubdomains(true);
307 verified_site_pattern.SetPath("/*");
308
309 if (!verified_site_pattern.MatchesURL(requestor_url_)) {
310 CompleteInstall(kNotFromVerifiedSiteError); 305 CompleteInstall(kNotFromVerifiedSiteError);
311 return; 306 return;
312 } 307 }
313 } else { 308 } else {
314 CompleteInstall(kNoVerifiedSiteError); 309 CompleteInstall(kNoVerifiedSiteError);
315 return; 310 return;
316 } 311 }
317 312
318 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( 313 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper(
319 this, 314 this,
320 id_, 315 id_,
321 manifest, 316 manifest,
322 "", // We don't have any icon data. 317 "", // We don't have any icon data.
323 icon_url, 318 icon_url,
324 Profile::FromBrowserContext(web_contents()->GetBrowserContext())-> 319 Profile::FromBrowserContext(web_contents()->GetBrowserContext())->
325 GetRequestContext()); 320 GetRequestContext());
326 // The helper will call us back via OnWebstoreParseSucces or 321 // The helper will call us back via OnWebstoreParseSucces or
327 // OnWebstoreParseFailure. 322 // OnWebstoreParseFailure.
328 helper->Start(); 323 helper->Start();
329 } 324 }
330 325
326 // static
327 bool WebstoreInlineInstaller::IsRequestorUrlInVerifiedSite(
328 const GURL& requestor_url,
329 const std::string& verified_site) {
330 // Turn the verified site (which may be a bare domain, or have a port and/or a
331 // path) into a URL that can be parsed by URLPattern.
332 std::string verified_site_url =
333 StringPrintf("http://*.%s%s",
334 verified_site.c_str(),
335 verified_site.find('/') == std::string::npos ? "/*" : "*");
336
337 URLPattern verified_site_pattern(
338 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS);
339 URLPattern::ParseResult parse_result =
340 verified_site_pattern.Parse(verified_site_url);
341 if (parse_result != URLPattern::PARSE_SUCCESS) {
342 DLOG(WARNING) << "Could not parse " << verified_site_url <<
343 " as URL pattern " << parse_result;
344 return false;
345 }
346 verified_site_pattern.SetScheme("*");
347
348 return verified_site_pattern.MatchesURL(requestor_url);
349 }
350
331 void WebstoreInlineInstaller::OnWebstoreResponseParseFailure( 351 void WebstoreInlineInstaller::OnWebstoreResponseParseFailure(
332 const std::string& error) { 352 const std::string& error) {
333 CompleteInstall(error); 353 CompleteInstall(error);
334 } 354 }
335 355
336 void WebstoreInlineInstaller::OnWebstoreParseSuccess( 356 void WebstoreInlineInstaller::OnWebstoreParseSuccess(
337 const std::string& id, 357 const std::string& id,
338 const SkBitmap& icon, 358 const SkBitmap& icon,
339 base::DictionaryValue* manifest) { 359 base::DictionaryValue* manifest) {
340 // Check if the tab has gone away in the meantime. 360 // Check if the tab has gone away in the meantime.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 if (web_contents()) { 450 if (web_contents()) {
431 if (error.empty()) { 451 if (error.empty()) {
432 delegate_->OnInlineInstallSuccess(install_id_); 452 delegate_->OnInlineInstallSuccess(install_id_);
433 } else { 453 } else {
434 delegate_->OnInlineInstallFailure(install_id_, error); 454 delegate_->OnInlineInstallFailure(install_id_, error);
435 } 455 }
436 } 456 }
437 457
438 Release(); // Matches the AddRef in BeginInstall. 458 Release(); // Matches the AddRef in BeginInstall.
439 } 459 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698