OLD | NEW |
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/ui/webui/ntp/thumbnail_source.h" | 5 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/search/instant_io_context.h" | 11 #include "chrome/browser/search/instant_io_context.h" |
12 #include "chrome/browser/thumbnails/thumbnail_service.h" | 12 #include "chrome/browser/thumbnails/thumbnail_service.h" |
13 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" | 13 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
16 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
19 | 19 |
20 using content::BrowserThread; | 20 using content::BrowserThread; |
21 | 21 |
22 // Set ThumbnailService now as Profile isn't thread safe. | 22 // Set ThumbnailService now as Profile isn't thread safe. By default, perform |
| 23 // exact match only. |
23 ThumbnailSource::ThumbnailSource(Profile* profile) | 24 ThumbnailSource::ThumbnailSource(Profile* profile) |
24 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)), | 25 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)), |
25 profile_(profile) { | 26 profile_(profile), |
| 27 prefix_match_(false) { |
| 28 } |
| 29 |
| 30 ThumbnailSource::ThumbnailSource(Profile* profile, bool prefix_match) |
| 31 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)), |
| 32 profile_(profile), |
| 33 prefix_match_(prefix_match) { |
26 } | 34 } |
27 | 35 |
28 ThumbnailSource::~ThumbnailSource() { | 36 ThumbnailSource::~ThumbnailSource() { |
29 } | 37 } |
30 | 38 |
31 std::string ThumbnailSource::GetSource() const { | 39 std::string ThumbnailSource::GetSource() const { |
32 return chrome::kChromeUIThumbnailHost; | 40 return prefix_match_ ? |
| 41 chrome::kChromeUIThumbnailHost2 : chrome::kChromeUIThumbnailHost; |
33 } | 42 } |
34 | 43 |
35 void ThumbnailSource::StartDataRequest( | 44 void ThumbnailSource::StartDataRequest( |
36 const std::string& path, | 45 const std::string& path, |
37 int render_process_id, | 46 int render_process_id, |
38 int render_view_id, | 47 int render_view_id, |
39 const content::URLDataSource::GotDataCallback& callback) { | 48 const content::URLDataSource::GotDataCallback& callback) { |
40 scoped_refptr<base::RefCountedMemory> data; | 49 scoped_refptr<base::RefCountedMemory> data; |
41 if (thumbnail_service_->GetPageThumbnail(GURL(path), &data)) { | 50 if (thumbnail_service_->GetPageThumbnail(GURL(path), prefix_match_, &data)) { |
42 // We have the thumbnail. | 51 // We have the thumbnail. |
43 callback.Run(data.get()); | 52 callback.Run(data.get()); |
44 } else { | 53 } else { |
45 callback.Run(default_thumbnail_.get()); | 54 callback.Run(default_thumbnail_.get()); |
46 } | 55 } |
47 } | 56 } |
48 | 57 |
49 std::string ThumbnailSource::GetMimeType(const std::string&) const { | 58 std::string ThumbnailSource::GetMimeType(const std::string&) const { |
50 // We need to explicitly return a mime type, otherwise if the user tries to | 59 // We need to explicitly return a mime type, otherwise if the user tries to |
51 // drag the image they get no extension. | 60 // drag the image they get no extension. |
52 return "image/png"; | 61 return "image/png"; |
53 } | 62 } |
54 | 63 |
55 base::MessageLoop* ThumbnailSource::MessageLoopForRequestPath( | 64 base::MessageLoop* ThumbnailSource::MessageLoopForRequestPath( |
56 const std::string& path) const { | 65 const std::string& path) const { |
57 // TopSites can be accessed from the IO thread. | 66 // TopSites can be accessed from the IO thread. |
58 return thumbnail_service_.get() ? | 67 return thumbnail_service_.get() ? |
59 NULL : content::URLDataSource::MessageLoopForRequestPath(path); | 68 NULL : content::URLDataSource::MessageLoopForRequestPath(path); |
60 } | 69 } |
61 | 70 |
62 bool ThumbnailSource::ShouldServiceRequest( | 71 bool ThumbnailSource::ShouldServiceRequest( |
63 const net::URLRequest* request) const { | 72 const net::URLRequest* request) const { |
64 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) | 73 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) |
65 return InstantIOContext::ShouldServiceRequest(request); | 74 return InstantIOContext::ShouldServiceRequest(request); |
66 return URLDataSource::ShouldServiceRequest(request); | 75 return URLDataSource::ShouldServiceRequest(request); |
67 } | 76 } |
OLD | NEW |