blob: df3fad628c2c963ece2203b8ac05a758395bc617 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_
#define CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_
#include "base/memory/scoped_ptr.h"
#include "base/task/cancelable_task_tracker.h"
#include "components/favicon/core/fallback_icon_service.h"
#include "components/favicon_base/favicon_types.h"
#include "content/public/browser/url_data_source.h"
class Profile;
// LargeIconSource services explicit chrome:// requests for large icons.
//
// Format:
// chrome://large-icon/size/url
//
// Parameter:
// 'size' Required (including trailing '/')
// Positive integer to specify the large icon's size in pixels.
// 'url' Optional
// String to specify the page URL of the large icon.
//
// Example: chrome://large-icon/48/http://www.google.com/
// This requests a 48x48 large icon for http://www.google.com.
class LargeIconSource : public content::URLDataSource {
public:
explicit LargeIconSource(Profile* profile);
~LargeIconSource() override;
// content::URLDataSource implementation.
std::string GetSource() const override;
void StartDataRequest(
const std::string& path,
int render_process_id,
int render_frame_id,
const content::URLDataSource::GotDataCallback& callback) override;
std::string GetMimeType(const std::string&) const override;
bool ShouldReplaceExistingSource() const override;
bool ShouldServiceRequest(const net::URLRequest* request) const override;
protected:
struct IconRequest {
IconRequest();
IconRequest(const content::URLDataSource::GotDataCallback& callback_in,
const GURL& path_in,
int size_in);
~IconRequest();
content::URLDataSource::GotDataCallback callback;
GURL url;
int size;
};
private:
// Callback for icon data retrieval request.
void OnIconDataAvailable(
const IconRequest& request,
const favicon_base::FaviconRawBitmapResult& bitmap_result);
// Renders and sends a fallback icon.
void SendFallbackIcon(const IconRequest& request);
// Returns null to trigger "Not Found" response.
void SendNotFoundResponse(
const content::URLDataSource::GotDataCallback& callback);
Profile* profile_;
base::CancelableTaskTracker cancelable_task_tracker_;
scoped_ptr<FallbackIconService> fallback_icon_service_;
DISALLOW_COPY_AND_ASSIGN(LargeIconSource);
};
#endif // CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_
|