| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "mojo/fetcher/about_fetcher.h" | 5 #include "mojo/fetcher/about_fetcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 AboutFetcher::AboutFetcher(const GURL& url, | 35 AboutFetcher::AboutFetcher(const GURL& url, |
| 36 const FetchCallback& loader_callback) | 36 const FetchCallback& loader_callback) |
| 37 : Fetcher(loader_callback), url_(url) { | 37 : Fetcher(loader_callback), url_(url) { |
| 38 BuildResponse(); | 38 BuildResponse(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 AboutFetcher::~AboutFetcher() {} | 41 AboutFetcher::~AboutFetcher() {} |
| 42 | 42 |
| 43 void AboutFetcher::BuildResponse() { | 43 void AboutFetcher::BuildResponse() { |
| 44 if (url_ != GURL(kAboutBlankURL)) { | 44 response_ = URLResponse::New(); |
| 45 PostToRunCallback(false); | 45 response_->url = url_.spec(); |
| 46 return; | |
| 47 } | |
| 48 | 46 |
| 49 response_ = URLResponse::New(); | 47 // about: URLs other than about:blank are not supported yet. |
| 50 response_->url = kAboutBlankURL; | 48 // |
| 51 response_->status_code = 200; | 49 // TODO(yzshen): crbug.com/516494 Eventually we need a general solution to |
| 50 // generate error page for network errors/unrecognized app format/etc. |
| 51 response_->status_code = (url_ == GURL(kAboutBlankURL)) ? 200 : 404; |
| 52 |
| 52 response_->mime_type = "text/html"; | 53 response_->mime_type = "text/html"; |
| 53 PostToRunCallback(true); | 54 PostToRunCallback(true); |
| 54 } | 55 } |
| 55 | 56 |
| 56 void AboutFetcher::PostToRunCallback(bool success) { | 57 void AboutFetcher::PostToRunCallback(bool success) { |
| 57 // Also pass |this| on failure, so that we won't destroy the object while the | 58 // Also pass |this| on failure, so that we won't destroy the object while the |
| 58 // constructor is still on the call stack. | 59 // constructor is still on the call stack. |
| 59 base::MessageLoop::current()->PostTask( | 60 base::MessageLoop::current()->PostTask( |
| 60 FROM_HERE, | 61 FROM_HERE, |
| 61 base::Bind(RunFetcherCallback, loader_callback_, | 62 base::Bind(RunFetcherCallback, loader_callback_, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return false; | 103 return false; |
| 103 } | 104 } |
| 104 | 105 |
| 105 bool AboutFetcher::PeekFirstLine(std::string* line) { | 106 bool AboutFetcher::PeekFirstLine(std::string* line) { |
| 106 // The only URL handled currently is "about:blank" which doesn't have a body. | 107 // The only URL handled currently is "about:blank" which doesn't have a body. |
| 107 return false; | 108 return false; |
| 108 } | 109 } |
| 109 | 110 |
| 110 } // namespace fetcher | 111 } // namespace fetcher |
| 111 } // namespace mojo | 112 } // namespace mojo |
| OLD | NEW |