diff options
Diffstat (limited to 'chrome/browser')
38 files changed, 151 insertions, 137 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index 5b031f527..631aebd 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -20,6 +20,7 @@ #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" +#include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" #include "googleurl/src/url_canon_ip.h" #include "grit/generated_resources.h" @@ -118,8 +119,9 @@ AutocompleteInput::Type AutocompleteInput::Parse(const std::wstring& text, // reach the renderer or else the renderer handles internally without // reaching the URLRequest logic. We thus won't catch these above, but we // should still claim to handle them. - if ((parsed_scheme == L"view-source") || (parsed_scheme == L"javascript") || - (parsed_scheme == L"data")) + if (LowerCaseEqualsASCII(parsed_scheme, chrome::kViewSourceScheme) || + LowerCaseEqualsASCII(parsed_scheme, chrome::kJavaScriptScheme) || + LowerCaseEqualsASCII(parsed_scheme, chrome::kDataScheme)) return URL; // Finally, check and see if the user has explicitly opened this scheme as diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index c4bc67b..6866cf4 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -2032,6 +2032,9 @@ void Browser::UpdateCommandsForTabState() { WebContents* web_contents = current_tab->AsWebContents(); bool is_web_contents = web_contents != NULL; + // Current navigation entry, may be NULL. + NavigationEntry* active_entry = current_tab->controller()->GetActiveEntry(); + // Page-related commands // Only allow bookmarking for web content in normal windows. command_updater_.UpdateCommandEnabled(IDC_STAR, @@ -2039,8 +2042,7 @@ void Browser::UpdateCommandsForTabState() { window_->SetStarredState(is_web_contents && web_contents->is_starred()); // View-source should not be enabled if already in view-source mode. command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE, - is_web_contents && (current_tab->type() != TAB_CONTENTS_VIEW_SOURCE) && - current_tab->controller()->GetActiveEntry()); + is_web_contents && active_entry && !active_entry->IsViewSourceMode()); command_updater_.UpdateCommandEnabled(IDC_PRINT, is_web_contents); command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, is_web_contents && SavePackage::IsSavableURL(current_tab->GetURL())); diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons index 4ef5838..e0b346c 100644 --- a/chrome/browser/browser.scons +++ b/chrome/browser/browser.scons @@ -587,8 +587,6 @@ input_files = ChromeFileList([ 'tab_contents/tab_contents_type.h', 'tab_contents/tab_util.cc', 'tab_contents/tab_util.h', - 'tab_contents/view_source_contents.cc', - 'tab_contents/view_source_contents.h', 'tab_contents/web_contents.cc', 'tab_contents/web_contents.h', 'tab_contents/web_contents_view.cc', diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index e8ee21e..317ed07 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -2222,14 +2222,6 @@ > </File> <File - RelativePath=".\tab_contents\view_source_contents.cc" - > - </File> - <File - RelativePath=".\tab_contents\view_source_contents.h" - > - </File> - <File RelativePath=".\tab_contents\web_contents.cc" > </File> diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc index 839e3d1..49707cf 100644 --- a/chrome/browser/history/history.cc +++ b/chrome/browser/history/history.cc @@ -44,6 +44,7 @@ #include "chrome/common/l10n_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/thumbnail_score.h" +#include "chrome/common/url_constants.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -571,12 +572,12 @@ bool HistoryService::CanAddURL(const GURL& url) const { if (!url.is_valid()) return false; - if (url.SchemeIs("javascript") || - url.SchemeIs("chrome") || - url.SchemeIs("view-source")) + if (url.SchemeIs(chrome::kJavaScriptScheme) || + url.SchemeIs(chrome::kChromeUIScheme) || + url.SchemeIs(chrome::kViewSourceScheme)) return false; - if (url.SchemeIs("about")) { + if (url.SchemeIs(chrome::kAboutScheme)) { std::string path = url.path(); if (path.empty() || LowerCaseEqualsASCII(path, "blank")) return false; diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc index c251f8a..c448dbb 100644 --- a/chrome/browser/printing/print_view_manager.cc +++ b/chrome/browser/printing/print_view_manager.cc @@ -40,7 +40,7 @@ void PrintViewManager::Stop() { TerminatePrintJob(true); } -bool PrintViewManager::OnRendererGone(RenderViewHost* render_view_host) { +bool PrintViewManager::OnRenderViewGone(RenderViewHost* render_view_host) { if (!print_job_.get()) return true; diff --git a/chrome/browser/printing/print_view_manager.h b/chrome/browser/printing/print_view_manager.h index 1392ac57..698c714 100644 --- a/chrome/browser/printing/print_view_manager.h +++ b/chrome/browser/printing/print_view_manager.h @@ -36,7 +36,7 @@ class PrintViewManager : public NotificationObserver, // Terminates or cancels the print job if one was pending, depending on the // current state. Returns false if the renderer was not valuable. - bool OnRendererGone(RenderViewHost* render_view_host); + bool OnRenderViewGone(RenderViewHost* render_view_host); // Received a notification from the renderer that the number of printed page // has just been calculated.. diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index 096930d..b1efc93 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -789,7 +789,7 @@ void BrowserRenderProcessHost::OnChannelError() { IDMap<IPC::Channel::Listener> local_listeners(listeners_); for (listeners_iterator i = local_listeners.begin(); i != local_listeners.end(); ++i) { - i->second->OnMessageReceived(ViewHostMsg_RendererGone(i->first)); + i->second->OnMessageReceived(ViewHostMsg_RenderViewGone(i->first)); } // at this point, this object should be deleted } diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 8770bcf..edff720 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -179,7 +179,7 @@ bool RenderViewHost::CreateRenderView() { routing_id(), enable_dom_ui_bindings_, enable_external_host_bindings_)); // Let our delegate know that we created a RenderView. - delegate_->RendererCreated(this); + delegate_->RenderViewCreated(this); return true; } @@ -671,8 +671,8 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_ShowView, OnMsgShowView) IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnMsgShowWidget) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunModal, OnMsgRunModal) - IPC_MESSAGE_HANDLER(ViewHostMsg_RendererReady, OnMsgRendererReady) - IPC_MESSAGE_HANDLER(ViewHostMsg_RendererGone, OnMsgRendererGone) + IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnMsgRenderViewReady) + IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewGone, OnMsgRenderViewGone) IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_FrameNavigate, OnMsgNavigate(msg)) IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateState, OnMsgUpdateState) IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTitle, OnMsgUpdateTitle) @@ -818,12 +818,12 @@ void RenderViewHost::OnMsgRunModal(IPC::Message* reply_msg) { // an app-modal fashion. } -void RenderViewHost::OnMsgRendererReady() { +void RenderViewHost::OnMsgRenderViewReady() { WasResized(); - delegate_->RendererReady(this); + delegate_->RenderViewReady(this); } -void RenderViewHost::OnMsgRendererGone() { +void RenderViewHost::OnMsgRenderViewGone() { // Our base class RenderWidgetHouse needs to reset some stuff. RendererExited(); @@ -831,7 +831,7 @@ void RenderViewHost::OnMsgRendererGone() { // from a crashed renderer. renderer_initialized_ = false; - delegate_->RendererGone(this); + delegate_->RenderViewGone(this); OnDebugDisconnect(); } diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 15d0c6f..2974db6 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -428,8 +428,8 @@ class RenderViewHost : public RenderWidgetHost { bool user_gesture); void OnMsgShowWidget(int route_id, const gfx::Rect& initial_pos); void OnMsgRunModal(IPC::Message* reply_msg); - void OnMsgRendererReady(); - void OnMsgRendererGone(); + void OnMsgRenderViewReady(); + void OnMsgRenderViewGone(); void OnMsgNavigate(const IPC::Message& msg); void OnMsgUpdateState(int32 page_id, const std::string& state); diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index 67ac07e..7c7fe4a 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -150,13 +150,13 @@ class RenderViewHostDelegate { // The RenderView is being constructed (message sent to the renderer process // to construct a RenderView). Now is a good time to send other setup events // to the RenderView. This precedes any other commands to the RenderView. - virtual void RendererCreated(RenderViewHost* render_view_host) { } + virtual void RenderViewCreated(RenderViewHost* render_view_host) { } // The RenderView has been constructed. - virtual void RendererReady(RenderViewHost* render_view_host) { } + virtual void RenderViewReady(RenderViewHost* render_view_host) { } // The RenderView died somehow (crashed or was killed by the user). - virtual void RendererGone(RenderViewHost* render_view_host) { } + virtual void RenderViewGone(RenderViewHost* render_view_host) { } // The RenderView was navigated to a different page. virtual void DidNavigate(RenderViewHost* render_view_host, diff --git a/chrome/browser/renderer_host/render_widget_host.cc b/chrome/browser/renderer_host/render_widget_host.cc index 1f0ab85..b27f835 100644 --- a/chrome/browser/renderer_host/render_widget_host.cc +++ b/chrome/browser/renderer_host/render_widget_host.cc @@ -91,8 +91,8 @@ void RenderWidgetHost::Shutdown() { } IPC_DEFINE_MESSAGE_MAP(RenderWidgetHost) - IPC_MESSAGE_HANDLER(ViewHostMsg_RendererReady, OnMsgRendererReady) - IPC_MESSAGE_HANDLER(ViewHostMsg_RendererGone, OnMsgRendererGone) + IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnMsgRenderViewReady) + IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewGone, OnMsgRenderViewGone) IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnMsgClose) IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnMsgRequestMove) IPC_MESSAGE_HANDLER(ViewHostMsg_PaintRect, OnMsgPaintRect) @@ -321,8 +321,8 @@ void RenderWidgetHost::RendererExited() { is_hidden_ = false; if (view_) { - view_->RendererGone(); - view_ = NULL; // The View should be deleted by RendererGone. + view_->RenderViewGone(); + view_ = NULL; // The View should be deleted by RenderViewGone. } BackingStoreManager::RemoveBackingStore(this); @@ -376,11 +376,11 @@ void RenderWidgetHost::RendererIsResponsive() { } } -void RenderWidgetHost::OnMsgRendererReady() { +void RenderWidgetHost::OnMsgRenderViewReady() { WasResized(); } -void RenderWidgetHost::OnMsgRendererGone() { +void RenderWidgetHost::OnMsgRenderViewGone() { // TODO(evanm): This synchronously ends up calling "delete this". // Is that really what we want in response to this message? I'm matching // previous behavior of the code here. diff --git a/chrome/browser/renderer_host/render_widget_host.h b/chrome/browser/renderer_host/render_widget_host.h index 8c8f007..df0c417 100644 --- a/chrome/browser/renderer_host/render_widget_host.h +++ b/chrome/browser/renderer_host/render_widget_host.h @@ -247,8 +247,8 @@ class RenderWidgetHost : public IPC::Channel::Listener { void RendererIsResponsive(); // IPC message handlers - void OnMsgRendererReady(); - void OnMsgRendererGone(); + void OnMsgRenderViewReady(); + void OnMsgRenderViewGone(); void OnMsgClose(); void OnMsgRequestMove(const gfx::Rect& pos); void OnMsgPaintRect(const ViewHostMsg_PaintRect_Params& params); diff --git a/chrome/browser/renderer_host/render_widget_host_view.h b/chrome/browser/renderer_host/render_widget_host_view.h index b451fd3..7b00158 100644 --- a/chrome/browser/renderer_host/render_widget_host_view.h +++ b/chrome/browser/renderer_host/render_widget_host_view.h @@ -100,7 +100,7 @@ class RenderWidgetHostView { const gfx::Rect& rect, int dx, int dy) = 0; // Notifies the View that the renderer has ceased to exist. - virtual void RendererGone() = 0; + virtual void RenderViewGone() = 0; // Tells the View to destroy itself. virtual void Destroy() = 0; diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc index c955abc..1151152 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc @@ -261,7 +261,7 @@ void RenderWidgetHostViewGtk::DidScrollRect(const gfx::Rect& rect, int dx, Paint(rect); } -void RenderWidgetHostViewGtk::RendererGone() { +void RenderWidgetHostViewGtk::RenderViewGone() { NOTIMPLEMENTED(); } diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.h b/chrome/browser/renderer_host/render_widget_host_view_gtk.h index d839f06..9d342ff 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_gtk.h +++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.h @@ -44,7 +44,7 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView { void DidPaintRect(const gfx::Rect& rect); void DidScrollRect( const gfx::Rect& rect, int dx, int dy); - void RendererGone(); + void RenderViewGone(); void Destroy(); void SetTooltipText(const std::wstring& tooltip_text); // --------------------------------------------------------------------------- diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.h b/chrome/browser/renderer_host/render_widget_host_view_mac.h index a9221c9..13d4fb6 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.h +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.h @@ -75,7 +75,7 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView { virtual void IMEUpdateStatus(int control, const gfx::Rect& caret_rect); virtual void DidPaintRect(const gfx::Rect& rect); virtual void DidScrollRect(const gfx::Rect& rect, int dx, int dy); - virtual void RendererGone(); + virtual void RenderViewGone(); virtual void Destroy(); virtual void SetTooltipText(const std::wstring& tooltip_text); diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm index afc0f25..24a68ac 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -181,7 +181,7 @@ void RenderWidgetHostViewMac::DidScrollRect( [cocoa_view_ setNeedsDisplayInRect:[cocoa_view_ RectToNSRect:dirty_rect]]; } -void RenderWidgetHostViewMac::RendererGone() { +void RenderWidgetHostViewMac::RenderViewGone() { // TODO(darin): keep this around, and draw sad-tab into it. UpdateCursorIfOverSelf(); Destroy(); diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc index b9fe070..6369485 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_win.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc @@ -400,7 +400,7 @@ void RenderWidgetHostViewWin::DidScrollRect( Redraw(gfx::Rect(invalid_rect)); } -void RenderWidgetHostViewWin::RendererGone() { +void RenderWidgetHostViewWin::RenderViewGone() { // TODO(darin): keep this around, and draw sad-tab into it. UpdateCursorIfOverSelf(); DestroyWindow(); diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.h b/chrome/browser/renderer_host/render_widget_host_view_win.h index 02887c5..dad1b5d 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_win.h +++ b/chrome/browser/renderer_host/render_widget_host_view_win.h @@ -134,7 +134,7 @@ class RenderWidgetHostViewWin : virtual void IMEUpdateStatus(int control, const gfx::Rect& caret_rect); virtual void DidPaintRect(const gfx::Rect& rect); virtual void DidScrollRect(const gfx::Rect& rect, int dx, int dy); - virtual void RendererGone(); + virtual void RenderViewGone(); virtual void Destroy(); virtual void SetTooltipText(const std::wstring& tooltip_text); diff --git a/chrome/browser/renderer_host/renderer_security_policy.cc b/chrome/browser/renderer_host/renderer_security_policy.cc index 3350f59..71a71ec 100644 --- a/chrome/browser/renderer_host/renderer_security_policy.cc +++ b/chrome/browser/renderer_host/renderer_security_policy.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "base/string_util.h" +#include "chrome/common/url_constants.h" #ifdef CHROME_PERSONALIZATION #include "chrome/personalization/personalization.h" #endif @@ -85,9 +86,9 @@ RendererSecurityPolicy::RendererSecurityPolicy() { RegisterWebSafeScheme("chrome-extension"); // We know about the following psuedo schemes and treat them specially. - RegisterPseudoScheme("about"); - RegisterPseudoScheme("javascript"); - RegisterPseudoScheme("view-source"); + RegisterPseudoScheme(chrome::kAboutScheme); + RegisterPseudoScheme(chrome::kJavaScriptScheme); + RegisterPseudoScheme(chrome::kViewSourceScheme); } // static diff --git a/chrome/browser/renderer_host/test_render_view_host.h b/chrome/browser/renderer_host/test_render_view_host.h index 380222a..b6d011e 100644 --- a/chrome/browser/renderer_host/test_render_view_host.h +++ b/chrome/browser/renderer_host/test_render_view_host.h @@ -64,7 +64,7 @@ class TestRenderWidgetHostView : public RenderWidgetHostView { virtual void IMEUpdateStatus(int control, const gfx::Rect& caret_rect) {} virtual void DidPaintRect(const gfx::Rect& rect) {} virtual void DidScrollRect(const gfx::Rect& rect, int dx, int dy) {} - virtual void RendererGone() {} + virtual void RenderViewGone() {} virtual void Destroy() {} virtual void PrepareToDestroy() {} virtual void SetTooltipText(const std::wstring& tooltip_text) {} diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc index cb9fe98..4511447 100644 --- a/chrome/browser/tab_contents/interstitial_page.cc +++ b/chrome/browser/tab_contents/interstitial_page.cc @@ -371,7 +371,7 @@ void InterstitialPage::DidNavigate( #endif } -void InterstitialPage::RendererGone(RenderViewHost* render_view_host) { +void InterstitialPage::RenderViewGone(RenderViewHost* render_view_host) { // Our renderer died. This should not happen in normal cases. // Just dismiss the interstitial. DontProceed(); diff --git a/chrome/browser/tab_contents/interstitial_page.h b/chrome/browser/tab_contents/interstitial_page.h index f6fe1ee..d05d0aa 100644 --- a/chrome/browser/tab_contents/interstitial_page.h +++ b/chrome/browser/tab_contents/interstitial_page.h @@ -86,7 +86,7 @@ class InterstitialPage : public NotificationObserver, } virtual void DidNavigate(RenderViewHost* render_view_host, const ViewHostMsg_FrameNavigate_Params& params); - virtual void RendererGone(RenderViewHost* render_view_host); + virtual void RenderViewGone(RenderViewHost* render_view_host); virtual void DomOperationResponse(const std::string& json_string, int automation_id); virtual void UpdateTitle(RenderViewHost* render_view_host, diff --git a/chrome/browser/tab_contents/navigation_controller.cc b/chrome/browser/tab_contents/navigation_controller.cc index 91d0d84..def6c34 100644 --- a/chrome/browser/tab_contents/navigation_controller.cc +++ b/chrome/browser/tab_contents/navigation_controller.cc @@ -17,6 +17,7 @@ #include "chrome/common/notification_service.h" #include "chrome/common/render_messages.h" #include "chrome/common/resource_bundle.h" +#include "chrome/common/url_constants.h" #include "webkit/glue/webkit_glue.h" #if defined(OS_WIN) @@ -55,7 +56,7 @@ void SetContentStateIfEmpty(NavigationEntry* entry) { entry->tab_type() == TAB_CONTENTS_NEW_TAB_UI || entry->tab_type() == TAB_CONTENTS_ABOUT_UI || entry->tab_type() == TAB_CONTENTS_HTML_DIALOG || - entry->tab_type() == TAB_CONTENTS_VIEW_SOURCE)) { + entry->IsViewSourceMode())) { entry->set_content_state( webkit_glue::CreateHistoryStateForURL(entry->url())); } @@ -467,6 +468,11 @@ NavigationEntry* NavigationController::CreateNavigationEntry( else type = TabContents::TypeForURL(&real_url); + if (url.SchemeIs(chrome::kViewSourceScheme)) { + // Load the inner URL instead, setting the original URL as the "display". + real_url = GURL(url.path()); + } + NavigationEntry* entry = new NavigationEntry(type, NULL, -1, real_url, referrer, std::wstring(), transition); diff --git a/chrome/browser/tab_contents/navigation_controller.h b/chrome/browser/tab_contents/navigation_controller.h index a7518c3..00b6b0f 100644 --- a/chrome/browser/tab_contents/navigation_controller.h +++ b/chrome/browser/tab_contents/navigation_controller.h @@ -160,7 +160,6 @@ class NavigationController { // // If you are trying to get the current state of the NavigationController, // this is the method you will typically want to call. - // NavigationEntry* GetActiveEntry() const; // Returns the index from which we would go back/forward or reload. This is diff --git a/chrome/browser/tab_contents/navigation_entry.cc b/chrome/browser/tab_contents/navigation_entry.cc index bf0951c..e243f8a 100644 --- a/chrome/browser/tab_contents/navigation_entry.cc +++ b/chrome/browser/tab_contents/navigation_entry.cc @@ -4,6 +4,7 @@ #include "chrome/browser/tab_contents/navigation_entry.h" +#include "chrome/common/url_constants.h" #include "chrome/common/resource_bundle.h" // Use this to get a new unique ID for a NavigationEntry during construction. @@ -62,3 +63,7 @@ const std::wstring& NavigationEntry::GetTitleForDisplay() { return display_url_as_string_; return title_; } + +bool NavigationEntry::IsViewSourceMode() const { + return display_url_.SchemeIs(chrome::kViewSourceScheme); +} diff --git a/chrome/browser/tab_contents/navigation_entry.h b/chrome/browser/tab_contents/navigation_entry.h index 377e8df..20d3fd4 100644 --- a/chrome/browser/tab_contents/navigation_entry.h +++ b/chrome/browser/tab_contents/navigation_entry.h @@ -309,6 +309,16 @@ class NavigationEntry { return ssl_; } + // Page-related helpers ------------------------------------------------------ + + // Returns the title to be displayed on the tab. This could be the title of + // the page if it is available or the URL. + const std::wstring& GetTitleForDisplay(); + + // Returns true if the current tab is in view source mode. This will be false + // if there is no navigation. + bool IsViewSourceMode() const; + // Tracking stuff ------------------------------------------------------------ // The transition type indicates what the user did to move to this page from @@ -359,10 +369,6 @@ class NavigationEntry { return restored_; } - // Returns the title to be displayed on the tab. This could be the title of - // the page if it is available or the URL. - const std::wstring& GetTitleForDisplay(); - private: // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING // Session/Tab restore save portions of this class so that it can be recreated diff --git a/chrome/browser/tab_contents/render_view_context_menu_controller.cc b/chrome/browser/tab_contents/render_view_context_menu_controller.cc index 8882628..df373e4 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_controller.cc +++ b/chrome/browser/tab_contents/render_view_context_menu_controller.cc @@ -24,6 +24,7 @@ #include "chrome/common/l10n_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" +#include "chrome/common/url_constants.h" #include "grit/generated_resources.h" #include "net/base/escape.h" #include "net/base/net_util.h" @@ -519,17 +520,17 @@ bool RenderViewContextMenuController::IsDevCommandEnabled(int id) const { return false; // Don't inspect view source. - if (source_web_contents_->type() == TAB_CONTENTS_VIEW_SOURCE) + if (active_entry->IsViewSourceMode()) return false; // Don't inspect inspector, new tab UI, etc. - if (active_entry->url().SchemeIs("chrome")) + if (active_entry->url().SchemeIs(chrome::kChromeUIScheme)) return false; // Don't inspect about:network, about:memory, etc. // However, we do want to inspect about:blank, which is often // used by ordinary web pages. - if (active_entry->display_url().SchemeIs("about") && + if (active_entry->display_url().SchemeIs(chrome::kAboutScheme) && !LowerCaseEqualsASCII(active_entry->display_url().path(), "blank")) return false; diff --git a/chrome/browser/tab_contents/render_view_host_manager.cc b/chrome/browser/tab_contents/render_view_host_manager.cc index d315eac..b1062bc 100644 --- a/chrome/browser/tab_contents/render_view_host_manager.cc +++ b/chrome/browser/tab_contents/render_view_host_manager.cc @@ -267,6 +267,21 @@ bool RenderViewHostManager::ShouldTransitionCrossSite() { return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab); } +bool RenderViewHostManager::ShouldSwapRenderViewsForNavigation( + const NavigationEntry* cur_entry, + const NavigationEntry* new_entry) const { + if (!cur_entry || !new_entry) + return false; + + // We can't switch a RenderView between view source and non-view source mode + // without screwing up the session history sometimes (when navigating between + // "view-source:http://foo.com/" and "http://foo.com/", WebKit doesn't treat + // it as a new navigation). So require a view switch. + if (cur_entry->IsViewSourceMode() != new_entry->IsViewSourceMode()) + return true; + return false; +} + SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( const NavigationEntry& entry, SiteInstance* curr_instance) { @@ -413,12 +428,12 @@ void RenderViewHostManager::SwapToRenderView( (*new_render_view_host) = NULL; // If the view is gone, then this RenderViewHost died while it was hidden. - // We ignored the RendererGone call at the time, so we should send it now + // We ignored the RenderViewGone call at the time, so we should send it now // to make sure the sad tab shows up, etc. if (render_view_host_->view()) render_view_host_->view()->Show(); else - delegate_->RendererGoneFromRenderManager(render_view_host_); + delegate_->RenderViewGoneFromRenderManager(render_view_host_); // Make sure the size is up to date. (Fix for bug 1079768.) delegate_->UpdateRenderViewSizeForRenderManager(); @@ -463,7 +478,9 @@ RenderViewHost* RenderViewHostManager::UpdateRendererStateNavigate( if (ShouldTransitionCrossSite()) new_instance = GetSiteInstanceForEntry(entry, curr_instance); - if (new_instance != curr_instance) { + if (new_instance != curr_instance || ShouldSwapRenderViewsForNavigation( + delegate_->GetLastCommittedNavigationEntryForRenderManager(), + &entry)) { // New SiteInstance. DCHECK(!cross_navigation_pending_); diff --git a/chrome/browser/tab_contents/render_view_host_manager.h b/chrome/browser/tab_contents/render_view_host_manager.h index 268b298..160ecff 100644 --- a/chrome/browser/tab_contents/render_view_host_manager.h +++ b/chrome/browser/tab_contents/render_view_host_manager.h @@ -42,11 +42,16 @@ class RenderViewHostManager : public NotificationObserver { bool proceed, bool* proceed_to_fire_unload) = 0; virtual void DidStartLoadingFromRenderManager( RenderViewHost* render_view_host, int32 page_id) = 0; - virtual void RendererGoneFromRenderManager( + virtual void RenderViewGoneFromRenderManager( RenderViewHost* render_view_host) = 0; virtual void UpdateRenderViewSizeForRenderManager() = 0; virtual void NotifySwappedFromRenderManager() = 0; virtual NavigationController* GetControllerForRenderManager() = 0; + + // Returns the navigation entry of the current navigation, or NULL if there + // is none. + virtual NavigationEntry* + GetLastCommittedNavigationEntryForRenderManager() = 0; }; // The factory is optional. It is used by unit tests to supply custom render @@ -167,6 +172,13 @@ class RenderViewHostManager : public NotificationObserver { // switch. Can be overridden in unit tests. bool ShouldTransitionCrossSite(); + // Returns true if the two navigation entries are incompatible in some way + // other than site instances. This will cause us to swap RenderViewHosts even + // if the site instances are the same. Either of the entries may be NULL. + bool ShouldSwapRenderViewsForNavigation( + const NavigationEntry* cur_entry, + const NavigationEntry* new_entry) const; + // Returns an appropriate SiteInstance object for the given NavigationEntry, // possibly reusing the current SiteInstance. // Never called if --process-per-tab is used. @@ -200,7 +212,9 @@ class RenderViewHostManager : public NotificationObserver { // Our delegate, not owned by us. Guaranteed non-NULL. Delegate* delegate_; - // Whether a cross-site request is pending (in the new process model). + // Whether a navigation requiring different RenderView's is pending. This is + // either cross-site request is (in the new process model), or when required + // for the view type (like view source versus not). bool cross_navigation_pending_; // Allows tests to create their own render view host types. diff --git a/chrome/browser/tab_contents/tab_contents_factory.cc b/chrome/browser/tab_contents/tab_contents_factory.cc index 9a5063f..045a01c 100644 --- a/chrome/browser/tab_contents/tab_contents_factory.cc +++ b/chrome/browser/tab_contents/tab_contents_factory.cc @@ -11,7 +11,6 @@ #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/debugger/debugger_contents.h" #include "chrome/browser/tab_contents/tab_contents_factory.h" -#include "chrome/browser/tab_contents/view_source_contents.h" #include "chrome/browser/tab_contents/web_contents.h" #include "net/base/net_util.h" @@ -58,9 +57,6 @@ TabContents* TabContents::CreateWithType(TabContentsType type, case TAB_CONTENTS_NATIVE_UI: contents = new NativeUIContents(profile); break; - case TAB_CONTENTS_VIEW_SOURCE: - contents = new ViewSourceContents(profile, instance); - break; case TAB_CONTENTS_ABOUT_UI: contents = new BrowserAboutHandler(profile, instance, NULL); break; @@ -119,11 +115,6 @@ TabContentsType TabContents::TypeForURL(GURL* url) { if (url->SchemeIs(DOMUIContents::GetScheme().c_str())) return TAB_CONTENTS_DOM_UI; - if (url->SchemeIs("view-source")) { - // Load the inner URL instead, but render it using a ViewSourceContents. - *url = GURL(url->path()); - return TAB_CONTENTS_VIEW_SOURCE; - } #elif defined(OS_POSIX) NOTIMPLEMENTED(); #endif diff --git a/chrome/browser/tab_contents/tab_contents_type.h b/chrome/browser/tab_contents/tab_contents_type.h index 87cd6452..53e79b0 100644 --- a/chrome/browser/tab_contents/tab_contents_type.h +++ b/chrome/browser/tab_contents/tab_contents_type.h @@ -16,7 +16,6 @@ enum TabContentsType { TAB_CONTENTS_CHROME_VIEW_CONTENTS, TAB_CONTENTS_NEW_TAB_UI, TAB_CONTENTS_NATIVE_UI, - TAB_CONTENTS_VIEW_SOURCE, TAB_CONTENTS_HTML_DIALOG, TAB_CONTENTS_ABOUT_UI, TAB_CONTENTS_DEBUGGER, diff --git a/chrome/browser/tab_contents/view_source_contents.cc b/chrome/browser/tab_contents/view_source_contents.cc deleted file mode 100644 index be95c5b..0000000 --- a/chrome/browser/tab_contents/view_source_contents.cc +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/tab_contents/view_source_contents.h" - -#include "chrome/browser/renderer_host/render_view_host.h" -#include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/common/render_messages.h" - -ViewSourceContents::ViewSourceContents(Profile* profile, SiteInstance* instance) - : WebContents(profile, instance, NULL, MSG_ROUTING_NONE, NULL) { - set_type(TAB_CONTENTS_VIEW_SOURCE); -} - -void ViewSourceContents::RendererCreated(RenderViewHost* host) { - // Make sure the renderer is in view source mode. - host->Send(new ViewMsg_EnableViewSourceMode(host->routing_id())); -} - diff --git a/chrome/browser/tab_contents/view_source_contents.h b/chrome/browser/tab_contents/view_source_contents.h deleted file mode 100644 index f09f14b..0000000 --- a/chrome/browser/tab_contents/view_source_contents.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_TAB_CONTENTS_VIEW_SOURCE_CONTENTS_H_ -#define CHROME_BROWSER_TAB_CONTENTS_VIEW_SOURCE_CONTENTS_H_ - -#include "chrome/browser/tab_contents/web_contents.h" - -// We use this class to implement view-source: URLs. -class ViewSourceContents : public WebContents { - public: - ViewSourceContents(Profile* profile, SiteInstance* instance); - - protected: - // RenderViewHostDelegate overrides: - virtual void RendererCreated(RenderViewHost* host); - - // WebContents overrides: - // We override updating history with a no-op so these pages - // are not saved to history. - virtual void UpdateHistoryForNavigation(const GURL& url, - const ViewHostMsg_FrameNavigate_Params& params) { } -}; - -#endif // CHROME_BROWSER_TAB_CONTENTS_VIEW_SOURCE_CONTENTS_H_ - diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc index ecf33c9..11665cc 100644 --- a/chrome/browser/tab_contents/web_contents.cc +++ b/chrome/browser/tab_contents/web_contents.cc @@ -36,6 +36,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/render_messages.h" +#include "chrome/common/url_constants.h" #include "grit/locale_settings.h" #include "net/base/mime_util.h" #include "net/base/net_errors.h" @@ -391,7 +392,7 @@ bool WebContents::NavigateToPendingEntry(bool reload) { // do not generate content. What we really need is a message from the // renderer telling us that a new page was not created. The same message // could be used for mailto: URLs and the like. - if (entry->url().SchemeIs("javascript")) + if (entry->url().SchemeIs(chrome::kJavaScriptScheme)) return false; } @@ -672,7 +673,21 @@ Profile* WebContents::GetProfile() const { return profile(); } -void WebContents::RendererReady(RenderViewHost* rvh) { +void WebContents::RenderViewCreated(RenderViewHost* render_view_host) { + if (!controller()) + return; + NavigationEntry* entry = controller()->GetActiveEntry(); + if (!entry) + return; + + if (entry->IsViewSourceMode()) { + // Put the renderer in view source mode. + render_view_host->Send( + new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); + } +} + +void WebContents::RenderViewReady(RenderViewHost* rvh) { if (rvh != render_view_host()) { // Don't notify the world, since this came from a renderer in the // background. @@ -683,9 +698,9 @@ void WebContents::RendererReady(RenderViewHost* rvh) { SetIsCrashed(false); } -void WebContents::RendererGone(RenderViewHost* rvh) { +void WebContents::RenderViewGone(RenderViewHost* rvh) { // Ask the print preview if this renderer was valuable. - if (!printing_.OnRendererGone(rvh)) + if (!printing_.OnRenderViewGone(rvh)) return; if (rvh != render_view_host()) { // The pending page's RenderViewHost is gone. @@ -1456,6 +1471,13 @@ void WebContents::UpdateRenderViewSizeForRenderManager() { view_->SizeContents(view_->GetContainerSize()); } +NavigationEntry* +WebContents::GetLastCommittedNavigationEntryForRenderManager() { + if (!controller()) + return NULL; + return controller()->GetLastCommittedEntry(); +} + bool WebContents::CreateRenderViewForRenderManager( RenderViewHost* render_view_host) { RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); diff --git a/chrome/browser/tab_contents/web_contents.h b/chrome/browser/tab_contents/web_contents.h index 08ac907..3974a78 100644 --- a/chrome/browser/tab_contents/web_contents.h +++ b/chrome/browser/tab_contents/web_contents.h @@ -107,6 +107,8 @@ class WebContents : public TabContents, return view_.get(); } + // Page state getters & setters ---------------------------------------------- + bool is_starred() const { return is_starred_; } const std::wstring& encoding() const { return encoding_; } @@ -282,8 +284,9 @@ class WebContents : public TabContents, virtual RenderViewHostDelegate::Save* GetSaveDelegate() const; virtual Profile* GetProfile() const; virtual WebContents* GetAsWebContents() { return this; } - virtual void RendererReady(RenderViewHost* render_view_host); - virtual void RendererGone(RenderViewHost* render_view_host); + virtual void RenderViewCreated(RenderViewHost* render_view_host); + virtual void RenderViewReady(RenderViewHost* render_view_host); + virtual void RenderViewGone(RenderViewHost* render_view_host); virtual void DidNavigate(RenderViewHost* render_view_host, const ViewHostMsg_FrameNavigate_Params& params); virtual void UpdateState(RenderViewHost* render_view_host, @@ -405,8 +408,9 @@ class WebContents : public TabContents, RenderViewHost* render_view_host, int32 page_id) { DidStartLoading(render_view_host, page_id); } - virtual void RendererGoneFromRenderManager(RenderViewHost* render_view_host) { - RendererGone(render_view_host); + virtual void RenderViewGoneFromRenderManager( + RenderViewHost* render_view_host) { + RenderViewGone(render_view_host); } virtual void UpdateRenderViewSizeForRenderManager(); virtual void NotifySwappedFromRenderManager() { @@ -415,6 +419,7 @@ class WebContents : public TabContents, virtual NavigationController* GetControllerForRenderManager() { return controller(); } + virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager(); // Initializes the given renderer if necessary and creates the view ID // corresponding to this view host. If this method is not called and the diff --git a/chrome/browser/tab_contents/web_contents_unittest.cc b/chrome/browser/tab_contents/web_contents_unittest.cc index 60f795e..9e595af0 100644 --- a/chrome/browser/tab_contents/web_contents_unittest.cc +++ b/chrome/browser/tab_contents/web_contents_unittest.cc @@ -125,8 +125,8 @@ class TestInterstitialPage : public InterstitialPage { DidNavigate(render_view_host(), params); } - void TestRendererGone() { - RendererGone(render_view_host()); + void TestRenderViewGone() { + RenderViewGone(render_view_host()); } bool is_showing() const { @@ -1032,7 +1032,7 @@ TEST_F(WebContentsTest, InterstitialCrasher) { TestInterstitialPageStateGuard state_guard(interstitial); interstitial->Show(); // Simulate a renderer crash before the interstitial is shown. - interstitial->TestRendererGone(); + interstitial->TestRenderViewGone(); // The interstitial should have been dismissed. EXPECT_TRUE(deleted); EXPECT_EQ(TestInterstitialPage::CANCELED, state); @@ -1043,7 +1043,7 @@ TEST_F(WebContentsTest, InterstitialCrasher) { interstitial->Show(); interstitial->TestDidNavigate(1, url); // Simulate a renderer crash. - interstitial->TestRendererGone(); + interstitial->TestRenderViewGone(); // The interstitial should have been dismissed. EXPECT_TRUE(deleted); EXPECT_EQ(TestInterstitialPage::CANCELED, state); |