#ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_
#define CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_
#include <string>
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/translate/translate_bubble_model.h"
#include "components/translate/content/browser/content_translate_driver.h"
#include "components/translate/core/browser/translate_client.h"
#include "components/translate/core/common/translate_errors.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
#if defined(CLD2_DYNAMIC_MODE)
#include "base/basictypes.h"
#include "base/lazy_instance.h"
#include "base/memory/weak_ptr.h"
#include "base/synchronization/lock.h"
#include "base/task_runner.h"
#endif
namespace base {
class File;
}
namespace content {
class BrowserContext;
class WebContents;
}
struct LanguageDetectionDetails;
class PrefService;
class TranslateAcceptLanguages;
class TranslatePrefs;
class TranslateManager;
class TranslateTabHelper
: public TranslateClient,
public content::WebContentsObserver,
public content::WebContentsUserData<TranslateTabHelper> {
public:
virtual ~TranslateTabHelper();
LanguageState& GetLanguageState();
ContentTranslateDriver& translate_driver() { return translate_driver_; }
static scoped_ptr<TranslatePrefs> CreateTranslatePrefs(PrefService* prefs);
static TranslateAcceptLanguages* GetTranslateAcceptLanguages(
content::BrowserContext* browser_context);
static TranslateManager* GetManagerFromWebContents(
content::WebContents* web_contents);
TranslateManager* GetTranslateManager();
content::WebContents* GetWebContents();
enum TranslateStep {
BEFORE_TRANSLATE,
TRANSLATING,
AFTER_TRANSLATE,
TRANSLATE_ERROR
};
void ShowTranslateUI(TranslateStep step,
const std::string source_language,
const std::string target_language,
TranslateErrors::Type error_type,
bool triggered_from_menu);
virtual TranslateDriver* GetTranslateDriver() OVERRIDE;
virtual PrefService* GetPrefs() OVERRIDE;
virtual scoped_ptr<TranslatePrefs> GetTranslatePrefs() OVERRIDE;
virtual TranslateAcceptLanguages* GetTranslateAcceptLanguages() OVERRIDE;
private:
explicit TranslateTabHelper(content::WebContents* web_contents);
friend class content::WebContentsUserData<TranslateTabHelper>;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void DidNavigateAnyFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) OVERRIDE;
virtual void WebContentsDestroyed(
content::WebContents* web_contents) OVERRIDE;
void OnLanguageDetermined(const LanguageDetectionDetails& details,
bool page_needs_translation);
void OnPageTranslated(int32 page_id,
const std::string& original_lang,
const std::string& translated_lang,
TranslateErrors::Type error_type);
#if defined(CLD2_DYNAMIC_MODE)
void OnCLDDataRequested();
static void HandleCLDDataRequest();
void MaybeSendCLDDataAvailable();
void SendCLDDataAvailable(const base::File* handle,
const uint64 data_offset,
const uint64 data_length);
base::WeakPtrFactory<TranslateTabHelper> weak_pointer_factory_;
static base::File* s_cached_file_;
static uint64 s_cached_data_offset_;
static uint64 s_cached_data_length_;
static base::LazyInstance<base::Lock> s_file_lock_;
#endif
void ShowBubble(TranslateStep step, TranslateErrors::Type error_type);
ContentTranslateDriver translate_driver_;
scoped_ptr<TranslateManager> translate_manager_;
DISALLOW_COPY_AND_ASSIGN(TranslateTabHelper);
};
#endif