1 // Copyright 2013 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.
5 #ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_
6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_
10 #include "content/public/child/request_peer.h"
11 #include "content/public/common/resource_response_info.h"
17 // The ExtensionLocalizationPeer is a proxy to a
18 // content::RequestPeer instance. It is used to pre-process
19 // CSS files requested by extensions to replace localization templates with the
20 // appropriate localized strings.
22 // Call the factory method CreateExtensionLocalizationPeer() to obtain an
23 // instance of ExtensionLocalizationPeer based on the original Peer.
24 class ExtensionLocalizationPeer
: public content::RequestPeer
{
26 ~ExtensionLocalizationPeer() override
;
28 static ExtensionLocalizationPeer
* CreateExtensionLocalizationPeer(
29 content::RequestPeer
* peer
,
30 IPC::Sender
* message_sender
,
31 const std::string
& mime_type
,
32 const GURL
& request_url
);
34 // content::RequestPeer methods.
35 void OnUploadProgress(uint64 position
, uint64 size
) override
;
36 bool OnReceivedRedirect(const net::RedirectInfo
& redirect_info
,
37 const content::ResourceResponseInfo
& info
) override
;
38 void OnReceivedResponse(const content::ResourceResponseInfo
& info
) override
;
39 void OnDownloadedData(int len
, int encoded_data_length
) override
{}
40 void OnReceivedData(scoped_ptr
<ReceivedData
> data
) override
;
41 void OnCompletedRequest(int error_code
,
42 bool was_ignored_by_handler
,
43 bool stale_copy_in_cache
,
44 const std::string
& security_info
,
45 const base::TimeTicks
& completion_time
,
46 int64 total_transfer_size
) override
;
47 void OnReceivedCompletedResponse(const content::ResourceResponseInfo
& info
,
48 scoped_ptr
<ReceivedData
> data
,
50 bool was_ignored_by_handler
,
51 bool stale_copy_in_cache
,
52 const std::string
& security_info
,
53 const base::TimeTicks
& completion_time
,
54 int64 total_transfer_size
) override
;
57 friend class ExtensionLocalizationPeerTest
;
59 // Use CreateExtensionLocalizationPeer to create an instance.
60 ExtensionLocalizationPeer(content::RequestPeer
* peer
,
61 IPC::Sender
* message_sender
,
62 const GURL
& request_url
);
64 // Loads message catalogs, and replaces all __MSG_some_name__ templates within
66 void ReplaceMessages();
68 // Original peer that handles the request once we are done processing data_.
69 content::RequestPeer
* original_peer_
;
71 // We just pass though the response info. This holds the copy of the original.
72 content::ResourceResponseInfo response_info_
;
74 // Sends ExtensionHostMsg_GetMessageBundle message to the browser to fetch
76 IPC::Sender
* message_sender_
;
78 // Buffer for incoming data. We wait until OnCompletedRequest before using it.
81 // Original request URL.
85 DISALLOW_COPY_AND_ASSIGN(ExtensionLocalizationPeer
);
88 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_