| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // Searches for an |AutofillMsg_FillForm| message in the queue of sent IPC | 84 // Searches for an |AutofillMsg_FillForm| message in the queue of sent IPC |
| 85 // messages. If none is present, returns false. Otherwise, extracts the first | 85 // messages. If none is present, returns false. Otherwise, extracts the first |
| 86 // |AutofillMsg_FillForm| message, fills the output parameters with the values | 86 // |AutofillMsg_FillForm| message, fills the output parameters with the values |
| 87 // of the message's parameters, and clears the queue of sent messages. | 87 // of the message's parameters, and clears the queue of sent messages. |
| 88 bool GetAutofillFillFormMessage(int* page_id, FormData* results) { | 88 bool GetAutofillFillFormMessage(int* page_id, FormData* results) { |
| 89 const uint32 kMsgID = AutofillMsg_FillForm::ID; | 89 const uint32 kMsgID = AutofillMsg_FillForm::ID; |
| 90 const IPC::Message* message = | 90 const IPC::Message* message = |
| 91 process()->sink().GetFirstMessageMatching(kMsgID); | 91 process()->sink().GetFirstMessageMatching(kMsgID); |
| 92 if (!message) | 92 if (!message) |
| 93 return false; | 93 return false; |
| 94 Tuple2<int, FormData> autofill_param; | 94 Tuple<int, FormData> autofill_param; |
| 95 if (!AutofillMsg_FillForm::Read(message, &autofill_param)) | 95 if (!AutofillMsg_FillForm::Read(message, &autofill_param)) |
| 96 return false; | 96 return false; |
| 97 if (page_id) | 97 if (page_id) |
| 98 *page_id = autofill_param.a; | 98 *page_id = get<0>(autofill_param); |
| 99 if (results) | 99 if (results) |
| 100 *results = autofill_param.b; | 100 *results = get<1>(autofill_param); |
| 101 process()->sink().ClearMessages(); | 101 process()->sink().ClearMessages(); |
| 102 return true; | 102 return true; |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Searches for an |AutofillMsg_PreviewForm| message in the queue of sent IPC | 105 // Searches for an |AutofillMsg_PreviewForm| message in the queue of sent IPC |
| 106 // messages. If none is present, returns false. Otherwise, extracts the first | 106 // messages. If none is present, returns false. Otherwise, extracts the first |
| 107 // |AutofillMsg_PreviewForm| message, fills the output parameters with the | 107 // |AutofillMsg_PreviewForm| message, fills the output parameters with the |
| 108 // values of the message's parameters, and clears the queue of sent messages. | 108 // values of the message's parameters, and clears the queue of sent messages. |
| 109 bool GetAutofillPreviewFormMessage(int* page_id, FormData* results) { | 109 bool GetAutofillPreviewFormMessage(int* page_id, FormData* results) { |
| 110 const uint32 kMsgID = AutofillMsg_PreviewForm::ID; | 110 const uint32 kMsgID = AutofillMsg_PreviewForm::ID; |
| 111 const IPC::Message* message = | 111 const IPC::Message* message = |
| 112 process()->sink().GetFirstMessageMatching(kMsgID); | 112 process()->sink().GetFirstMessageMatching(kMsgID); |
| 113 if (!message) | 113 if (!message) |
| 114 return false; | 114 return false; |
| 115 Tuple2<int, FormData> autofill_param; | 115 Tuple<int, FormData> autofill_param; |
| 116 if (!AutofillMsg_PreviewForm::Read(message, &autofill_param)) | 116 if (!AutofillMsg_PreviewForm::Read(message, &autofill_param)) |
| 117 return false; | 117 return false; |
| 118 if (page_id) | 118 if (page_id) |
| 119 *page_id = autofill_param.a; | 119 *page_id = get<0>(autofill_param); |
| 120 if (results) | 120 if (results) |
| 121 *results = autofill_param.b; | 121 *results = get<1>(autofill_param); |
| 122 process()->sink().ClearMessages(); | 122 process()->sink().ClearMessages(); |
| 123 return true; | 123 return true; |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Searches for an |AutofillMsg_FieldTypePredictionsAvailable| message in the | 126 // Searches for an |AutofillMsg_FieldTypePredictionsAvailable| message in the |
| 127 // queue of sent IPC messages. If none is present, returns false. Otherwise, | 127 // queue of sent IPC messages. If none is present, returns false. Otherwise, |
| 128 // extracts the first |AutofillMsg_FieldTypePredictionsAvailable| message, | 128 // extracts the first |AutofillMsg_FieldTypePredictionsAvailable| message, |
| 129 // fills the output parameter with the values of the message's parameter, and | 129 // fills the output parameter with the values of the message's parameter, and |
| 130 // clears the queue of sent messages. | 130 // clears the queue of sent messages. |
| 131 bool GetFieldTypePredictionsAvailable( | 131 bool GetFieldTypePredictionsAvailable( |
| 132 std::vector<FormDataPredictions>* predictions) { | 132 std::vector<FormDataPredictions>* predictions) { |
| 133 const uint32 kMsgID = AutofillMsg_FieldTypePredictionsAvailable::ID; | 133 const uint32 kMsgID = AutofillMsg_FieldTypePredictionsAvailable::ID; |
| 134 const IPC::Message* message = | 134 const IPC::Message* message = |
| 135 process()->sink().GetFirstMessageMatching(kMsgID); | 135 process()->sink().GetFirstMessageMatching(kMsgID); |
| 136 if (!message) | 136 if (!message) |
| 137 return false; | 137 return false; |
| 138 Tuple1<std::vector<FormDataPredictions> > autofill_param; | 138 Tuple<std::vector<FormDataPredictions> > autofill_param; |
| 139 if (!AutofillMsg_FieldTypePredictionsAvailable::Read(message, | 139 if (!AutofillMsg_FieldTypePredictionsAvailable::Read(message, |
| 140 &autofill_param)) | 140 &autofill_param)) |
| 141 return false; | 141 return false; |
| 142 if (predictions) | 142 if (predictions) |
| 143 *predictions = autofill_param.a; | 143 *predictions = get<0>(autofill_param); |
| 144 | 144 |
| 145 process()->sink().ClearMessages(); | 145 process()->sink().ClearMessages(); |
| 146 return true; | 146 return true; |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Searches for a message matching |messageID| in the queue of sent IPC | 149 // Searches for a message matching |messageID| in the queue of sent IPC |
| 150 // messages. If none is present, returns false. Otherwise, extracts the first | 150 // messages. If none is present, returns false. Otherwise, extracts the first |
| 151 // matching message, fills the output parameter with the string16 from the | 151 // matching message, fills the output parameter with the string16 from the |
| 152 // message's parameter, and clears the queue of sent messages. | 152 // message's parameter, and clears the queue of sent messages. |
| 153 bool GetString16FromMessageWithID(uint32 messageID, base::string16* value) { | 153 bool GetString16FromMessageWithID(uint32 messageID, base::string16* value) { |
| 154 const IPC::Message* message = | 154 const IPC::Message* message = |
| 155 process()->sink().GetFirstMessageMatching(messageID); | 155 process()->sink().GetFirstMessageMatching(messageID); |
| 156 if (!message) | 156 if (!message) |
| 157 return false; | 157 return false; |
| 158 Tuple1<base::string16> autofill_param; | 158 Tuple<base::string16> autofill_param; |
| 159 switch (messageID) { | 159 switch (messageID) { |
| 160 case AutofillMsg_FillFieldWithValue::ID: | 160 case AutofillMsg_FillFieldWithValue::ID: |
| 161 if (!AutofillMsg_FillFieldWithValue::Read(message, &autofill_param)) | 161 if (!AutofillMsg_FillFieldWithValue::Read(message, &autofill_param)) |
| 162 return false; | 162 return false; |
| 163 break; | 163 break; |
| 164 case AutofillMsg_PreviewFieldWithValue::ID: | 164 case AutofillMsg_PreviewFieldWithValue::ID: |
| 165 if (!AutofillMsg_PreviewFieldWithValue::Read(message, &autofill_param)) | 165 if (!AutofillMsg_PreviewFieldWithValue::Read(message, &autofill_param)) |
| 166 return false; | 166 return false; |
| 167 break; | 167 break; |
| 168 case AutofillMsg_AcceptDataListSuggestion::ID: | 168 case AutofillMsg_AcceptDataListSuggestion::ID: |
| 169 if (!AutofillMsg_AcceptDataListSuggestion::Read(message, | 169 if (!AutofillMsg_AcceptDataListSuggestion::Read(message, |
| 170 &autofill_param)) | 170 &autofill_param)) |
| 171 return false; | 171 return false; |
| 172 break; | 172 break; |
| 173 default: | 173 default: |
| 174 NOTREACHED(); | 174 NOTREACHED(); |
| 175 } | 175 } |
| 176 if (value) | 176 if (value) |
| 177 *value = autofill_param.a; | 177 *value = get<0>(autofill_param); |
| 178 process()->sink().ClearMessages(); | 178 process()->sink().ClearMessages(); |
| 179 return true; | 179 return true; |
| 180 } | 180 } |
| 181 | 181 |
| 182 // Searches for a message matching |messageID| in the queue of sent IPC | 182 // Searches for a message matching |messageID| in the queue of sent IPC |
| 183 // messages. If none is present, returns false. Otherwise, clears the queue | 183 // messages. If none is present, returns false. Otherwise, clears the queue |
| 184 // of sent messages and returns true. | 184 // of sent messages and returns true. |
| 185 bool HasMessageMatchingID(uint32 messageID) { | 185 bool HasMessageMatchingID(uint32 messageID) { |
| 186 const IPC::Message* message = | 186 const IPC::Message* message = |
| 187 process()->sink().GetFirstMessageMatching(messageID); | 187 process()->sink().GetFirstMessageMatching(messageID); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 base::string16 input_value(base::ASCIIToUTF16("barqux")); | 314 base::string16 input_value(base::ASCIIToUTF16("barqux")); |
| 315 base::string16 output_value; | 315 base::string16 output_value; |
| 316 driver_->RendererShouldPreviewFieldWithValue(input_value); | 316 driver_->RendererShouldPreviewFieldWithValue(input_value); |
| 317 EXPECT_TRUE(GetString16FromMessageWithID( | 317 EXPECT_TRUE(GetString16FromMessageWithID( |
| 318 AutofillMsg_PreviewFieldWithValue::ID, | 318 AutofillMsg_PreviewFieldWithValue::ID, |
| 319 &output_value)); | 319 &output_value)); |
| 320 EXPECT_EQ(input_value, output_value); | 320 EXPECT_EQ(input_value, output_value); |
| 321 } | 321 } |
| 322 | 322 |
| 323 } // namespace autofill | 323 } // namespace autofill |
| OLD | NEW |