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