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
3 // found in the LICENSE file.
5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_
10 #include "ipc/ipc_sender.h"
11 #include "webkit/glue/resource_loader_bridge.h"
13 // The ExtensionLocalizationPeer is a proxy to a
14 // webkit_glue::ResourceLoaderBridge::Peer instance. It is used to pre-process
15 // CSS files requested by extensions to replace localization templates with the
16 // appropriate localized strings.
18 // Call the factory method CreateExtensionLocalizationPeer() to obtain an
19 // instance of ExtensionLocalizationPeer based on the original Peer.
20 class ExtensionLocalizationPeer
21 : public webkit_glue::ResourceLoaderBridge::Peer
{
23 virtual ~ExtensionLocalizationPeer();
25 static ExtensionLocalizationPeer
* CreateExtensionLocalizationPeer(
26 webkit_glue::ResourceLoaderBridge::Peer
* peer
,
27 IPC::Sender
* message_sender
,
28 const std::string
& mime_type
,
29 const GURL
& request_url
);
31 // ResourceLoaderBridge::Peer methods.
32 virtual void OnUploadProgress(uint64 position
, uint64 size
) OVERRIDE
;
33 virtual bool OnReceivedRedirect(
35 const webkit_glue::ResourceResponseInfo
& info
,
36 bool* has_new_first_party_for_cookies
,
37 GURL
* new_first_party_for_cookies
) OVERRIDE
;
38 virtual void OnReceivedResponse(
39 const webkit_glue::ResourceResponseInfo
& info
) OVERRIDE
;
40 virtual void OnDownloadedData(int len
) OVERRIDE
{}
41 virtual void OnReceivedData(const char* data
,
43 int encoded_data_length
) OVERRIDE
;
44 virtual void OnCompletedRequest(
46 bool was_ignored_by_handler
,
47 const std::string
& security_info
,
48 const base::TimeTicks
& completion_time
) OVERRIDE
;
51 friend class ExtensionLocalizationPeerTest
;
53 // Use CreateExtensionLocalizationPeer to create an instance.
54 ExtensionLocalizationPeer(
55 webkit_glue::ResourceLoaderBridge::Peer
* peer
,
56 IPC::Sender
* message_sender
,
57 const GURL
& request_url
);
59 // Loads message catalogs, and replaces all __MSG_some_name__ templates within
61 void ReplaceMessages();
63 // Original peer that handles the request once we are done processing data_.
64 webkit_glue::ResourceLoaderBridge::Peer
* original_peer_
;
66 // We just pass though the response info. This holds the copy of the original.
67 webkit_glue::ResourceResponseInfo response_info_
;
69 // Sends ExtensionHostMsg_GetMessageBundle message to the browser to fetch
71 IPC::Sender
* message_sender_
;
73 // Buffer for incoming data. We wait until OnCompletedRequest before using it.
76 // Original request URL.
80 DISALLOW_COPY_AND_ASSIGN(ExtensionLocalizationPeer
);
83 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_