diff options
author | jungshik@google.com <jungshik@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-22 20:23:52 +0000 |
---|---|---|
committer | jungshik@google.com <jungshik@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-22 20:23:52 +0000 |
commit | 50dd8bb2e19a67adcef0f3bfbabd935a4e94de3c (patch) | |
tree | b6880001fbf5fc69c2c7417ca26682d3629062ed /chrome | |
parent | a74c9d049e625be4b542697e1a77c10364dc7cd2 (diff) | |
download | chromium_src-50dd8bb2e19a67adcef0f3bfbabd935a4e94de3c.zip chromium_src-50dd8bb2e19a67adcef0f3bfbabd935a4e94de3c.tar.gz chromium_src-50dd8bb2e19a67adcef0f3bfbabd935a4e94de3c.tar.bz2 |
Make the character encoding override work again. There are two other bugs with character encoding override, but it seems that it's better to fix them separately.
BUG=3315
Review URL: http://codereview.chromium.org/7647
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3759 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_commands.cc | 9 | ||||
-rw-r--r-- | chrome/browser/encoding_menu_controller_delegate.cc | 12 | ||||
-rw-r--r-- | chrome/browser/render_view_host.h | 4 | ||||
-rw-r--r-- | chrome/browser/render_view_host_delegate.h | 2 | ||||
-rw-r--r-- | chrome/browser/tab_contents.h | 7 | ||||
-rw-r--r-- | chrome/browser/web_contents.cc | 4 | ||||
-rw-r--r-- | chrome/browser/web_contents.h | 21 |
7 files changed, 37 insertions, 22 deletions
diff --git a/chrome/browser/browser_commands.cc b/chrome/browser/browser_commands.cc index b743984..1945c8e 100644 --- a/chrome/browser/browser_commands.cc +++ b/chrome/browser/browser_commands.cc @@ -628,12 +628,13 @@ void Browser::ExecuteCommand(int id) { case IDC_ENCODING_WINDOWS1255: case IDC_ENCODING_WINDOWS1258: { UserMetrics::RecordAction(L"OverrideEncoding", profile_); - const std::wstring cur_encoding_name = + const std::wstring selected_encoding = CharacterEncoding::GetCanonicalEncodingNameByCommandId(id); TabContents* current_tab = GetSelectedTabContents(); - if (!cur_encoding_name.empty() && current_tab) - current_tab->set_encoding(cur_encoding_name); - // Update user recently selected encoding list. + if (!selected_encoding.empty() && current_tab && + current_tab->AsWebContents()) + current_tab->AsWebContents()->override_encoding(selected_encoding); + // Update the list of recently selected encodings. std::wstring new_selected_encoding_list; if (CharacterEncoding::UpdateRecentlySelectdEncoding( profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding), diff --git a/chrome/browser/encoding_menu_controller_delegate.cc b/chrome/browser/encoding_menu_controller_delegate.cc index 0d5ecb1..3b12114 100644 --- a/chrome/browser/encoding_menu_controller_delegate.cc +++ b/chrome/browser/encoding_menu_controller_delegate.cc @@ -9,7 +9,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/character_encoding.h" #include "chrome/browser/profile.h" -#include "chrome/browser/tab_contents.h" +#include "chrome/browser/web_contents.h" #include "chrome/common/l10n_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" @@ -29,9 +29,11 @@ bool EncodingMenuControllerDelegate::IsItemChecked(int id) const { TabContents* current_tab = browser_->GetSelectedTabContents(); if (!current_tab) return false; - std::wstring encoding_name = current_tab->encoding(); - if (encoding_name.empty()) - encoding_name = profile->GetPrefs()->GetString(prefs::kDefaultCharset); + std::wstring encoding; + if (current_tab->AsWebContents()) + encoding = current_tab->AsWebContents()->encoding(); + if (encoding.empty()) + encoding = profile->GetPrefs()->GetString(prefs::kDefaultCharset); switch (id) { case IDC_ENCODING_AUTO_DETECT: return profile->GetPrefs()->GetBoolean( @@ -73,7 +75,7 @@ bool EncodingMenuControllerDelegate::IsItemChecked(int id) const { case IDC_ENCODING_ISO88598: case IDC_ENCODING_WINDOWS1255: case IDC_ENCODING_WINDOWS1258: - return (!encoding_name.empty() && encoding_name == + return (!encoding.empty() && encoding == CharacterEncoding::GetCanonicalEncodingNameByCommandId(id)); default: return false; diff --git a/chrome/browser/render_view_host.h b/chrome/browser/render_view_host.h index 8bf8e7f..70214b9 100644 --- a/chrome/browser/render_view_host.h +++ b/chrome/browser/render_view_host.h @@ -189,7 +189,7 @@ class RenderViewHost : public RenderWidgetHost { void Zoom(PageZoom::Function function); // Change the encoding of the page. - void SetPageEncoding(const std::wstring& encoding_name); + void SetPageEncoding(const std::wstring& encoding); // Change the alternate error page URL. An empty GURL disables the use of // alternate error pages. @@ -408,7 +408,7 @@ class RenderViewHost : public RenderWidgetHost { const std::wstring& title, const std::string& state); void OnMsgUpdateTitle(int32 page_id, const std::wstring& title); - void OnMsgUpdateEncoding(const std::wstring& encoding_name); + void OnMsgUpdateEncoding(const std::wstring& encoding); void OnMsgUpdateTargetURL(int32 page_id, const GURL& url); void OnMsgThumbnail(const IPC::Message& msg); void OnMsgClose(); diff --git a/chrome/browser/render_view_host_delegate.h b/chrome/browser/render_view_host_delegate.h index 3657005..39048eb 100644 --- a/chrome/browser/render_view_host_delegate.h +++ b/chrome/browser/render_view_host_delegate.h @@ -167,7 +167,7 @@ class RenderViewHostDelegate { // The page's encoding was changed and should be updated. virtual void UpdateEncoding(RenderViewHost* render_view_host, - const std::wstring& encoding_name) { } + const std::wstring& encoding) { } // The destination URL has changed should be updated virtual void UpdateTargetURL(int32 page_id, const GURL& url) { } diff --git a/chrome/browser/tab_contents.h b/chrome/browser/tab_contents.h index 899a63e..2b55c35 100644 --- a/chrome/browser/tab_contents.h +++ b/chrome/browser/tab_contents.h @@ -209,11 +209,6 @@ class TabContents : public PageNavigator, // Returns a human-readable description the tab's loading state. virtual std::wstring GetStatusText() const { return std::wstring(); } - const std::wstring& encoding() { return encoding_name_; } - void set_encoding(const std::wstring& encoding_name) { - encoding_name_ = encoding_name; - } - // Return whether this tab contents is loading a resource. bool is_loading() const { return is_loading_; } @@ -518,8 +513,6 @@ class TabContents : public PageNavigator, // The id used in the ViewStorage to store the last focused view. int last_focused_view_storage_id_; - std::wstring encoding_name_; - // See capturing_contents() above. bool capturing_contents_; diff --git a/chrome/browser/web_contents.cc b/chrome/browser/web_contents.cc index c0a048d..f283c64 100644 --- a/chrome/browser/web_contents.cc +++ b/chrome/browser/web_contents.cc @@ -789,8 +789,8 @@ void WebContents::UpdateTitle(RenderViewHost* rvh, void WebContents::UpdateEncoding(RenderViewHost* render_view_host, - const std::wstring& encoding_name) { - set_encoding(encoding_name); + const std::wstring& encoding) { + set_encoding(encoding); } void WebContents::UpdateTargetURL(int32 page_id, const GURL& url) { diff --git a/chrome/browser/web_contents.h b/chrome/browser/web_contents.h index b42c4ec..f73bb97 100644 --- a/chrome/browser/web_contents.h +++ b/chrome/browser/web_contents.h @@ -72,6 +72,11 @@ class WebContents : public TabContents, bool is_starred() const { return is_starred_; } + const std::wstring& encoding() const { return encoding_; } + void set_encoding(const std::wstring& encoding) { + encoding_ = encoding; + } + // TabContents (public overrides) -------------------------------------------- virtual void Destroy(); @@ -188,6 +193,16 @@ class WebContents : public TabContents, // Returns true if this WebContents will notify about disconnection. bool notify_disconnection() const { return notify_disconnection_; } + // Override the encoding and reload the page by sending down + // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda + // the opposite of this, by which 'browser' is notified of + // the encoding of the current tab from 'renderer' (determined by + // auto-detect, http header, meta, bom detection, etc). + void override_encoding(const std::wstring& encoding) { + set_encoding(encoding); + render_view_host()->SetPageEncoding(encoding); + } + protected: // Should be deleted via CloseContents. virtual ~WebContents(); @@ -219,7 +234,7 @@ class WebContents : public TabContents, int32 page_id, const std::wstring& title); virtual void UpdateEncoding(RenderViewHost* render_view_host, - const std::wstring& encoding_name); + const std::wstring& encoding); virtual void UpdateTargetURL(int32 page_id, const GURL& url); virtual void UpdateThumbnail(const GURL& url, const SkBitmap& bitmap, @@ -362,6 +377,7 @@ class WebContents : public TabContents, GearsCreateShortcutCallbackFunctor* callback_functor; }; + // NotificationObserver ------------------------------------------------------ virtual void Observe(NotificationType type, @@ -521,6 +537,9 @@ class WebContents : public TabContents, // used to check whether we can do something for some special contents. std::string contents_mime_type_; + // Character encoding. TODO(jungshik) : convert to std::string + std::wstring encoding_; + PendingInstall pending_install_; // The last time that the download shelf was made visible. |