OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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_BROWSER_GARBLED_TEXT_HELPER_H_ |
| 6 #define CHROME_BROWSER_GARBLED_TEXT_HELPER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/garbled_text_url_tracker.h" |
| 14 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 15 #include "content/public/browser/web_contents_observer.h" |
| 16 |
| 17 class Profile; |
| 18 |
| 19 namespace content { |
| 20 class WebContents; |
| 21 } |
| 22 |
| 23 // This class is instantiated per tab and lives on UI thread. |
| 24 // Once containing text of the page is detected as garbled, the instance prompts |
| 25 // the user to enable encoding detection for this site through infobar, and |
| 26 // redirects the approval to |GarbledTextService|. |
| 27 class GarbledTextHelper : public base::SupportsWeakPtr<GarbledTextHelper>, |
| 28 public content::WebContentsObserver, |
| 29 public content::NotificationObserver { |
| 30 public: |
| 31 typedef GarbledTextURLTracker::GarbledURLs GarbledURLs; |
| 32 |
| 33 explicit GarbledTextHelper(content::WebContents* web_contents); |
| 34 virtual ~GarbledTextHelper(); |
| 35 |
| 36 private: |
| 37 friend class GarbledTextHelperTest; |
| 38 |
| 39 Profile* GetProfile(); |
| 40 |
| 41 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 42 virtual void DidNavigateAnyFrame( |
| 43 const content::LoadCommittedDetails& details, |
| 44 const content::FrameNavigateParams& params) OVERRIDE; |
| 45 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE; |
| 46 |
| 47 virtual void Observe(int type, |
| 48 const content::NotificationSource& source, |
| 49 const content::NotificationDetails& details) OVERRIDE; |
| 50 |
| 51 // Handles |ViewHostMsg_GarbledTextDetected|. |
| 52 void OnGarbledTextDetected(const GarbledURLs& garbled_urls); |
| 53 |
| 54 // Completion callback for |GrabledTextService::UpdateBlacklist()|. |
| 55 void WillFinishUpdatingBlacklist(); |
| 56 |
| 57 void OnEnableStateChanged(bool enabled); |
| 58 |
| 59 // Called when the user accepts enabling encoding detection for |garbled_urls| |
| 60 // through infobar. |
| 61 void EnableEncodingDetection(const GarbledURLs& garbled_urls); |
| 62 |
| 63 PrefChangeRegistrar pref_change_registrar_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(GarbledTextHelper); |
| 66 }; |
| 67 |
| 68 #endif // CHROME_BROWSER_GARBLED_TEXT_HELPER_H_ |
OLD | NEW |