| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 items->Append(item); | 197 items->Append(item); |
| 198 } | 198 } |
| 199 DictionaryValue* return_value = new DictionaryValue; | 199 DictionaryValue* return_value = new DictionaryValue; |
| 200 return_value->Set("tabs", items); | 200 return_value->Set("tabs", items); |
| 201 return return_value; | 201 return return_value; |
| 202 } | 202 } |
| 203 | 203 |
| 204 void InitialLoadObserver::ConditionMet() { | 204 void InitialLoadObserver::ConditionMet() { |
| 205 registrar_.RemoveAll(); | 205 registrar_.RemoveAll(); |
| 206 if (automation_) | 206 if (automation_.get()) |
| 207 automation_->OnInitialTabLoadsComplete(); | 207 automation_->OnInitialTabLoadsComplete(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 NewTabUILoadObserver::NewTabUILoadObserver(AutomationProvider* automation, | 210 NewTabUILoadObserver::NewTabUILoadObserver(AutomationProvider* automation, |
| 211 Profile* profile) | 211 Profile* profile) |
| 212 : automation_(automation->AsWeakPtr()) { | 212 : automation_(automation->AsWeakPtr()) { |
| 213 registrar_.Add(this, chrome::NOTIFICATION_INITIAL_NEW_TAB_UI_LOAD, | 213 registrar_.Add(this, chrome::NOTIFICATION_INITIAL_NEW_TAB_UI_LOAD, |
| 214 content::Source<Profile>(profile)); | 214 content::Source<Profile>(profile)); |
| 215 } | 215 } |
| 216 | 216 |
| 217 NewTabUILoadObserver::~NewTabUILoadObserver() { | 217 NewTabUILoadObserver::~NewTabUILoadObserver() { |
| 218 } | 218 } |
| 219 | 219 |
| 220 void NewTabUILoadObserver::Observe(int type, | 220 void NewTabUILoadObserver::Observe(int type, |
| 221 const content::NotificationSource& source, | 221 const content::NotificationSource& source, |
| 222 const content::NotificationDetails& details)
{ | 222 const content::NotificationDetails& details)
{ |
| 223 if (type == chrome::NOTIFICATION_INITIAL_NEW_TAB_UI_LOAD) { | 223 if (type == chrome::NOTIFICATION_INITIAL_NEW_TAB_UI_LOAD) { |
| 224 content::Details<int> load_time(details); | 224 content::Details<int> load_time(details); |
| 225 if (automation_) { | 225 if (automation_.get()) { |
| 226 automation_->Send( | 226 automation_->Send( |
| 227 new AutomationMsg_InitialNewTabUILoadComplete(*load_time.ptr())); | 227 new AutomationMsg_InitialNewTabUILoadComplete(*load_time.ptr())); |
| 228 } | 228 } |
| 229 } else { | 229 } else { |
| 230 NOTREACHED(); | 230 NOTREACHED(); |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 | 233 |
| 234 NavigationControllerRestoredObserver::NavigationControllerRestoredObserver( | 234 NavigationControllerRestoredObserver::NavigationControllerRestoredObserver( |
| 235 AutomationProvider* automation, | 235 AutomationProvider* automation, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 257 SendDone(); | 257 SendDone(); |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 bool NavigationControllerRestoredObserver::FinishedRestoring() { | 261 bool NavigationControllerRestoredObserver::FinishedRestoring() { |
| 262 return (!controller_->NeedsReload() && !controller_->GetPendingEntry() && | 262 return (!controller_->NeedsReload() && !controller_->GetPendingEntry() && |
| 263 !controller_->GetWebContents()->IsLoading()); | 263 !controller_->GetWebContents()->IsLoading()); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void NavigationControllerRestoredObserver::SendDone() { | 266 void NavigationControllerRestoredObserver::SendDone() { |
| 267 if (automation_) { | 267 if (automation_.get()) { |
| 268 AutomationJSONReply(automation_, reply_message_.release()) | 268 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 269 .SendSuccess(NULL); | 269 .SendSuccess(NULL); |
| 270 } | 270 } |
| 271 delete this; | 271 delete this; |
| 272 } | 272 } |
| 273 | 273 |
| 274 NavigationNotificationObserver::NavigationNotificationObserver( | 274 NavigationNotificationObserver::NavigationNotificationObserver( |
| 275 NavigationController* controller, | 275 NavigationController* controller, |
| 276 AutomationProvider* automation, | 276 AutomationProvider* automation, |
| 277 IPC::Message* reply_message, | 277 IPC::Message* reply_message, |
| 278 int number_of_navigations, | 278 int number_of_navigations, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 302 if (include_current_navigation && controller->GetWebContents()->IsLoading()) | 302 if (include_current_navigation && controller->GetWebContents()->IsLoading()) |
| 303 navigation_started_ = true; | 303 navigation_started_ = true; |
| 304 } | 304 } |
| 305 | 305 |
| 306 NavigationNotificationObserver::~NavigationNotificationObserver() { | 306 NavigationNotificationObserver::~NavigationNotificationObserver() { |
| 307 } | 307 } |
| 308 | 308 |
| 309 void NavigationNotificationObserver::Observe( | 309 void NavigationNotificationObserver::Observe( |
| 310 int type, const content::NotificationSource& source, | 310 int type, const content::NotificationSource& source, |
| 311 const content::NotificationDetails& details) { | 311 const content::NotificationDetails& details) { |
| 312 if (!automation_) { | 312 if (!automation_.get()) { |
| 313 delete this; | 313 delete this; |
| 314 return; | 314 return; |
| 315 } | 315 } |
| 316 | 316 |
| 317 // We listen for 2 events to determine when the navigation started because: | 317 // We listen for 2 events to determine when the navigation started because: |
| 318 // - when this is used by the WaitForNavigation method, we might be invoked | 318 // - when this is used by the WaitForNavigation method, we might be invoked |
| 319 // afer the load has started (but not after the entry was committed, as | 319 // afer the load has started (but not after the entry was committed, as |
| 320 // WaitForNavigation compares times of the last navigation). | 320 // WaitForNavigation compares times of the last navigation). |
| 321 // - when this is used with a page requiring authentication, we will not get | 321 // - when this is used with a page requiring authentication, we will not get |
| 322 // a chrome::NAV_ENTRY_COMMITTED until after we authenticate, so | 322 // a chrome::NAV_ENTRY_COMMITTED until after we authenticate, so |
| (...skipping 18 matching lines...) Expand all Loading... |
| 341 ConditionMet(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED); | 341 ConditionMet(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED); |
| 342 } else if (type == chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN) { | 342 } else if (type == chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN) { |
| 343 ConditionMet(AUTOMATION_MSG_NAVIGATION_BLOCKED_BY_MODAL_DIALOG); | 343 ConditionMet(AUTOMATION_MSG_NAVIGATION_BLOCKED_BY_MODAL_DIALOG); |
| 344 } else { | 344 } else { |
| 345 NOTREACHED(); | 345 NOTREACHED(); |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 | 348 |
| 349 void NavigationNotificationObserver::ConditionMet( | 349 void NavigationNotificationObserver::ConditionMet( |
| 350 AutomationMsg_NavigationResponseValues navigation_result) { | 350 AutomationMsg_NavigationResponseValues navigation_result) { |
| 351 if (automation_) { | 351 if (automation_.get()) { |
| 352 if (use_json_interface_) { | 352 if (use_json_interface_) { |
| 353 if (navigation_result == AUTOMATION_MSG_NAVIGATION_SUCCESS) { | 353 if (navigation_result == AUTOMATION_MSG_NAVIGATION_SUCCESS) { |
| 354 DictionaryValue dict; | 354 DictionaryValue dict; |
| 355 dict.SetInteger("result", navigation_result); | 355 dict.SetInteger("result", navigation_result); |
| 356 AutomationJSONReply(automation_, reply_message_.release()).SendSuccess( | 356 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 357 &dict); | 357 .SendSuccess(&dict); |
| 358 } else { | 358 } else { |
| 359 AutomationJSONReply(automation_, reply_message_.release()).SendError( | 359 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 360 base::StringPrintf("Navigation failed with error code=%d.", | 360 .SendError(base::StringPrintf( |
| 361 navigation_result)); | 361 "Navigation failed with error code=%d.", navigation_result)); |
| 362 } | 362 } |
| 363 } else { | 363 } else { |
| 364 IPC::ParamTraits<int>::Write( | 364 IPC::ParamTraits<int>::Write( |
| 365 reply_message_.get(), navigation_result); | 365 reply_message_.get(), navigation_result); |
| 366 automation_->Send(reply_message_.release()); | 366 automation_->Send(reply_message_.release()); |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 | 369 |
| 370 delete this; | 370 delete this; |
| 371 } | 371 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 automation), | 405 automation), |
| 406 parent_(parent), | 406 parent_(parent), |
| 407 reply_message_(reply_message), | 407 reply_message_(reply_message), |
| 408 use_json_interface_(use_json_interface) { | 408 use_json_interface_(use_json_interface) { |
| 409 } | 409 } |
| 410 | 410 |
| 411 TabAppendedNotificationObserver::~TabAppendedNotificationObserver() {} | 411 TabAppendedNotificationObserver::~TabAppendedNotificationObserver() {} |
| 412 | 412 |
| 413 void TabAppendedNotificationObserver::ObserveTab( | 413 void TabAppendedNotificationObserver::ObserveTab( |
| 414 NavigationController* controller) { | 414 NavigationController* controller) { |
| 415 if (!automation_ || !reply_message_.get()) | 415 if (!automation_.get() || !reply_message_.get()) |
| 416 return; | 416 return; |
| 417 | 417 |
| 418 if (automation_->GetIndexForNavigationController(controller, parent_) == | 418 if (automation_->GetIndexForNavigationController(controller, parent_) == |
| 419 TabStripModel::kNoTab) { | 419 TabStripModel::kNoTab) { |
| 420 // This tab notification doesn't belong to the parent_. | 420 // This tab notification doesn't belong to the parent_. |
| 421 return; | 421 return; |
| 422 } | 422 } |
| 423 | 423 |
| 424 new NavigationNotificationObserver(controller, automation_, | 424 new NavigationNotificationObserver(controller, |
| 425 automation_.get(), |
| 425 reply_message_.release(), | 426 reply_message_.release(), |
| 426 1, false, use_json_interface_); | 427 1, |
| 428 false, |
| 429 use_json_interface_); |
| 427 } | 430 } |
| 428 | 431 |
| 429 IPC::Message* TabAppendedNotificationObserver::ReleaseReply() { | 432 IPC::Message* TabAppendedNotificationObserver::ReleaseReply() { |
| 430 return reply_message_.release(); | 433 return reply_message_.release(); |
| 431 } | 434 } |
| 432 | 435 |
| 433 TabClosedNotificationObserver::TabClosedNotificationObserver( | 436 TabClosedNotificationObserver::TabClosedNotificationObserver( |
| 434 AutomationProvider* automation, | 437 AutomationProvider* automation, |
| 435 bool wait_until_closed, | 438 bool wait_until_closed, |
| 436 IPC::Message* reply_message, | 439 IPC::Message* reply_message, |
| 437 bool use_json_interface) | 440 bool use_json_interface) |
| 438 : TabStripNotificationObserver((wait_until_closed ? | 441 : TabStripNotificationObserver((wait_until_closed ? |
| 439 static_cast<int>(content::NOTIFICATION_WEB_CONTENTS_DESTROYED) : | 442 static_cast<int>(content::NOTIFICATION_WEB_CONTENTS_DESTROYED) : |
| 440 static_cast<int>(chrome::NOTIFICATION_TAB_CLOSING)), automation), | 443 static_cast<int>(chrome::NOTIFICATION_TAB_CLOSING)), automation), |
| 441 reply_message_(reply_message), | 444 reply_message_(reply_message), |
| 442 use_json_interface_(use_json_interface), | 445 use_json_interface_(use_json_interface), |
| 443 for_browser_command_(false) { | 446 for_browser_command_(false) { |
| 444 } | 447 } |
| 445 | 448 |
| 446 TabClosedNotificationObserver::~TabClosedNotificationObserver() {} | 449 TabClosedNotificationObserver::~TabClosedNotificationObserver() {} |
| 447 | 450 |
| 448 void TabClosedNotificationObserver::ObserveTab( | 451 void TabClosedNotificationObserver::ObserveTab( |
| 449 NavigationController* controller) { | 452 NavigationController* controller) { |
| 450 if (!automation_) | 453 if (!automation_.get()) |
| 451 return; | 454 return; |
| 452 | 455 |
| 453 if (use_json_interface_) { | 456 if (use_json_interface_) { |
| 454 AutomationJSONReply(automation_, | 457 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 455 reply_message_.release()).SendSuccess(NULL); | 458 .SendSuccess(NULL); |
| 456 } else { | 459 } else { |
| 457 if (for_browser_command_) { | 460 if (for_browser_command_) { |
| 458 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(), | 461 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(), |
| 459 true); | 462 true); |
| 460 } else { | 463 } else { |
| 461 AutomationMsg_CloseTab::WriteReplyParams(reply_message_.get(), true); | 464 AutomationMsg_CloseTab::WriteReplyParams(reply_message_.get(), true); |
| 462 } | 465 } |
| 463 automation_->Send(reply_message_.release()); | 466 automation_->Send(reply_message_.release()); |
| 464 } | 467 } |
| 465 } | 468 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 490 bool foreground) { | 493 bool foreground) { |
| 491 CheckTabCount(); | 494 CheckTabCount(); |
| 492 } | 495 } |
| 493 | 496 |
| 494 void TabCountChangeObserver::TabDetachedAt(WebContents* contents, | 497 void TabCountChangeObserver::TabDetachedAt(WebContents* contents, |
| 495 int index) { | 498 int index) { |
| 496 CheckTabCount(); | 499 CheckTabCount(); |
| 497 } | 500 } |
| 498 | 501 |
| 499 void TabCountChangeObserver::TabStripModelDeleted() { | 502 void TabCountChangeObserver::TabStripModelDeleted() { |
| 500 if (automation_) { | 503 if (automation_.get()) { |
| 501 AutomationMsg_WaitForTabCountToBecome::WriteReplyParams( | 504 AutomationMsg_WaitForTabCountToBecome::WriteReplyParams( |
| 502 reply_message_.get(), false); | 505 reply_message_.get(), false); |
| 503 automation_->Send(reply_message_.release()); | 506 automation_->Send(reply_message_.release()); |
| 504 } | 507 } |
| 505 | 508 |
| 506 delete this; | 509 delete this; |
| 507 } | 510 } |
| 508 | 511 |
| 509 void TabCountChangeObserver::CheckTabCount() { | 512 void TabCountChangeObserver::CheckTabCount() { |
| 510 if (tab_strip_model_->count() != target_tab_count_) | 513 if (tab_strip_model_->count() != target_tab_count_) |
| 511 return; | 514 return; |
| 512 | 515 |
| 513 if (automation_) { | 516 if (automation_.get()) { |
| 514 AutomationMsg_WaitForTabCountToBecome::WriteReplyParams( | 517 AutomationMsg_WaitForTabCountToBecome::WriteReplyParams( |
| 515 reply_message_.get(), true); | 518 reply_message_.get(), true); |
| 516 automation_->Send(reply_message_.release()); | 519 automation_->Send(reply_message_.release()); |
| 517 } | 520 } |
| 518 | 521 |
| 519 delete this; | 522 delete this; |
| 520 } | 523 } |
| 521 | 524 |
| 522 bool DidExtensionViewsStopLoading(ExtensionProcessManager* manager) { | 525 bool DidExtensionViewsStopLoading(ExtensionProcessManager* manager) { |
| 523 ExtensionProcessManager::ViewSet all_views = manager->GetAllViews(); | 526 ExtensionProcessManager::ViewSet all_views = manager->GetAllViews(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 543 content::NotificationService::AllSources()); | 546 content::NotificationService::AllSources()); |
| 544 } | 547 } |
| 545 | 548 |
| 546 ExtensionUninstallObserver::~ExtensionUninstallObserver() { | 549 ExtensionUninstallObserver::~ExtensionUninstallObserver() { |
| 547 } | 550 } |
| 548 | 551 |
| 549 void ExtensionUninstallObserver::Observe( | 552 void ExtensionUninstallObserver::Observe( |
| 550 int type, | 553 int type, |
| 551 const content::NotificationSource& source, | 554 const content::NotificationSource& source, |
| 552 const content::NotificationDetails& details) { | 555 const content::NotificationDetails& details) { |
| 553 if (!automation_) { | 556 if (!automation_.get()) { |
| 554 delete this; | 557 delete this; |
| 555 return; | 558 return; |
| 556 } | 559 } |
| 557 | 560 |
| 558 switch (type) { | 561 switch (type) { |
| 559 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { | 562 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
| 560 if (id_ == content::Details<extensions::Extension>(details).ptr()->id()) { | 563 if (id_ == content::Details<extensions::Extension>(details).ptr()->id()) { |
| 561 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 564 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 562 return_value->SetBoolean("success", true); | 565 return_value->SetBoolean("success", true); |
| 563 AutomationJSONReply(automation_, reply_message_.release()) | 566 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 564 .SendSuccess(return_value.get()); | 567 .SendSuccess(return_value.get()); |
| 565 delete this; | 568 delete this; |
| 566 return; | 569 return; |
| 567 } | 570 } |
| 568 break; | 571 break; |
| 569 } | 572 } |
| 570 | 573 |
| 571 case chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED: { | 574 case chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED: { |
| 572 const extensions::Extension* extension = | 575 const extensions::Extension* extension = |
| 573 content::Details<extensions::Extension>(details).ptr(); | 576 content::Details<extensions::Extension>(details).ptr(); |
| 574 if (id_ == extension->id()) { | 577 if (id_ == extension->id()) { |
| 575 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 578 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 576 return_value->SetBoolean("success", false); | 579 return_value->SetBoolean("success", false); |
| 577 AutomationJSONReply(automation_, reply_message_.release()) | 580 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 578 .SendSuccess(return_value.get()); | 581 .SendSuccess(return_value.get()); |
| 579 delete this; | 582 delete this; |
| 580 return; | 583 return; |
| 581 } | 584 } |
| 582 break; | 585 break; |
| 583 } | 586 } |
| 584 | 587 |
| 585 default: | 588 default: |
| 586 NOTREACHED(); | 589 NOTREACHED(); |
| 587 } | 590 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 610 content::NotificationService::AllSources()); | 613 content::NotificationService::AllSources()); |
| 611 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, | 614 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
| 612 content::NotificationService::AllSources()); | 615 content::NotificationService::AllSources()); |
| 613 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | 616 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| 614 content::NotificationService::AllSources()); | 617 content::NotificationService::AllSources()); |
| 615 } | 618 } |
| 616 | 619 |
| 617 void ExtensionReadyNotificationObserver::Observe( | 620 void ExtensionReadyNotificationObserver::Observe( |
| 618 int type, const content::NotificationSource& source, | 621 int type, const content::NotificationSource& source, |
| 619 const content::NotificationDetails& details) { | 622 const content::NotificationDetails& details) { |
| 620 if (!automation_) { | 623 if (!automation_.get()) { |
| 621 delete this; | 624 delete this; |
| 622 return; | 625 return; |
| 623 } | 626 } |
| 624 | 627 |
| 625 switch (type) { | 628 switch (type) { |
| 626 case content::NOTIFICATION_LOAD_STOP: | 629 case content::NOTIFICATION_LOAD_STOP: |
| 627 // Only continue on with this method if our extension has been loaded | 630 // Only continue on with this method if our extension has been loaded |
| 628 // and all the extension views have stopped loading. | 631 // and all the extension views have stopped loading. |
| 629 if (!extension_ || !DidExtensionViewsStopLoading(manager_)) | 632 if (!extension_ || !DidExtensionViewsStopLoading(manager_)) |
| 630 return; | 633 return; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 650 } | 653 } |
| 651 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: | 654 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: |
| 652 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: | 655 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: |
| 653 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: | 656 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
| 654 break; | 657 break; |
| 655 default: | 658 default: |
| 656 NOTREACHED(); | 659 NOTREACHED(); |
| 657 break; | 660 break; |
| 658 } | 661 } |
| 659 | 662 |
| 660 AutomationJSONReply reply(automation_, reply_message_.release()); | 663 AutomationJSONReply reply(automation_.get(), reply_message_.release()); |
| 661 if (extension_) { | 664 if (extension_) { |
| 662 DictionaryValue dict; | 665 DictionaryValue dict; |
| 663 dict.SetString("id", extension_->id()); | 666 dict.SetString("id", extension_->id()); |
| 664 reply.SendSuccess(&dict); | 667 reply.SendSuccess(&dict); |
| 665 } else { | 668 } else { |
| 666 reply.SendError("Extension could not be installed"); | 669 reply.SendError("Extension could not be installed"); |
| 667 } | 670 } |
| 668 delete this; | 671 delete this; |
| 669 } | 672 } |
| 670 | 673 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 695 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 698 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 696 content::NotificationService::AllSources()); | 699 content::NotificationService::AllSources()); |
| 697 } | 700 } |
| 698 | 701 |
| 699 ExtensionsUpdatedObserver::~ExtensionsUpdatedObserver() { | 702 ExtensionsUpdatedObserver::~ExtensionsUpdatedObserver() { |
| 700 } | 703 } |
| 701 | 704 |
| 702 void ExtensionsUpdatedObserver::Observe( | 705 void ExtensionsUpdatedObserver::Observe( |
| 703 int type, const content::NotificationSource& source, | 706 int type, const content::NotificationSource& source, |
| 704 const content::NotificationDetails& details) { | 707 const content::NotificationDetails& details) { |
| 705 if (!automation_) { | 708 if (!automation_.get()) { |
| 706 delete this; | 709 delete this; |
| 707 return; | 710 return; |
| 708 } | 711 } |
| 709 | 712 |
| 710 DCHECK(type == content::NOTIFICATION_LOAD_STOP); | 713 DCHECK(type == content::NOTIFICATION_LOAD_STOP); |
| 711 MaybeReply(); | 714 MaybeReply(); |
| 712 } | 715 } |
| 713 | 716 |
| 714 void ExtensionsUpdatedObserver::UpdateCheckFinished() { | 717 void ExtensionsUpdatedObserver::UpdateCheckFinished() { |
| 715 if (!automation_) { | 718 if (!automation_.get()) { |
| 716 delete this; | 719 delete this; |
| 717 return; | 720 return; |
| 718 } | 721 } |
| 719 | 722 |
| 720 // Extension updater has completed updating all extensions. | 723 // Extension updater has completed updating all extensions. |
| 721 updater_finished_ = true; | 724 updater_finished_ = true; |
| 722 MaybeReply(); | 725 MaybeReply(); |
| 723 } | 726 } |
| 724 | 727 |
| 725 void ExtensionsUpdatedObserver::MaybeReply() { | 728 void ExtensionsUpdatedObserver::MaybeReply() { |
| 726 // Send the reply if (1) the extension updater has finished updating all | 729 // Send the reply if (1) the extension updater has finished updating all |
| 727 // extensions; and (2) all extension views have stopped loading. | 730 // extensions; and (2) all extension views have stopped loading. |
| 728 if (updater_finished_ && DidExtensionViewsStopLoading(manager_)) { | 731 if (updater_finished_ && DidExtensionViewsStopLoading(manager_)) { |
| 729 AutomationJSONReply reply(automation_, reply_message_.release()); | 732 AutomationJSONReply reply(automation_.get(), reply_message_.release()); |
| 730 reply.SendSuccess(NULL); | 733 reply.SendSuccess(NULL); |
| 731 delete this; | 734 delete this; |
| 732 } | 735 } |
| 733 } | 736 } |
| 734 | 737 |
| 735 BrowserOpenedNotificationObserver::BrowserOpenedNotificationObserver( | 738 BrowserOpenedNotificationObserver::BrowserOpenedNotificationObserver( |
| 736 AutomationProvider* automation, | 739 AutomationProvider* automation, |
| 737 IPC::Message* reply_message, | 740 IPC::Message* reply_message, |
| 738 bool use_json_interface) | 741 bool use_json_interface) |
| 739 : automation_(automation->AsWeakPtr()), | 742 : automation_(automation->AsWeakPtr()), |
| 740 reply_message_(reply_message), | 743 reply_message_(reply_message), |
| 741 new_window_id_(extension_misc::kUnknownWindowId), | 744 new_window_id_(extension_misc::kUnknownWindowId), |
| 742 use_json_interface_(use_json_interface), | 745 use_json_interface_(use_json_interface), |
| 743 for_browser_command_(false) { | 746 for_browser_command_(false) { |
| 744 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, | 747 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
| 745 content::NotificationService::AllBrowserContextsAndSources()); | 748 content::NotificationService::AllBrowserContextsAndSources()); |
| 746 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 749 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 747 content::NotificationService::AllBrowserContextsAndSources()); | 750 content::NotificationService::AllBrowserContextsAndSources()); |
| 748 } | 751 } |
| 749 | 752 |
| 750 BrowserOpenedNotificationObserver::~BrowserOpenedNotificationObserver() { | 753 BrowserOpenedNotificationObserver::~BrowserOpenedNotificationObserver() { |
| 751 } | 754 } |
| 752 | 755 |
| 753 void BrowserOpenedNotificationObserver::Observe( | 756 void BrowserOpenedNotificationObserver::Observe( |
| 754 int type, | 757 int type, |
| 755 const content::NotificationSource& source, | 758 const content::NotificationSource& source, |
| 756 const content::NotificationDetails& details) { | 759 const content::NotificationDetails& details) { |
| 757 if (!automation_) { | 760 if (!automation_.get()) { |
| 758 delete this; | 761 delete this; |
| 759 return; | 762 return; |
| 760 } | 763 } |
| 761 | 764 |
| 762 if (type == chrome::NOTIFICATION_BROWSER_OPENED) { | 765 if (type == chrome::NOTIFICATION_BROWSER_OPENED) { |
| 763 // Store the new browser ID and continue waiting for a new tab within it | 766 // Store the new browser ID and continue waiting for a new tab within it |
| 764 // to stop loading. | 767 // to stop loading. |
| 765 new_window_id_ = ExtensionTabUtil::GetWindowId( | 768 new_window_id_ = ExtensionTabUtil::GetWindowId( |
| 766 content::Source<Browser>(source).ptr()); | 769 content::Source<Browser>(source).ptr()); |
| 767 } else { | 770 } else { |
| 768 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type); | 771 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type); |
| 769 // Only send the result if the loaded tab is in the new window. | 772 // Only send the result if the loaded tab is in the new window. |
| 770 NavigationController* controller = | 773 NavigationController* controller = |
| 771 content::Source<NavigationController>(source).ptr(); | 774 content::Source<NavigationController>(source).ptr(); |
| 772 SessionTabHelper* session_tab_helper = | 775 SessionTabHelper* session_tab_helper = |
| 773 SessionTabHelper::FromWebContents(controller->GetWebContents()); | 776 SessionTabHelper::FromWebContents(controller->GetWebContents()); |
| 774 int window_id = session_tab_helper ? session_tab_helper->window_id().id() | 777 int window_id = session_tab_helper ? session_tab_helper->window_id().id() |
| 775 : -1; | 778 : -1; |
| 776 if (window_id == new_window_id_) { | 779 if (window_id == new_window_id_) { |
| 777 if (use_json_interface_) { | 780 if (use_json_interface_) { |
| 778 AutomationJSONReply(automation_, | 781 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 779 reply_message_.release()).SendSuccess(NULL); | 782 .SendSuccess(NULL); |
| 780 } else { | 783 } else { |
| 781 if (for_browser_command_) { | 784 if (for_browser_command_) { |
| 782 AutomationMsg_WindowExecuteCommand::WriteReplyParams( | 785 AutomationMsg_WindowExecuteCommand::WriteReplyParams( |
| 783 reply_message_.get(), true); | 786 reply_message_.get(), true); |
| 784 } | 787 } |
| 785 automation_->Send(reply_message_.release()); | 788 automation_->Send(reply_message_.release()); |
| 786 } | 789 } |
| 787 delete this; | 790 delete this; |
| 788 return; | 791 return; |
| 789 } | 792 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 808 content::Source<Browser>(browser)); | 811 content::Source<Browser>(browser)); |
| 809 } | 812 } |
| 810 | 813 |
| 811 BrowserClosedNotificationObserver::~BrowserClosedNotificationObserver() {} | 814 BrowserClosedNotificationObserver::~BrowserClosedNotificationObserver() {} |
| 812 | 815 |
| 813 void BrowserClosedNotificationObserver::Observe( | 816 void BrowserClosedNotificationObserver::Observe( |
| 814 int type, const content::NotificationSource& source, | 817 int type, const content::NotificationSource& source, |
| 815 const content::NotificationDetails& details) { | 818 const content::NotificationDetails& details) { |
| 816 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_CLOSED, type); | 819 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_CLOSED, type); |
| 817 | 820 |
| 818 if (!automation_) { | 821 if (!automation_.get()) { |
| 819 delete this; | 822 delete this; |
| 820 return; | 823 return; |
| 821 } | 824 } |
| 822 | 825 |
| 823 // The automation layer doesn't support non-native desktops. | 826 // The automation layer doesn't support non-native desktops. |
| 824 int browser_count = static_cast<int>(BrowserList::GetInstance( | 827 int browser_count = static_cast<int>(BrowserList::GetInstance( |
| 825 chrome::HOST_DESKTOP_TYPE_NATIVE)->size()); | 828 chrome::HOST_DESKTOP_TYPE_NATIVE)->size()); |
| 826 // We get the notification before the browser is removed from the BrowserList. | 829 // We get the notification before the browser is removed from the BrowserList. |
| 827 bool app_closing = browser_count == 1; | 830 bool app_closing = browser_count == 1; |
| 828 | 831 |
| 829 if (use_json_interface_) { | 832 if (use_json_interface_) { |
| 830 AutomationJSONReply(automation_, | 833 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 831 reply_message_.release()).SendSuccess(NULL); | 834 .SendSuccess(NULL); |
| 832 } else { | 835 } else { |
| 833 if (for_browser_command_) { | 836 if (for_browser_command_) { |
| 834 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(), | 837 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(), |
| 835 true); | 838 true); |
| 836 } else { | 839 } else { |
| 837 AutomationMsg_CloseBrowser::WriteReplyParams(reply_message_.get(), true, | 840 AutomationMsg_CloseBrowser::WriteReplyParams(reply_message_.get(), true, |
| 838 app_closing); | 841 app_closing); |
| 839 } | 842 } |
| 840 automation_->Send(reply_message_.release()); | 843 automation_->Send(reply_message_.release()); |
| 841 } | 844 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 // The automation layer doesn't support non-native desktops. | 876 // The automation layer doesn't support non-native desktops. |
| 874 int current_count = static_cast<int>(BrowserList::GetInstance( | 877 int current_count = static_cast<int>(BrowserList::GetInstance( |
| 875 chrome::HOST_DESKTOP_TYPE_NATIVE)->size()); | 878 chrome::HOST_DESKTOP_TYPE_NATIVE)->size()); |
| 876 if (type == chrome::NOTIFICATION_BROWSER_CLOSED) { | 879 if (type == chrome::NOTIFICATION_BROWSER_CLOSED) { |
| 877 // At the time of the notification the browser being closed is not removed | 880 // At the time of the notification the browser being closed is not removed |
| 878 // from the list. The real count is one less than the reported count. | 881 // from the list. The real count is one less than the reported count. |
| 879 DCHECK_LT(0, current_count); | 882 DCHECK_LT(0, current_count); |
| 880 current_count--; | 883 current_count--; |
| 881 } | 884 } |
| 882 | 885 |
| 883 if (!automation_) { | 886 if (!automation_.get()) { |
| 884 delete this; | 887 delete this; |
| 885 return; | 888 return; |
| 886 } | 889 } |
| 887 | 890 |
| 888 if (current_count == target_count_) { | 891 if (current_count == target_count_) { |
| 889 AutomationMsg_WaitForBrowserWindowCountToBecome::WriteReplyParams( | 892 AutomationMsg_WaitForBrowserWindowCountToBecome::WriteReplyParams( |
| 890 reply_message_.get(), true); | 893 reply_message_.get(), true); |
| 891 automation_->Send(reply_message_.release()); | 894 automation_->Send(reply_message_.release()); |
| 892 delete this; | 895 delete this; |
| 893 } | 896 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 break; | 981 break; |
| 979 } | 982 } |
| 980 } | 983 } |
| 981 return result; | 984 return result; |
| 982 } | 985 } |
| 983 | 986 |
| 984 void ExecuteBrowserCommandObserver::Observe( | 987 void ExecuteBrowserCommandObserver::Observe( |
| 985 int type, const content::NotificationSource& source, | 988 int type, const content::NotificationSource& source, |
| 986 const content::NotificationDetails& details) { | 989 const content::NotificationDetails& details) { |
| 987 if (type == notification_type_) { | 990 if (type == notification_type_) { |
| 988 if (automation_) { | 991 if (automation_.get()) { |
| 989 if (use_json_interface_) { | 992 if (use_json_interface_) { |
| 990 AutomationJSONReply(automation_, | 993 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 991 reply_message_.release()).SendSuccess(NULL); | 994 .SendSuccess(NULL); |
| 992 } else { | 995 } else { |
| 993 AutomationMsg_WindowExecuteCommand::WriteReplyParams( | 996 AutomationMsg_WindowExecuteCommand::WriteReplyParams( |
| 994 reply_message_.get(), true); | 997 reply_message_.get(), true); |
| 995 automation_->Send(reply_message_.release()); | 998 automation_->Send(reply_message_.release()); |
| 996 } | 999 } |
| 997 } | 1000 } |
| 998 delete this; | 1001 delete this; |
| 999 } else { | 1002 } else { |
| 1000 NOTREACHED(); | 1003 NOTREACHED(); |
| 1001 } | 1004 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 | 1057 |
| 1055 void FindInPageNotificationObserver::Observe( | 1058 void FindInPageNotificationObserver::Observe( |
| 1056 int type, const content::NotificationSource& source, | 1059 int type, const content::NotificationSource& source, |
| 1057 const content::NotificationDetails& details) { | 1060 const content::NotificationDetails& details) { |
| 1058 content::Details<FindNotificationDetails> find_details(details); | 1061 content::Details<FindNotificationDetails> find_details(details); |
| 1059 if (!(find_details->final_update() && reply_message_ != NULL)) { | 1062 if (!(find_details->final_update() && reply_message_ != NULL)) { |
| 1060 DVLOG(1) << "Ignoring, since we only care about the final message"; | 1063 DVLOG(1) << "Ignoring, since we only care about the final message"; |
| 1061 return; | 1064 return; |
| 1062 } | 1065 } |
| 1063 | 1066 |
| 1064 if (!automation_) { | 1067 if (!automation_.get()) { |
| 1065 delete this; | 1068 delete this; |
| 1066 return; | 1069 return; |
| 1067 } | 1070 } |
| 1068 | 1071 |
| 1069 // We get multiple responses and one of those will contain the ordinal. | 1072 // We get multiple responses and one of those will contain the ordinal. |
| 1070 // This message comes to us before the final update is sent. | 1073 // This message comes to us before the final update is sent. |
| 1071 if (find_details->request_id() == kFindInPageRequestId) { | 1074 if (find_details->request_id() == kFindInPageRequestId) { |
| 1072 if (reply_with_json_) { | 1075 if (reply_with_json_) { |
| 1073 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 1076 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 1074 return_value->SetInteger("match_count", | 1077 return_value->SetInteger("match_count", |
| 1075 find_details->number_of_matches()); | 1078 find_details->number_of_matches()); |
| 1076 gfx::Rect rect = find_details->selection_rect(); | 1079 gfx::Rect rect = find_details->selection_rect(); |
| 1077 // If MatchCount is > 0, then rect should not be Empty. | 1080 // If MatchCount is > 0, then rect should not be Empty. |
| 1078 // We dont guard it here because we want to let the test | 1081 // We dont guard it here because we want to let the test |
| 1079 // code catch this invalid case if needed. | 1082 // code catch this invalid case if needed. |
| 1080 if (!rect.IsEmpty()) { | 1083 if (!rect.IsEmpty()) { |
| 1081 return_value->SetInteger("match_left", rect.x()); | 1084 return_value->SetInteger("match_left", rect.x()); |
| 1082 return_value->SetInteger("match_top", rect.y()); | 1085 return_value->SetInteger("match_top", rect.y()); |
| 1083 return_value->SetInteger("match_right", rect.right()); | 1086 return_value->SetInteger("match_right", rect.right()); |
| 1084 return_value->SetInteger("match_bottom", rect.bottom()); | 1087 return_value->SetInteger("match_bottom", rect.bottom()); |
| 1085 } | 1088 } |
| 1086 AutomationJSONReply(automation_, reply_message_.release()) | 1089 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1087 .SendSuccess(return_value.get()); | 1090 .SendSuccess(return_value.get()); |
| 1088 delete this; | 1091 delete this; |
| 1089 } else { | 1092 } else { |
| 1090 if (find_details->active_match_ordinal() > -1) { | 1093 if (find_details->active_match_ordinal() > -1) { |
| 1091 active_match_ordinal_ = find_details->active_match_ordinal(); | 1094 active_match_ordinal_ = find_details->active_match_ordinal(); |
| 1092 AutomationMsg_Find::WriteReplyParams(reply_message_.get(), | 1095 AutomationMsg_Find::WriteReplyParams(reply_message_.get(), |
| 1093 active_match_ordinal_, find_details->number_of_matches()); | 1096 active_match_ordinal_, find_details->number_of_matches()); |
| 1094 automation_->Send(reply_message_.release()); | 1097 automation_->Send(reply_message_.release()); |
| 1095 } | 1098 } |
| 1096 } | 1099 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 : DomOperationObserver(0), | 1145 : DomOperationObserver(0), |
| 1143 automation_(automation->AsWeakPtr()), | 1146 automation_(automation->AsWeakPtr()), |
| 1144 reply_message_(reply_message), | 1147 reply_message_(reply_message), |
| 1145 use_json_interface_(use_json_interface) { | 1148 use_json_interface_(use_json_interface) { |
| 1146 } | 1149 } |
| 1147 | 1150 |
| 1148 DomOperationMessageSender::~DomOperationMessageSender() {} | 1151 DomOperationMessageSender::~DomOperationMessageSender() {} |
| 1149 | 1152 |
| 1150 void DomOperationMessageSender::OnDomOperationCompleted( | 1153 void DomOperationMessageSender::OnDomOperationCompleted( |
| 1151 const std::string& json) { | 1154 const std::string& json) { |
| 1152 if (automation_) { | 1155 if (automation_.get()) { |
| 1153 if (use_json_interface_) { | 1156 if (use_json_interface_) { |
| 1154 DictionaryValue dict; | 1157 DictionaryValue dict; |
| 1155 dict.SetString("result", json); | 1158 dict.SetString("result", json); |
| 1156 AutomationJSONReply(automation_, reply_message_.release()) | 1159 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1157 .SendSuccess(&dict); | 1160 .SendSuccess(&dict); |
| 1158 } else { | 1161 } else { |
| 1159 AutomationMsg_DomOperation::WriteReplyParams(reply_message_.get(), json); | 1162 AutomationMsg_DomOperation::WriteReplyParams(reply_message_.get(), json); |
| 1160 automation_->Send(reply_message_.release()); | 1163 automation_->Send(reply_message_.release()); |
| 1161 } | 1164 } |
| 1162 } | 1165 } |
| 1163 delete this; | 1166 delete this; |
| 1164 } | 1167 } |
| 1165 | 1168 |
| 1166 void DomOperationMessageSender::OnModalDialogShown() { | 1169 void DomOperationMessageSender::OnModalDialogShown() { |
| 1167 if (automation_ && use_json_interface_) { | 1170 if (automation_.get() && use_json_interface_) { |
| 1168 AutomationJSONReply(automation_, reply_message_.release()) | 1171 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1169 .SendErrorCode(automation::kBlockedByModalDialog); | 1172 .SendErrorCode(automation::kBlockedByModalDialog); |
| 1170 delete this; | 1173 delete this; |
| 1171 } | 1174 } |
| 1172 } | 1175 } |
| 1173 | 1176 |
| 1174 void DomOperationMessageSender::OnJavascriptBlocked() { | 1177 void DomOperationMessageSender::OnJavascriptBlocked() { |
| 1175 if (automation_ && use_json_interface_) { | 1178 if (automation_.get() && use_json_interface_) { |
| 1176 AutomationJSONReply(automation_, reply_message_.release()) | 1179 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1177 .SendError("Javascript execution was blocked"); | 1180 .SendError("Javascript execution was blocked"); |
| 1178 delete this; | 1181 delete this; |
| 1179 } | 1182 } |
| 1180 } | 1183 } |
| 1181 | 1184 |
| 1182 MetricEventDurationObserver::MetricEventDurationObserver() { | 1185 MetricEventDurationObserver::MetricEventDurationObserver() { |
| 1183 registrar_.Add(this, chrome::NOTIFICATION_METRIC_EVENT_DURATION, | 1186 registrar_.Add(this, chrome::NOTIFICATION_METRIC_EVENT_DURATION, |
| 1184 content::NotificationService::AllSources()); | 1187 content::NotificationService::AllSources()); |
| 1185 } | 1188 } |
| 1186 | 1189 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED); | 1238 type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED); |
| 1236 CheckCount(); | 1239 CheckCount(); |
| 1237 } | 1240 } |
| 1238 | 1241 |
| 1239 void InfoBarCountObserver::CheckCount() { | 1242 void InfoBarCountObserver::CheckCount() { |
| 1240 InfoBarService* infobar_service = | 1243 InfoBarService* infobar_service = |
| 1241 InfoBarService::FromWebContents(web_contents_); | 1244 InfoBarService::FromWebContents(web_contents_); |
| 1242 if (infobar_service->infobar_count() != target_count_) | 1245 if (infobar_service->infobar_count() != target_count_) |
| 1243 return; | 1246 return; |
| 1244 | 1247 |
| 1245 if (automation_) { | 1248 if (automation_.get()) { |
| 1246 AutomationMsg_WaitForInfoBarCount::WriteReplyParams(reply_message_.get(), | 1249 AutomationMsg_WaitForInfoBarCount::WriteReplyParams(reply_message_.get(), |
| 1247 true); | 1250 true); |
| 1248 automation_->Send(reply_message_.release()); | 1251 automation_->Send(reply_message_.release()); |
| 1249 } | 1252 } |
| 1250 delete this; | 1253 delete this; |
| 1251 } | 1254 } |
| 1252 | 1255 |
| 1253 AutomationProviderBookmarkModelObserver:: | 1256 AutomationProviderBookmarkModelObserver:: |
| 1254 AutomationProviderBookmarkModelObserver( | 1257 AutomationProviderBookmarkModelObserver( |
| 1255 AutomationProvider* provider, | 1258 AutomationProvider* provider, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1276 void AutomationProviderBookmarkModelObserver::BookmarkModelBeingDeleted( | 1279 void AutomationProviderBookmarkModelObserver::BookmarkModelBeingDeleted( |
| 1277 BookmarkModel* model) { | 1280 BookmarkModel* model) { |
| 1278 ReplyAndDelete(false); | 1281 ReplyAndDelete(false); |
| 1279 } | 1282 } |
| 1280 | 1283 |
| 1281 IPC::Message* AutomationProviderBookmarkModelObserver::ReleaseReply() { | 1284 IPC::Message* AutomationProviderBookmarkModelObserver::ReleaseReply() { |
| 1282 return reply_message_.release(); | 1285 return reply_message_.release(); |
| 1283 } | 1286 } |
| 1284 | 1287 |
| 1285 void AutomationProviderBookmarkModelObserver::ReplyAndDelete(bool success) { | 1288 void AutomationProviderBookmarkModelObserver::ReplyAndDelete(bool success) { |
| 1286 if (automation_provider_) { | 1289 if (automation_provider_.get()) { |
| 1287 if (use_json_interface_) { | 1290 if (use_json_interface_) { |
| 1288 AutomationJSONReply(automation_provider_, | 1291 AutomationJSONReply(automation_provider_.get(), reply_message_.release()) |
| 1289 reply_message_.release()).SendSuccess(NULL); | 1292 .SendSuccess(NULL); |
| 1290 } else { | 1293 } else { |
| 1291 AutomationMsg_WaitForBookmarkModelToLoad::WriteReplyParams( | 1294 AutomationMsg_WaitForBookmarkModelToLoad::WriteReplyParams( |
| 1292 reply_message_.get(), success); | 1295 reply_message_.get(), success); |
| 1293 automation_provider_->Send(reply_message_.release()); | 1296 automation_provider_->Send(reply_message_.release()); |
| 1294 } | 1297 } |
| 1295 } | 1298 } |
| 1296 delete this; | 1299 delete this; |
| 1297 } | 1300 } |
| 1298 | 1301 |
| 1299 AutomationProviderDownloadUpdatedObserver:: | 1302 AutomationProviderDownloadUpdatedObserver:: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1313 | 1316 |
| 1314 void AutomationProviderDownloadUpdatedObserver::OnDownloadUpdated( | 1317 void AutomationProviderDownloadUpdatedObserver::OnDownloadUpdated( |
| 1315 DownloadItem* download) { | 1318 DownloadItem* download) { |
| 1316 // If this observer is watching for open, only send the reply if the download | 1319 // If this observer is watching for open, only send the reply if the download |
| 1317 // has been auto-opened. | 1320 // has been auto-opened. |
| 1318 if (wait_for_open_ && !download->GetAutoOpened()) | 1321 if (wait_for_open_ && !download->GetAutoOpened()) |
| 1319 return; | 1322 return; |
| 1320 | 1323 |
| 1321 download->RemoveObserver(this); | 1324 download->RemoveObserver(this); |
| 1322 | 1325 |
| 1323 if (provider_) { | 1326 if (provider_.get()) { |
| 1324 scoped_ptr<DictionaryValue> return_value( | 1327 scoped_ptr<DictionaryValue> return_value( |
| 1325 provider_->GetDictionaryFromDownloadItem(download, incognito_)); | 1328 provider_->GetDictionaryFromDownloadItem(download, incognito_)); |
| 1326 AutomationJSONReply(provider_, reply_message_.release()).SendSuccess( | 1329 AutomationJSONReply(provider_.get(), reply_message_.release()) |
| 1327 return_value.get()); | 1330 .SendSuccess(return_value.get()); |
| 1328 } | 1331 } |
| 1329 delete this; | 1332 delete this; |
| 1330 } | 1333 } |
| 1331 | 1334 |
| 1332 void AutomationProviderDownloadUpdatedObserver::OnDownloadOpened( | 1335 void AutomationProviderDownloadUpdatedObserver::OnDownloadOpened( |
| 1333 DownloadItem* download) { | 1336 DownloadItem* download) { |
| 1334 download->RemoveObserver(this); | 1337 download->RemoveObserver(this); |
| 1335 | 1338 |
| 1336 if (provider_) { | 1339 if (provider_.get()) { |
| 1337 scoped_ptr<DictionaryValue> return_value( | 1340 scoped_ptr<DictionaryValue> return_value( |
| 1338 provider_->GetDictionaryFromDownloadItem(download, incognito_)); | 1341 provider_->GetDictionaryFromDownloadItem(download, incognito_)); |
| 1339 AutomationJSONReply(provider_, reply_message_.release()).SendSuccess( | 1342 AutomationJSONReply(provider_.get(), reply_message_.release()) |
| 1340 return_value.get()); | 1343 .SendSuccess(return_value.get()); |
| 1341 } | 1344 } |
| 1342 delete this; | 1345 delete this; |
| 1343 } | 1346 } |
| 1344 | 1347 |
| 1345 AutomationProviderDownloadModelChangedObserver:: | 1348 AutomationProviderDownloadModelChangedObserver:: |
| 1346 AutomationProviderDownloadModelChangedObserver( | 1349 AutomationProviderDownloadModelChangedObserver( |
| 1347 AutomationProvider* provider, | 1350 AutomationProvider* provider, |
| 1348 IPC::Message* reply_message, | 1351 IPC::Message* reply_message, |
| 1349 DownloadManager* download_manager) | 1352 DownloadManager* download_manager) |
| 1350 : provider_(provider->AsWeakPtr()), | 1353 : provider_(provider->AsWeakPtr()), |
| 1351 reply_message_(reply_message), | 1354 reply_message_(reply_message), |
| 1352 notifier_(download_manager, this) { | 1355 notifier_(download_manager, this) { |
| 1353 } | 1356 } |
| 1354 | 1357 |
| 1355 AutomationProviderDownloadModelChangedObserver:: | 1358 AutomationProviderDownloadModelChangedObserver:: |
| 1356 ~AutomationProviderDownloadModelChangedObserver() {} | 1359 ~AutomationProviderDownloadModelChangedObserver() {} |
| 1357 | 1360 |
| 1358 void AutomationProviderDownloadModelChangedObserver::ModelChanged() { | 1361 void AutomationProviderDownloadModelChangedObserver::ModelChanged() { |
| 1359 if (provider_) | 1362 if (provider_.get()) |
| 1360 AutomationJSONReply(provider_, reply_message_.release()).SendSuccess(NULL); | 1363 AutomationJSONReply(provider_.get(), reply_message_.release()) |
| 1364 .SendSuccess(NULL); |
| 1361 delete this; | 1365 delete this; |
| 1362 } | 1366 } |
| 1363 | 1367 |
| 1364 void AutomationProviderDownloadModelChangedObserver::OnDownloadCreated( | 1368 void AutomationProviderDownloadModelChangedObserver::OnDownloadCreated( |
| 1365 DownloadManager* manager, DownloadItem* item) { | 1369 DownloadManager* manager, DownloadItem* item) { |
| 1366 ModelChanged(); | 1370 ModelChanged(); |
| 1367 } | 1371 } |
| 1368 | 1372 |
| 1369 void AutomationProviderDownloadModelChangedObserver::OnDownloadRemoved( | 1373 void AutomationProviderDownloadModelChangedObserver::OnDownloadRemoved( |
| 1370 DownloadManager* manager, DownloadItem* item) { | 1374 DownloadManager* manager, DownloadItem* item) { |
| 1371 ModelChanged(); | 1375 ModelChanged(); |
| 1372 } | 1376 } |
| 1373 | 1377 |
| 1374 AllDownloadsCompleteObserver::AllDownloadsCompleteObserver( | 1378 AllDownloadsCompleteObserver::AllDownloadsCompleteObserver( |
| 1375 AutomationProvider* provider, | 1379 AutomationProvider* provider, |
| 1376 IPC::Message* reply_message, | 1380 IPC::Message* reply_message, |
| 1377 DownloadManager* download_manager, | 1381 DownloadManager* download_manager, |
| 1378 ListValue* pre_download_ids) | 1382 ListValue* pre_download_ids) |
| 1379 : provider_(provider->AsWeakPtr()), | 1383 : provider_(provider->AsWeakPtr()), |
| 1380 reply_message_(reply_message), | 1384 reply_message_(reply_message), |
| 1381 download_manager_(download_manager) { | 1385 download_manager_(download_manager) { |
| 1382 for (ListValue::iterator it = pre_download_ids->begin(); | 1386 for (ListValue::iterator it = pre_download_ids->begin(); |
| 1383 it != pre_download_ids->end(); ++it) { | 1387 it != pre_download_ids->end(); ++it) { |
| 1384 int val = 0; | 1388 int val = 0; |
| 1385 if ((*it)->GetAsInteger(&val)) { | 1389 if ((*it)->GetAsInteger(&val)) { |
| 1386 pre_download_ids_.insert(val); | 1390 pre_download_ids_.insert(val); |
| 1387 } else { | 1391 } else { |
| 1388 AutomationJSONReply(provider_, reply_message_.release()) | 1392 AutomationJSONReply(provider_.get(), reply_message_.release()) |
| 1389 .SendError("Cannot convert ID of prior download to integer."); | 1393 .SendError("Cannot convert ID of prior download to integer."); |
| 1390 delete this; | 1394 delete this; |
| 1391 return; | 1395 return; |
| 1392 } | 1396 } |
| 1393 } | 1397 } |
| 1394 download_manager_->AddObserver(this); | 1398 download_manager_->AddObserver(this); |
| 1395 DownloadManager::DownloadVector all_items; | 1399 DownloadManager::DownloadVector all_items; |
| 1396 download_manager->GetAllDownloads(&all_items); | 1400 download_manager->GetAllDownloads(&all_items); |
| 1397 for (DownloadManager::DownloadVector::const_iterator | 1401 for (DownloadManager::DownloadVector::const_iterator |
| 1398 it = all_items.begin(); it != all_items.end(); ++it) { | 1402 it = all_items.begin(); it != all_items.end(); ++it) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1437 pending_downloads_.erase(download); | 1441 pending_downloads_.erase(download); |
| 1438 ReplyIfNecessary(); | 1442 ReplyIfNecessary(); |
| 1439 } | 1443 } |
| 1440 } | 1444 } |
| 1441 | 1445 |
| 1442 void AllDownloadsCompleteObserver::ReplyIfNecessary() { | 1446 void AllDownloadsCompleteObserver::ReplyIfNecessary() { |
| 1443 if (!pending_downloads_.empty()) | 1447 if (!pending_downloads_.empty()) |
| 1444 return; | 1448 return; |
| 1445 | 1449 |
| 1446 download_manager_->RemoveObserver(this); | 1450 download_manager_->RemoveObserver(this); |
| 1447 if (provider_) | 1451 if (provider_.get()) |
| 1448 AutomationJSONReply(provider_, reply_message_.release()).SendSuccess(NULL); | 1452 AutomationJSONReply(provider_.get(), reply_message_.release()) |
| 1453 .SendSuccess(NULL); |
| 1449 delete this; | 1454 delete this; |
| 1450 } | 1455 } |
| 1451 | 1456 |
| 1452 AutomationProviderSearchEngineObserver::AutomationProviderSearchEngineObserver( | 1457 AutomationProviderSearchEngineObserver::AutomationProviderSearchEngineObserver( |
| 1453 AutomationProvider* provider, | 1458 AutomationProvider* provider, |
| 1454 Profile* profile, | 1459 Profile* profile, |
| 1455 IPC::Message* reply_message) | 1460 IPC::Message* reply_message) |
| 1456 : provider_(provider->AsWeakPtr()), | 1461 : provider_(provider->AsWeakPtr()), |
| 1457 profile_(profile), | 1462 profile_(profile), |
| 1458 reply_message_(reply_message) { | 1463 reply_message_(reply_message) { |
| 1459 } | 1464 } |
| 1460 | 1465 |
| 1461 AutomationProviderSearchEngineObserver:: | 1466 AutomationProviderSearchEngineObserver:: |
| 1462 ~AutomationProviderSearchEngineObserver() {} | 1467 ~AutomationProviderSearchEngineObserver() {} |
| 1463 | 1468 |
| 1464 void AutomationProviderSearchEngineObserver::OnTemplateURLServiceChanged() { | 1469 void AutomationProviderSearchEngineObserver::OnTemplateURLServiceChanged() { |
| 1465 if (provider_) { | 1470 if (provider_.get()) { |
| 1466 TemplateURLService* url_service = | 1471 TemplateURLService* url_service = |
| 1467 TemplateURLServiceFactory::GetForProfile(profile_); | 1472 TemplateURLServiceFactory::GetForProfile(profile_); |
| 1468 url_service->RemoveObserver(this); | 1473 url_service->RemoveObserver(this); |
| 1469 AutomationJSONReply(provider_, reply_message_.release()).SendSuccess(NULL); | 1474 AutomationJSONReply(provider_.get(), reply_message_.release()) |
| 1475 .SendSuccess(NULL); |
| 1470 } | 1476 } |
| 1471 delete this; | 1477 delete this; |
| 1472 } | 1478 } |
| 1473 | 1479 |
| 1474 AutomationProviderHistoryObserver::AutomationProviderHistoryObserver( | 1480 AutomationProviderHistoryObserver::AutomationProviderHistoryObserver( |
| 1475 AutomationProvider* provider, | 1481 AutomationProvider* provider, |
| 1476 IPC::Message* reply_message) | 1482 IPC::Message* reply_message) |
| 1477 : provider_(provider->AsWeakPtr()), | 1483 : provider_(provider->AsWeakPtr()), |
| 1478 reply_message_(reply_message) { | 1484 reply_message_(reply_message) { |
| 1479 } | 1485 } |
| 1480 | 1486 |
| 1481 AutomationProviderHistoryObserver::~AutomationProviderHistoryObserver() {} | 1487 AutomationProviderHistoryObserver::~AutomationProviderHistoryObserver() {} |
| 1482 | 1488 |
| 1483 void AutomationProviderHistoryObserver::HistoryQueryComplete( | 1489 void AutomationProviderHistoryObserver::HistoryQueryComplete( |
| 1484 HistoryService::Handle request_handle, | 1490 HistoryService::Handle request_handle, |
| 1485 history::QueryResults* results) { | 1491 history::QueryResults* results) { |
| 1486 if (!provider_) { | 1492 if (!provider_.get()) { |
| 1487 delete this; | 1493 delete this; |
| 1488 return; | 1494 return; |
| 1489 } | 1495 } |
| 1490 | 1496 |
| 1491 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 1497 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 1492 | 1498 |
| 1493 ListValue* history_list = new ListValue; | 1499 ListValue* history_list = new ListValue; |
| 1494 for (size_t i = 0; i < results->size(); ++i) { | 1500 for (size_t i = 0; i < results->size(); ++i) { |
| 1495 DictionaryValue* page_value = new DictionaryValue; | 1501 DictionaryValue* page_value = new DictionaryValue; |
| 1496 history::URLResult const &page = (*results)[i]; | 1502 history::URLResult const &page = (*results)[i]; |
| 1497 page_value->SetString("title", page.title()); | 1503 page_value->SetString("title", page.title()); |
| 1498 page_value->SetString("url", page.url().spec()); | 1504 page_value->SetString("url", page.url().spec()); |
| 1499 page_value->SetDouble("time", | 1505 page_value->SetDouble("time", |
| 1500 static_cast<double>(page.visit_time().ToDoubleT())); | 1506 static_cast<double>(page.visit_time().ToDoubleT())); |
| 1501 page_value->SetString("snippet", page.snippet().text()); | 1507 page_value->SetString("snippet", page.snippet().text()); |
| 1502 page_value->SetBoolean( | 1508 page_value->SetBoolean( |
| 1503 "starred", | 1509 "starred", |
| 1504 BookmarkModelFactory::GetForProfile( | 1510 BookmarkModelFactory::GetForProfile( |
| 1505 provider_->profile())->IsBookmarked(page.url())); | 1511 provider_->profile())->IsBookmarked(page.url())); |
| 1506 history_list->Append(page_value); | 1512 history_list->Append(page_value); |
| 1507 } | 1513 } |
| 1508 | 1514 |
| 1509 return_value->Set("history", history_list); | 1515 return_value->Set("history", history_list); |
| 1510 // Return history info. | 1516 // Return history info. |
| 1511 AutomationJSONReply reply(provider_, reply_message_.release()); | 1517 AutomationJSONReply reply(provider_.get(), reply_message_.release()); |
| 1512 reply.SendSuccess(return_value.get()); | 1518 reply.SendSuccess(return_value.get()); |
| 1513 delete this; | 1519 delete this; |
| 1514 } | 1520 } |
| 1515 | 1521 |
| 1516 AutomationProviderImportSettingsObserver:: | 1522 AutomationProviderImportSettingsObserver:: |
| 1517 AutomationProviderImportSettingsObserver( | 1523 AutomationProviderImportSettingsObserver( |
| 1518 AutomationProvider* provider, | 1524 AutomationProvider* provider, |
| 1519 IPC::Message* reply_message) | 1525 IPC::Message* reply_message) |
| 1520 : provider_(provider->AsWeakPtr()), | 1526 : provider_(provider->AsWeakPtr()), |
| 1521 reply_message_(reply_message) { | 1527 reply_message_(reply_message) { |
| 1522 } | 1528 } |
| 1523 | 1529 |
| 1524 AutomationProviderImportSettingsObserver:: | 1530 AutomationProviderImportSettingsObserver:: |
| 1525 ~AutomationProviderImportSettingsObserver() {} | 1531 ~AutomationProviderImportSettingsObserver() {} |
| 1526 | 1532 |
| 1527 void AutomationProviderImportSettingsObserver::ImportStarted() { | 1533 void AutomationProviderImportSettingsObserver::ImportStarted() { |
| 1528 } | 1534 } |
| 1529 | 1535 |
| 1530 void AutomationProviderImportSettingsObserver::ImportItemStarted( | 1536 void AutomationProviderImportSettingsObserver::ImportItemStarted( |
| 1531 importer::ImportItem item) { | 1537 importer::ImportItem item) { |
| 1532 } | 1538 } |
| 1533 | 1539 |
| 1534 void AutomationProviderImportSettingsObserver::ImportItemEnded( | 1540 void AutomationProviderImportSettingsObserver::ImportItemEnded( |
| 1535 importer::ImportItem item) { | 1541 importer::ImportItem item) { |
| 1536 } | 1542 } |
| 1537 | 1543 |
| 1538 void AutomationProviderImportSettingsObserver::ImportEnded() { | 1544 void AutomationProviderImportSettingsObserver::ImportEnded() { |
| 1539 if (provider_) | 1545 if (provider_.get()) |
| 1540 AutomationJSONReply(provider_, reply_message_.release()).SendSuccess(NULL); | 1546 AutomationJSONReply(provider_.get(), reply_message_.release()) |
| 1547 .SendSuccess(NULL); |
| 1541 delete this; | 1548 delete this; |
| 1542 } | 1549 } |
| 1543 | 1550 |
| 1544 AutomationProviderGetPasswordsObserver::AutomationProviderGetPasswordsObserver( | 1551 AutomationProviderGetPasswordsObserver::AutomationProviderGetPasswordsObserver( |
| 1545 AutomationProvider* provider, | 1552 AutomationProvider* provider, |
| 1546 IPC::Message* reply_message) | 1553 IPC::Message* reply_message) |
| 1547 : provider_(provider->AsWeakPtr()), | 1554 : provider_(provider->AsWeakPtr()), |
| 1548 reply_message_(reply_message) { | 1555 reply_message_(reply_message) { |
| 1549 } | 1556 } |
| 1550 | 1557 |
| 1551 AutomationProviderGetPasswordsObserver:: | 1558 AutomationProviderGetPasswordsObserver:: |
| 1552 ~AutomationProviderGetPasswordsObserver() {} | 1559 ~AutomationProviderGetPasswordsObserver() {} |
| 1553 | 1560 |
| 1554 void AutomationProviderGetPasswordsObserver::OnPasswordStoreRequestDone( | 1561 void AutomationProviderGetPasswordsObserver::OnPasswordStoreRequestDone( |
| 1555 CancelableRequestProvider::Handle handle, | 1562 CancelableRequestProvider::Handle handle, |
| 1556 const std::vector<content::PasswordForm*>& result) { | 1563 const std::vector<content::PasswordForm*>& result) { |
| 1557 if (!provider_) { | 1564 if (!provider_.get()) { |
| 1558 delete this; | 1565 delete this; |
| 1559 return; | 1566 return; |
| 1560 } | 1567 } |
| 1561 | 1568 |
| 1562 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 1569 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 1563 | 1570 |
| 1564 ListValue* passwords = new ListValue; | 1571 ListValue* passwords = new ListValue; |
| 1565 for (std::vector<content::PasswordForm*>::const_iterator it = | 1572 for (std::vector<content::PasswordForm*>::const_iterator it = |
| 1566 result.begin(); it != result.end(); ++it) { | 1573 result.begin(); it != result.end(); ++it) { |
| 1567 DictionaryValue* password_val = new DictionaryValue; | 1574 DictionaryValue* password_val = new DictionaryValue; |
| 1568 content::PasswordForm* password_form = *it; | 1575 content::PasswordForm* password_form = *it; |
| 1569 password_val->SetString("username_value", password_form->username_value); | 1576 password_val->SetString("username_value", password_form->username_value); |
| 1570 password_val->SetString("password_value", password_form->password_value); | 1577 password_val->SetString("password_value", password_form->password_value); |
| 1571 password_val->SetString("signon_realm", password_form->signon_realm); | 1578 password_val->SetString("signon_realm", password_form->signon_realm); |
| 1572 password_val->SetDouble( | 1579 password_val->SetDouble( |
| 1573 "time", static_cast<double>(password_form->date_created.ToDoubleT())); | 1580 "time", static_cast<double>(password_form->date_created.ToDoubleT())); |
| 1574 password_val->SetString("origin_url", password_form->origin.spec()); | 1581 password_val->SetString("origin_url", password_form->origin.spec()); |
| 1575 password_val->SetString("username_element", | 1582 password_val->SetString("username_element", |
| 1576 password_form->username_element); | 1583 password_form->username_element); |
| 1577 password_val->SetString("password_element", | 1584 password_val->SetString("password_element", |
| 1578 password_form->password_element); | 1585 password_form->password_element); |
| 1579 password_val->SetString("submit_element", password_form->submit_element); | 1586 password_val->SetString("submit_element", password_form->submit_element); |
| 1580 password_val->SetString("action_target", password_form->action.spec()); | 1587 password_val->SetString("action_target", password_form->action.spec()); |
| 1581 password_val->SetBoolean("blacklist", password_form->blacklisted_by_user); | 1588 password_val->SetBoolean("blacklist", password_form->blacklisted_by_user); |
| 1582 passwords->Append(password_val); | 1589 passwords->Append(password_val); |
| 1583 } | 1590 } |
| 1584 | 1591 |
| 1585 return_value->Set("passwords", passwords); | 1592 return_value->Set("passwords", passwords); |
| 1586 AutomationJSONReply(provider_, reply_message_.release()).SendSuccess( | 1593 AutomationJSONReply(provider_.get(), reply_message_.release()) |
| 1587 return_value.get()); | 1594 .SendSuccess(return_value.get()); |
| 1588 delete this; | 1595 delete this; |
| 1589 } | 1596 } |
| 1590 | 1597 |
| 1591 void AutomationProviderGetPasswordsObserver::OnGetPasswordStoreResults( | 1598 void AutomationProviderGetPasswordsObserver::OnGetPasswordStoreResults( |
| 1592 const std::vector<content::PasswordForm*>& results) { | 1599 const std::vector<content::PasswordForm*>& results) { |
| 1593 // TODO(kaiwang): Implement when I refactor | 1600 // TODO(kaiwang): Implement when I refactor |
| 1594 // PasswordManager::GetAutofillableLogins. | 1601 // PasswordManager::GetAutofillableLogins. |
| 1595 NOTIMPLEMENTED(); | 1602 NOTIMPLEMENTED(); |
| 1596 } | 1603 } |
| 1597 | 1604 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1653 | 1660 |
| 1654 // Notify the UI thread that we're done listening. | 1661 // Notify the UI thread that we're done listening. |
| 1655 BrowserThread::PostTask( | 1662 BrowserThread::PostTask( |
| 1656 BrowserThread::UI, | 1663 BrowserThread::UI, |
| 1657 FROM_HERE, | 1664 FROM_HERE, |
| 1658 base::Bind(&PasswordStoreLoginsChangedObserver::IndicateDone, this)); | 1665 base::Bind(&PasswordStoreLoginsChangedObserver::IndicateDone, this)); |
| 1659 } | 1666 } |
| 1660 | 1667 |
| 1661 void PasswordStoreLoginsChangedObserver::IndicateDone() { | 1668 void PasswordStoreLoginsChangedObserver::IndicateDone() { |
| 1662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1663 if (automation_) { | 1670 if (automation_.get()) { |
| 1664 if (result_key_.empty()) { | 1671 if (result_key_.empty()) { |
| 1665 AutomationJSONReply(automation_, reply_message_.release()) | 1672 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1666 .SendSuccess(NULL); | 1673 .SendSuccess(NULL); |
| 1667 } else { | 1674 } else { |
| 1668 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 1675 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 1669 return_value->SetBoolean(result_key_, true); | 1676 return_value->SetBoolean(result_key_, true); |
| 1670 AutomationJSONReply(automation_, reply_message_.release()) | 1677 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1671 .SendSuccess(return_value.get()); | 1678 .SendSuccess(return_value.get()); |
| 1672 } | 1679 } |
| 1673 } | 1680 } |
| 1674 Release(); | 1681 Release(); |
| 1675 } | 1682 } |
| 1676 | 1683 |
| 1677 void PasswordStoreLoginsChangedObserver::IndicateError( | 1684 void PasswordStoreLoginsChangedObserver::IndicateError( |
| 1678 const std::string& error) { | 1685 const std::string& error) { |
| 1679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1680 if (automation_) | 1687 if (automation_.get()) |
| 1681 AutomationJSONReply(automation_, reply_message_.release()).SendError(error); | 1688 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1689 .SendError(error); |
| 1682 Release(); | 1690 Release(); |
| 1683 } | 1691 } |
| 1684 | 1692 |
| 1685 OmniboxAcceptNotificationObserver::OmniboxAcceptNotificationObserver( | 1693 OmniboxAcceptNotificationObserver::OmniboxAcceptNotificationObserver( |
| 1686 NavigationController* controller, | 1694 NavigationController* controller, |
| 1687 AutomationProvider* automation, | 1695 AutomationProvider* automation, |
| 1688 IPC::Message* reply_message) | 1696 IPC::Message* reply_message) |
| 1689 : automation_(automation->AsWeakPtr()), | 1697 : automation_(automation->AsWeakPtr()), |
| 1690 reply_message_(reply_message), | 1698 reply_message_(reply_message), |
| 1691 controller_(controller) { | 1699 controller_(controller) { |
| 1692 content::Source<NavigationController> source(controller_); | 1700 content::Source<NavigationController> source(controller_); |
| 1693 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, source); | 1701 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, source); |
| 1694 // Pages requiring auth don't send LOAD_STOP. | 1702 // Pages requiring auth don't send LOAD_STOP. |
| 1695 registrar_.Add(this, chrome::NOTIFICATION_AUTH_NEEDED, source); | 1703 registrar_.Add(this, chrome::NOTIFICATION_AUTH_NEEDED, source); |
| 1696 } | 1704 } |
| 1697 | 1705 |
| 1698 OmniboxAcceptNotificationObserver::~OmniboxAcceptNotificationObserver() { | 1706 OmniboxAcceptNotificationObserver::~OmniboxAcceptNotificationObserver() { |
| 1699 } | 1707 } |
| 1700 | 1708 |
| 1701 void OmniboxAcceptNotificationObserver::Observe( | 1709 void OmniboxAcceptNotificationObserver::Observe( |
| 1702 int type, | 1710 int type, |
| 1703 const content::NotificationSource& source, | 1711 const content::NotificationSource& source, |
| 1704 const content::NotificationDetails& details) { | 1712 const content::NotificationDetails& details) { |
| 1705 if (type == content::NOTIFICATION_LOAD_STOP || | 1713 if (type == content::NOTIFICATION_LOAD_STOP || |
| 1706 type == chrome::NOTIFICATION_AUTH_NEEDED) { | 1714 type == chrome::NOTIFICATION_AUTH_NEEDED) { |
| 1707 if (automation_) { | 1715 if (automation_.get()) { |
| 1708 AutomationJSONReply(automation_, | 1716 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1709 reply_message_.release()).SendSuccess(NULL); | 1717 .SendSuccess(NULL); |
| 1710 } | 1718 } |
| 1711 delete this; | 1719 delete this; |
| 1712 } else { | 1720 } else { |
| 1713 NOTREACHED(); | 1721 NOTREACHED(); |
| 1714 } | 1722 } |
| 1715 } | 1723 } |
| 1716 | 1724 |
| 1717 SavePackageNotificationObserver::SavePackageNotificationObserver( | 1725 SavePackageNotificationObserver::SavePackageNotificationObserver( |
| 1718 content::DownloadManager* download_manager, | 1726 content::DownloadManager* download_manager, |
| 1719 AutomationProvider* automation, | 1727 AutomationProvider* automation, |
| 1720 IPC::Message* reply_message) | 1728 IPC::Message* reply_message) |
| 1721 : download_manager_(download_manager), | 1729 : download_manager_(download_manager), |
| 1722 automation_(automation->AsWeakPtr()), | 1730 automation_(automation->AsWeakPtr()), |
| 1723 reply_message_(reply_message) { | 1731 reply_message_(reply_message) { |
| 1724 download_manager_->AddObserver(this); | 1732 download_manager_->AddObserver(this); |
| 1725 } | 1733 } |
| 1726 | 1734 |
| 1727 SavePackageNotificationObserver::~SavePackageNotificationObserver() { | 1735 SavePackageNotificationObserver::~SavePackageNotificationObserver() { |
| 1728 download_manager_->RemoveObserver(this); | 1736 download_manager_->RemoveObserver(this); |
| 1729 } | 1737 } |
| 1730 | 1738 |
| 1731 void SavePackageNotificationObserver::OnSavePackageSuccessfullyFinished( | 1739 void SavePackageNotificationObserver::OnSavePackageSuccessfullyFinished( |
| 1732 content::DownloadManager* manager, content::DownloadItem* item) { | 1740 content::DownloadManager* manager, content::DownloadItem* item) { |
| 1733 if (automation_) { | 1741 if (automation_.get()) { |
| 1734 AutomationJSONReply(automation_, | 1742 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1735 reply_message_.release()).SendSuccess(NULL); | 1743 .SendSuccess(NULL); |
| 1736 } | 1744 } |
| 1737 delete this; | 1745 delete this; |
| 1738 } | 1746 } |
| 1739 | 1747 |
| 1740 void SavePackageNotificationObserver::ManagerGoingDown( | 1748 void SavePackageNotificationObserver::ManagerGoingDown( |
| 1741 content::DownloadManager* manager) { | 1749 content::DownloadManager* manager) { |
| 1742 delete this; | 1750 delete this; |
| 1743 } | 1751 } |
| 1744 | 1752 |
| 1745 namespace { | 1753 namespace { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1789 } // namespace | 1797 } // namespace |
| 1790 | 1798 |
| 1791 NTPInfoObserver::NTPInfoObserver(AutomationProvider* automation, | 1799 NTPInfoObserver::NTPInfoObserver(AutomationProvider* automation, |
| 1792 IPC::Message* reply_message) | 1800 IPC::Message* reply_message) |
| 1793 : automation_(automation->AsWeakPtr()), | 1801 : automation_(automation->AsWeakPtr()), |
| 1794 reply_message_(reply_message), | 1802 reply_message_(reply_message), |
| 1795 request_(0), | 1803 request_(0), |
| 1796 ntp_info_(new DictionaryValue) { | 1804 ntp_info_(new DictionaryValue) { |
| 1797 top_sites_ = automation_->profile()->GetTopSites(); | 1805 top_sites_ = automation_->profile()->GetTopSites(); |
| 1798 if (!top_sites_) { | 1806 if (!top_sites_) { |
| 1799 AutomationJSONReply(automation_, reply_message_.release()) | 1807 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1800 .SendError("Profile does not have service for querying the top sites."); | 1808 .SendError("Profile does not have service for querying the top sites."); |
| 1801 return; | 1809 return; |
| 1802 } | 1810 } |
| 1803 TabRestoreService* service = | 1811 TabRestoreService* service = |
| 1804 TabRestoreServiceFactory::GetForProfile(automation_->profile()); | 1812 TabRestoreServiceFactory::GetForProfile(automation_->profile()); |
| 1805 if (!service) { | 1813 if (!service) { |
| 1806 AutomationJSONReply(automation_, reply_message_.release()) | 1814 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1807 .SendError("No TabRestoreService."); | 1815 .SendError("No TabRestoreService."); |
| 1808 return; | 1816 return; |
| 1809 } | 1817 } |
| 1810 | 1818 |
| 1811 // Collect information about the apps in the new tab page. | 1819 // Collect information about the apps in the new tab page. |
| 1812 ExtensionService* ext_service = extensions::ExtensionSystem::Get( | 1820 ExtensionService* ext_service = extensions::ExtensionSystem::Get( |
| 1813 automation_->profile())->extension_service(); | 1821 automation_->profile())->extension_service(); |
| 1814 if (!ext_service) { | 1822 if (!ext_service) { |
| 1815 AutomationJSONReply(automation_, reply_message_.release()) | 1823 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1816 .SendError("No ExtensionService."); | 1824 .SendError("No ExtensionService."); |
| 1817 return; | 1825 return; |
| 1818 } | 1826 } |
| 1819 // Process enabled extensions. | 1827 // Process enabled extensions. |
| 1820 ListValue* apps_list = new ListValue(); | 1828 ListValue* apps_list = new ListValue(); |
| 1821 const ExtensionSet* extensions = ext_service->extensions(); | 1829 const ExtensionSet* extensions = ext_service->extensions(); |
| 1822 std::vector<DictionaryValue*>* enabled_apps = GetAppInfoFromExtensions( | 1830 std::vector<DictionaryValue*>* enabled_apps = GetAppInfoFromExtensions( |
| 1823 extensions, ext_service); | 1831 extensions, ext_service); |
| 1824 for (std::vector<DictionaryValue*>::const_iterator app = | 1832 for (std::vector<DictionaryValue*>::const_iterator app = |
| 1825 enabled_apps->begin(); app != enabled_apps->end(); ++app) { | 1833 enabled_apps->begin(); app != enabled_apps->end(); ++app) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1892 } | 1900 } |
| 1893 } | 1901 } |
| 1894 } | 1902 } |
| 1895 | 1903 |
| 1896 void NTPInfoObserver::OnTopSitesLoaded() { | 1904 void NTPInfoObserver::OnTopSitesLoaded() { |
| 1897 request_ = top_sites_->StartQueryForMostVisited(); | 1905 request_ = top_sites_->StartQueryForMostVisited(); |
| 1898 } | 1906 } |
| 1899 | 1907 |
| 1900 void NTPInfoObserver::OnTopSitesReceived( | 1908 void NTPInfoObserver::OnTopSitesReceived( |
| 1901 const history::MostVisitedURLList& visited_list) { | 1909 const history::MostVisitedURLList& visited_list) { |
| 1902 if (!automation_) { | 1910 if (!automation_.get()) { |
| 1903 delete this; | 1911 delete this; |
| 1904 return; | 1912 return; |
| 1905 } | 1913 } |
| 1906 | 1914 |
| 1907 ListValue* list_value = new ListValue; | 1915 ListValue* list_value = new ListValue; |
| 1908 for (size_t i = 0; i < visited_list.size(); ++i) { | 1916 for (size_t i = 0; i < visited_list.size(); ++i) { |
| 1909 const history::MostVisitedURL& visited = visited_list[i]; | 1917 const history::MostVisitedURL& visited = visited_list[i]; |
| 1910 if (visited.url.spec().empty()) | 1918 if (visited.url.spec().empty()) |
| 1911 break; // This is the signal that there are no more real visited sites. | 1919 break; // This is the signal that there are no more real visited sites. |
| 1912 DictionaryValue* dict = new DictionaryValue; | 1920 DictionaryValue* dict = new DictionaryValue; |
| 1913 dict->SetString("url", visited.url.spec()); | 1921 dict->SetString("url", visited.url.spec()); |
| 1914 dict->SetString("title", visited.title); | 1922 dict->SetString("title", visited.title); |
| 1915 list_value->Append(dict); | 1923 list_value->Append(dict); |
| 1916 } | 1924 } |
| 1917 ntp_info_->Set("most_visited", list_value); | 1925 ntp_info_->Set("most_visited", list_value); |
| 1918 AutomationJSONReply(automation_, | 1926 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1919 reply_message_.release()).SendSuccess(ntp_info_.get()); | 1927 .SendSuccess(ntp_info_.get()); |
| 1920 delete this; | 1928 delete this; |
| 1921 } | 1929 } |
| 1922 | 1930 |
| 1923 AppLaunchObserver::AppLaunchObserver( | 1931 AppLaunchObserver::AppLaunchObserver( |
| 1924 NavigationController* controller, | 1932 NavigationController* controller, |
| 1925 AutomationProvider* automation, | 1933 AutomationProvider* automation, |
| 1926 IPC::Message* reply_message, | 1934 IPC::Message* reply_message, |
| 1927 extension_misc::LaunchContainer launch_container) | 1935 extension_misc::LaunchContainer launch_container) |
| 1928 : controller_(controller), | 1936 : controller_(controller), |
| 1929 automation_(automation->AsWeakPtr()), | 1937 automation_(automation->AsWeakPtr()), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1953 ExtensionTabUtil::GetWindowId(content::Source<Browser>(source).ptr()); | 1961 ExtensionTabUtil::GetWindowId(content::Source<Browser>(source).ptr()); |
| 1954 return; | 1962 return; |
| 1955 } | 1963 } |
| 1956 | 1964 |
| 1957 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type); | 1965 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type); |
| 1958 SessionTabHelper* session_tab_helper = SessionTabHelper::FromWebContents( | 1966 SessionTabHelper* session_tab_helper = SessionTabHelper::FromWebContents( |
| 1959 content::Source<NavigationController>(source)->GetWebContents()); | 1967 content::Source<NavigationController>(source)->GetWebContents()); |
| 1960 if ((launch_container_ == extension_misc::LAUNCH_TAB) || | 1968 if ((launch_container_ == extension_misc::LAUNCH_TAB) || |
| 1961 (session_tab_helper && | 1969 (session_tab_helper && |
| 1962 (session_tab_helper->window_id().id() == new_window_id_))) { | 1970 (session_tab_helper->window_id().id() == new_window_id_))) { |
| 1963 if (automation_) { | 1971 if (automation_.get()) { |
| 1964 AutomationJSONReply(automation_, | 1972 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 1965 reply_message_.release()).SendSuccess(NULL); | 1973 .SendSuccess(NULL); |
| 1966 } | 1974 } |
| 1967 delete this; | 1975 delete this; |
| 1968 } | 1976 } |
| 1969 } | 1977 } |
| 1970 | 1978 |
| 1971 namespace { | 1979 namespace { |
| 1972 | 1980 |
| 1973 // Returns whether all active notifications have an associated process ID. | 1981 // Returns whether all active notifications have an associated process ID. |
| 1974 bool AreActiveNotificationProcessesReady() { | 1982 bool AreActiveNotificationProcessesReady() { |
| 1975 BalloonNotificationUIManager* manager = | 1983 BalloonNotificationUIManager* manager = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1999 content::NotificationService::AllSources()); | 2007 content::NotificationService::AllSources()); |
| 2000 } | 2008 } |
| 2001 } | 2009 } |
| 2002 | 2010 |
| 2003 GetAllNotificationsObserver::~GetAllNotificationsObserver() {} | 2011 GetAllNotificationsObserver::~GetAllNotificationsObserver() {} |
| 2004 | 2012 |
| 2005 void GetAllNotificationsObserver::Observe( | 2013 void GetAllNotificationsObserver::Observe( |
| 2006 int type, | 2014 int type, |
| 2007 const content::NotificationSource& source, | 2015 const content::NotificationSource& source, |
| 2008 const content::NotificationDetails& details) { | 2016 const content::NotificationDetails& details) { |
| 2009 if (!automation_) { | 2017 if (!automation_.get()) { |
| 2010 delete this; | 2018 delete this; |
| 2011 return; | 2019 return; |
| 2012 } | 2020 } |
| 2013 if (AreActiveNotificationProcessesReady()) | 2021 if (AreActiveNotificationProcessesReady()) |
| 2014 SendMessage(); | 2022 SendMessage(); |
| 2015 } | 2023 } |
| 2016 | 2024 |
| 2017 base::DictionaryValue* GetAllNotificationsObserver::NotificationToJson( | 2025 base::DictionaryValue* GetAllNotificationsObserver::NotificationToJson( |
| 2018 const Notification* note) { | 2026 const Notification* note) { |
| 2019 DictionaryValue* dict = new base::DictionaryValue(); | 2027 DictionaryValue* dict = new base::DictionaryValue(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2045 } | 2053 } |
| 2046 list->Append(note); | 2054 list->Append(note); |
| 2047 } | 2055 } |
| 2048 std::vector<const Notification*> queued_notes; | 2056 std::vector<const Notification*> queued_notes; |
| 2049 manager->GetQueuedNotificationsForTesting(&queued_notes); | 2057 manager->GetQueuedNotificationsForTesting(&queued_notes); |
| 2050 std::vector<const Notification*>::const_iterator queued_iter; | 2058 std::vector<const Notification*>::const_iterator queued_iter; |
| 2051 for (queued_iter = queued_notes.begin(); queued_iter != queued_notes.end(); | 2059 for (queued_iter = queued_notes.begin(); queued_iter != queued_notes.end(); |
| 2052 ++queued_iter) { | 2060 ++queued_iter) { |
| 2053 list->Append(NotificationToJson(*queued_iter)); | 2061 list->Append(NotificationToJson(*queued_iter)); |
| 2054 } | 2062 } |
| 2055 AutomationJSONReply(automation_, | 2063 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2056 reply_message_.release()).SendSuccess(&return_value); | 2064 .SendSuccess(&return_value); |
| 2057 delete this; | 2065 delete this; |
| 2058 } | 2066 } |
| 2059 | 2067 |
| 2060 NewNotificationBalloonObserver::NewNotificationBalloonObserver( | 2068 NewNotificationBalloonObserver::NewNotificationBalloonObserver( |
| 2061 AutomationProvider* provider, | 2069 AutomationProvider* provider, |
| 2062 IPC::Message* reply_message) | 2070 IPC::Message* reply_message) |
| 2063 : automation_(provider->AsWeakPtr()), | 2071 : automation_(provider->AsWeakPtr()), |
| 2064 reply_message_(reply_message) { | 2072 reply_message_(reply_message) { |
| 2065 registrar_.Add(this, chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED, | 2073 registrar_.Add(this, chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED, |
| 2066 content::NotificationService::AllSources()); | 2074 content::NotificationService::AllSources()); |
| 2067 } | 2075 } |
| 2068 | 2076 |
| 2069 NewNotificationBalloonObserver::~NewNotificationBalloonObserver() { } | 2077 NewNotificationBalloonObserver::~NewNotificationBalloonObserver() { } |
| 2070 | 2078 |
| 2071 void NewNotificationBalloonObserver::Observe( | 2079 void NewNotificationBalloonObserver::Observe( |
| 2072 int type, | 2080 int type, |
| 2073 const content::NotificationSource& source, | 2081 const content::NotificationSource& source, |
| 2074 const content::NotificationDetails& details) { | 2082 const content::NotificationDetails& details) { |
| 2075 if (automation_) { | 2083 if (automation_.get()) { |
| 2076 AutomationJSONReply(automation_, | 2084 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2077 reply_message_.release()).SendSuccess(NULL); | 2085 .SendSuccess(NULL); |
| 2078 } | 2086 } |
| 2079 delete this; | 2087 delete this; |
| 2080 } | 2088 } |
| 2081 | 2089 |
| 2082 OnNotificationBalloonCountObserver::OnNotificationBalloonCountObserver( | 2090 OnNotificationBalloonCountObserver::OnNotificationBalloonCountObserver( |
| 2083 AutomationProvider* provider, | 2091 AutomationProvider* provider, |
| 2084 IPC::Message* reply_message, | 2092 IPC::Message* reply_message, |
| 2085 int count) | 2093 int count) |
| 2086 : automation_(provider->AsWeakPtr()), | 2094 : automation_(provider->AsWeakPtr()), |
| 2087 reply_message_(reply_message), | 2095 reply_message_(reply_message), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2103 int type, | 2111 int type, |
| 2104 const content::NotificationSource& source, | 2112 const content::NotificationSource& source, |
| 2105 const content::NotificationDetails& details) { | 2113 const content::NotificationDetails& details) { |
| 2106 CheckBalloonCount(); | 2114 CheckBalloonCount(); |
| 2107 } | 2115 } |
| 2108 | 2116 |
| 2109 void OnNotificationBalloonCountObserver::CheckBalloonCount() { | 2117 void OnNotificationBalloonCountObserver::CheckBalloonCount() { |
| 2110 bool balloon_count_met = AreActiveNotificationProcessesReady() && | 2118 bool balloon_count_met = AreActiveNotificationProcessesReady() && |
| 2111 static_cast<int>(collection_->GetActiveBalloons().size()) == count_; | 2119 static_cast<int>(collection_->GetActiveBalloons().size()) == count_; |
| 2112 | 2120 |
| 2113 if (balloon_count_met && automation_) { | 2121 if (balloon_count_met && automation_.get()) { |
| 2114 AutomationJSONReply(automation_, | 2122 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2115 reply_message_.release()).SendSuccess(NULL); | 2123 .SendSuccess(NULL); |
| 2116 } | 2124 } |
| 2117 | 2125 |
| 2118 if (balloon_count_met || !automation_) { | 2126 if (balloon_count_met || !automation_.get()) { |
| 2119 collection_->set_on_collection_changed_callback(base::Closure()); | 2127 collection_->set_on_collection_changed_callback(base::Closure()); |
| 2120 delete this; | 2128 delete this; |
| 2121 } | 2129 } |
| 2122 } | 2130 } |
| 2123 | 2131 |
| 2124 RendererProcessClosedObserver::RendererProcessClosedObserver( | 2132 RendererProcessClosedObserver::RendererProcessClosedObserver( |
| 2125 AutomationProvider* automation, | 2133 AutomationProvider* automation, |
| 2126 IPC::Message* reply_message) | 2134 IPC::Message* reply_message) |
| 2127 : automation_(automation->AsWeakPtr()), | 2135 : automation_(automation->AsWeakPtr()), |
| 2128 reply_message_(reply_message) { | 2136 reply_message_(reply_message) { |
| 2129 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 2137 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 2130 content::NotificationService::AllSources()); | 2138 content::NotificationService::AllSources()); |
| 2131 } | 2139 } |
| 2132 | 2140 |
| 2133 RendererProcessClosedObserver::~RendererProcessClosedObserver() {} | 2141 RendererProcessClosedObserver::~RendererProcessClosedObserver() {} |
| 2134 | 2142 |
| 2135 void RendererProcessClosedObserver::Observe( | 2143 void RendererProcessClosedObserver::Observe( |
| 2136 int type, | 2144 int type, |
| 2137 const content::NotificationSource& source, | 2145 const content::NotificationSource& source, |
| 2138 const content::NotificationDetails& details) { | 2146 const content::NotificationDetails& details) { |
| 2139 if (automation_) { | 2147 if (automation_.get()) { |
| 2140 AutomationJSONReply(automation_, | 2148 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2141 reply_message_.release()).SendSuccess(NULL); | 2149 .SendSuccess(NULL); |
| 2142 } | 2150 } |
| 2143 delete this; | 2151 delete this; |
| 2144 } | 2152 } |
| 2145 | 2153 |
| 2146 InputEventAckNotificationObserver::InputEventAckNotificationObserver( | 2154 InputEventAckNotificationObserver::InputEventAckNotificationObserver( |
| 2147 AutomationProvider* automation, | 2155 AutomationProvider* automation, |
| 2148 IPC::Message* reply_message, | 2156 IPC::Message* reply_message, |
| 2149 int event_type, | 2157 int event_type, |
| 2150 int count) | 2158 int count) |
| 2151 : automation_(automation->AsWeakPtr()), | 2159 : automation_(automation->AsWeakPtr()), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2163 content::NotificationService::AllSources()); | 2171 content::NotificationService::AllSources()); |
| 2164 } | 2172 } |
| 2165 | 2173 |
| 2166 InputEventAckNotificationObserver::~InputEventAckNotificationObserver() {} | 2174 InputEventAckNotificationObserver::~InputEventAckNotificationObserver() {} |
| 2167 | 2175 |
| 2168 void InputEventAckNotificationObserver::Observe( | 2176 void InputEventAckNotificationObserver::Observe( |
| 2169 int type, | 2177 int type, |
| 2170 const content::NotificationSource& source, | 2178 const content::NotificationSource& source, |
| 2171 const content::NotificationDetails& details) { | 2179 const content::NotificationDetails& details) { |
| 2172 if (type == chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN) { | 2180 if (type == chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN) { |
| 2173 AutomationJSONReply(automation_, | 2181 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2174 reply_message_.release()).SendSuccess(NULL); | 2182 .SendSuccess(NULL); |
| 2175 delete this; | 2183 delete this; |
| 2176 return; | 2184 return; |
| 2177 } | 2185 } |
| 2178 | 2186 |
| 2179 content::Details<int> request_details(details); | 2187 content::Details<int> request_details(details); |
| 2180 // If the event type matches for |count_| times, replies with a JSON message. | 2188 // If the event type matches for |count_| times, replies with a JSON message. |
| 2181 if (event_type_ == *request_details.ptr()) { | 2189 if (event_type_ == *request_details.ptr()) { |
| 2182 if (--count_ == 0 && automation_) { | 2190 if (--count_ == 0 && automation_.get()) { |
| 2183 AutomationJSONReply(automation_, | 2191 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2184 reply_message_.release()).SendSuccess(NULL); | 2192 .SendSuccess(NULL); |
| 2185 delete this; | 2193 delete this; |
| 2186 } | 2194 } |
| 2187 } else { | 2195 } else { |
| 2188 LOG(WARNING) << "Ignoring unexpected event type: " | 2196 LOG(WARNING) << "Ignoring unexpected event type: " |
| 2189 << *request_details.ptr() << " (expected: " << event_type_ | 2197 << *request_details.ptr() << " (expected: " << event_type_ |
| 2190 << ")"; | 2198 << ")"; |
| 2191 } | 2199 } |
| 2192 } | 2200 } |
| 2193 | 2201 |
| 2194 NewTabObserver::NewTabObserver(AutomationProvider* automation, | 2202 NewTabObserver::NewTabObserver(AutomationProvider* automation, |
| 2195 IPC::Message* reply_message, | 2203 IPC::Message* reply_message, |
| 2196 bool use_json_interface) | 2204 bool use_json_interface) |
| 2197 : automation_(automation->AsWeakPtr()), | 2205 : automation_(automation->AsWeakPtr()), |
| 2198 reply_message_(reply_message), | 2206 reply_message_(reply_message), |
| 2199 use_json_interface_(use_json_interface) { | 2207 use_json_interface_(use_json_interface) { |
| 2200 // Use TAB_PARENTED to detect the new tab. | 2208 // Use TAB_PARENTED to detect the new tab. |
| 2201 registrar_.Add(this, | 2209 registrar_.Add(this, |
| 2202 chrome::NOTIFICATION_TAB_PARENTED, | 2210 chrome::NOTIFICATION_TAB_PARENTED, |
| 2203 content::NotificationService::AllSources()); | 2211 content::NotificationService::AllSources()); |
| 2204 } | 2212 } |
| 2205 | 2213 |
| 2206 void NewTabObserver::Observe(int type, | 2214 void NewTabObserver::Observe(int type, |
| 2207 const content::NotificationSource& source, | 2215 const content::NotificationSource& source, |
| 2208 const content::NotificationDetails& details) { | 2216 const content::NotificationDetails& details) { |
| 2209 DCHECK_EQ(chrome::NOTIFICATION_TAB_PARENTED, type); | 2217 DCHECK_EQ(chrome::NOTIFICATION_TAB_PARENTED, type); |
| 2210 NavigationController* controller = | 2218 NavigationController* controller = |
| 2211 &(content::Source<content::WebContents>(source).ptr()->GetController()); | 2219 &(content::Source<content::WebContents>(source).ptr()->GetController()); |
| 2212 if (automation_) { | 2220 if (automation_.get()) { |
| 2213 // TODO(phajdan.jr): Clean up this hack. We write the correct return type | 2221 // TODO(phajdan.jr): Clean up this hack. We write the correct return type |
| 2214 // here, but don't send the message. NavigationNotificationObserver | 2222 // here, but don't send the message. NavigationNotificationObserver |
| 2215 // will wait properly for the load to finish, and send the message, | 2223 // will wait properly for the load to finish, and send the message, |
| 2216 // but it will also append its own return value at the end of the reply. | 2224 // but it will also append its own return value at the end of the reply. |
| 2217 if (!use_json_interface_) | 2225 if (!use_json_interface_) |
| 2218 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(), | 2226 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(), |
| 2219 true); | 2227 true); |
| 2220 new NavigationNotificationObserver(controller, automation_, | 2228 new NavigationNotificationObserver(controller, |
| 2229 automation_.get(), |
| 2221 reply_message_.release(), | 2230 reply_message_.release(), |
| 2222 1, false, use_json_interface_); | 2231 1, |
| 2232 false, |
| 2233 use_json_interface_); |
| 2223 } | 2234 } |
| 2224 delete this; | 2235 delete this; |
| 2225 } | 2236 } |
| 2226 | 2237 |
| 2227 NewTabObserver::~NewTabObserver() { | 2238 NewTabObserver::~NewTabObserver() { |
| 2228 } | 2239 } |
| 2229 | 2240 |
| 2230 WaitForProcessLauncherThreadToGoIdleObserver:: | 2241 WaitForProcessLauncherThreadToGoIdleObserver:: |
| 2231 WaitForProcessLauncherThreadToGoIdleObserver( | 2242 WaitForProcessLauncherThreadToGoIdleObserver( |
| 2232 AutomationProvider* automation, IPC::Message* reply_message) | 2243 AutomationProvider* automation, IPC::Message* reply_message) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2261 RunOnProcessLauncherThread2() { | 2272 RunOnProcessLauncherThread2() { |
| 2262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::PROCESS_LAUNCHER)); | 2273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::PROCESS_LAUNCHER)); |
| 2263 BrowserThread::PostTask( | 2274 BrowserThread::PostTask( |
| 2264 BrowserThread::UI, FROM_HERE, | 2275 BrowserThread::UI, FROM_HERE, |
| 2265 base::Bind(&WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread, | 2276 base::Bind(&WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread, |
| 2266 this)); | 2277 this)); |
| 2267 } | 2278 } |
| 2268 | 2279 |
| 2269 void WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread() { | 2280 void WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread() { |
| 2270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2271 if (automation_) | 2282 if (automation_.get()) |
| 2272 automation_->Send(reply_message_.release()); | 2283 automation_->Send(reply_message_.release()); |
| 2273 Release(); | 2284 Release(); |
| 2274 } | 2285 } |
| 2275 | 2286 |
| 2276 DragTargetDropAckNotificationObserver::DragTargetDropAckNotificationObserver( | 2287 DragTargetDropAckNotificationObserver::DragTargetDropAckNotificationObserver( |
| 2277 AutomationProvider* automation, | 2288 AutomationProvider* automation, |
| 2278 IPC::Message* reply_message) | 2289 IPC::Message* reply_message) |
| 2279 : automation_(automation->AsWeakPtr()), | 2290 : automation_(automation->AsWeakPtr()), |
| 2280 reply_message_(reply_message) { | 2291 reply_message_(reply_message) { |
| 2281 registrar_.Add( | 2292 registrar_.Add( |
| 2282 this, | 2293 this, |
| 2283 content::NOTIFICATION_RENDER_VIEW_HOST_DID_RECEIVE_DRAG_TARGET_DROP_ACK, | 2294 content::NOTIFICATION_RENDER_VIEW_HOST_DID_RECEIVE_DRAG_TARGET_DROP_ACK, |
| 2284 content::NotificationService::AllSources()); | 2295 content::NotificationService::AllSources()); |
| 2285 registrar_.Add( | 2296 registrar_.Add( |
| 2286 this, | 2297 this, |
| 2287 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, | 2298 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, |
| 2288 content::NotificationService::AllSources()); | 2299 content::NotificationService::AllSources()); |
| 2289 } | 2300 } |
| 2290 | 2301 |
| 2291 DragTargetDropAckNotificationObserver:: | 2302 DragTargetDropAckNotificationObserver:: |
| 2292 ~DragTargetDropAckNotificationObserver() {} | 2303 ~DragTargetDropAckNotificationObserver() {} |
| 2293 | 2304 |
| 2294 void DragTargetDropAckNotificationObserver::Observe( | 2305 void DragTargetDropAckNotificationObserver::Observe( |
| 2295 int type, | 2306 int type, |
| 2296 const content::NotificationSource& source, | 2307 const content::NotificationSource& source, |
| 2297 const content::NotificationDetails& details) { | 2308 const content::NotificationDetails& details) { |
| 2298 if (automation_) { | 2309 if (automation_.get()) { |
| 2299 AutomationJSONReply(automation_, | 2310 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2300 reply_message_.release()).SendSuccess(NULL); | 2311 .SendSuccess(NULL); |
| 2301 } | 2312 } |
| 2302 delete this; | 2313 delete this; |
| 2303 } | 2314 } |
| 2304 | 2315 |
| 2305 ProcessInfoObserver::ProcessInfoObserver( | 2316 ProcessInfoObserver::ProcessInfoObserver( |
| 2306 AutomationProvider* automation, | 2317 AutomationProvider* automation, |
| 2307 IPC::Message* reply_message) | 2318 IPC::Message* reply_message) |
| 2308 : automation_(automation->AsWeakPtr()), | 2319 : automation_(automation->AsWeakPtr()), |
| 2309 reply_message_(reply_message) {} | 2320 reply_message_(reply_message) {} |
| 2310 | 2321 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2373 proc_data->Set("titles", titles); | 2384 proc_data->Set("titles", titles); |
| 2374 | 2385 |
| 2375 proc_list->Append(proc_data); | 2386 proc_list->Append(proc_data); |
| 2376 } | 2387 } |
| 2377 browser_data->Set("processes", proc_list); | 2388 browser_data->Set("processes", proc_list); |
| 2378 | 2389 |
| 2379 browser_proc_list->Append(browser_data); | 2390 browser_proc_list->Append(browser_data); |
| 2380 } | 2391 } |
| 2381 return_value->Set("browsers", browser_proc_list); | 2392 return_value->Set("browsers", browser_proc_list); |
| 2382 | 2393 |
| 2383 if (automation_) { | 2394 if (automation_.get()) { |
| 2384 AutomationJSONReply(automation_, reply_message_.release()) | 2395 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2385 .SendSuccess(return_value.get()); | 2396 .SendSuccess(return_value.get()); |
| 2386 } | 2397 } |
| 2387 } | 2398 } |
| 2388 | 2399 |
| 2389 V8HeapStatsObserver::V8HeapStatsObserver( | 2400 V8HeapStatsObserver::V8HeapStatsObserver( |
| 2390 AutomationProvider* automation, | 2401 AutomationProvider* automation, |
| 2391 IPC::Message* reply_message, | 2402 IPC::Message* reply_message, |
| 2392 base::ProcessId renderer_id) | 2403 base::ProcessId renderer_id) |
| 2393 : automation_(automation->AsWeakPtr()), | 2404 : automation_(automation->AsWeakPtr()), |
| 2394 reply_message_(reply_message), | 2405 reply_message_(reply_message), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2416 ChromeRenderMessageFilter::V8HeapStatsDetails* v8_heap_details = | 2427 ChromeRenderMessageFilter::V8HeapStatsDetails* v8_heap_details = |
| 2417 content::Details<ChromeRenderMessageFilter::V8HeapStatsDetails>(details) | 2428 content::Details<ChromeRenderMessageFilter::V8HeapStatsDetails>(details) |
| 2418 .ptr(); | 2429 .ptr(); |
| 2419 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2430 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2420 return_value->SetInteger("renderer_id", updated_renderer_id); | 2431 return_value->SetInteger("renderer_id", updated_renderer_id); |
| 2421 return_value->SetInteger("v8_memory_allocated", | 2432 return_value->SetInteger("v8_memory_allocated", |
| 2422 v8_heap_details->v8_memory_allocated()); | 2433 v8_heap_details->v8_memory_allocated()); |
| 2423 return_value->SetInteger("v8_memory_used", | 2434 return_value->SetInteger("v8_memory_used", |
| 2424 v8_heap_details->v8_memory_used()); | 2435 v8_heap_details->v8_memory_used()); |
| 2425 | 2436 |
| 2426 if (automation_) { | 2437 if (automation_.get()) { |
| 2427 AutomationJSONReply(automation_, reply_message_.release()) | 2438 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2428 .SendSuccess(return_value.get()); | 2439 .SendSuccess(return_value.get()); |
| 2429 } | 2440 } |
| 2430 delete this; | 2441 delete this; |
| 2431 } | 2442 } |
| 2432 | 2443 |
| 2433 FPSObserver::FPSObserver( | 2444 FPSObserver::FPSObserver( |
| 2434 AutomationProvider* automation, | 2445 AutomationProvider* automation, |
| 2435 IPC::Message* reply_message, | 2446 IPC::Message* reply_message, |
| 2436 base::ProcessId renderer_id, | 2447 base::ProcessId renderer_id, |
| 2437 int routing_id) | 2448 int routing_id) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2463 content::Details<ChromeRenderMessageFilter::FPSDetails>(details).ptr(); | 2474 content::Details<ChromeRenderMessageFilter::FPSDetails>(details).ptr(); |
| 2464 // Only return information for the routing id of the host render view we're | 2475 // Only return information for the routing id of the host render view we're |
| 2465 // interested in. | 2476 // interested in. |
| 2466 if (routing_id_ != fps_details->routing_id()) | 2477 if (routing_id_ != fps_details->routing_id()) |
| 2467 return; | 2478 return; |
| 2468 | 2479 |
| 2469 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2480 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2470 return_value->SetInteger("renderer_id", updated_renderer_id); | 2481 return_value->SetInteger("renderer_id", updated_renderer_id); |
| 2471 return_value->SetInteger("routing_id", fps_details->routing_id()); | 2482 return_value->SetInteger("routing_id", fps_details->routing_id()); |
| 2472 return_value->SetDouble("fps", fps_details->fps()); | 2483 return_value->SetDouble("fps", fps_details->fps()); |
| 2473 if (automation_) { | 2484 if (automation_.get()) { |
| 2474 AutomationJSONReply(automation_, reply_message_.release()) | 2485 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2475 .SendSuccess(return_value.get()); | 2486 .SendSuccess(return_value.get()); |
| 2476 } | 2487 } |
| 2477 delete this; | 2488 delete this; |
| 2478 } | 2489 } |
| 2479 | 2490 |
| 2480 BrowserOpenedWithNewProfileNotificationObserver:: | 2491 BrowserOpenedWithNewProfileNotificationObserver:: |
| 2481 BrowserOpenedWithNewProfileNotificationObserver( | 2492 BrowserOpenedWithNewProfileNotificationObserver( |
| 2482 AutomationProvider* automation, | 2493 AutomationProvider* automation, |
| 2483 IPC::Message* reply_message) | 2494 IPC::Message* reply_message) |
| 2484 : automation_(automation->AsWeakPtr()), | 2495 : automation_(automation->AsWeakPtr()), |
| 2485 reply_message_(reply_message), | 2496 reply_message_(reply_message), |
| 2486 new_window_id_(extension_misc::kUnknownWindowId) { | 2497 new_window_id_(extension_misc::kUnknownWindowId) { |
| 2487 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, | 2498 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, |
| 2488 content::NotificationService::AllBrowserContextsAndSources()); | 2499 content::NotificationService::AllBrowserContextsAndSources()); |
| 2489 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, | 2500 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
| 2490 content::NotificationService::AllBrowserContextsAndSources()); | 2501 content::NotificationService::AllBrowserContextsAndSources()); |
| 2491 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 2502 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 2492 content::NotificationService::AllBrowserContextsAndSources()); | 2503 content::NotificationService::AllBrowserContextsAndSources()); |
| 2493 } | 2504 } |
| 2494 | 2505 |
| 2495 BrowserOpenedWithNewProfileNotificationObserver:: | 2506 BrowserOpenedWithNewProfileNotificationObserver:: |
| 2496 ~BrowserOpenedWithNewProfileNotificationObserver() { | 2507 ~BrowserOpenedWithNewProfileNotificationObserver() { |
| 2497 } | 2508 } |
| 2498 | 2509 |
| 2499 void BrowserOpenedWithNewProfileNotificationObserver::Observe( | 2510 void BrowserOpenedWithNewProfileNotificationObserver::Observe( |
| 2500 int type, | 2511 int type, |
| 2501 const content::NotificationSource& source, | 2512 const content::NotificationSource& source, |
| 2502 const content::NotificationDetails& details) { | 2513 const content::NotificationDetails& details) { |
| 2503 if (!automation_) { | 2514 if (!automation_.get()) { |
| 2504 delete this; | 2515 delete this; |
| 2505 return; | 2516 return; |
| 2506 } | 2517 } |
| 2507 | 2518 |
| 2508 if (type == chrome::NOTIFICATION_PROFILE_CREATED) { | 2519 if (type == chrome::NOTIFICATION_PROFILE_CREATED) { |
| 2509 // As part of multi-profile creation, a new browser window will | 2520 // As part of multi-profile creation, a new browser window will |
| 2510 // automatically be opened. | 2521 // automatically be opened. |
| 2511 Profile* profile = content::Source<Profile>(source).ptr(); | 2522 Profile* profile = content::Source<Profile>(source).ptr(); |
| 2512 if (!profile) { | 2523 if (!profile) { |
| 2513 AutomationJSONReply(automation_, | 2524 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2514 reply_message_.release()).SendError("Profile could not be created."); | 2525 .SendError("Profile could not be created."); |
| 2515 return; | 2526 return; |
| 2516 } | 2527 } |
| 2517 } else if (type == chrome::NOTIFICATION_BROWSER_OPENED) { | 2528 } else if (type == chrome::NOTIFICATION_BROWSER_OPENED) { |
| 2518 // Store the new browser ID and continue waiting for a new tab within it | 2529 // Store the new browser ID and continue waiting for a new tab within it |
| 2519 // to stop loading. | 2530 // to stop loading. |
| 2520 new_window_id_ = ExtensionTabUtil::GetWindowId( | 2531 new_window_id_ = ExtensionTabUtil::GetWindowId( |
| 2521 content::Source<Browser>(source).ptr()); | 2532 content::Source<Browser>(source).ptr()); |
| 2522 } else { | 2533 } else { |
| 2523 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type); | 2534 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type); |
| 2524 // Only send the result if the loaded tab is in the new window. | 2535 // Only send the result if the loaded tab is in the new window. |
| 2525 NavigationController* controller = | 2536 NavigationController* controller = |
| 2526 content::Source<NavigationController>(source).ptr(); | 2537 content::Source<NavigationController>(source).ptr(); |
| 2527 SessionTabHelper* session_tab_helper = | 2538 SessionTabHelper* session_tab_helper = |
| 2528 SessionTabHelper::FromWebContents(controller->GetWebContents()); | 2539 SessionTabHelper::FromWebContents(controller->GetWebContents()); |
| 2529 int window_id = session_tab_helper ? session_tab_helper->window_id().id() | 2540 int window_id = session_tab_helper ? session_tab_helper->window_id().id() |
| 2530 : -1; | 2541 : -1; |
| 2531 if (window_id == new_window_id_) { | 2542 if (window_id == new_window_id_) { |
| 2532 if (automation_) { | 2543 if (automation_.get()) { |
| 2533 AutomationJSONReply(automation_, reply_message_.release()) | 2544 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2534 .SendSuccess(NULL); | 2545 .SendSuccess(NULL); |
| 2535 } | 2546 } |
| 2536 delete this; | 2547 delete this; |
| 2537 } | 2548 } |
| 2538 } | 2549 } |
| 2539 } | 2550 } |
| 2540 | 2551 |
| 2541 ExtensionPopupObserver::ExtensionPopupObserver( | 2552 ExtensionPopupObserver::ExtensionPopupObserver( |
| 2542 AutomationProvider* automation, | 2553 AutomationProvider* automation, |
| 2543 IPC::Message* reply_message, | 2554 IPC::Message* reply_message, |
| 2544 const std::string& extension_id) | 2555 const std::string& extension_id) |
| 2545 : automation_(automation->AsWeakPtr()), | 2556 : automation_(automation->AsWeakPtr()), |
| 2546 reply_message_(reply_message), | 2557 reply_message_(reply_message), |
| 2547 extension_id_(extension_id) { | 2558 extension_id_(extension_id) { |
| 2548 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 2559 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
| 2549 content::NotificationService::AllSources()); | 2560 content::NotificationService::AllSources()); |
| 2550 } | 2561 } |
| 2551 | 2562 |
| 2552 ExtensionPopupObserver::~ExtensionPopupObserver() { | 2563 ExtensionPopupObserver::~ExtensionPopupObserver() { |
| 2553 } | 2564 } |
| 2554 | 2565 |
| 2555 void ExtensionPopupObserver::Observe( | 2566 void ExtensionPopupObserver::Observe( |
| 2556 int type, | 2567 int type, |
| 2557 const content::NotificationSource& source, | 2568 const content::NotificationSource& source, |
| 2558 const content::NotificationDetails& details) { | 2569 const content::NotificationDetails& details) { |
| 2559 if (!automation_) { | 2570 if (!automation_.get()) { |
| 2560 delete this; | 2571 delete this; |
| 2561 return; | 2572 return; |
| 2562 } | 2573 } |
| 2563 | 2574 |
| 2564 extensions::ExtensionHost* host = | 2575 extensions::ExtensionHost* host = |
| 2565 content::Details<extensions::ExtensionHost>(details).ptr(); | 2576 content::Details<extensions::ExtensionHost>(details).ptr(); |
| 2566 if (host->extension_id() == extension_id_ && | 2577 if (host->extension_id() == extension_id_ && |
| 2567 host->extension_host_type() == extensions::VIEW_TYPE_EXTENSION_POPUP) { | 2578 host->extension_host_type() == extensions::VIEW_TYPE_EXTENSION_POPUP) { |
| 2568 AutomationJSONReply(automation_, reply_message_.release()) | 2579 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2569 .SendSuccess(NULL); | 2580 .SendSuccess(NULL); |
| 2570 delete this; | 2581 delete this; |
| 2571 } | 2582 } |
| 2572 } | 2583 } |
| 2573 | 2584 |
| 2574 #if defined(OS_LINUX) | 2585 #if defined(OS_LINUX) |
| 2575 WindowMaximizedObserver::WindowMaximizedObserver( | 2586 WindowMaximizedObserver::WindowMaximizedObserver( |
| 2576 AutomationProvider* automation, | 2587 AutomationProvider* automation, |
| 2577 IPC::Message* reply_message) | 2588 IPC::Message* reply_message) |
| 2578 : automation_(automation->AsWeakPtr()), | 2589 : automation_(automation->AsWeakPtr()), |
| 2579 reply_message_(reply_message) { | 2590 reply_message_(reply_message) { |
| 2580 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_MAXIMIZED, | 2591 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_MAXIMIZED, |
| 2581 content::NotificationService::AllSources()); | 2592 content::NotificationService::AllSources()); |
| 2582 } | 2593 } |
| 2583 | 2594 |
| 2584 WindowMaximizedObserver::~WindowMaximizedObserver() {} | 2595 WindowMaximizedObserver::~WindowMaximizedObserver() {} |
| 2585 | 2596 |
| 2586 void WindowMaximizedObserver::Observe( | 2597 void WindowMaximizedObserver::Observe( |
| 2587 int type, | 2598 int type, |
| 2588 const content::NotificationSource& source, | 2599 const content::NotificationSource& source, |
| 2589 const content::NotificationDetails& details) { | 2600 const content::NotificationDetails& details) { |
| 2590 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_WINDOW_MAXIMIZED, type); | 2601 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_WINDOW_MAXIMIZED, type); |
| 2591 | 2602 |
| 2592 if (automation_) { | 2603 if (automation_.get()) { |
| 2593 AutomationJSONReply(automation_, reply_message_.release()) | 2604 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2594 .SendSuccess(NULL); | 2605 .SendSuccess(NULL); |
| 2595 } | 2606 } |
| 2596 delete this; | 2607 delete this; |
| 2597 } | 2608 } |
| 2598 #endif // defined(OS_LINUX) | 2609 #endif // defined(OS_LINUX) |
| 2599 | 2610 |
| 2600 BrowserOpenedWithExistingProfileNotificationObserver:: | 2611 BrowserOpenedWithExistingProfileNotificationObserver:: |
| 2601 BrowserOpenedWithExistingProfileNotificationObserver( | 2612 BrowserOpenedWithExistingProfileNotificationObserver( |
| 2602 AutomationProvider* automation, | 2613 AutomationProvider* automation, |
| 2603 IPC::Message* reply_message, | 2614 IPC::Message* reply_message, |
| 2604 int num_loads) | 2615 int num_loads) |
| 2605 : automation_(automation->AsWeakPtr()), | 2616 : automation_(automation->AsWeakPtr()), |
| 2606 reply_message_(reply_message), | 2617 reply_message_(reply_message), |
| 2607 new_window_id_(extension_misc::kUnknownWindowId), | 2618 new_window_id_(extension_misc::kUnknownWindowId), |
| 2608 num_loads_(num_loads) { | 2619 num_loads_(num_loads) { |
| 2609 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, | 2620 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
| 2610 content::NotificationService::AllBrowserContextsAndSources()); | 2621 content::NotificationService::AllBrowserContextsAndSources()); |
| 2611 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 2622 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 2612 content::NotificationService::AllBrowserContextsAndSources()); | 2623 content::NotificationService::AllBrowserContextsAndSources()); |
| 2613 } | 2624 } |
| 2614 | 2625 |
| 2615 BrowserOpenedWithExistingProfileNotificationObserver:: | 2626 BrowserOpenedWithExistingProfileNotificationObserver:: |
| 2616 ~BrowserOpenedWithExistingProfileNotificationObserver() { | 2627 ~BrowserOpenedWithExistingProfileNotificationObserver() { |
| 2617 } | 2628 } |
| 2618 | 2629 |
| 2619 void BrowserOpenedWithExistingProfileNotificationObserver::Observe( | 2630 void BrowserOpenedWithExistingProfileNotificationObserver::Observe( |
| 2620 int type, | 2631 int type, |
| 2621 const content::NotificationSource& source, | 2632 const content::NotificationSource& source, |
| 2622 const content::NotificationDetails& details) { | 2633 const content::NotificationDetails& details) { |
| 2623 if (!automation_) { | 2634 if (!automation_.get()) { |
| 2624 delete this; | 2635 delete this; |
| 2625 return; | 2636 return; |
| 2626 } | 2637 } |
| 2627 | 2638 |
| 2628 if (type == chrome::NOTIFICATION_BROWSER_OPENED) { | 2639 if (type == chrome::NOTIFICATION_BROWSER_OPENED) { |
| 2629 // Store the new browser ID and continue waiting for NOTIFICATION_LOAD_STOP. | 2640 // Store the new browser ID and continue waiting for NOTIFICATION_LOAD_STOP. |
| 2630 new_window_id_ = ExtensionTabUtil::GetWindowId( | 2641 new_window_id_ = ExtensionTabUtil::GetWindowId( |
| 2631 content::Source<Browser>(source).ptr()); | 2642 content::Source<Browser>(source).ptr()); |
| 2632 } else if (type == content::NOTIFICATION_LOAD_STOP) { | 2643 } else if (type == content::NOTIFICATION_LOAD_STOP) { |
| 2633 // Only consider if the loaded tab is in the new window. | 2644 // Only consider if the loaded tab is in the new window. |
| 2634 NavigationController* controller = | 2645 NavigationController* controller = |
| 2635 content::Source<NavigationController>(source).ptr(); | 2646 content::Source<NavigationController>(source).ptr(); |
| 2636 SessionTabHelper* session_tab_helper = | 2647 SessionTabHelper* session_tab_helper = |
| 2637 SessionTabHelper::FromWebContents(controller->GetWebContents()); | 2648 SessionTabHelper::FromWebContents(controller->GetWebContents()); |
| 2638 int window_id = session_tab_helper ? session_tab_helper->window_id().id() | 2649 int window_id = session_tab_helper ? session_tab_helper->window_id().id() |
| 2639 : -1; | 2650 : -1; |
| 2640 if (window_id == new_window_id_ && --num_loads_ == 0) { | 2651 if (window_id == new_window_id_ && --num_loads_ == 0) { |
| 2641 if (automation_) { | 2652 if (automation_.get()) { |
| 2642 AutomationJSONReply(automation_, reply_message_.release()) | 2653 AutomationJSONReply(automation_.get(), reply_message_.release()) |
| 2643 .SendSuccess(NULL); | 2654 .SendSuccess(NULL); |
| 2644 } | 2655 } |
| 2645 delete this; | 2656 delete this; |
| 2646 } | 2657 } |
| 2647 } else { | 2658 } else { |
| 2648 NOTREACHED(); | 2659 NOTREACHED(); |
| 2649 } | 2660 } |
| 2650 } | 2661 } |
| OLD | NEW |