| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/favicon_source.h" | 5 #include "chrome/browser/ui/webui/favicon_source.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "chrome/browser/history/top_sites.h" | 9 #include "chrome/browser/history/top_sites.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 if (path.size() > 5 && path.substr(0, 5) == "size/") { | 52 if (path.size() > 5 && path.substr(0, 5) == "size/") { |
| 53 size_t slash = path.find("/", 5); | 53 size_t slash = path.find("/", 5); |
| 54 std::string size = path.substr(5, slash - 5); | 54 std::string size = path.substr(5, slash - 5); |
| 55 int pixel_size = atoi(size.c_str()); | 55 int pixel_size = atoi(size.c_str()); |
| 56 CHECK(pixel_size == 32 || pixel_size == 16) << | 56 CHECK(pixel_size == 32 || pixel_size == 16) << |
| 57 "only 32x32 and 16x16 icons are supported"; | 57 "only 32x32 and 16x16 icons are supported"; |
| 58 request_size_map_[request_id] = pixel_size; | 58 request_size_map_[request_id] = pixel_size; |
| 59 url = GURL(path.substr(slash + 1)); | 59 url = GURL(path.substr(slash + 1)); |
| 60 } else { | 60 } else { |
| 61 // URL requests prefixed with "origin/" are converted to a form with an |
| 62 // empty path and a valid scheme. (e.g., example.com --> |
| 63 // http://example.com/ or http://example.com/a --> http://example.com/) |
| 64 if (path.size() > 7 && path.substr(0, 7) == "origin/") { |
| 65 std::string originalUrl = path.substr(7); |
| 66 |
| 67 // If the original URL does not specify a scheme (e.g., example.com |
| 68 // instead of http://example.com), add "http://" as a default. |
| 69 if (!GURL(originalUrl).has_scheme()) |
| 70 originalUrl = "http://" + originalUrl; |
| 71 |
| 72 // Strip the path beyond the top-level domain. |
| 73 url = GURL(originalUrl).GetOrigin(); |
| 74 } else { |
| 75 url = GURL(path); |
| 76 } |
| 77 |
| 61 request_size_map_[request_id] = 16; | 78 request_size_map_[request_id] = 16; |
| 62 url = GURL(path); | |
| 63 } | 79 } |
| 64 | 80 |
| 65 // Intercept requests for prepopulated pages. | 81 // Intercept requests for prepopulated pages. |
| 66 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) { | 82 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) { |
| 67 if (url.spec() == | 83 if (url.spec() == |
| 68 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { | 84 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { |
| 69 request_size_map_.erase(request_id); | 85 request_size_map_.erase(request_id); |
| 70 SendResponse(request_id, | 86 SendResponse(request_id, |
| 71 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 87 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
| 72 history::kPrepopulatedPages[i].favicon_id)); | 88 history::kPrepopulatedPages[i].favicon_id)); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 default_favicon_ = | 145 default_favicon_ = |
| 130 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 146 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
| 131 IDR_DEFAULT_FAVICON); | 147 IDR_DEFAULT_FAVICON); |
| 132 } | 148 } |
| 133 bytes = default_favicon_; | 149 bytes = default_favicon_; |
| 134 } | 150 } |
| 135 request_size_map_.erase(request_id); | 151 request_size_map_.erase(request_id); |
| 136 | 152 |
| 137 SendResponse(request_id, bytes); | 153 SendResponse(request_id, bytes); |
| 138 } | 154 } |
| OLD | NEW |