summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 17:21:10 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 17:21:10 +0000
commitdaa8c58ee49795d292312bbf217999c93693919c (patch)
tree561a327f148d74b0522871f15103e25a27b841f5 /chrome
parent0b97342d07fd3ef047432b52809d31d10432ee85 (diff)
downloadchromium_src-daa8c58ee49795d292312bbf217999c93693919c.zip
chromium_src-daa8c58ee49795d292312bbf217999c93693919c.tar.gz
chromium_src-daa8c58ee49795d292312bbf217999c93693919c.tar.bz2
Extract form related classes from the guts of WebFrameImpl.
Instead of having WebFrameImpl generate SearchableFormData, PasswordForm, and AutofillForm classes, allow the embedder (RenderView) to do so. This is done to help minimize the dependencies WebFrameImpl has on other code, which will make it easier to move WebFrame and WebDataSource into the WebKit API. Most significant change: Now, RenderView always sets a NavigationState on WebDataSource instances. We used to only do so for browser initiated navigations. This is done so that we can store things like SearchableFormData and friends on the NavigationState. To facilitate this change, it was necessary to add a way through the WebKit API to refer to a HTMLFormElement. This CL introduces WebForm, which is like a RefPtr<HTMLFormElement>, so you can just copy a WebForm around by value and the right thing happens. Some of the other changes are about moving more things into the webkit_glue namespace. On hindsight, I probably should have done that as a separate CL. BUG=10041 TEST=none R=brettw Review URL: http://codereview.chromium.org/126083 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18395 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autofill_manager.cc4
-rw-r--r--chrome/browser/autofill_manager.h7
-rw-r--r--chrome/browser/password_manager/password_manager.cc11
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc2
-rw-r--r--chrome/browser/renderer_host/render_view_host.h7
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.h4
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc2
-rw-r--r--chrome/browser/tab_contents/tab_contents.h8
-rw-r--r--chrome/browser/webdata/web_data_service.cc1
-rw-r--r--chrome/browser/webdata/web_data_service.h4
-rw-r--r--chrome/browser/webdata/web_database.cc1
-rw-r--r--chrome/browser/webdata/web_database.h16
-rw-r--r--chrome/browser/webdata/web_database_unittest.cc1
-rw-r--r--chrome/common/render_messages.h12
-rw-r--r--chrome/common/render_messages_internal.h4
-rw-r--r--chrome/renderer/render_view.cc228
-rw-r--r--chrome/renderer/render_view.h24
17 files changed, 202 insertions, 134 deletions
diff --git a/chrome/browser/autofill_manager.cc b/chrome/browser/autofill_manager.cc
index 441d708..3e87674 100644
--- a/chrome/browser/autofill_manager.cc
+++ b/chrome/browser/autofill_manager.cc
@@ -46,7 +46,7 @@ Profile* AutofillManager::profile() {
return tab_contents_->profile();
}
-void AutofillManager::AutofillFormSubmitted(const AutofillForm& form) {
+void AutofillManager::AutofillFormSubmitted(const webkit_glue::AutofillForm& form) {
StoreFormEntriesInWebDatabase(form);
}
@@ -117,7 +117,7 @@ void AutofillManager::OnWebDataServiceRequestDone(WebDataService::Handle h,
}
void AutofillManager::StoreFormEntriesInWebDatabase(
- const AutofillForm& form) {
+ const webkit_glue::AutofillForm& form) {
if (!*form_autofill_enabled_)
return;
diff --git a/chrome/browser/autofill_manager.h b/chrome/browser/autofill_manager.h
index 020c2ce..06320fc 100644
--- a/chrome/browser/autofill_manager.h
+++ b/chrome/browser/autofill_manager.h
@@ -10,7 +10,10 @@
#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/common/pref_member.h"
+namespace webkit_glue {
class AutofillForm;
+}
+
class Profile;
class TabContents;
@@ -27,7 +30,7 @@ class AutofillManager : public WebDataServiceConsumer {
// 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 AutofillForm& form);
+ 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.
@@ -47,7 +50,7 @@ class AutofillManager : public WebDataServiceConsumer {
static void RegisterUserPrefs(PrefService* prefs);
private:
- void StoreFormEntriesInWebDatabase(const AutofillForm& form);
+ void StoreFormEntriesInWebDatabase(const webkit_glue::AutofillForm& form);
TabContents* tab_contents_;
diff --git a/chrome/browser/password_manager/password_manager.cc b/chrome/browser/password_manager/password_manager.cc
index e09aa08..5566e99 100644
--- a/chrome/browser/password_manager/password_manager.cc
+++ b/chrome/browser/password_manager/password_manager.cc
@@ -226,11 +226,12 @@ void PasswordManager::Autofill(
// schemed password form may have been freed, so we need to distinguish.
bool action_mismatch = form_for_autofill.action.GetWithEmptyPath() !=
preferred_match->action.GetWithEmptyPath();
- PasswordFormDomManager::FillData fill_data;
- PasswordFormDomManager::InitFillData(form_for_autofill,
- best_matches, preferred_match,
- action_mismatch,
- &fill_data);
+ webkit_glue::PasswordFormDomManager::FillData fill_data;
+ webkit_glue::PasswordFormDomManager::InitFillData(form_for_autofill,
+ best_matches,
+ preferred_match,
+ action_mismatch,
+ &fill_data);
tab_contents_->render_view_host()->FillPasswordForm(fill_data);
return;
}
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index dff92be..fff947a 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -48,6 +48,8 @@
#endif
using base::TimeDelta;
+using webkit_glue::AutofillForm;
+using webkit_glue::PasswordFormDomManager;
using WebKit::WebConsoleMessage;
using WebKit::WebFindOptions;
using WebKit::WebInputEvent;
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index 8759231..8773323 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -19,7 +19,6 @@
#include "webkit/glue/password_form_dom_manager.h"
#include "webkit/glue/window_open_disposition.h"
-class AutofillForm;
class NavigationEntry;
class RenderViewHostDelegate;
class SiteInstance;
@@ -44,6 +43,7 @@ enum LoadState;
}
namespace webkit_glue {
+class AutofillForm;
struct WebApplicationInfo;
}
@@ -213,7 +213,8 @@ class RenderViewHost : public RenderWidgetHost {
// Fill out a password form and trigger DOM autocomplete in the case
// of multiple matching logins.
- void FillPasswordForm(const PasswordFormDomManager::FillData& form_data);
+ void FillPasswordForm(
+ const webkit_glue::PasswordFormDomManager::FillData& form_data);
// D&d drop target messages that get sent to WebKit.
void DragTargetDragEnter(const WebDropData& drop_data,
@@ -518,7 +519,7 @@ class RenderViewHost : public RenderWidgetHost {
const std::string& json_arguments,
IPC::Message* reply_msg);
void OnMsgPasswordFormsSeen(const std::vector<PasswordForm>& forms);
- void OnMsgAutofillFormSubmitted(const AutofillForm& forms);
+ void OnMsgAutofillFormSubmitted(const webkit_glue::AutofillForm& forms);
void OnMsgStartDragging(const WebDropData& drop_data);
void OnUpdateDragCursor(bool is_drop_target);
void OnTakeFocus(bool reverse);
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h
index 0626b5e..52a72c7 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.h
+++ b/chrome/browser/renderer_host/render_view_host_delegate.h
@@ -21,7 +21,6 @@
#include "chrome/browser/extensions/extension_function_dispatcher.h"
-class AutofillForm;
class ExtensionFunctionDispatcher;
class NavigationEntry;
class Profile;
@@ -45,6 +44,7 @@ class Message;
}
namespace webkit_glue {
+class AutofillForm;
struct WebApplicationInfo;
}
@@ -329,7 +329,7 @@ class RenderViewHostDelegate {
virtual void PasswordFormsSeen(const std::vector<PasswordForm>& forms) { }
// Forms fillable by autofill have been detected in the page.
- virtual void AutofillFormSubmitted(const AutofillForm& form) { }
+ 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
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 06ffba6..0ccd724 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -1960,7 +1960,7 @@ void TabContents::PasswordFormsSeen(
}
void TabContents::AutofillFormSubmitted(
- const AutofillForm& form) {
+ const webkit_glue::AutofillForm& form) {
GetAutofillManager()->AutofillFormSubmitted(form);
}
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index c496b51..d57f221 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -48,20 +48,24 @@ namespace gfx {
class Rect;
class Size;
}
+
namespace views {
class WindowDelegate;
}
+
namespace base {
class WaitableEvent;
}
+
namespace webkit_glue {
+class AutofillForm;
struct WebApplicationInfo;
}
+
namespace IPC {
class Message;
}
-class AutofillForm;
class AutofillManager;
class BlockedPopupContainer;
class DOMUI;
@@ -801,7 +805,7 @@ class TabContents : public PageNavigator,
const std::string& json_arguments,
IPC::Message* reply_msg);
virtual void PasswordFormsSeen(const std::vector<PasswordForm>& forms);
- virtual void AutofillFormSubmitted(const AutofillForm& form);
+ 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,
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc
index e514847..7dbf1eb 100644
--- a/chrome/browser/webdata/web_data_service.cc
+++ b/chrome/browser/webdata/web_data_service.cc
@@ -19,6 +19,7 @@
////////////////////////////////////////////////////////////////////////////////
using base::Time;
+using webkit_glue::AutofillForm;
WebDataService::WebDataService() : thread_(NULL),
db_(NULL),
diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h
index 4c38e1b..212e958 100644
--- a/chrome/browser/webdata/web_data_service.h
+++ b/chrome/browser/webdata/web_data_service.h
@@ -368,7 +368,7 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> {
// Schedules a task to add form elements to the web database.
void AddAutofillFormElements(
- const std::vector<AutofillForm::Element>& elements);
+ const std::vector<webkit_glue::AutofillForm::Element>& elements);
// Initiates the request for a vector of values which have been entered in
// form input fields named |name|. The method OnWebDataServiceRequestDone of
@@ -457,7 +457,7 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> {
//
//////////////////////////////////////////////////////////////////////////////
void AddAutofillFormElementsImpl(
- GenericRequest<std::vector<AutofillForm::Element> >* request);
+ GenericRequest<std::vector<webkit_glue::AutofillForm::Element> >* request);
void GetFormValuesForElementNameImpl(WebDataRequest* request,
const std::wstring& name, const std::wstring& prefix, int limit);
void RemoveFormElementsAddedBetweenImpl(
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index e6a1731..8914906 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -94,6 +94,7 @@
////////////////////////////////////////////////////////////////////////////////
using base::Time;
+using webkit_glue::AutofillForm;
// Current version number.
static const int kCurrentVersionNumber = 22;
diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h
index 3b5197b..c4d0d23 100644
--- a/chrome/browser/webdata/web_database.h
+++ b/chrome/browser/webdata/web_database.h
@@ -127,10 +127,11 @@ class WebDatabase {
// Records the form elements in |elements| in the database in the autofill
// table.
bool AddAutofillFormElements(
- const std::vector<AutofillForm::Element>& elements);
+ const std::vector<webkit_glue::AutofillForm::Element>& elements);
// Records a single form element in in the database in the autofill table.
- bool AddAutofillFormElement(const AutofillForm::Element& element);
+ bool AddAutofillFormElement(
+ const webkit_glue::AutofillForm::Element& element);
// Retrieves a vector of all values which have been recorded in the autofill
// table as the value in a form element with name |name| and which start with
@@ -160,9 +161,10 @@ class WebDatabase {
// Gets the pair_id and count entries from name and value specified in
// |element|. Sets *count to 0 if there is no such row in the table.
- bool GetIDAndCountOfFormElement(const AutofillForm::Element& element,
- int64* pair_id,
- int* count) const;
+ bool GetIDAndCountOfFormElement(
+ const webkit_glue::AutofillForm::Element& element,
+ int64* pair_id,
+ int* count) const;
// Gets the count only given the pair_id.
bool GetCountOfFormElement(int64 pair_id,
@@ -173,7 +175,9 @@ class WebDatabase {
// Adds a new row to the autofill table with name and value given in
// |element|. Sets *pair_id to the pair_id of the new row.
- bool InsertFormElement(const AutofillForm::Element& element, int64* pair_id);
+ bool InsertFormElement(
+ const webkit_glue::AutofillForm::Element& element,
+ int64* pair_id);
// Adds a new row to the autofill_dates table.
bool InsertPairIDAndDate(int64 pair_id, const base::Time date_created);
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc
index 4c27b1e..a456f91 100644
--- a/chrome/browser/webdata/web_database_unittest.cc
+++ b/chrome/browser/webdata/web_database_unittest.cc
@@ -18,6 +18,7 @@
using base::Time;
using base::TimeDelta;
+using webkit_glue::AutofillForm;
class WebDatabaseTest : public testing::Test {
protected:
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 63f210f..9ccce61 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -704,11 +704,11 @@ struct ParamTraits<PasswordForm> {
// Traits for AutofillForm_Params structure to pack/unpack.
template <>
-struct ParamTraits<AutofillForm> {
- typedef AutofillForm param_type;
+struct ParamTraits<webkit_glue::AutofillForm> {
+ typedef webkit_glue::AutofillForm param_type;
static void Write(Message* m, const param_type& p) {
WriteParam(m, p.elements.size());
- for (std::vector<AutofillForm::Element>::const_iterator itr =
+ for (std::vector<webkit_glue::AutofillForm::Element>::const_iterator itr =
p.elements.begin();
itr != p.elements.end();
itr++) {
@@ -1127,10 +1127,10 @@ struct ParamTraits<scoped_refptr<net::UploadData> > {
}
};
-// Traits for PasswordFormDomManager::FillData.
+// Traits for webkit_glue::PasswordFormDomManager::FillData.
template <>
-struct ParamTraits<PasswordFormDomManager::FillData> {
- typedef PasswordFormDomManager::FillData param_type;
+struct ParamTraits<webkit_glue::PasswordFormDomManager::FillData> {
+ typedef webkit_glue::PasswordFormDomManager::FillData param_type;
static void Write(Message* m, const param_type& p) {
WriteParam(m, p.basic_data);
WriteParam(m, p.additional_logins);
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 2ff6eec..16d5fb9 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -293,7 +293,7 @@ IPC_BEGIN_MESSAGES(View)
// Fill a password form and prepare field autocomplete for multiple
// matching logins.
IPC_MESSAGE_ROUTED1(ViewMsg_FillPasswordForm,
- PasswordFormDomManager::FillData /* form_data */)
+ webkit_glue::PasswordFormDomManager::FillData)
// D&d drop target messages.
IPC_MESSAGE_ROUTED3(ViewMsg_DragTargetDragEnter,
@@ -988,7 +988,7 @@ IPC_BEGIN_MESSAGES(ViewHost)
// Notification that a form has been submitted. The user hit the button.
IPC_MESSAGE_ROUTED1(ViewHostMsg_AutofillFormSubmitted,
- AutofillForm /* form */)
+ webkit_glue::AutofillForm /* form */)
// Used to tell the parent the user started dragging in the content area. The
// WebDropData struct contains contextual information about the pieces of the
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 7c26b73..3922941 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -54,6 +54,7 @@
#include "skia/ext/bitmap_platform_device.h"
#include "skia/ext/image_operations.h"
#include "webkit/api/public/WebDragData.h"
+#include "webkit/api/public/WebForm.h"
#include "webkit/api/public/WebPoint.h"
#include "webkit/api/public/WebRect.h"
#include "webkit/api/public/WebScriptSource.h"
@@ -88,8 +89,12 @@
using base::Time;
using base::TimeDelta;
+using webkit_glue::AutofillForm;
+using webkit_glue::PasswordFormDomManager;
+using webkit_glue::SearchableFormData;
using WebKit::WebConsoleMessage;
using WebKit::WebDragData;
+using WebKit::WebForm;
using WebKit::WebRect;
using WebKit::WebScriptSource;
using WebKit::WebWorker;
@@ -139,13 +144,21 @@ static const char* const kBackForwardNavigationScheme = "history";
// Associated with browser-initiated navigations to hold tracking data.
class RenderView::NavigationState : public WebDataSource::ExtraData {
public:
- NavigationState(int32 pending_page_id,
- PageTransition::Type transition,
- Time request_time)
- : transition_type(transition),
- request_time(request_time),
- request_committed(false),
- pending_page_id_(pending_page_id) {
+ static NavigationState* CreateBrowserInitiated(
+ int32 pending_page_id,
+ PageTransition::Type transition_type,
+ Time request_time) {
+ return new NavigationState(transition_type, request_time, false,
+ pending_page_id);
+ }
+
+ static NavigationState* CreateContentInitiated() {
+ // We assume navigations initiated by content are link clicks.
+ return new NavigationState(PageTransition::LINK, Time(), true, -1);
+ }
+
+ static NavigationState* FromDataSource(WebDataSource* ds) {
+ return static_cast<NavigationState*>(ds->GetExtraData());
}
// Contains the page_id for this navigation or -1 if there is none yet.
@@ -156,17 +169,55 @@ class RenderView::NavigationState : public WebDataSource::ExtraData {
// Contains the transition type that the browser specified when it
// initiated the load.
- PageTransition::Type transition_type;
+ PageTransition::Type transition_type() const { return transition_type_; }
+ void set_transition_type(PageTransition::Type type) {
+ transition_type_ = type;
+ }
// The time that this navigation was requested.
- Time request_time;
+ const Time& request_time() const { return request_time_; }
// True if we have already processed the "DidCommitLoad" event for this
// request. Used by session history.
- bool request_committed;
+ bool request_committed() const { return request_committed_; }
+ void set_request_committed(bool value) { request_committed_ = value; }
+
+ // True if this navigation was not initiated via WebFrame::LoadRequest.
+ bool is_content_initiated() const { return is_content_initiated_; }
+
+ SearchableFormData* searchable_form_data() const {
+ return searchable_form_data_.get();
+ }
+ void set_searchable_form_data(SearchableFormData* data) {
+ searchable_form_data_.reset(data);
+ }
+
+ PasswordForm* password_form_data() const {
+ return password_form_data_.get();
+ }
+ void set_password_form_data(PasswordForm* data) {
+ password_form_data_.reset(data);
+ }
private:
+ NavigationState(PageTransition::Type transition_type,
+ const Time& request_time,
+ bool is_content_initiated,
+ int32 pending_page_id)
+ : transition_type_(transition_type),
+ request_time_(request_time),
+ request_committed_(false),
+ is_content_initiated_(is_content_initiated),
+ pending_page_id_(pending_page_id) {
+ }
+
+ PageTransition::Type transition_type_;
+ Time request_time_;
+ bool request_committed_;
+ bool is_content_initiated_;
int32 pending_page_id_;
+ scoped_ptr<SearchableFormData> searchable_form_data_;
+ scoped_ptr<PasswordForm> password_form_data_;
DISALLOW_COPY_AND_ASSIGN(NavigationState);
};
@@ -645,7 +696,7 @@ void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
// as a browser initiated event. Instead, we want it to look as if the page
// initiated any load resulting from JS execution.
if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
- pending_navigation_state_.reset(new NavigationState(
+ pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
params.page_id, params.transition, params.request_time));
}
@@ -841,9 +892,8 @@ void RenderView::UpdateURL(WebFrame* frame) {
const WebRequest& initial_request = ds->GetInitialRequest();
const WebResponse& response = ds->GetResponse();
- // This will be null if we did not initiate the navigation.
- NavigationState* navigation_state =
- static_cast<NavigationState*>(ds->GetExtraData());
+ NavigationState* navigation_state = NavigationState::FromDataSource(ds);
+ DCHECK(navigation_state);
ViewHostMsg_FrameNavigate_Params params;
params.http_status_code = response.GetHttpStatusCode();
@@ -872,7 +922,7 @@ void RenderView::UpdateURL(WebFrame* frame) {
params.should_update_history = !ds->HasUnreachableURL();
const SearchableFormData* searchable_form_data =
- frame->GetDataSource()->GetSearchableFormData();
+ navigation_state->searchable_form_data();
if (searchable_form_data) {
params.searchable_form_url = searchable_form_data->url();
params.searchable_form_element_name = searchable_form_data->element_name();
@@ -880,7 +930,7 @@ void RenderView::UpdateURL(WebFrame* frame) {
}
const PasswordForm* password_form_data =
- frame->GetDataSource()->GetPasswordFormData();
+ navigation_state->password_form_data();
if (password_form_data)
params.password_form = *password_form_data;
@@ -893,10 +943,7 @@ void RenderView::UpdateURL(WebFrame* frame) {
// Update contents MIME type for main frame.
params.contents_mime_type = ds->GetResponse().GetMimeType();
- // We assume top level navigations initiated by the renderer are link
- // clicks.
- params.transition = navigation_state ?
- navigation_state->transition_type : PageTransition::LINK;
+ params.transition = navigation_state->transition_type();
if (!PageTransition::IsMainFrame(params.transition)) {
// If the main frame does a load, it should not be reported as a subframe
// navigation. This can occur in the following case:
@@ -912,11 +959,6 @@ void RenderView::UpdateURL(WebFrame* frame) {
params.transition = PageTransition::LINK;
}
- if (params.transition == PageTransition::LINK &&
- frame->GetDataSource()->IsFormSubmit()) {
- params.transition = PageTransition::FORM_SUBMIT;
- }
-
// If we have a valid consumed client redirect source,
// the page contained a client redirect (meta refresh, document.loc...),
// so we set the referrer and transition to match.
@@ -954,9 +996,8 @@ void RenderView::UpdateURL(WebFrame* frame) {
std::max(last_page_id_sent_to_browser_, page_id_);
// If we end up reusing this WebRequest (for example, due to a #ref click),
- // we don't want the transition type to persist.
- if (navigation_state)
- navigation_state->transition_type = PageTransition::LINK; // Just clear it.
+ // we don't want the transition type to persist. Just clear it.
+ navigation_state->set_transition_type(PageTransition::LINK);
#if defined(OS_WIN)
if (web_accessibility_manager_.get()) {
@@ -1065,7 +1106,13 @@ void RenderView::DidStopLoading(WebView* webview) {
}
void RenderView::DidCreateDataSource(WebFrame* frame, WebDataSource* ds) {
- ds->SetExtraData(pending_navigation_state_.release());
+ // The rest of RenderView assumes that a WebDataSource will always have a
+ // non-null NavigationState.
+ if (pending_navigation_state_.get()) {
+ ds->SetExtraData(pending_navigation_state_.release());
+ } else {
+ ds->SetExtraData(NavigationState::CreateContentInitiated());
+ }
}
void RenderView::DidStartProvisionalLoadForFrame(
@@ -1079,13 +1126,14 @@ void RenderView::DidStartProvisionalLoadForFrame(
completed_client_redirect_src_ = GURL();
}
+ // We may have better knowledge of when this navigation was requested.
WebDataSource* ds = frame->GetProvisionalDataSource();
if (ds) {
- NavigationState* navigation_state =
- static_cast<NavigationState*>(ds->GetExtraData());
- if (navigation_state)
- ds->SetRequestTime(navigation_state->request_time);
+ NavigationState* navigation_state = NavigationState::FromDataSource(ds);
+ if (!navigation_state->request_time().is_null())
+ ds->SetRequestTime(navigation_state->request_time());
}
+
Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
routing_id_, webview->GetMainFrame() == frame,
frame->GetProvisionalDataSource()->GetRequest().GetURL()));
@@ -1156,9 +1204,7 @@ void RenderView::DidFailProvisionalLoadWithError(WebView* webview,
// 'replace' load. This is necessary to avoid messing up session history.
// Otherwise, we do a normal load, which simulates a 'go' navigation as far
// as session history is concerned.
- NavigationState* navigation_state =
- static_cast<NavigationState*>(ds->GetExtraData());
- bool replace = navigation_state && !navigation_state->is_new_navigation();
+ bool replace = !NavigationState::FromDataSource(ds)->is_new_navigation();
// Use the alternate error page service if this is a DNS failure or
// connection failure. ERR_CONNECTION_FAILED can be dropped once we no longer
@@ -1225,8 +1271,8 @@ void RenderView::LoadNavigationErrorPage(WebFrame* frame,
void RenderView::DidCommitLoadForFrame(WebView *webview, WebFrame* frame,
bool is_new_navigation) {
- NavigationState* navigation_state = static_cast<NavigationState*>(
- frame->GetDataSource()->GetExtraData());
+ NavigationState* navigation_state =
+ NavigationState::FromDataSource(frame->GetDataSource());
if (is_new_navigation) {
// When we perform a new navigation, we need to update the previous session
@@ -1251,8 +1297,8 @@ void RenderView::DidCommitLoadForFrame(WebView *webview, WebFrame* frame,
// Note that we need to check if the page ID changed. In the case of a
// reload, the page ID doesn't change, and UpdateSessionHistory gets the
// previous URL and the current page ID, which would be wrong.
- if (navigation_state && !navigation_state->is_new_navigation() &&
- !navigation_state->request_committed &&
+ if (!navigation_state->is_new_navigation() &&
+ !navigation_state->request_committed() &&
page_id_ != navigation_state->pending_page_id()) {
// This is a successful session history navigation!
UpdateSessionHistory(frame);
@@ -1265,8 +1311,7 @@ void RenderView::DidCommitLoadForFrame(WebView *webview, WebFrame* frame,
// a session history navigation, because if we attempted a session history
// navigation without valid HistoryItem state, WebCore will think it is a
// new navigation.
- if (navigation_state)
- navigation_state->request_committed = true;
+ navigation_state->set_request_committed(true);
UpdateURL(frame);
@@ -1304,6 +1349,10 @@ void RenderView::DidFinishDocumentLoadForFrame(WebView* webview,
WebFrame* frame) {
Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
+ // The document has now been fully loaded. Scan for password forms to be
+ // sent up to the browser.
+ SendPasswordForms(frame);
+
// Check whether we have new encoding name.
UpdateEncoding(frame, webview->GetMainFrameEncodingName());
@@ -1323,9 +1372,10 @@ void RenderView::DidChangeLocationWithinPageForFrame(WebView* webview,
// could end up having a non-null pending navigation state. We just need to
// update the ExtraData on the datasource so that others who read the
// ExtraData will get the new NavigationState. Similarly, if we did not
- // initiate this navigation, then we need to take care to clear any pre-
- // existing navigation state.
- frame->GetDataSource()->SetExtraData(pending_navigation_state_.release());
+ // initiate this navigation, then we need to take care to reset any pre-
+ // existing navigation state to a content-initiated navigation state.
+ // DidCreateDataSource conveniently takes care of this for us.
+ DidCreateDataSource(frame, frame->GetDataSource());
DidCommitLoadForFrame(webview, frame, is_new_navigation);
@@ -1334,25 +1384,6 @@ void RenderView::DidChangeLocationWithinPageForFrame(WebView* webview,
UpdateTitle(frame, UTF16ToWideHack(title));
}
-void RenderView::DidReceiveIconForFrame(WebView* webview,
- WebFrame* frame) {
-}
-
-void RenderView::WillPerformClientRedirect(WebView* webview,
- WebFrame* frame,
- const GURL& src_url,
- const GURL& dest_url,
- unsigned int delay_seconds,
- unsigned int fire_date) {
-}
-
-void RenderView::DidCancelClientRedirect(WebView* webview,
- WebFrame* frame) {
-}
-
-void RenderView::WillCloseFrame(WebView* view, WebFrame* frame) {
-}
-
void RenderView::DidCompleteClientRedirect(WebView* webview,
WebFrame* frame,
const GURL& source) {
@@ -1360,6 +1391,27 @@ void RenderView::DidCompleteClientRedirect(WebView* webview,
completed_client_redirect_src_ = source;
}
+void RenderView::WillSubmitForm(WebView* webview, WebFrame* frame,
+ const WebForm& form) {
+ NavigationState* navigation_state =
+ NavigationState::FromDataSource(frame->GetProvisionalDataSource());
+
+ if (navigation_state->transition_type() == PageTransition::LINK)
+ navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
+
+ // Save these to be processed when the ensuing navigation is committed.
+ navigation_state->set_searchable_form_data(
+ SearchableFormData::Create(form));
+ navigation_state->set_password_form_data(
+ PasswordFormDomManager::CreatePasswordForm(form));
+
+ if (form.isAutoCompleteEnabled()) {
+ scoped_ptr<AutofillForm> autofill_form(AutofillForm::Create(form));
+ if (autofill_form.get())
+ Send(new ViewHostMsg_AutofillFormSubmitted(routing_id_, *autofill_form));
+ }
+}
+
void RenderView::WillSendRequest(WebView* webview,
uint32 identifier,
WebRequest* request) {
@@ -1414,11 +1466,11 @@ WindowOpenDisposition RenderView::DispositionForNavigationAction(
WebNavigationType type,
WindowOpenDisposition disposition,
bool is_redirect) {
- // GetExtraData is NULL when we did not issue the request ourselves (see
- // OnNavigate), and so such a request may correspond to a link-click,
- // script, or drag-n-drop initiated navigation.
+ // A content initiated navigation may have originated from a link-click,
+ // script, drag-n-drop operation, etc.
bool is_content_initiated =
- !frame->GetProvisionalDataSource()->GetExtraData();
+ NavigationState::FromDataSource(frame->GetProvisionalDataSource())->
+ is_content_initiated();
// Webkit is asking whether to navigate to a new URL.
// This is fine normally, except if we're showing UI from one security
@@ -2262,16 +2314,6 @@ void RenderView::OnSetPageEncoding(const std::wstring& encoding_name) {
webview()->SetPageEncoding(encoding_name);
}
-void RenderView::OnPasswordFormsSeen(WebView* webview,
- const std::vector<PasswordForm>& forms) {
- Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, forms));
-}
-
-void RenderView::OnAutofillFormSubmitted(WebView* webview,
- const AutofillForm& form) {
- Send(new ViewHostMsg_AutofillFormSubmitted(routing_id_, form));
-}
-
void RenderView::NavigateBackForwardSoon(int offset) {
history_back_list_count_ += offset;
history_forward_list_count_ -= offset;
@@ -2472,7 +2514,7 @@ void RenderView::OnFormFill(const FormData& form) {
}
void RenderView::OnFillPasswordForm(
- const PasswordFormDomManager::FillData& form_data) {
+ const webkit_glue::PasswordFormDomManager::FillData& form_data) {
webkit_glue::FillPasswordForm(this->webview(), form_data);
}
@@ -2679,11 +2721,8 @@ void RenderView::DidAddHistoryItem() {
WebDataSource* ds = main_frame->GetDataSource();
DCHECK(ds != NULL);
- NavigationState* navigation_state =
- static_cast<NavigationState*>(ds->GetExtraData());
-
- if (navigation_state &&
- navigation_state->transition_type == PageTransition::START_PAGE)
+ NavigationState* navigation_state = NavigationState::FromDataSource(ds);
+ if (navigation_state->transition_type() == PageTransition::START_PAGE)
return;
history_back_list_count_++;
@@ -2852,3 +2891,24 @@ void RenderView::FocusAccessibilityObject(
NOTIMPLEMENTED();
#endif
}
+
+void RenderView::SendPasswordForms(WebFrame* frame) {
+ std::vector<WebForm> forms;
+ frame->GetForms(&forms);
+
+ std::vector<PasswordForm> password_forms;
+ for (size_t i = 0; i < forms.size(); ++i) {
+ const WebForm& form = forms[i];
+
+ // Respect autocomplete=off.
+ if (form.isAutoCompleteEnabled()) {
+ scoped_ptr<PasswordForm> password_form(
+ PasswordFormDomManager::CreatePasswordForm(form));
+ if (password_form.get())
+ password_forms.push_back(*password_form);
+ }
+ }
+
+ if (!password_forms.empty())
+ Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
+}
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 237b79c..f1108eb 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -207,23 +207,15 @@ class RenderView : public RenderWidget,
virtual void DidChangeLocationWithinPageForFrame(WebView* webview,
WebFrame* frame,
bool is_new_navigation);
- virtual void DidReceiveIconForFrame(WebView* webview, WebFrame* frame);
virtual void DidContentsSizeChange(WebWidget* webwidget,
int new_width,
int new_height);
- virtual void WillPerformClientRedirect(WebView* webview,
- WebFrame* frame,
- const GURL& src_url,
- const GURL& dest_url,
- unsigned int delay_seconds,
- unsigned int fire_date);
- virtual void DidCancelClientRedirect(WebView* webview,
- WebFrame* frame);
virtual void DidCompleteClientRedirect(WebView* webview,
WebFrame* frame,
const GURL& source);
- virtual void WillCloseFrame(WebView* webview, WebFrame* frame);
+ virtual void WillSubmitForm(WebView* webview, WebFrame* frame,
+ const WebKit::WebForm& form);
virtual void WillSendRequest(WebView* webview,
uint32 identifier,
WebRequest* request);
@@ -300,12 +292,6 @@ class RenderView : public RenderWidget,
virtual void PasteFromSelectionClipboard();
- virtual void OnPasswordFormsSeen(WebView* webview,
- const std::vector<PasswordForm>& forms);
-
- virtual void OnAutofillFormSubmitted(WebView* webview,
- const AutofillForm& form);
-
virtual void ReportFindInPageMatchCount(int count, int request_id,
bool final_update);
virtual void ReportFindInPageSelection(int request_id,
@@ -506,7 +492,8 @@ class RenderView : public RenderWidget,
const FilePath& local_directory_name);
void OnUploadFileRequest(const ViewMsg_UploadFile_Params& p);
void OnFormFill(const FormData& form);
- void OnFillPasswordForm(const PasswordFormDomManager::FillData& form_data);
+ void OnFillPasswordForm(
+ const webkit_glue::PasswordFormDomManager::FillData& form_data);
void OnDragTargetDragEnter(const WebDropData& drop_data,
const gfx::Point& client_pt,
const gfx::Point& screen_pt);
@@ -620,6 +607,9 @@ class RenderView : public RenderWidget,
void DumpLoadHistograms() const;
+ // Scan the given frame for password forms and send them up to the browser.
+ void SendPasswordForms(WebFrame* frame);
+
// Bitwise-ORed set of extra bindings that have been enabled. See
// BindingsPolicy for details.
int enabled_bindings_;