OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_ |
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_ | 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_sender.h" |
12 #include "webkit/glue/resource_loader_bridge.h" | 12 #include "webkit/glue/resource_loader_bridge.h" |
13 | 13 |
14 // The ExtensionLocalizationPeer is a proxy to a | 14 // The ExtensionLocalizationPeer is a proxy to a |
15 // webkit_glue::ResourceLoaderBridge::Peer instance. It is used to pre-process | 15 // webkit_glue::ResourceLoaderBridge::Peer instance. It is used to pre-process |
16 // CSS files requested by extensions to replace localization templates with the | 16 // CSS files requested by extensions to replace localization templates with the |
17 // appropriate localized strings. | 17 // appropriate localized strings. |
18 // | 18 // |
19 // Call the factory method CreateExtensionLocalizationPeer() to obtain an | 19 // Call the factory method CreateExtensionLocalizationPeer() to obtain an |
20 // instance of ExtensionLocalizationPeer based on the original Peer. | 20 // instance of ExtensionLocalizationPeer based on the original Peer. |
21 class ExtensionLocalizationPeer | 21 class ExtensionLocalizationPeer |
22 : public webkit_glue::ResourceLoaderBridge::Peer { | 22 : public webkit_glue::ResourceLoaderBridge::Peer { |
23 public: | 23 public: |
24 virtual ~ExtensionLocalizationPeer(); | 24 virtual ~ExtensionLocalizationPeer(); |
25 | 25 |
26 static ExtensionLocalizationPeer* CreateExtensionLocalizationPeer( | 26 static ExtensionLocalizationPeer* CreateExtensionLocalizationPeer( |
27 webkit_glue::ResourceLoaderBridge::Peer* peer, | 27 webkit_glue::ResourceLoaderBridge::Peer* peer, |
28 IPC::Message::Sender* message_sender, | 28 IPC::Sender* message_sender, |
29 const std::string& mime_type, | 29 const std::string& mime_type, |
30 const GURL& request_url); | 30 const GURL& request_url); |
31 | 31 |
32 // ResourceLoaderBridge::Peer methods. | 32 // ResourceLoaderBridge::Peer methods. |
33 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; | 33 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; |
34 virtual bool OnReceivedRedirect( | 34 virtual bool OnReceivedRedirect( |
35 const GURL& new_url, | 35 const GURL& new_url, |
36 const webkit_glue::ResourceResponseInfo& info, | 36 const webkit_glue::ResourceResponseInfo& info, |
37 bool* has_new_first_party_for_cookies, | 37 bool* has_new_first_party_for_cookies, |
38 GURL* new_first_party_for_cookies) OVERRIDE; | 38 GURL* new_first_party_for_cookies) OVERRIDE; |
39 virtual void OnReceivedResponse( | 39 virtual void OnReceivedResponse( |
40 const webkit_glue::ResourceResponseInfo& info) OVERRIDE; | 40 const webkit_glue::ResourceResponseInfo& info) OVERRIDE; |
41 virtual void OnDownloadedData(int len) OVERRIDE {} | 41 virtual void OnDownloadedData(int len) OVERRIDE {} |
42 virtual void OnReceivedData(const char* data, | 42 virtual void OnReceivedData(const char* data, |
43 int data_length, | 43 int data_length, |
44 int encoded_data_length) OVERRIDE; | 44 int encoded_data_length) OVERRIDE; |
45 virtual void OnCompletedRequest( | 45 virtual void OnCompletedRequest( |
46 const net::URLRequestStatus& status, | 46 const net::URLRequestStatus& status, |
47 const std::string& security_info, | 47 const std::string& security_info, |
48 const base::TimeTicks& completion_time) OVERRIDE; | 48 const base::TimeTicks& completion_time) OVERRIDE; |
49 | 49 |
50 private: | 50 private: |
51 friend class ExtensionLocalizationPeerTest; | 51 friend class ExtensionLocalizationPeerTest; |
52 | 52 |
53 // Use CreateExtensionLocalizationPeer to create an instance. | 53 // Use CreateExtensionLocalizationPeer to create an instance. |
54 ExtensionLocalizationPeer( | 54 ExtensionLocalizationPeer( |
55 webkit_glue::ResourceLoaderBridge::Peer* peer, | 55 webkit_glue::ResourceLoaderBridge::Peer* peer, |
56 IPC::Message::Sender* message_sender, | 56 IPC::Sender* message_sender, |
57 const GURL& request_url); | 57 const GURL& request_url); |
58 | 58 |
59 // Loads message catalogs, and replaces all __MSG_some_name__ templates within | 59 // Loads message catalogs, and replaces all __MSG_some_name__ templates within |
60 // loaded file. | 60 // loaded file. |
61 void ReplaceMessages(); | 61 void ReplaceMessages(); |
62 | 62 |
63 // Original peer that handles the request once we are done processing data_. | 63 // Original peer that handles the request once we are done processing data_. |
64 webkit_glue::ResourceLoaderBridge::Peer* original_peer_; | 64 webkit_glue::ResourceLoaderBridge::Peer* original_peer_; |
65 | 65 |
66 // We just pass though the response info. This holds the copy of the original. | 66 // We just pass though the response info. This holds the copy of the original. |
67 webkit_glue::ResourceResponseInfo response_info_; | 67 webkit_glue::ResourceResponseInfo response_info_; |
68 | 68 |
69 // Sends ExtensionHostMsg_GetMessageBundle message to the browser to fetch | 69 // Sends ExtensionHostMsg_GetMessageBundle message to the browser to fetch |
70 // message catalog. | 70 // message catalog. |
71 IPC::Message::Sender* message_sender_; | 71 IPC::Sender* message_sender_; |
72 | 72 |
73 // Buffer for incoming data. We wait until OnCompletedRequest before using it. | 73 // Buffer for incoming data. We wait until OnCompletedRequest before using it. |
74 std::string data_; | 74 std::string data_; |
75 | 75 |
76 // Original request URL. | 76 // Original request URL. |
77 GURL request_url_; | 77 GURL request_url_; |
78 | 78 |
79 private: | 79 private: |
80 DISALLOW_COPY_AND_ASSIGN(ExtensionLocalizationPeer); | 80 DISALLOW_COPY_AND_ASSIGN(ExtensionLocalizationPeer); |
81 }; | 81 }; |
82 | 82 |
83 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_ | 83 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_ |
OLD | NEW |