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

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

Issue 10071035: RefCounted types should not have public destructors, chrome/browser/extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compile fix Created 8 years, 8 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) 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 <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"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 std::string webstore_item_id, 150 std::string webstore_item_id,
151 GURL requestor_url, 151 GURL requestor_url,
152 Delegate* delegate) 152 Delegate* delegate)
153 : content::WebContentsObserver(web_contents), 153 : content::WebContentsObserver(web_contents),
154 install_id_(install_id), 154 install_id_(install_id),
155 return_route_id_(return_route_id), 155 return_route_id_(return_route_id),
156 id_(webstore_item_id), 156 id_(webstore_item_id),
157 requestor_url_(requestor_url), 157 requestor_url_(requestor_url),
158 delegate_(delegate), 158 delegate_(delegate),
159 average_rating_(0.0), 159 average_rating_(0.0),
160 rating_count_(0) {} 160 rating_count_(0) {
161
162 WebstoreInlineInstaller::~WebstoreInlineInstaller() {
163 } 161 }
164 162
165 void WebstoreInlineInstaller::BeginInstall() { 163 void WebstoreInlineInstaller::BeginInstall() {
166 AddRef(); // Balanced in CompleteInstall or WebContentsDestroyed. 164 AddRef(); // Balanced in CompleteInstall or WebContentsDestroyed.
167 165
168 if (!Extension::IdIsValid(id_)) { 166 if (!Extension::IdIsValid(id_)) {
169 CompleteInstall(kInvalidWebstoreItemId); 167 CompleteInstall(kInvalidWebstoreItemId);
170 return; 168 return;
171 } 169 }
172 170
173 GURL webstore_data_url(extension_urls::GetWebstoreItemJsonDataURL(id_)); 171 GURL webstore_data_url(extension_urls::GetWebstoreItemJsonDataURL(id_));
174 172
175 webstore_data_url_fetcher_.reset(content::URLFetcher::Create( 173 webstore_data_url_fetcher_.reset(content::URLFetcher::Create(
176 webstore_data_url, content::URLFetcher::GET, this)); 174 webstore_data_url, content::URLFetcher::GET, this));
177 Profile* profile = Profile::FromBrowserContext( 175 Profile* profile = Profile::FromBrowserContext(
178 web_contents()->GetBrowserContext()); 176 web_contents()->GetBrowserContext());
179 webstore_data_url_fetcher_->SetRequestContext( 177 webstore_data_url_fetcher_->SetRequestContext(
180 profile->GetRequestContext()); 178 profile->GetRequestContext());
181 // Use the requesting page as the referrer both since that is more correct 179 // Use the requesting page as the referrer both since that is more correct
182 // (it is the page that caused this request to happen) and so that we can 180 // (it is the page that caused this request to happen) and so that we can
183 // track top sites that trigger inline install requests. 181 // track top sites that trigger inline install requests.
184 webstore_data_url_fetcher_->SetReferrer(requestor_url_.spec()); 182 webstore_data_url_fetcher_->SetReferrer(requestor_url_.spec());
185 webstore_data_url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 183 webstore_data_url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
186 net::LOAD_DO_NOT_SAVE_COOKIES | 184 net::LOAD_DO_NOT_SAVE_COOKIES |
187 net::LOAD_DISABLE_CACHE); 185 net::LOAD_DISABLE_CACHE);
188 webstore_data_url_fetcher_->Start(); 186 webstore_data_url_fetcher_->Start();
189 } 187 }
190 188
189 WebstoreInlineInstaller::~WebstoreInlineInstaller() {}
190
191 void WebstoreInlineInstaller::OnURLFetchComplete( 191 void WebstoreInlineInstaller::OnURLFetchComplete(
192 const content::URLFetcher* source) { 192 const content::URLFetcher* source) {
193 CHECK_EQ(webstore_data_url_fetcher_.get(), source); 193 CHECK_EQ(webstore_data_url_fetcher_.get(), source);
194 // We shouldn't be getting UrlFetcher callbacks if the WebContents has gone 194 // We shouldn't be getting UrlFetcher callbacks if the WebContents has gone
195 // away; we stop any in in-progress fetches in WebContentsDestroyed. 195 // away; we stop any in in-progress fetches in WebContentsDestroyed.
196 CHECK(web_contents()); 196 CHECK(web_contents());
197 197
198 if (!webstore_data_url_fetcher_->GetStatus().is_success() || 198 if (!webstore_data_url_fetcher_->GetStatus().is_success() ||
199 webstore_data_url_fetcher_->GetResponseCode() != 200) { 199 webstore_data_url_fetcher_->GetResponseCode() != 200) {
200 CompleteInstall(kWebstoreRequestError); 200 CompleteInstall(kWebstoreRequestError);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 manifest, 315 manifest,
316 "", // We don't have any icon data. 316 "", // We don't have any icon data.
317 icon_url, 317 icon_url,
318 Profile::FromBrowserContext(web_contents()->GetBrowserContext())-> 318 Profile::FromBrowserContext(web_contents()->GetBrowserContext())->
319 GetRequestContext()); 319 GetRequestContext());
320 // The helper will call us back via OnWebstoreParseSucces or 320 // The helper will call us back via OnWebstoreParseSucces or
321 // OnWebstoreParseFailure. 321 // OnWebstoreParseFailure.
322 helper->Start(); 322 helper->Start();
323 } 323 }
324 324
325 // static
326 bool WebstoreInlineInstaller::IsRequestorURLInVerifiedSite(
327 const GURL& requestor_url,
328 const std::string& verified_site) {
329 // Turn the verified site (which may be a bare domain, or have a port and/or a
330 // path) into a URL that can be parsed by URLPattern.
331 std::string verified_site_url =
332 StringPrintf("http://*.%s%s",
333 verified_site.c_str(),
334 verified_site.find('/') == std::string::npos ? "/*" : "*");
335
336 URLPattern verified_site_pattern(
337 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS);
338 URLPattern::ParseResult parse_result =
339 verified_site_pattern.Parse(verified_site_url);
340 if (parse_result != URLPattern::PARSE_SUCCESS) {
341 DLOG(WARNING) << "Could not parse " << verified_site_url <<
342 " as URL pattern " << parse_result;
343 return false;
344 }
345 verified_site_pattern.SetScheme("*");
346
347 return verified_site_pattern.MatchesURL(requestor_url);
348 }
349
350 void WebstoreInlineInstaller::OnWebstoreResponseParseFailure( 325 void WebstoreInlineInstaller::OnWebstoreResponseParseFailure(
351 const std::string& error) { 326 const std::string& error) {
352 CompleteInstall(error); 327 CompleteInstall(error);
353 } 328 }
354 329
355 void WebstoreInlineInstaller::OnWebstoreParseSuccess( 330 void WebstoreInlineInstaller::OnWebstoreParseSuccess(
356 const std::string& id, 331 const std::string& id,
357 const SkBitmap& icon, 332 const SkBitmap& icon,
358 base::DictionaryValue* manifest) { 333 base::DictionaryValue* manifest) {
359 // Check if the tab has gone away in the meantime. 334 // Check if the tab has gone away in the meantime.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 if (web_contents()) { 421 if (web_contents()) {
447 if (error.empty()) { 422 if (error.empty()) {
448 delegate_->OnInlineInstallSuccess(install_id_, return_route_id_); 423 delegate_->OnInlineInstallSuccess(install_id_, return_route_id_);
449 } else { 424 } else {
450 delegate_->OnInlineInstallFailure(install_id_, return_route_id_, error); 425 delegate_->OnInlineInstallFailure(install_id_, return_route_id_, error);
451 } 426 }
452 } 427 }
453 428
454 Release(); // Matches the AddRef in BeginInstall. 429 Release(); // Matches the AddRef in BeginInstall.
455 } 430 }
431
432 // static
433 bool WebstoreInlineInstaller::IsRequestorURLInVerifiedSite(
434 const GURL& requestor_url,
435 const std::string& verified_site) {
436 // Turn the verified site (which may be a bare domain, or have a port and/or a
437 // path) into a URL that can be parsed by URLPattern.
438 std::string verified_site_url =
439 StringPrintf("http://*.%s%s",
440 verified_site.c_str(),
441 verified_site.find('/') == std::string::npos ? "/*" : "*");
442
443 URLPattern verified_site_pattern(
444 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS);
445 URLPattern::ParseResult parse_result =
446 verified_site_pattern.Parse(verified_site_url);
447 if (parse_result != URLPattern::PARSE_SUCCESS) {
448 DLOG(WARNING) << "Could not parse " << verified_site_url <<
449 " as URL pattern " << parse_result;
450 return false;
451 }
452 verified_site_pattern.SetScheme("*");
453
454 return verified_site_pattern.MatchesURL(requestor_url);
455 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/safe_manifest_parser.cc ('k') | chrome/browser/extensions/webstore_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698