Commit 4f869257 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Store web_frame id in autofillDriver

Due to crbug.com/892612, the AutofillDriver can live
longer than the webFrame.
As a consequence, it is not possible to store the
frame pointer and the WebFrame must be retrieved using
the frame ID before each use.

Bug: 935003
Change-Id: I5462907be5d7d2f70900c135af16ac3e774fae16
Reviewed-on: https://chromium-review.googlesource.com/c/1488791Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636051}
parent 849f0634
......@@ -713,9 +713,11 @@ TEST_F(AutofillAgentTests, FrameInitializationOrderFrames) {
test_web_state_.RemoveWebFrame(fake_main_frame_->GetFrameId());
// Both frames available, then page loaded.
test_web_state_.SetLoading(true);
auto main_frame_unique =
std::make_unique<web::FakeWebFrame>("main", true, GURL());
web::FakeWebFrame* main_frame = main_frame_unique.get();
test_web_state_.AddWebFrame(std::move(main_frame_unique));
autofill::AutofillDriverIOS* main_frame_driver =
autofill::AutofillDriverIOS::FromWebStateAndWebFrame(&test_web_state_,
main_frame);
......@@ -725,13 +727,11 @@ TEST_F(AutofillAgentTests, FrameInitializationOrderFrames) {
EXPECT_TRUE(main_frame_driver->is_processed());
});
FakeWebFrameCallback* iframe = iframe_unique.get();
test_web_state_.AddWebFrame(std::move(iframe_unique));
autofill::AutofillDriverIOS* iframe_driver =
autofill::AutofillDriverIOS::FromWebStateAndWebFrame(&test_web_state_,
iframe);
EXPECT_FALSE(iframe_driver->IsInMainFrame());
test_web_state_.SetLoading(true);
test_web_state_.AddWebFrame(std::move(main_frame_unique));
test_web_state_.AddWebFrame(std::move(iframe_unique));
EXPECT_FALSE(main_frame_driver->is_processed());
EXPECT_FALSE(iframe_driver->is_processed());
test_web_state_.SetLoading(false);
......
......@@ -80,9 +80,9 @@ class AutofillDriverIOS : public AutofillDriver {
// The WebState with which this object is associated.
web::WebState* web_state_ = nullptr;
// The WebState with which this object is associated.
// nullptr if frame messaging is disabled.
web::WebFrame* web_frame_ = nullptr;
// The id of the WebFrame with which this object is associated.
// "" if frame messaging is disabled.
std::string web_frame_id_;
// AutofillDriverIOSBridge instance that is passed in.
__unsafe_unretained id<AutofillDriverIOSBridge> bridge_;
......
......@@ -12,6 +12,7 @@
#include "components/autofill/ios/browser/autofill_switches.h"
#include "ios/web/public/browser_state.h"
#import "ios/web/public/origin_util.h"
#import "ios/web/public/web_state/web_frame_util.h"
#import "ios/web/public/web_state/web_state.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
......@@ -63,10 +64,10 @@ AutofillDriverIOS::AutofillDriverIOS(
const std::string& app_locale,
AutofillManager::AutofillDownloadManagerState enable_download_manager)
: web_state_(web_state),
web_frame_(web_frame),
bridge_(bridge),
autofill_manager_(this, client, app_locale, enable_download_manager),
autofill_external_delegate_(&autofill_manager_, this) {
web_frame_id_ = web::GetWebFrameId(web_frame);
autofill_manager_.SetExternalDelegate(&autofill_external_delegate_);
}
......@@ -77,7 +78,8 @@ bool AutofillDriverIOS::IsIncognito() const {
}
bool AutofillDriverIOS::IsInMainFrame() const {
return web_frame_ ? web_frame_->IsMainFrame() : true;
web::WebFrame* web_frame = web::GetWebFrameWithId(web_state_, web_frame_id_);
return web_frame ? web_frame->IsMainFrame() : true;
}
net::URLRequestContextGetter* AutofillDriverIOS::GetURLRequestContext() {
......@@ -98,7 +100,8 @@ void AutofillDriverIOS::SendFormDataToRenderer(
int query_id,
RendererFormDataAction action,
const FormData& data) {
[bridge_ fillFormData:data inFrame:web_frame_];
web::WebFrame* web_frame = web::GetWebFrameWithId(web_state_, web_frame_id_);
[bridge_ fillFormData:data inFrame:web_frame];
}
void AutofillDriverIOS::PropagateAutofillPredictions(
......@@ -108,8 +111,9 @@ void AutofillDriverIOS::PropagateAutofillPredictions(
void AutofillDriverIOS::SendAutofillTypePredictionsToRenderer(
const std::vector<FormStructure*>& forms) {
web::WebFrame* web_frame = web::GetWebFrameWithId(web_state_, web_frame_id_);
[bridge_ fillFormDataPredictions:FormStructure::GetFieldTypePredictions(forms)
inFrame:web_frame_];
inFrame:web_frame];
}
void AutofillDriverIOS::RendererShouldAcceptDataListSuggestion(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment