| 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } | 374 } |
| 375 | 375 |
| 376 TabStripNotificationObserver::~TabStripNotificationObserver() { | 376 TabStripNotificationObserver::~TabStripNotificationObserver() { |
| 377 } | 377 } |
| 378 | 378 |
| 379 void TabStripNotificationObserver::Observe( | 379 void TabStripNotificationObserver::Observe( |
| 380 int type, | 380 int type, |
| 381 const content::NotificationSource& source, | 381 const content::NotificationSource& source, |
| 382 const content::NotificationDetails& details) { | 382 const content::NotificationDetails& details) { |
| 383 if (type == notification_) { | 383 if (type == notification_) { |
| 384 if (type == content::NOTIFICATION_TAB_PARENTED) { | 384 if (type == chrome::NOTIFICATION_TAB_PARENTED) { |
| 385 ObserveTab(&(content::Source<TabContentsWrapper>(source).ptr()-> | 385 ObserveTab(&(content::Source<TabContentsWrapper>(source).ptr()-> |
| 386 web_contents()->GetController())); | 386 web_contents()->GetController())); |
| 387 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
| 388 ObserveTab(&(content::Source<content::WebContents>(source).ptr()-> |
| 389 GetController())); |
| 387 } else { | 390 } else { |
| 388 ObserveTab(content::Source<NavigationController>(source).ptr()); | 391 ObserveTab(content::Source<NavigationController>(source).ptr()); |
| 389 } | 392 } |
| 390 delete this; | 393 delete this; |
| 391 } else { | 394 } else { |
| 392 NOTREACHED(); | 395 NOTREACHED(); |
| 393 } | 396 } |
| 394 } | 397 } |
| 395 | 398 |
| 396 TabAppendedNotificationObserver::TabAppendedNotificationObserver( | 399 TabAppendedNotificationObserver::TabAppendedNotificationObserver( |
| 397 Browser* parent, AutomationProvider* automation, | 400 Browser* parent, AutomationProvider* automation, |
| 398 IPC::Message* reply_message) | 401 IPC::Message* reply_message) |
| 399 : TabStripNotificationObserver(content::NOTIFICATION_TAB_PARENTED, | 402 : TabStripNotificationObserver(chrome::NOTIFICATION_TAB_PARENTED, |
| 400 automation), | 403 automation), |
| 401 parent_(parent), | 404 parent_(parent), |
| 402 reply_message_(reply_message) { | 405 reply_message_(reply_message) { |
| 403 } | 406 } |
| 404 | 407 |
| 405 TabAppendedNotificationObserver::~TabAppendedNotificationObserver() {} | 408 TabAppendedNotificationObserver::~TabAppendedNotificationObserver() {} |
| 406 | 409 |
| 407 void TabAppendedNotificationObserver::ObserveTab( | 410 void TabAppendedNotificationObserver::ObserveTab( |
| 408 NavigationController* controller) { | 411 NavigationController* controller) { |
| 409 if (!automation_) | 412 if (!automation_) |
| 410 return; | 413 return; |
| 411 | 414 |
| 412 if (automation_->GetIndexForNavigationController(controller, parent_) == | 415 if (automation_->GetIndexForNavigationController(controller, parent_) == |
| 413 TabStripModel::kNoTab) { | 416 TabStripModel::kNoTab) { |
| 414 // This tab notification doesn't belong to the parent_. | 417 // This tab notification doesn't belong to the parent_. |
| 415 return; | 418 return; |
| 416 } | 419 } |
| 417 | 420 |
| 418 new NavigationNotificationObserver(controller, automation_, | 421 new NavigationNotificationObserver(controller, automation_, |
| 419 reply_message_.release(), | 422 reply_message_.release(), |
| 420 1, false, false); | 423 1, false, false); |
| 421 } | 424 } |
| 422 | 425 |
| 423 TabClosedNotificationObserver::TabClosedNotificationObserver( | 426 TabClosedNotificationObserver::TabClosedNotificationObserver( |
| 424 AutomationProvider* automation, bool wait_until_closed, | 427 AutomationProvider* automation, bool wait_until_closed, |
| 425 IPC::Message* reply_message) | 428 IPC::Message* reply_message) |
| 426 : TabStripNotificationObserver(wait_until_closed ? | 429 : TabStripNotificationObserver( |
| 427 content::NOTIFICATION_TAB_CLOSED : content::NOTIFICATION_TAB_CLOSING, | 430 wait_until_closed |
| 431 ? static_cast<int>(content::NOTIFICATION_WEB_CONTENTS_DESTROYED) |
| 432 : static_cast<int>(chrome::NOTIFICATION_TAB_CLOSING), |
| 428 automation), | 433 automation), |
| 429 reply_message_(reply_message), | 434 reply_message_(reply_message), |
| 430 for_browser_command_(false) { | 435 for_browser_command_(false) { |
| 431 } | 436 } |
| 432 | 437 |
| 433 TabClosedNotificationObserver::~TabClosedNotificationObserver() {} | 438 TabClosedNotificationObserver::~TabClosedNotificationObserver() {} |
| 434 | 439 |
| 435 void TabClosedNotificationObserver::ObserveTab( | 440 void TabClosedNotificationObserver::ObserveTab( |
| 436 NavigationController* controller) { | 441 NavigationController* controller) { |
| 437 if (!automation_) | 442 if (!automation_) |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 | 1014 |
| 1010 namespace { | 1015 namespace { |
| 1011 | 1016 |
| 1012 // Define mapping from command to notification | 1017 // Define mapping from command to notification |
| 1013 struct CommandNotification { | 1018 struct CommandNotification { |
| 1014 int command; | 1019 int command; |
| 1015 int notification_type; | 1020 int notification_type; |
| 1016 }; | 1021 }; |
| 1017 | 1022 |
| 1018 const struct CommandNotification command_notifications[] = { | 1023 const struct CommandNotification command_notifications[] = { |
| 1019 {IDC_DUPLICATE_TAB, content::NOTIFICATION_TAB_PARENTED}, | 1024 {IDC_DUPLICATE_TAB, chrome::NOTIFICATION_TAB_PARENTED}, |
| 1020 | 1025 |
| 1021 // Returns as soon as the restored tab is created. To further wait until | 1026 // Returns as soon as the restored tab is created. To further wait until |
| 1022 // the content page is loaded, use WaitForTabToBeRestored. | 1027 // the content page is loaded, use WaitForTabToBeRestored. |
| 1023 {IDC_RESTORE_TAB, content::NOTIFICATION_TAB_PARENTED}, | 1028 {IDC_RESTORE_TAB, chrome::NOTIFICATION_TAB_PARENTED}, |
| 1024 | 1029 |
| 1025 // For the following commands, we need to wait for a new tab to be created, | 1030 // For the following commands, we need to wait for a new tab to be created, |
| 1026 // load to finish, and title to change. | 1031 // load to finish, and title to change. |
| 1027 {IDC_MANAGE_EXTENSIONS, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED}, | 1032 {IDC_MANAGE_EXTENSIONS, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED}, |
| 1028 {IDC_OPTIONS, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED}, | 1033 {IDC_OPTIONS, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED}, |
| 1029 {IDC_PRINT, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED}, | 1034 {IDC_PRINT, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED}, |
| 1030 {IDC_SHOW_DOWNLOADS, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED}, | 1035 {IDC_SHOW_DOWNLOADS, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED}, |
| 1031 {IDC_SHOW_HISTORY, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED}, | 1036 {IDC_SHOW_HISTORY, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED}, |
| 1032 }; | 1037 }; |
| 1033 | 1038 |
| (...skipping 1642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2676 delete this; | 2681 delete this; |
| 2677 } | 2682 } |
| 2678 } | 2683 } |
| 2679 | 2684 |
| 2680 NewTabObserver::NewTabObserver(AutomationProvider* automation, | 2685 NewTabObserver::NewTabObserver(AutomationProvider* automation, |
| 2681 IPC::Message* reply_message) | 2686 IPC::Message* reply_message) |
| 2682 : automation_(automation->AsWeakPtr()), | 2687 : automation_(automation->AsWeakPtr()), |
| 2683 reply_message_(reply_message) { | 2688 reply_message_(reply_message) { |
| 2684 // Use TAB_PARENTED to detect the new tab. | 2689 // Use TAB_PARENTED to detect the new tab. |
| 2685 registrar_.Add(this, | 2690 registrar_.Add(this, |
| 2686 content::NOTIFICATION_TAB_PARENTED, | 2691 chrome::NOTIFICATION_TAB_PARENTED, |
| 2687 content::NotificationService::AllSources()); | 2692 content::NotificationService::AllSources()); |
| 2688 } | 2693 } |
| 2689 | 2694 |
| 2690 void NewTabObserver::Observe(int type, | 2695 void NewTabObserver::Observe(int type, |
| 2691 const content::NotificationSource& source, | 2696 const content::NotificationSource& source, |
| 2692 const content::NotificationDetails& details) { | 2697 const content::NotificationDetails& details) { |
| 2693 DCHECK_EQ(content::NOTIFICATION_TAB_PARENTED, type); | 2698 DCHECK_EQ(chrome::NOTIFICATION_TAB_PARENTED, type); |
| 2694 NavigationController* controller = | 2699 NavigationController* controller = |
| 2695 &(content::Source<TabContentsWrapper>(source).ptr()-> | 2700 &(content::Source<TabContentsWrapper>(source).ptr()-> |
| 2696 web_contents()->GetController()); | 2701 web_contents()->GetController()); |
| 2697 if (automation_) { | 2702 if (automation_) { |
| 2698 // TODO(phajdan.jr): Clean up this hack. We write the correct return type | 2703 // TODO(phajdan.jr): Clean up this hack. We write the correct return type |
| 2699 // here, but don't send the message. NavigationNotificationObserver | 2704 // here, but don't send the message. NavigationNotificationObserver |
| 2700 // will wait properly for the load to finish, and send the message, | 2705 // will wait properly for the load to finish, and send the message, |
| 2701 // but it will also append its own return value at the end of the reply. | 2706 // but it will also append its own return value at the end of the reply. |
| 2702 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(), | 2707 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_.get(), |
| 2703 true); | 2708 true); |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3130 } | 3135 } |
| 3131 | 3136 |
| 3132 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 3137 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| 3133 if (host->extension_id() == extension_id_ && | 3138 if (host->extension_id() == extension_id_ && |
| 3134 host->extension_host_type() == chrome::VIEW_TYPE_EXTENSION_POPUP) { | 3139 host->extension_host_type() == chrome::VIEW_TYPE_EXTENSION_POPUP) { |
| 3135 AutomationJSONReply(automation_, reply_message_.release()) | 3140 AutomationJSONReply(automation_, reply_message_.release()) |
| 3136 .SendSuccess(NULL); | 3141 .SendSuccess(NULL); |
| 3137 delete this; | 3142 delete this; |
| 3138 } | 3143 } |
| 3139 } | 3144 } |
| OLD | NEW |