diff options
author | jnd@google.com <jnd@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-18 21:24:29 +0000 |
---|---|---|
committer | jnd@google.com <jnd@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-18 21:24:29 +0000 |
commit | 72c94f309664498277eee70eeccc05b44f0f255a (patch) | |
tree | 65d2fedf4b6907c4971dae0e8526d3c20efe9264 /chrome/browser | |
parent | ea8c4104164fcb225003bf074d3d4693929e00da (diff) | |
download | chromium_src-72c94f309664498277eee70eeccc05b44f0f255a.zip chromium_src-72c94f309664498277eee70eeccc05b44f0f255a.tar.gz chromium_src-72c94f309664498277eee70eeccc05b44f0f255a.tar.bz2 |
The CL is consist of CLs(1624,1580) for bug:1281734 which are reviewed and LG by brett. I just merge them to single one for passing compilation.
The CL is to fix bug http://b/issue?id=1281734. FireFox uses encoding used by the original webpage to decode the source of the webpage, Chrome does not. We need to add a new parameter which carries the override encoding when opening a view-source URL for viewing its source.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@997 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
20 files changed, 121 insertions, 40 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index bc8408f..63c91ea 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -533,7 +533,8 @@ void Browser::ProcessPendingUIUpdates() { void Browser::OpenURLFromTab(TabContents* source, const GURL& url, WindowOpenDisposition disposition, - PageTransition::Type transition) { + PageTransition::Type transition, + const std::wstring& override_encoding) { // No code for these yet DCHECK((disposition != NEW_POPUP) && (disposition != SAVE_TO_DISK)); @@ -648,6 +649,14 @@ void Browser::OpenURLFromTab(TabContents* source, // front-most. new_contents->Focus(); } + + if (!override_encoding.empty()) { + // The new tab needs a special encoding, such as a view source page + // which should use the same encoding as the original page. + WebContents* web_contents = new_contents->AsWebContents(); + if (web_contents) + web_contents->set_override_encoding(override_encoding); + } } void Browser::NavigationStateChanged(const TabContents* source, diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 6b467183..b2c29aa 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -292,9 +292,10 @@ class Browser : public TabStripModelDelegate, // Overridden from TabContentsDelegate: virtual void OpenURLFromTab(TabContents* source, - const GURL& url, - WindowOpenDisposition disposition, - PageTransition::Type transition); + const GURL& url, + WindowOpenDisposition disposition, + PageTransition::Type transition, + const std::wstring& override_encoding); virtual void NavigationStateChanged(const TabContents* source, unsigned changed_flags); virtual void ReplaceContents(TabContents* source, TabContents* new_contents); diff --git a/chrome/browser/debugger/debugger_view.cc b/chrome/browser/debugger/debugger_view.cc index b594861..46bdbdb 100644 --- a/chrome/browser/debugger/debugger_view.cc +++ b/chrome/browser/debugger/debugger_view.cc @@ -153,9 +153,10 @@ void DebuggerView::SetDebuggerBreak(bool is_broken) { } void DebuggerView::OpenURLFromTab(TabContents* source, - const GURL& url, - WindowOpenDisposition disposition, - PageTransition::Type transition) { + const GURL& url, + WindowOpenDisposition disposition, + PageTransition::Type transition, + const std::wstring& override_encoding) { BrowserList::GetLastActive()->OpenURL(url, disposition, transition); } diff --git a/chrome/browser/debugger/debugger_view.h b/chrome/browser/debugger/debugger_view.h index f866651..16213ed 100644 --- a/chrome/browser/debugger/debugger_view.h +++ b/chrome/browser/debugger/debugger_view.h @@ -84,7 +84,8 @@ class DebuggerView : public ChromeViews::View, virtual void OpenURLFromTab(TabContents* source, const GURL& url, WindowOpenDisposition disposition, - PageTransition::Type transition); + PageTransition::Type transition, + const std::wstring& override_encoding); // Overridden from TabContentsDelegate: virtual void NavigationStateChanged(const TabContents* source, diff --git a/chrome/browser/external_tab_container.cc b/chrome/browser/external_tab_container.cc index 13bb2a7..bb56384 100644 --- a/chrome/browser/external_tab_container.cc +++ b/chrome/browser/external_tab_container.cc @@ -149,10 +149,12 @@ LRESULT ExternalTabContainer::OnSize(UINT, WPARAM, LPARAM, BOOL& handled) { // needs to be fully fleshed out based on the requirements of the // "Chrome tab in external browser" feature. -void ExternalTabContainer::OpenURLFromTab(TabContents* source, - const GURL& url, - WindowOpenDisposition disposition, - PageTransition::Type transition) { +void ExternalTabContainer::OpenURLFromTab( + TabContents* source, + const GURL& url, + WindowOpenDisposition disposition, + PageTransition::Type transition, + const std::wstring& override_encoding) { switch (disposition) { case CURRENT_TAB: case NEW_FOREGROUND_TAB: diff --git a/chrome/browser/external_tab_container.h b/chrome/browser/external_tab_container.h index b8ccc8c..7bfb213 100644 --- a/chrome/browser/external_tab_container.h +++ b/chrome/browser/external_tab_container.h @@ -80,7 +80,8 @@ class ExternalTabContainer : public TabContentsDelegate, virtual void OpenURLFromTab(TabContents* source, const GURL& url, WindowOpenDisposition disposition, - PageTransition::Type transition); + PageTransition::Type transition, + const std::wstring& override_encoding); virtual void NavigationStateChanged(const TabContents* source, unsigned changed_flags); virtual void ReplaceContents(TabContents* source, TabContents* new_contents); diff --git a/chrome/browser/navigation_controller_unittest.cc b/chrome/browser/navigation_controller_unittest.cc index cce2cf9..9176df6 100644 --- a/chrome/browser/navigation_controller_unittest.cc +++ b/chrome/browser/navigation_controller_unittest.cc @@ -154,7 +154,8 @@ class NavigationControllerTest : public testing::Test, virtual void OpenURLFromTab(TabContents*, const GURL&, WindowOpenDisposition, - PageTransition::Type) {} + PageTransition::Type, + const std::wstring& override_encoding) {} virtual void NavigationStateChanged(const TabContents*, unsigned flags) {} virtual void ReplaceContents(TabContents* source, diff --git a/chrome/browser/render_view_context_menu_controller.cc b/chrome/browser/render_view_context_menu_controller.cc index 790f641..c4ec6ad 100644 --- a/chrome/browser/render_view_context_menu_controller.cc +++ b/chrome/browser/render_view_context_menu_controller.cc @@ -67,6 +67,15 @@ RenderViewContextMenuController::~RenderViewContextMenuController() { /////////////////////////////////////////////////////////////////////////////// // Controller methods +void RenderViewContextMenuController::OpenURLWithOverrideEncoding( + const GURL& url, + WindowOpenDisposition disposition, + PageTransition::Type transition, + const std::wstring& override_encoding) { + source_web_contents_->OpenURLWithOverrideEncoding(url, disposition, + transition, override_encoding); +} + void RenderViewContextMenuController::OpenURL( const GURL& url, WindowOpenDisposition disposition, @@ -298,8 +307,10 @@ void RenderViewContextMenuController::ExecuteCommand(int id) { break; case IDS_CONTENT_CONTEXT_VIEWPAGESOURCE: - OpenURL(GURL("view-source:" + params_.page_url.spec()), - NEW_FOREGROUND_TAB, PageTransition::GENERATED); + OpenURLWithOverrideEncoding( + GURL("view-source:" + params_.page_url.spec()), + NEW_FOREGROUND_TAB, PageTransition::GENERATED, + source_web_contents_->GetEncoding()); break; case IDS_CONTENT_CONTEXT_INSPECTELEMENT: @@ -334,8 +345,10 @@ void RenderViewContextMenuController::ExecuteCommand(int id) { break; case IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE: - OpenURL(GURL("view-source:" + params_.frame_url.spec()), - NEW_FOREGROUND_TAB, PageTransition::GENERATED); + OpenURLWithOverrideEncoding( + GURL("view-source:" + params_.frame_url.spec()), + NEW_FOREGROUND_TAB, PageTransition::GENERATED, + params_.frame_encoding); break; case IDS_CONTENT_CONTEXT_VIEWFRAMEINFO: diff --git a/chrome/browser/render_view_context_menu_controller.h b/chrome/browser/render_view_context_menu_controller.h index f4cc15b..3817dd6 100644 --- a/chrome/browser/render_view_context_menu_controller.h +++ b/chrome/browser/render_view_context_menu_controller.h @@ -48,12 +48,19 @@ class RenderViewContextMenuController : public Menu::Delegate { virtual bool GetAcceleratorInfo(int id, ChromeViews::Accelerator* accel); private: - // Opens the specified URL string in a new tab. If |in_current_window| is - // false, a new window is created to hold the new tab. + // Opens the specified URL string with a disposition specified by parameter + // |disposition|. void OpenURL(const GURL& url, WindowOpenDisposition disposition, PageTransition::Type transition); + // Opens the specified URL string with a disposition specified by parameter + // |disposition| and forces the new page on using |override_encoding|. + void OpenURLWithOverrideEncoding(const GURL& url, + WindowOpenDisposition disposition, + PageTransition::Type transition, + const std::wstring& override_encoding); + // Copy to the clipboard an image located at a point in the RenderView void CopyImageAt(int x, int y); diff --git a/chrome/browser/tab_contents.cc b/chrome/browser/tab_contents.cc index 419a796..62f6fb1 100644 --- a/chrome/browser/tab_contents.cc +++ b/chrome/browser/tab_contents.cc @@ -424,11 +424,24 @@ void TabContents::DidMoveOrResize(ConstrainedWindow* window) { /////////////////////////////////////////////////////////////////////////////// // PageNavigator methods +void TabContents::OpenURLWithOverrideEncoding( + const GURL& url, + WindowOpenDisposition disposition, + PageTransition::Type transition, + const std::wstring& override_encoding) { + if (delegate_) { + delegate_->OpenURLFromTab(this, url, disposition, transition, + override_encoding); + } +} + void TabContents::OpenURL(const GURL& url, WindowOpenDisposition disposition, PageTransition::Type transition) { - if (delegate_) - delegate_->OpenURLFromTab(this, url, disposition, transition); + if (delegate_) { + delegate_->OpenURLFromTab(this, url, disposition, transition, + std::wstring()); + } } /////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/tab_contents.h b/chrome/browser/tab_contents.h index 5a56f5e..2b3338a 100644 --- a/chrome/browser/tab_contents.h +++ b/chrome/browser/tab_contents.h @@ -373,6 +373,12 @@ class TabContents : public PageNavigator, WindowOpenDisposition disposition, PageTransition::Type transition); + virtual void OpenURLWithOverrideEncoding( + const GURL& url, + WindowOpenDisposition disposition, + PageTransition::Type transition, + const std::wstring& override_encoding); + // NotificationObserver implementation. virtual void Observe(NotificationType type, const NotificationSource& source, diff --git a/chrome/browser/tab_contents_delegate.h b/chrome/browser/tab_contents_delegate.h index 7bd4137..2b94e34 100644 --- a/chrome/browser/tab_contents_delegate.h +++ b/chrome/browser/tab_contents_delegate.h @@ -53,13 +53,13 @@ class TabContentsDelegate : public PageNavigator { virtual void OpenURLFromTab(TabContents* source, const GURL& url, WindowOpenDisposition disposition, - PageTransition::Type transition) = 0; + PageTransition::Type transition, + const std::wstring& override_encoding) = 0; virtual void OpenURL(const GURL& url, WindowOpenDisposition disposition, - PageTransition::Type transition) - { - OpenURLFromTab(NULL, url, disposition, transition); + PageTransition::Type transition) { + OpenURLFromTab(NULL, url, disposition, transition, std::wstring()); } // Called to inform the delegate that the tab content's navigation state diff --git a/chrome/browser/tabs/dragged_tab_controller.cc b/chrome/browser/tabs/dragged_tab_controller.cc index 6a17a459..cdfb8df 100644 --- a/chrome/browser/tabs/dragged_tab_controller.cc +++ b/chrome/browser/tabs/dragged_tab_controller.cc @@ -166,15 +166,18 @@ bool DraggedTabController::IsDragSourceTab(Tab* tab) const { /////////////////////////////////////////////////////////////////////////////// // DraggedTabController, PageNavigator implementation: -void DraggedTabController::OpenURLFromTab(TabContents* source, - const GURL& url, - WindowOpenDisposition disposition, - PageTransition::Type transition) { +void DraggedTabController::OpenURLFromTab( + TabContents* source, + const GURL& url, + WindowOpenDisposition disposition, + PageTransition::Type transition, + const std::wstring& override_encoding) { if (original_delegate_) { if (disposition == CURRENT_TAB) disposition = NEW_WINDOW; - original_delegate_->OpenURLFromTab(source, url, disposition, transition); + original_delegate_->OpenURLFromTab(source, url, disposition, transition, + override_encoding); } } diff --git a/chrome/browser/tabs/dragged_tab_controller.h b/chrome/browser/tabs/dragged_tab_controller.h index d3352c5..e95776d 100644 --- a/chrome/browser/tabs/dragged_tab_controller.h +++ b/chrome/browser/tabs/dragged_tab_controller.h @@ -106,7 +106,8 @@ class DraggedTabController : public TabContentsDelegate, virtual void OpenURLFromTab(TabContents* source, const GURL& url, WindowOpenDisposition disposition, - PageTransition::Type transition); + PageTransition::Type transition, + const std::wstring& override_encoding); virtual void NavigationStateChanged(const TabContents* source, unsigned changed_flags); virtual void ReplaceContents(TabContents* source, diff --git a/chrome/browser/views/constrained_window_impl.cc b/chrome/browser/views/constrained_window_impl.cc index 7524debc..3dfdc20 100644 --- a/chrome/browser/views/constrained_window_impl.cc +++ b/chrome/browser/views/constrained_window_impl.cc @@ -1041,10 +1041,12 @@ void ConstrainedWindowImpl::ActivateContents(TabContents* contents) { ActivateConstrainedWindow(); } -void ConstrainedWindowImpl::OpenURLFromTab(TabContents* source, - const GURL& url, - WindowOpenDisposition disposition, - PageTransition::Type transition) { +void ConstrainedWindowImpl::OpenURLFromTab( + TabContents* source, + const GURL& url, + WindowOpenDisposition disposition, + PageTransition::Type transition, + const std::wstring& override_encoding) { // We ignore source right now. owner_->OpenURL(this, url, disposition, transition); } diff --git a/chrome/browser/views/constrained_window_impl.h b/chrome/browser/views/constrained_window_impl.h index 5a37e10..a91586b 100644 --- a/chrome/browser/views/constrained_window_impl.h +++ b/chrome/browser/views/constrained_window_impl.h @@ -80,7 +80,8 @@ class ConstrainedWindowImpl : public ConstrainedWindow, virtual void OpenURLFromTab(TabContents* source, const GURL& url, WindowOpenDisposition disposition, - PageTransition::Type transition); + PageTransition::Type transition, + const std::wstring& override_encoding); // Overridden from TabContentsDelegate: virtual void NavigationStateChanged(const TabContents* source, diff --git a/chrome/browser/views/html_dialog_view.cc b/chrome/browser/views/html_dialog_view.cc index 890d5a4..07f89c4 100644 --- a/chrome/browser/views/html_dialog_view.cc +++ b/chrome/browser/views/html_dialog_view.cc @@ -110,11 +110,13 @@ void HtmlDialogView::OnDialogClosed(const std::string& json_retval) { void HtmlDialogView::OpenURLFromTab(TabContents* source, const GURL& url, WindowOpenDisposition disposition, - PageTransition::Type transition) { + PageTransition::Type transition, + const std::wstring& override_encoding) { // Force all links to open in a new window, ignoring the incoming // disposition. This is a tabless, modal dialog so we can't just // open it in the current frame. - parent_browser_->OpenURLFromTab(source, url, NEW_WINDOW, transition); + parent_browser_->OpenURLFromTab(source, url, NEW_WINDOW, transition, + override_encoding); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/views/html_dialog_view.h b/chrome/browser/views/html_dialog_view.h index a07e5e3..51e9abb 100644 --- a/chrome/browser/views/html_dialog_view.h +++ b/chrome/browser/views/html_dialog_view.h @@ -82,7 +82,8 @@ class HtmlDialogView virtual void OpenURLFromTab(TabContents* source, const GURL& url, WindowOpenDisposition disposition, - PageTransition::Type transition); + PageTransition::Type transition, + const std::wstring& override_encoding); virtual void NavigationStateChanged(const TabContents* source, unsigned changed_flags); virtual void ReplaceContents(TabContents* source, diff --git a/chrome/browser/web_contents.cc b/chrome/browser/web_contents.cc index 96834dc..891ec4b 100644 --- a/chrome/browser/web_contents.cc +++ b/chrome/browser/web_contents.cc @@ -1766,6 +1766,15 @@ void WebContents::DidStartLoading(RenderViewHost* rvh, int32 page_id) { if (plugin_installer_ != NULL) plugin_installer_->OnStartLoading(); SetIsLoading(true, NULL); + + // Overrides the page's encoding if we need to open this page with specified + // encoding. + if (!override_encoding_.empty()) { + SetPageEncoding(override_encoding_); + // Once we override the new encoding, we need to clear the encoding value + // for avoiding overriding it again. + override_encoding_.clear(); + } } void WebContents::DidStopLoading(RenderViewHost* rvh, int32 page_id) { diff --git a/chrome/browser/web_contents.h b/chrome/browser/web_contents.h index 09a07d0..865cfab 100644 --- a/chrome/browser/web_contents.h +++ b/chrome/browser/web_contents.h @@ -359,6 +359,10 @@ class WebContents : public TabContents, // Returns true if this WebContents will notify about disconnection. bool notify_disconnection() const { return notify_disconnection_; } + void set_override_encoding(const std::wstring& override_encoding) { + override_encoding_ = override_encoding; + } + protected: FRIEND_TEST(WebContentsTest, OnMessageReceived); @@ -822,6 +826,9 @@ class WebContents : public TabContents, // Non-null if we're displaying content for a web app. scoped_refptr<WebApp> web_app_; + // Specified encoding which is used to override current tab's encoding. + std::wstring override_encoding_; + DISALLOW_COPY_AND_ASSIGN(WebContents); }; |