OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher.h" |
| 6 |
| 7 #include "content/public/browser/browser_context.h" |
| 8 #include "content/public/common/url_fetcher.h" |
| 9 #include "net/base/load_flags.h" |
| 10 |
| 11 WebUIURLFetcher::WebUIURLFetcher(content::BrowserContext* context, |
| 12 const WebUILoadFileCallback& callback) |
| 13 : context_(context), callback_(callback) { |
| 14 } |
| 15 |
| 16 WebUIURLFetcher::~WebUIURLFetcher() { |
| 17 } |
| 18 |
| 19 void WebUIURLFetcher::Start(int render_process_id, |
| 20 int render_view_id, |
| 21 const GURL& url) { |
| 22 fetcher_.reset(net::URLFetcher::Create(url, net::URLFetcher::GET, this)); |
| 23 fetcher_->SetRequestContext(context_->GetRequestContext()); |
| 24 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
| 25 |
| 26 content::AssociateURLFetcherWithRenderFrame( |
| 27 fetcher_.get(), url, render_process_id, render_view_id); |
| 28 fetcher_->Start(); |
| 29 } |
| 30 |
| 31 void WebUIURLFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
| 32 CHECK_EQ(fetcher_.get(), source); |
| 33 |
| 34 std::string data; |
| 35 bool result = false; |
| 36 if (fetcher_->GetStatus().status() == net::URLRequestStatus::SUCCESS) { |
| 37 result = fetcher_->GetResponseAsString(&data); |
| 38 DCHECK(result); |
| 39 } |
| 40 fetcher_.reset(); |
| 41 callback_.Run(result, data); |
| 42 callback_.Reset(); |
| 43 } |
OLD | NEW |