diff options
18 files changed, 276 insertions, 236 deletions
diff --git a/chrome/browser/autofill_manager.cc b/chrome/browser/autofill_manager.cc index 3e87674..08b631e 100644 --- a/chrome/browser/autofill_manager.cc +++ b/chrome/browser/autofill_manager.cc @@ -11,6 +11,10 @@ #include "chrome/common/pref_service.h" #include "webkit/glue/autofill_form.h" +// Limit on the number of suggestions to appear in the pop-up menu under an +// text input element in a form. +static const int kMaxAutofillMenuItems = 6; + // static void AutofillManager::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterBooleanPref(prefs::kFormAutofillEnabled, true); @@ -50,11 +54,10 @@ void AutofillManager::AutofillFormSubmitted(const webkit_glue::AutofillForm& for StoreFormEntriesInWebDatabase(form); } -void AutofillManager::FetchValuesForName(const std::wstring& name, - const std::wstring& prefix, - int limit, - int64 node_id, - int request_id) { +void AutofillManager::GetAutofillSuggestions(const std::wstring& name, + const std::wstring& prefix, + int64 node_id, + int request_id) { if (!*form_autofill_enabled_) return; @@ -70,12 +73,12 @@ void AutofillManager::FetchValuesForName(const std::wstring& name, node_id_ = node_id; request_id_ = request_id; - pending_query_handle_ = web_data_service-> - GetFormValuesForElementName(name, prefix, limit, this); + pending_query_handle_ = web_data_service->GetFormValuesForElementName( + name, prefix, kMaxAutofillMenuItems, this); } -void AutofillManager::RemoveValueForName(const std::wstring& name, - const std::wstring& value) { +void AutofillManager::RemoveAutofillEntry(const std::wstring& name, + const std::wstring& value) { WebDataService* web_data_service = profile()->GetWebDataService(Profile::EXPLICIT_ACCESS); if (!web_data_service) { diff --git a/chrome/browser/autofill_manager.h b/chrome/browser/autofill_manager.h index 06320fc..8fa241e 100644 --- a/chrome/browser/autofill_manager.h +++ b/chrome/browser/autofill_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -7,6 +7,7 @@ #include <string> +#include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/browser/webdata/web_data_service.h" #include "chrome/common/pref_member.h" @@ -19,7 +20,8 @@ class TabContents; // Per-tab autofill manager. Handles receiving form data from the renderer and // the storing and retrieving of form data through WebDataService. -class AutofillManager : public WebDataServiceConsumer { +class AutofillManager : public RenderViewHostDelegate::Autofill, + public WebDataServiceConsumer { public: explicit AutofillManager(TabContents* tab_contents); virtual ~AutofillManager(); @@ -28,20 +30,14 @@ class AutofillManager : public WebDataServiceConsumer { Profile* profile(); - // Called when a form is submitted (i.e. when the user hits the submit button) - // to store the form entries in the profile's sql database. - void AutofillFormSubmitted(const webkit_glue::AutofillForm& form); - - // Starts a query into the database for the values corresponding to name. - // OnWebDataServiceRequestDone gets called when the query completes. - void FetchValuesForName(const std::wstring& name, - const std::wstring& prefix, - int limit, - int64 node_id, - int request_id); - - // Removes the specified name/value pair from the database. - void RemoveValueForName(const std::wstring& name, const std::wstring& value); + // RenderViewHostDelegate::Autofill implementation. + virtual void AutofillFormSubmitted(const webkit_glue::AutofillForm& form); + virtual void GetAutofillSuggestions(const std::wstring& name, + const std::wstring& prefix, + int64 node_id, + int request_id); + virtual void RemoveAutofillEntry(const std::wstring& name, + const std::wstring& value); // WebDataServiceConsumer implementation. virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index f54cf5f..fb9bbb5 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -212,13 +212,13 @@ void ExtensionHost::DidInsertCSS() { #endif } -RenderViewHostDelegate::View* ExtensionHost::GetViewDelegate() const { +RenderViewHostDelegate::View* ExtensionHost::GetViewDelegate() { // TODO(erikkay) this is unfortunate. The interface declares that this method // must be const (no good reason for it as far as I can tell) which means you // can't return self without doing this const_cast. Either we need to change // the interface, or we need to split out the view delegate into another // object (which is how TabContents works). - return const_cast<ExtensionHost*>(this); + return this; } void ExtensionHost::CreateNewWindow(int route_id, diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index b2f32b2..e94648a 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -66,7 +66,7 @@ class ExtensionHost : public RenderViewHostDelegate, void RecoverCrashedExtension(); // RenderViewHostDelegate implementation. - virtual RenderViewHostDelegate::View* GetViewDelegate() const; + virtual RenderViewHostDelegate::View* GetViewDelegate(); virtual const GURL& GetURL() const { return url_; } virtual void RenderViewCreated(RenderViewHost* render_view_host); virtual void RenderViewGone(RenderViewHost* render_view_host); diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc index d1040b2..6121cb2 100644 --- a/chrome/browser/printing/print_view_manager.cc +++ b/chrome/browser/printing/print_view_manager.cc @@ -56,6 +56,21 @@ bool PrintViewManager::OnRenderViewGone(RenderViewHost* render_view_host) { return true; } +std::wstring PrintViewManager::RenderSourceName() { + std::wstring name(UTF16ToWideHack(owner_.GetTitle())); + if (name.empty()) + name = l10n_util::GetString(IDS_DEFAULT_PRINT_DOCUMENT_TITLE); + return name; +} + +GURL PrintViewManager::RenderSourceUrl() { + NavigationEntry* entry = owner_.controller().GetActiveEntry(); + if (entry) + return entry->display_url(); + else + return GURL(); +} + void PrintViewManager::DidGetPrintedPagesCount(int cookie, int number_pages) { DCHECK_GT(cookie, 0); if (!OpportunisticallyCreatePrintJob(cookie)) @@ -117,21 +132,6 @@ void PrintViewManager::DidPrintPage( ShouldQuitFromInnerMessageLoop(); } -std::wstring PrintViewManager::RenderSourceName() { - std::wstring name(UTF16ToWideHack(owner_.GetTitle())); - if (name.empty()) - name = l10n_util::GetString(IDS_DEFAULT_PRINT_DOCUMENT_TITLE); - return name; -} - -GURL PrintViewManager::RenderSourceUrl() { - NavigationEntry* entry = owner_.controller().GetActiveEntry(); - if (entry) - return entry->display_url(); - else - return GURL(); -} - void PrintViewManager::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { diff --git a/chrome/browser/printing/print_view_manager.h b/chrome/browser/printing/print_view_manager.h index 2945b0c..ee87fa2 100644 --- a/chrome/browser/printing/print_view_manager.h +++ b/chrome/browser/printing/print_view_manager.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ #include "base/ref_counted.h" +#include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/common/notification_registrar.h" #include "printing/printed_pages_source.h" @@ -22,7 +23,8 @@ class PrintJobWorkerOwner; // Manages the print commands in relation to a TabContents. TabContents // delegates a few printing related commands to this instance. class PrintViewManager : public NotificationObserver, - public PrintedPagesSource { + public PrintedPagesSource, + public RenderViewHostDelegate::Printing { public: PrintViewManager(TabContents& owner); virtual ~PrintViewManager(); @@ -34,18 +36,14 @@ class PrintViewManager : public NotificationObserver, // current state. Returns false if the renderer was not valuable. bool OnRenderViewGone(RenderViewHost* render_view_host); - // Received a notification from the renderer that the number of printed page - // has just been calculated.. - void DidGetPrintedPagesCount(int cookie, int number_pages); - - // Received a notification from the renderer that a printed page page is - // finished renderering. - void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params); - // PrintedPagesSource implementation. virtual std::wstring RenderSourceName(); virtual GURL RenderSourceUrl(); + // RenderViewHostDelegate::Printing implementation. + virtual void DidGetPrintedPagesCount(int cookie, int number_pages); + virtual void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params); + // NotificationObserver implementation. virtual void Observe(NotificationType type, const NotificationSource& source, diff --git a/chrome/browser/renderer_host/cross_site_resource_handler.cc b/chrome/browser/renderer_host/cross_site_resource_handler.cc index 2580344..fdb7d4a 100644 --- a/chrome/browser/renderer_host/cross_site_resource_handler.cc +++ b/chrome/browser/renderer_host/cross_site_resource_handler.cc @@ -50,8 +50,12 @@ class CancelPendingRenderViewTask : public Task { void Run() { RenderViewHost* view = RenderViewHost::FromID(render_process_host_id_, render_view_id_); - if (view) - view->delegate()->OnCrossSiteNavigationCanceled(); + if (view) { + RenderViewHostDelegate::RendererManagement* management_delegate = + view->delegate()->GetRendererManagementDelegate(); + if (management_delegate) + management_delegate->OnCrossSiteNavigationCanceled(); + } } private: diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 84f13d6..8e8f161 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -368,7 +368,12 @@ int RenderViewHost::GetPendingRequestId() { void RenderViewHost::OnCrossSiteResponse(int new_render_process_host_id, int new_request_id) { - delegate_->OnCrossSiteResponse(new_render_process_host_id, new_request_id); + RenderViewHostDelegate::RendererManagement* management_delegate = + delegate_->GetRendererManagementDelegate(); + if (management_delegate) { + management_delegate->OnCrossSiteResponse(new_render_process_host_id, + new_request_id); + } } void RenderViewHost::Stop() { @@ -625,6 +630,8 @@ void RenderViewHost::GotFocus() { } bool RenderViewHost::CanBlur() const { + // TODO(brettw) is seems like this function is never implemented. It and the + // messages leading here should be removed. return delegate_->CanBlur(); } @@ -750,9 +757,8 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateDragCursor, OnUpdateDragCursor) IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) IPC_MESSAGE_HANDLER(ViewHostMsg_PageHasOSDD, OnMsgPageHasOSDD) - IPC_MESSAGE_FORWARD(ViewHostMsg_DidGetPrintedPagesCount, - delegate_, - RenderViewHostDelegate::DidGetPrintedPagesCount) + IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetPrintedPagesCount, + OnDidGetPrintedPagesCount) IPC_MESSAGE_HANDLER(ViewHostMsg_DidPrintPage, DidPrintPage) IPC_MESSAGE_HANDLER(ViewHostMsg_AddMessageToConsole, OnAddMessageToConsole) IPC_MESSAGE_HANDLER(ViewHostMsg_ForwardToDevToolsAgent, @@ -1222,7 +1228,10 @@ void RenderViewHost::OnMsgPasswordFormsSeen( void RenderViewHost::OnMsgAutofillFormSubmitted( const webkit_glue::AutofillForm& form) { - delegate_->AutofillFormSubmitted(form); + RenderViewHostDelegate::Autofill* autofill_delegate = + delegate_->GetAutofillDelegate(); + if (autofill_delegate) + autofill_delegate->AutofillFormSubmitted(form); } void RenderViewHost::OnMsgStartDragging( @@ -1249,9 +1258,19 @@ void RenderViewHost::OnMsgPageHasOSDD(int32 page_id, const GURL& doc_url, delegate_->PageHasOSDD(this, page_id, doc_url, autodetected); } +void RenderViewHost::OnDidGetPrintedPagesCount(int cookie, int number_pages) { + RenderViewHostDelegate::Printing* printing_delegate = + delegate_->GetPrintingDelegate(); + if (printing_delegate) + printing_delegate->DidGetPrintedPagesCount(cookie, number_pages); +} + void RenderViewHost::DidPrintPage( const ViewHostMsg_DidPrintPage_Params& params) { - delegate_->DidPrintPage(params); + RenderViewHostDelegate::Printing* printing_delegate = + delegate_->GetPrintingDelegate(); + if (printing_delegate) + printing_delegate->DidPrintPage(params); } void RenderViewHost::OnAddMessageToConsole(const std::wstring& message, @@ -1383,19 +1402,31 @@ void RenderViewHost::OnMsgShouldCloseACK(bool proceed) { StopHangMonitorTimeout(); DCHECK(is_waiting_for_unload_ack_); is_waiting_for_unload_ack_ = false; - delegate_->ShouldClosePage(proceed); + + RenderViewHostDelegate::RendererManagement* management_delegate = + delegate_->GetRendererManagementDelegate(); + if (management_delegate) + management_delegate->ShouldClosePage(proceed); } void RenderViewHost::OnQueryFormFieldAutofill(const std::wstring& field_name, const std::wstring& user_text, int64 node_id, int request_id) { - delegate_->GetAutofillSuggestions(field_name, user_text, node_id, request_id); + RenderViewHostDelegate::Autofill* autofill_delegate = + delegate_->GetAutofillDelegate(); + if (autofill_delegate) { + autofill_delegate->GetAutofillSuggestions(field_name, user_text, + node_id, request_id); + } } void RenderViewHost::OnRemoveAutofillEntry(const std::wstring& field_name, const std::wstring& value) { - delegate_->RemoveAutofillEntry(field_name, value); + RenderViewHostDelegate::Autofill* autofill_delegate = + delegate_->GetAutofillDelegate(); + if (autofill_delegate) + autofill_delegate->RemoveAutofillEntry(field_name, value); } void RenderViewHost::AutofillSuggestionsReturned( diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 210d74f..de4c70c 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -502,6 +502,7 @@ class RenderViewHost : public RenderWidgetHost, void OnUpdateDragCursor(bool is_drop_target); void OnTakeFocus(bool reverse); void OnMsgPageHasOSDD(int32 page_id, const GURL& doc_url, bool autodetected); + void OnDidGetPrintedPagesCount(int cookie, int number_pages); void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params); void OnAddMessageToConsole(const std::wstring& message, int32 line_no, diff --git a/chrome/browser/renderer_host/render_view_host_delegate.cc b/chrome/browser/renderer_host/render_view_host_delegate.cc index b976176..1afbdac 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.cc +++ b/chrome/browser/renderer_host/render_view_host_delegate.cc @@ -9,26 +9,41 @@ #include "googleurl/src/gurl.h" #include "webkit/glue/webpreferences.h" -RenderViewHostDelegate::View* RenderViewHostDelegate::GetViewDelegate() const { +RenderViewHostDelegate::View* RenderViewHostDelegate::GetViewDelegate() { + return NULL; +} + +RenderViewHostDelegate::RendererManagement* +RenderViewHostDelegate::GetRendererManagementDelegate() { return NULL; } RenderViewHostDelegate::BrowserIntegration* -RenderViewHostDelegate::GetBrowserIntegrationDelegate() const { +RenderViewHostDelegate::GetBrowserIntegrationDelegate() { return NULL; } RenderViewHostDelegate::Resource* -RenderViewHostDelegate::GetResourceDelegate() const { +RenderViewHostDelegate::GetResourceDelegate() { return NULL; } -RenderViewHostDelegate::Save* RenderViewHostDelegate::GetSaveDelegate() const { +RenderViewHostDelegate::Save* RenderViewHostDelegate::GetSaveDelegate() { + return NULL; +} + +RenderViewHostDelegate::Printing* +RenderViewHostDelegate::GetPrintingDelegate() { return NULL; } RenderViewHostDelegate::FavIcon* -RenderViewHostDelegate::GetFavIconDelegate() const { +RenderViewHostDelegate::GetFavIconDelegate() { + return NULL; +} + +RenderViewHostDelegate::Autofill* +RenderViewHostDelegate::GetAutofillDelegate() { return NULL; } diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index 28e9fdc..e33d64b 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -137,6 +137,29 @@ class RenderViewHostDelegate { virtual void UpdatePreferredWidth(int pref_width) = 0; }; + // RendererManagerment ------------------------------------------------------- + // Functions for managing switching of Renderers. For TabContents, this is + // implemented by the RenderViewHostManager + + class RendererManagement { + public: + // Notification whether we should close the page, after an explicit call to + // AttemptToClosePage. This is called before a cross-site request or before + // a tab/window is closed, to allow the appropriate renderer to approve or + // deny the request. |proceed| indicates whether the user chose to proceed. + virtual void ShouldClosePage(bool proceed) = 0; + + // Called by ResourceDispatcherHost when a response for a pending cross-site + // request is received. The ResourceDispatcherHost will pause the response + // until the onunload handler of the previous renderer is run. + virtual void OnCrossSiteResponse(int new_render_process_host_id, + int new_request_id) = 0; + + // Called the ResourceDispatcherHost's associate CrossSiteRequestHandler + // when a cross-site navigation has been canceled. + virtual void OnCrossSiteNavigationCanceled() = 0; + }; + // BrowserIntegration -------------------------------------------------------- // Functions that integrate with other browser services. @@ -264,6 +287,21 @@ class RenderViewHostDelegate { int32 status) = 0; }; + // Printing ------------------------------------------------------------------ + + class Printing { + public: + // Notification that the render view has calculated the number of printed + // pages. + virtual void DidGetPrintedPagesCount(int cookie, int number_pages) = 0; + + // Notification that the render view is done rendering one printed page. + // This call is synchronous, the renderer is waiting on us because of the + // EMF memory mapped data. + virtual void DidPrintPage( + const ViewHostMsg_DidPrintPage_Params& params) = 0; + }; + // FavIcon ------------------------------------------------------------------- // Interface for the renderer to supply favicon information. @@ -287,15 +325,44 @@ class RenderViewHostDelegate { const GURL& icon_url) = 0; }; + // AutoFill ------------------------------------------------------------------ + // Interface for autofill-related functions. + + class Autofill { + public: + // Forms fillable by autofill have been detected in the page. + virtual void AutofillFormSubmitted( + const webkit_glue::AutofillForm& form) = 0; + + // Called to retrieve a list of suggestions from the web database given + // the name of the field |field_name| and what the user has already typed + // in the field |user_text|. Appeals to the database thead to perform the + // query. When the database thread is finished, the autofill manager + // retrieves the calling RenderViewHost and then passes the vector of + // suggestions to RenderViewHost::AutofillSuggestionsReturned. + virtual void GetAutofillSuggestions(const std::wstring& field_name, + const std::wstring& user_text, + int64 node_id, + int request_id) = 0; + + // Called when the user has indicated that she wants to remove the specified + // autofill suggestion from the database. + virtual void RemoveAutofillEntry(const std::wstring& field_name, + const std::wstring& value) = 0; + }; + // --------------------------------------------------------------------------- // Returns the current delegate associated with a feature. May return NULL if // there is no corresponding delegate. - virtual View* GetViewDelegate() const; - virtual BrowserIntegration* GetBrowserIntegrationDelegate() const; - virtual Resource* GetResourceDelegate() const; - virtual Save* GetSaveDelegate() const; - virtual FavIcon* GetFavIconDelegate() const; + virtual View* GetViewDelegate(); + virtual RendererManagement* GetRendererManagementDelegate(); + virtual BrowserIntegration* GetBrowserIntegrationDelegate(); + virtual Resource* GetResourceDelegate(); + virtual Save* GetSaveDelegate(); + virtual Printing* GetPrintingDelegate(); + virtual FavIcon* GetFavIconDelegate(); + virtual Autofill* GetAutofillDelegate(); // Gets the URL that is currently being displayed, if there is one. virtual const GURL& GetURL() const; @@ -410,39 +477,11 @@ class RenderViewHostDelegate { virtual void PasswordFormsSeen( const std::vector<webkit_glue::PasswordForm>& forms) {} - // Forms fillable by autofill have been detected in the page. - virtual void AutofillFormSubmitted(const webkit_glue::AutofillForm& form) {} - - // Called to retrieve a list of suggestions from the web database given - // the name of the field |field_name| and what the user has already typed in - // the field |user_text|. Appeals to the database thead to perform the query. - // When the database thread is finished, the autofill manager retrieves the - // calling RenderViewHost and then passes the vector of suggestions to - // RenderViewHost::AutofillSuggestionsReturned. - virtual void GetAutofillSuggestions(const std::wstring& field_name, - const std::wstring& user_text, - int64 node_id, - int request_id) {} - - // Called when the user has indicated that she wants to remove the specified - // autofill suggestion from the database. - virtual void RemoveAutofillEntry(const std::wstring& field_name, - const std::wstring& value) {} - // Notification that the page has an OpenSearch description document. virtual void PageHasOSDD(RenderViewHost* render_view_host, int32 page_id, const GURL& doc_url, bool autodetected) {} - // Notification that the render view has calculated the number of printed - // pages. - virtual void DidGetPrintedPagesCount(int cookie, int number_pages) {} - - // Notification that the render view is done rendering one printed page. This - // call is synchronous, the renderer is waiting on us because of the EMF - // memory mapped data. - virtual void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params) {} - // |url| is assigned to a server that can provide alternate error pages. If // the returned URL is empty, the default error page built into WebKit will // be used. @@ -459,22 +498,6 @@ class RenderViewHostDelegate { // Notification from the renderer that JS runs out of memory. virtual void OnJSOutOfMemory() {} - // Notification whether we should close the page, after an explicit call to - // AttemptToClosePage. This is called before a cross-site request or before - // a tab/window is closed, to allow the appropriate renderer to approve or - // deny the request. |proceed| indicates whether the user chose to proceed. - virtual void ShouldClosePage(bool proceed) {} - - // Called by ResourceDispatcherHost when a response for a pending cross-site - // request is received. The ResourceDispatcherHost will pause the response - // until the onunload handler of the previous renderer is run. - virtual void OnCrossSiteResponse(int new_render_process_host_id, - int new_request_id) {} - - // Called the ResourceDispatcherHost's associate CrossSiteRequestHandler - // when a cross-site navigation has been canceled. - virtual void OnCrossSiteNavigationCanceled() {} - // Returns true if this this object can be blurred through a javascript // obj.blur() call. ConstrainedWindows shouldn't be able to be blurred, but // generally most other windows will be. diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc index 2eff140..c8863d9 100644 --- a/chrome/browser/tab_contents/interstitial_page.cc +++ b/chrome/browser/tab_contents/interstitial_page.cc @@ -281,7 +281,7 @@ void InterstitialPage::Observe(NotificationType type, } } -RenderViewHostDelegate::View* InterstitialPage::GetViewDelegate() const { +RenderViewHostDelegate::View* InterstitialPage::GetViewDelegate() { return rvh_view_delegate_.get(); } diff --git a/chrome/browser/tab_contents/interstitial_page.h b/chrome/browser/tab_contents/interstitial_page.h index 8ebfb51..05b2031 100644 --- a/chrome/browser/tab_contents/interstitial_page.h +++ b/chrome/browser/tab_contents/interstitial_page.h @@ -92,7 +92,7 @@ class InterstitialPage : public NotificationObserver, const NotificationDetails& details); // RenderViewHostDelegate implementation: - virtual View* GetViewDelegate() const; + virtual View* GetViewDelegate(); virtual const GURL& GetURL() const; virtual void RenderViewGone(RenderViewHost* render_view_host); virtual void DidNavigate(RenderViewHost* render_view_host, diff --git a/chrome/browser/tab_contents/render_view_host_manager.cc b/chrome/browser/tab_contents/render_view_host_manager.cc index 28f5a95..a34668c 100644 --- a/chrome/browser/tab_contents/render_view_host_manager.cc +++ b/chrome/browser/tab_contents/render_view_host_manager.cc @@ -180,27 +180,6 @@ void RenderViewHostManager::DidNavigateMainFrame( } } -void RenderViewHostManager::OnCrossSiteResponse(int new_render_process_host_id, - int new_request_id) { - // Should only see this while we have a pending renderer. - if (!cross_navigation_pending_) - return; - DCHECK(pending_render_view_host_); - - // Tell the old renderer to run its onunload handler. When it finishes, it - // will send a ClosePage_ACK to the ResourceDispatcherHost with the given - // IDs (of the pending RVH's request), allowing the pending RVH's response to - // resume. - render_view_host_->ClosePage(new_render_process_host_id, new_request_id); - - // ResourceDispatcherHost has told us to run the onunload handler, which - // means it is not a download or unsafe page, and we are going to perform the - // navigation. Thus, we no longer need to remember that the RenderViewHost - // is part of a pending cross-site request. - pending_render_view_host_->SetHasPendingCrossSiteRequest(false, - new_request_id); -} - void RenderViewHostManager::RendererAbortedProvisionalLoad( RenderViewHost* render_view_host) { // We used to cancel the pending renderer here for cross-site downloads. @@ -215,6 +194,17 @@ void RenderViewHostManager::RendererAbortedProvisionalLoad( // the response is not a download. } +void RenderViewHostManager::OnJavaScriptMessageBoxClosed( + IPC::Message* reply_msg, + bool success, + const std::wstring& prompt) { + render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt); +} + +void RenderViewHostManager::OnJavaScriptMessageBoxWindowDestroyed() { + render_view_host_->JavaScriptMessageBoxWindowDestroyed(); +} + void RenderViewHostManager::ShouldClosePage(bool proceed) { // Should only see this while we have a pending renderer. Otherwise, we // should ignore. @@ -245,15 +235,32 @@ void RenderViewHostManager::ShouldClosePage(bool proceed) { } } -void RenderViewHostManager::OnJavaScriptMessageBoxClosed( - IPC::Message* reply_msg, - bool success, - const std::wstring& prompt) { - render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt); +void RenderViewHostManager::OnCrossSiteResponse(int new_render_process_host_id, + int new_request_id) { + // Should only see this while we have a pending renderer. + if (!cross_navigation_pending_) + return; + DCHECK(pending_render_view_host_); + + // Tell the old renderer to run its onunload handler. When it finishes, it + // will send a ClosePage_ACK to the ResourceDispatcherHost with the given + // IDs (of the pending RVH's request), allowing the pending RVH's response to + // resume. + render_view_host_->ClosePage(new_render_process_host_id, new_request_id); + + // ResourceDispatcherHost has told us to run the onunload handler, which + // means it is not a download or unsafe page, and we are going to perform the + // navigation. Thus, we no longer need to remember that the RenderViewHost + // is part of a pending cross-site request. + pending_render_view_host_->SetHasPendingCrossSiteRequest(false, + new_request_id); } -void RenderViewHostManager::OnJavaScriptMessageBoxWindowDestroyed() { - render_view_host_->JavaScriptMessageBoxWindowDestroyed(); +void RenderViewHostManager::OnCrossSiteNavigationCanceled() { + DCHECK(cross_navigation_pending_); + cross_navigation_pending_ = false; + if (pending_render_view_host_) + CancelPending(); } bool RenderViewHostManager::ShouldTransitionCrossSite() { @@ -284,9 +291,10 @@ bool RenderViewHostManager::ShouldSwapProcessesForNavigation( // Also, we must switch if one is an extension and the other is not the exact // same extension. if (cur_entry->url().SchemeIs(chrome::kExtensionScheme) || - new_entry->url().SchemeIs(chrome::kExtensionScheme)) + new_entry->url().SchemeIs(chrome::kExtensionScheme)) { if (cur_entry->url().GetOrigin() != new_entry->url().GetOrigin()) return true; + } return false; } @@ -577,10 +585,3 @@ void RenderViewHostManager::CancelPending() { pending_dom_ui_.reset(); } - -void RenderViewHostManager::CrossSiteNavigationCanceled() { - DCHECK(cross_navigation_pending_); - cross_navigation_pending_ = false; - if (pending_render_view_host_) - CancelPending(); -} diff --git a/chrome/browser/tab_contents/render_view_host_manager.h b/chrome/browser/tab_contents/render_view_host_manager.h index a725d16..0b2460b 100644 --- a/chrome/browser/tab_contents/render_view_host_manager.h +++ b/chrome/browser/tab_contents/render_view_host_manager.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_observer.h" @@ -16,14 +17,14 @@ class InterstitialPage; class NavigationController; class NavigationEntry; class Profile; -class RenderViewHostDelegate; class RenderWidgetHostView; class SiteInstance; // Manages RenderViewHosts for a TabContents. Normally there is only one and // it is easy to do. But we can also have transitions of processes (and hence // RenderViewHosts) that can get complex. -class RenderViewHostManager { +class RenderViewHostManager + : public RenderViewHostDelegate::RendererManagement { public: // Functions implemented by our owner that we need. // @@ -126,23 +127,9 @@ class RenderViewHostManager { // Called when a renderer's main frame navigates. void DidNavigateMainFrame(RenderViewHost* render_view_host); - // Allows the TabContents to react when a cross-site response is ready to be - // delivered to a pending RenderViewHost. We must first run the onunload - // handler of the old RenderViewHost before we can allow it to proceed. - void OnCrossSiteResponse(int new_render_process_host_id, - int new_request_id); - - // Notifies that the navigation that initiated a cross-site transition has - // been canceled. - void CrossSiteNavigationCanceled(); - // Called when a provisional load on the given renderer is aborted. void RendererAbortedProvisionalLoad(RenderViewHost* render_view_host); - // Actually implements this RenderViewHostDelegate function for the - // TabContents. - void ShouldClosePage(bool proceed); - // Forwards the message to the RenderViewHost, which is the original one. void OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg, bool success, @@ -172,6 +159,12 @@ class RenderViewHostManager { return interstitial_page_; } + // RenderViewHostDelegate::RendererManagement implementation. + virtual void ShouldClosePage(bool proceed); + virtual void OnCrossSiteResponse(int new_render_process_host_id, + int new_request_id); + virtual void OnCrossSiteNavigationCanceled(); + private: friend class TestTabContents; diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index cddddfb..001be58 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -149,10 +149,6 @@ const wchar_t* kPrefsToObserve[] = { const int kPrefsToObserveLength = arraysize(kPrefsToObserve); -// Limit on the number of suggestions to appear in the pop-up menu under an -// text input element in a form. -const int kMaxAutofillMenuItems = 6; - // Returns true if the entry's transition type is FORM_SUBMIT. bool IsFormSubmit(const NavigationEntry* entry) { return (PageTransition::StripQualifier(entry->transition_type()) == @@ -415,12 +411,6 @@ bool TabContents::HostsExtension() const { return GetURL().SchemeIs(chrome::kExtensionScheme); } -AutofillManager* TabContents::GetAutofillManager() { - if (autofill_manager_.get() == NULL) - autofill_manager_.reset(new AutofillManager(this)); - return autofill_manager_.get(); -} - PasswordManager* TabContents::GetPasswordManager() { if (password_manager_.get() == NULL) password_manager_.reset(new PasswordManager(this)); @@ -1681,25 +1671,40 @@ void TabContents::DocumentLoadedInFrame() { controller_.DocumentLoadedInFrame(); } -RenderViewHostDelegate::View* TabContents::GetViewDelegate() const { +RenderViewHostDelegate::View* TabContents::GetViewDelegate() { return view_.get(); } +RenderViewHostDelegate::RendererManagement* +TabContents::GetRendererManagementDelegate() { + return &render_manager_; +} + RenderViewHostDelegate::BrowserIntegration* - TabContents::GetBrowserIntegrationDelegate() const { - return const_cast<TabContents*>(this); + TabContents::GetBrowserIntegrationDelegate() { + return this; } -RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() const { - return const_cast<TabContents*>(this); +RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() { + return this; } -RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() const { +RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() { return save_package_.get(); // May be NULL, but we can return NULL. } -RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() const { - return &const_cast<TabContents*>(this)->fav_icon_helper_; +RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() { + return &printing_; +} + +RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() { + return &fav_icon_helper_; +} + +RenderViewHostDelegate::Autofill* TabContents::GetAutofillDelegate() { + if (autofill_manager_.get() == NULL) + autofill_manager_.reset(new AutofillManager(this)); + return autofill_manager_.get(); } RendererPreferences TabContents::GetRendererPrefs() const { @@ -2068,22 +2073,6 @@ void TabContents::PasswordFormsSeen( GetPasswordManager()->PasswordFormsSeen(forms); } -void TabContents::AutofillFormSubmitted( - const webkit_glue::AutofillForm& form) { - GetAutofillManager()->AutofillFormSubmitted(form); -} - -void TabContents::GetAutofillSuggestions(const std::wstring& field_name, - const std::wstring& user_text, int64 node_id, int request_id) { - GetAutofillManager()->FetchValuesForName(field_name, user_text, - kMaxAutofillMenuItems, node_id, request_id); -} - -void TabContents::RemoveAutofillEntry(const std::wstring& field_name, - const std::wstring& value) { - GetAutofillManager()->RemoveValueForName(field_name, value); -} - // Checks to see if we should generate a keyword based on the OSDD, and if // necessary uses TemplateURLFetcher to download the OSDD and create a keyword. void TabContents::PageHasOSDD(RenderViewHost* render_view_host, @@ -2153,14 +2142,6 @@ void TabContents::PageHasOSDD(RenderViewHost* render_view_host, autodetected); } -void TabContents::DidGetPrintedPagesCount(int cookie, int number_pages) { - printing_.DidGetPrintedPagesCount(cookie, number_pages); -} - -void TabContents::DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params) { - printing_.DidPrintPage(params); -} - GURL TabContents::GetAlternateErrorPageURL() const { GURL url; // Disable alternate error pages when in OffTheRecord/Incognito mode. @@ -2200,10 +2181,6 @@ void TabContents::OnCrossSiteResponse(int new_render_process_host_id, new_request_id); } -void TabContents::OnCrossSiteNavigationCanceled() { - render_manager_.CrossSiteNavigationCanceled(); -} - bool TabContents::CanBlur() const { return delegate() ? delegate()->CanBlur() : true; } diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 6b8f417..99e99a1 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -142,9 +142,6 @@ class TabContents : public PageNavigator, // Returns true if contains content rendered by an extension. bool HostsExtension() const; - // Returns the AutofillManager, creating it if necessary. - AutofillManager* GetAutofillManager(); - // Returns the PasswordManager, creating it if necessary. PasswordManager* GetPasswordManager(); @@ -771,12 +768,16 @@ class TabContents : public PageNavigator, virtual void DocumentLoadedInFrame(); // RenderViewHostDelegate implementation. - virtual RenderViewHostDelegate::View* GetViewDelegate() const; + virtual RenderViewHostDelegate::View* GetViewDelegate(); + virtual RenderViewHostDelegate::RendererManagement* + GetRendererManagementDelegate(); virtual RenderViewHostDelegate::BrowserIntegration* - GetBrowserIntegrationDelegate() const; - virtual RenderViewHostDelegate::Resource* GetResourceDelegate() const; - virtual RenderViewHostDelegate::Save* GetSaveDelegate() const; - virtual RenderViewHostDelegate::FavIcon* GetFavIconDelegate() const; + GetBrowserIntegrationDelegate(); + virtual RenderViewHostDelegate::Resource* GetResourceDelegate(); + virtual RenderViewHostDelegate::Save* GetSaveDelegate(); + virtual RenderViewHostDelegate::Printing* GetPrintingDelegate(); + virtual RenderViewHostDelegate::FavIcon* GetFavIconDelegate(); + virtual RenderViewHostDelegate::Autofill* GetAutofillDelegate(); virtual TabContents* GetAsTabContents(); virtual void RenderViewCreated(RenderViewHost* render_view_host); virtual void RenderViewReady(RenderViewHost* render_view_host); @@ -828,15 +829,8 @@ class TabContents : public PageNavigator, IPC::Message* reply_msg); virtual void PasswordFormsSeen( const std::vector<webkit_glue::PasswordForm>& forms); - virtual void AutofillFormSubmitted(const webkit_glue::AutofillForm& form); - virtual void GetAutofillSuggestions(const std::wstring& field_name, - const std::wstring& user_text, int64 node_id, int request_id); - virtual void RemoveAutofillEntry(const std::wstring& field_name, - const std::wstring& value); virtual void PageHasOSDD(RenderViewHost* render_view_host, int32 page_id, const GURL& url, bool autodetected); - virtual void DidGetPrintedPagesCount(int cookie, int number_pages); - virtual void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params); virtual GURL GetAlternateErrorPageURL() const; virtual RendererPreferences GetRendererPrefs() const; virtual WebPreferences GetWebkitPrefs(); @@ -844,7 +838,6 @@ class TabContents : public PageNavigator, virtual void ShouldClosePage(bool proceed); virtual void OnCrossSiteResponse(int new_render_process_host_id, int new_request_id); - virtual void OnCrossSiteNavigationCanceled(); virtual bool CanBlur() const; virtual gfx::Rect GetRootWindowResizerRect() const; virtual void RendererUnresponsive(RenderViewHost* render_view_host, diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h index dd17bb7..8aab9f8 100644 --- a/chrome/common/temp_scaffolding_stubs.h +++ b/chrome/common/temp_scaffolding_stubs.h @@ -19,6 +19,7 @@ #include "base/string16.h" #include "build/build_config.h" #include "chrome/browser/dom_ui/html_dialog_ui.h" +#include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "googleurl/src/gurl.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -65,7 +66,7 @@ class ViewMsg_Print_Params; // http://code.google.com/p/chromium/issues/detail?id=9847 namespace printing { -class PrintViewManager { +class PrintViewManager : public RenderViewHostDelegate::Printing { public: PrintViewManager(TabContents&) { } void Stop() { NOTIMPLEMENTED(); } @@ -74,8 +75,12 @@ class PrintViewManager { NOTIMPLEMENTED(); return true; // Assume for now that all renderer crashes are important. } - void DidGetPrintedPagesCount(int, int) { NOTIMPLEMENTED(); } - void DidPrintPage(const ViewHostMsg_DidPrintPage_Params&) { + + // RenderViewHostDelegate::Printing implementation. + virtual void DidGetPrintedPagesCount(int cookie, int number_pages) { + NOTIMPLEMENTED(); + } + virtual void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params) { NOTIMPLEMENTED(); } }; |