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