| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/automation/automation_provider_observers.h" | 5 #include "chrome/browser/automation/automation_provider_observers.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 2224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2235 } | 2235 } |
| 2236 } | 2236 } |
| 2237 } else if (type == chrome::NOTIFICATION_BROWSER_WINDOW_READY) { | 2237 } else if (type == chrome::NOTIFICATION_BROWSER_WINDOW_READY) { |
| 2238 new_window_id_ = ExtensionTabUtil::GetWindowId( | 2238 new_window_id_ = ExtensionTabUtil::GetWindowId( |
| 2239 content::Source<Browser>(source).ptr()); | 2239 content::Source<Browser>(source).ptr()); |
| 2240 } else { | 2240 } else { |
| 2241 NOTREACHED(); | 2241 NOTREACHED(); |
| 2242 } | 2242 } |
| 2243 } | 2243 } |
| 2244 | 2244 |
| 2245 AutofillDisplayedObserver::AutofillDisplayedObserver( | |
| 2246 int notification, | |
| 2247 RenderViewHost* render_view_host, | |
| 2248 AutomationProvider* automation, | |
| 2249 IPC::Message* reply_message) | |
| 2250 : notification_(notification), | |
| 2251 render_view_host_(render_view_host), | |
| 2252 automation_(automation->AsWeakPtr()), | |
| 2253 reply_message_(reply_message) { | |
| 2254 content::Source<RenderViewHost> source(render_view_host_); | |
| 2255 registrar_.Add(this, notification_, source); | |
| 2256 } | |
| 2257 | |
| 2258 AutofillDisplayedObserver::~AutofillDisplayedObserver() {} | |
| 2259 | |
| 2260 void AutofillDisplayedObserver::Observe( | |
| 2261 int type, | |
| 2262 const content::NotificationSource& source, | |
| 2263 const content::NotificationDetails& details) { | |
| 2264 DCHECK_EQ(type, notification_); | |
| 2265 DCHECK_EQ(content::Source<RenderViewHost>(source).ptr(), render_view_host_); | |
| 2266 if (automation_) { | |
| 2267 AutomationJSONReply(automation_, | |
| 2268 reply_message_.release()).SendSuccess(NULL); | |
| 2269 } | |
| 2270 delete this; | |
| 2271 } | |
| 2272 | |
| 2273 AutofillChangedObserver::AutofillChangedObserver( | |
| 2274 AutomationProvider* automation, | |
| 2275 IPC::Message* reply_message, | |
| 2276 int num_profiles, | |
| 2277 int num_credit_cards) | |
| 2278 : automation_(automation->AsWeakPtr()), | |
| 2279 reply_message_(reply_message), | |
| 2280 num_profiles_(num_profiles), | |
| 2281 num_credit_cards_(num_credit_cards), | |
| 2282 done_event_(false, false) { | |
| 2283 DCHECK(num_profiles_ >= 0 && num_credit_cards_ >= 0); | |
| 2284 AddRef(); | |
| 2285 } | |
| 2286 | |
| 2287 AutofillChangedObserver::~AutofillChangedObserver() { | |
| 2288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 2289 } | |
| 2290 | |
| 2291 void AutofillChangedObserver::Init() { | |
| 2292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 2293 BrowserThread::PostTask( | |
| 2294 BrowserThread::DB, | |
| 2295 FROM_HERE, | |
| 2296 base::Bind(&AutofillChangedObserver::RegisterObserversTask, this)); | |
| 2297 done_event_.Wait(); | |
| 2298 } | |
| 2299 | |
| 2300 void AutofillChangedObserver::RegisterObserversTask() { | |
| 2301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
| 2302 registrar_.reset(new content::NotificationRegistrar); | |
| 2303 registrar_->Add(this, chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | |
| 2304 content::NotificationService::AllSources()); | |
| 2305 registrar_->Add(this, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | |
| 2306 content::NotificationService::AllSources()); | |
| 2307 done_event_.Signal(); | |
| 2308 } | |
| 2309 | |
| 2310 void AutofillChangedObserver::Observe( | |
| 2311 int type, | |
| 2312 const content::NotificationSource& source, | |
| 2313 const content::NotificationDetails& details) { | |
| 2314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
| 2315 | |
| 2316 if (type == chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED) { | |
| 2317 num_credit_cards_--; | |
| 2318 } else if (type == chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED) { | |
| 2319 num_profiles_--; | |
| 2320 } else { | |
| 2321 NOTREACHED(); | |
| 2322 } | |
| 2323 | |
| 2324 if (num_profiles_ <= 0 && num_credit_cards_ <= 0) { | |
| 2325 registrar_.reset(); // Must be done from the DB thread. | |
| 2326 | |
| 2327 // Notify the UI thread that we're done listening for all relevant | |
| 2328 // autofill notifications. | |
| 2329 BrowserThread::PostTask( | |
| 2330 BrowserThread::UI, | |
| 2331 FROM_HERE, | |
| 2332 base::Bind(&AutofillChangedObserver::IndicateDone, this)); | |
| 2333 } | |
| 2334 } | |
| 2335 | |
| 2336 void AutofillChangedObserver::IndicateDone() { | |
| 2337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 2338 if (automation_) { | |
| 2339 AutomationJSONReply(automation_, | |
| 2340 reply_message_.release()).SendSuccess(NULL); | |
| 2341 } | |
| 2342 Release(); | |
| 2343 } | |
| 2344 | |
| 2345 AutofillFormSubmittedObserver::AutofillFormSubmittedObserver( | |
| 2346 AutomationProvider* automation, | |
| 2347 IPC::Message* reply_message, | |
| 2348 PersonalDataManager* pdm) | |
| 2349 : automation_(automation->AsWeakPtr()), | |
| 2350 reply_message_(reply_message), | |
| 2351 pdm_(pdm), | |
| 2352 infobar_helper_(NULL) { | |
| 2353 pdm_->SetObserver(this); | |
| 2354 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | |
| 2355 content::NotificationService::AllSources()); | |
| 2356 } | |
| 2357 | |
| 2358 AutofillFormSubmittedObserver::~AutofillFormSubmittedObserver() { | |
| 2359 pdm_->RemoveObserver(this); | |
| 2360 | |
| 2361 if (infobar_helper_) { | |
| 2362 InfoBarDelegate* infobar = NULL; | |
| 2363 if (infobar_helper_->infobar_count() > 0 && | |
| 2364 (infobar = infobar_helper_->GetInfoBarDelegateAt(0))) { | |
| 2365 infobar_helper_->RemoveInfoBar(infobar); | |
| 2366 } | |
| 2367 } | |
| 2368 } | |
| 2369 | |
| 2370 void AutofillFormSubmittedObserver::OnPersonalDataChanged() { | |
| 2371 if (automation_) { | |
| 2372 AutomationJSONReply(automation_, | |
| 2373 reply_message_.release()).SendSuccess(NULL); | |
| 2374 } | |
| 2375 delete this; | |
| 2376 } | |
| 2377 | |
| 2378 void AutofillFormSubmittedObserver::OnInsufficientFormData() { | |
| 2379 if (automation_) { | |
| 2380 AutomationJSONReply(automation_, | |
| 2381 reply_message_.release()).SendSuccess(NULL); | |
| 2382 } | |
| 2383 delete this; | |
| 2384 } | |
| 2385 | |
| 2386 void AutofillFormSubmittedObserver::Observe( | |
| 2387 int type, | |
| 2388 const content::NotificationSource& source, | |
| 2389 const content::NotificationDetails& details) { | |
| 2390 DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED); | |
| 2391 | |
| 2392 // Accept in the infobar. | |
| 2393 infobar_helper_ = content::Source<InfoBarTabHelper>(source).ptr(); | |
| 2394 InfoBarDelegate* infobar = NULL; | |
| 2395 infobar = infobar_helper_->GetInfoBarDelegateAt(0); | |
| 2396 | |
| 2397 ConfirmInfoBarDelegate* confirm_infobar = infobar->AsConfirmInfoBarDelegate(); | |
| 2398 if (!confirm_infobar) { | |
| 2399 if (automation_) { | |
| 2400 AutomationJSONReply( | |
| 2401 automation_, reply_message_.release()).SendError( | |
| 2402 "Infobar is not a confirm infobar."); | |
| 2403 } | |
| 2404 delete this; | |
| 2405 return; | |
| 2406 } | |
| 2407 | |
| 2408 if (!confirm_infobar->Accept()) { | |
| 2409 if (automation_) { | |
| 2410 AutomationJSONReply( | |
| 2411 automation_, reply_message_.release()).SendError( | |
| 2412 "Could not accept in the infobar."); | |
| 2413 } | |
| 2414 delete this; | |
| 2415 return; | |
| 2416 } | |
| 2417 } | |
| 2418 | |
| 2419 namespace { | 2245 namespace { |
| 2420 | 2246 |
| 2421 // Returns whether all active notifications have an associated process ID. | 2247 // Returns whether all active notifications have an associated process ID. |
| 2422 bool AreActiveNotificationProcessesReady() { | 2248 bool AreActiveNotificationProcessesReady() { |
| 2423 NotificationUIManager* manager = g_browser_process->notification_ui_manager(); | 2249 NotificationUIManager* manager = g_browser_process->notification_ui_manager(); |
| 2424 const BalloonCollection::Balloons& balloons = | 2250 const BalloonCollection::Balloons& balloons = |
| 2425 manager->balloon_collection()->GetActiveBalloons(); | 2251 manager->balloon_collection()->GetActiveBalloons(); |
| 2426 BalloonCollection::Balloons::const_iterator iter; | 2252 BalloonCollection::Balloons::const_iterator iter; |
| 2427 for (iter = balloons.begin(); iter != balloons.end(); ++iter) { | 2253 for (iter = balloons.begin(); iter != balloons.end(); ++iter) { |
| 2428 BalloonHost* balloon_host = (*iter)->balloon_view()->GetHost(); | 2254 BalloonHost* balloon_host = (*iter)->balloon_view()->GetHost(); |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3169 if (automation_) { | 2995 if (automation_) { |
| 3170 AutomationJSONReply(automation_, reply_message_.release()) | 2996 AutomationJSONReply(automation_, reply_message_.release()) |
| 3171 .SendSuccess(NULL); | 2997 .SendSuccess(NULL); |
| 3172 } | 2998 } |
| 3173 delete this; | 2999 delete this; |
| 3174 } | 3000 } |
| 3175 } else { | 3001 } else { |
| 3176 NOTREACHED(); | 3002 NOTREACHED(); |
| 3177 } | 3003 } |
| 3178 } | 3004 } |
| OLD | NEW |