Extract SIGPIPE ignoring code to a common place.
[chromium-blink-merge.git] / chrome / common / extensions / extension_localization_peer.h
blobfd69f41fc4315e89a7204cc8f31cc364d1fcafab
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_
8 #include <string>
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 {
22 public:
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(
34 const GURL& new_url,
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,
42 int data_length,
43 int encoded_data_length) OVERRIDE;
44 virtual void OnCompletedRequest(
45 int error_code,
46 bool was_ignored_by_handler,
47 const std::string& security_info,
48 const base::TimeTicks& completion_time) OVERRIDE;
50 private:
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
60 // loaded file.
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
70 // message catalog.
71 IPC::Sender* message_sender_;
73 // Buffer for incoming data. We wait until OnCompletedRequest before using it.
74 std::string data_;
76 // Original request URL.
77 GURL request_url_;
79 private:
80 DISALLOW_COPY_AND_ASSIGN(ExtensionLocalizationPeer);
83 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_