| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| 11 #include "chrome/browser/automation/automation_provider.h" | 11 #include "chrome/browser/automation/automation_provider.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 13 #include "chrome/browser/browser_window.h" |
| 13 #include "chrome/browser/dom_operation_notification_details.h" | 14 #include "chrome/browser/dom_operation_notification_details.h" |
| 14 #include "chrome/browser/extensions/extension_host.h" | 15 #include "chrome/browser/extensions/extension_host.h" |
| 15 #include "chrome/browser/extensions/extension_process_manager.h" | 16 #include "chrome/browser/extensions/extension_process_manager.h" |
| 16 #include "chrome/browser/extensions/extension_updater.h" | 17 #include "chrome/browser/extensions/extension_updater.h" |
| 17 #include "chrome/browser/login_prompt.h" | 18 #include "chrome/browser/login_prompt.h" |
| 18 #include "chrome/browser/metrics/metric_event_duration_details.h" | 19 #include "chrome/browser/metrics/metric_event_duration_details.h" |
| 19 #include "chrome/browser/printing/print_job.h" | 20 #include "chrome/browser/printing/print_job.h" |
| 20 #include "chrome/browser/profile.h" | 21 #include "chrome/browser/profile.h" |
| 21 #include "chrome/browser/tab_contents/navigation_controller.h" | 22 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 22 #include "chrome/browser/tab_contents/tab_contents.h" | 23 #include "chrome/browser/tab_contents/tab_contents.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 if (reply_message_) { | 153 if (reply_message_) { |
| 153 // This means we did not receive a notification for this navigation. | 154 // This means we did not receive a notification for this navigation. |
| 154 // Send over a failed navigation status back to the caller to ensure that | 155 // Send over a failed navigation status back to the caller to ensure that |
| 155 // the caller does not hang waiting for the response. | 156 // the caller does not hang waiting for the response. |
| 156 IPC::ParamTraits<AutomationMsg_NavigationResponseValues>::Write( | 157 IPC::ParamTraits<AutomationMsg_NavigationResponseValues>::Write( |
| 157 reply_message_, AUTOMATION_MSG_NAVIGATION_ERROR); | 158 reply_message_, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 158 automation_->Send(reply_message_); | 159 automation_->Send(reply_message_); |
| 159 reply_message_ = NULL; | 160 reply_message_ = NULL; |
| 160 } | 161 } |
| 161 | 162 |
| 162 automation_->RemoveNavigationStatusListener(this); | 163 automation_->RemoveObserver(this); |
| 163 } | 164 } |
| 164 | 165 |
| 165 void NavigationNotificationObserver::Observe( | 166 void NavigationNotificationObserver::Observe( |
| 166 NotificationType type, const NotificationSource& source, | 167 NotificationType type, const NotificationSource& source, |
| 167 const NotificationDetails& details) { | 168 const NotificationDetails& details) { |
| 168 // We listen for 2 events to determine when the navigation started because: | 169 // We listen for 2 events to determine when the navigation started because: |
| 169 // - when this is used by the WaitForNavigation method, we might be invoked | 170 // - when this is used by the WaitForNavigation method, we might be invoked |
| 170 // afer the load has started (but not after the entry was committed, as | 171 // afer the load has started (but not after the entry was committed, as |
| 171 // WaitForNavigation compares times of the last navigation). | 172 // WaitForNavigation compares times of the last navigation). |
| 172 // - when this is used with a page requiring authentication, we will not get | 173 // - when this is used with a page requiring authentication, we will not get |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 TabStripNotificationObserver::~TabStripNotificationObserver() { | 228 TabStripNotificationObserver::~TabStripNotificationObserver() { |
| 228 } | 229 } |
| 229 | 230 |
| 230 void TabStripNotificationObserver::Observe(NotificationType type, | 231 void TabStripNotificationObserver::Observe(NotificationType type, |
| 231 const NotificationSource& source, | 232 const NotificationSource& source, |
| 232 const NotificationDetails& details) { | 233 const NotificationDetails& details) { |
| 233 if (type == notification_) { | 234 if (type == notification_) { |
| 234 ObserveTab(Source<NavigationController>(source).ptr()); | 235 ObserveTab(Source<NavigationController>(source).ptr()); |
| 235 | 236 |
| 236 // If verified, no need to observe anymore | 237 // If verified, no need to observe anymore |
| 237 automation_->RemoveTabStripObserver(this); | 238 automation_->RemoveObserver(this); |
| 238 delete this; | 239 delete this; |
| 239 } else { | 240 } else { |
| 240 NOTREACHED(); | 241 NOTREACHED(); |
| 241 } | 242 } |
| 242 } | 243 } |
| 243 | 244 |
| 244 TabAppendedNotificationObserver::TabAppendedNotificationObserver( | 245 TabAppendedNotificationObserver::TabAppendedNotificationObserver( |
| 245 Browser* parent, AutomationProvider* automation, | 246 Browser* parent, AutomationProvider* automation, |
| 246 IPC::Message* reply_message) | 247 IPC::Message* reply_message) |
| 247 : TabStripNotificationObserver(NotificationType::TAB_PARENTED, automation), | 248 : TabStripNotificationObserver(NotificationType::TAB_PARENTED, automation), |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 success_(false), | 807 success_(false), |
| 807 reply_message_(reply_message) { | 808 reply_message_(reply_message) { |
| 808 registrar_.Add(this, NotificationType::PRINT_JOB_EVENT, | 809 registrar_.Add(this, NotificationType::PRINT_JOB_EVENT, |
| 809 NotificationService::AllSources()); | 810 NotificationService::AllSources()); |
| 810 } | 811 } |
| 811 | 812 |
| 812 DocumentPrintedNotificationObserver::~DocumentPrintedNotificationObserver() { | 813 DocumentPrintedNotificationObserver::~DocumentPrintedNotificationObserver() { |
| 813 DCHECK(reply_message_ != NULL); | 814 DCHECK(reply_message_ != NULL); |
| 814 AutomationMsg_PrintNow::WriteReplyParams(reply_message_, success_); | 815 AutomationMsg_PrintNow::WriteReplyParams(reply_message_, success_); |
| 815 automation_->Send(reply_message_); | 816 automation_->Send(reply_message_); |
| 816 automation_->RemoveNavigationStatusListener(this); | 817 automation_->RemoveObserver(this); |
| 817 } | 818 } |
| 818 | 819 |
| 819 void DocumentPrintedNotificationObserver::Observe( | 820 void DocumentPrintedNotificationObserver::Observe( |
| 820 NotificationType type, const NotificationSource& source, | 821 NotificationType type, const NotificationSource& source, |
| 821 const NotificationDetails& details) { | 822 const NotificationDetails& details) { |
| 822 using namespace printing; | 823 using namespace printing; |
| 823 DCHECK(type == NotificationType::PRINT_JOB_EVENT); | 824 DCHECK(type == NotificationType::PRINT_JOB_EVENT); |
| 824 switch (Details<JobEventDetails>(details)->type()) { | 825 switch (Details<JobEventDetails>(details)->type()) { |
| 825 case JobEventDetails::JOB_DONE: { | 826 case JobEventDetails::JOB_DONE: { |
| 826 // Succeeded. | 827 // Succeeded. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 const NotificationDetails& details) { | 893 const NotificationDetails& details) { |
| 893 DCHECK(type == NotificationType::LOGIN_AUTHENTICATION); | 894 DCHECK(type == NotificationType::LOGIN_AUTHENTICATION); |
| 894 Details<AuthenticationNotificationDetails> auth_details(details); | 895 Details<AuthenticationNotificationDetails> auth_details(details); |
| 895 AutomationMsg_LoginWithUserAndPass::WriteReplyParams(reply_message_, | 896 AutomationMsg_LoginWithUserAndPass::WriteReplyParams(reply_message_, |
| 896 auth_details->success()); | 897 auth_details->success()); |
| 897 automation_->Send(reply_message_); | 898 automation_->Send(reply_message_); |
| 898 delete this; | 899 delete this; |
| 899 } | 900 } |
| 900 #endif | 901 #endif |
| 901 | 902 |
| 903 DownloadShelfVisibilityObserver::DownloadShelfVisibilityObserver( |
| 904 AutomationProvider* automation, |
| 905 Browser* browser, |
| 906 bool visibility, |
| 907 IPC::Message* reply_message) |
| 908 : automation_(automation), |
| 909 visibility_(visibility), |
| 910 reply_message_(reply_message) { |
| 911 registrar_.Add(this, NotificationType::DOWNLOAD_SHELF_VISIBILITY_CHANGED, |
| 912 Source<Browser>(browser)); |
| 913 } |
| 914 |
| 915 DownloadShelfVisibilityObserver::~DownloadShelfVisibilityObserver() { |
| 916 } |
| 917 |
| 918 void DownloadShelfVisibilityObserver::Observe( |
| 919 NotificationType type, |
| 920 const NotificationSource& source, |
| 921 const NotificationDetails& details) { |
| 922 if (type == NotificationType::DOWNLOAD_SHELF_VISIBILITY_CHANGED) { |
| 923 Browser* browser = Source<Browser>(source).ptr(); |
| 924 if (browser->window()->IsDownloadShelfVisible() == visibility_) { |
| 925 AutomationMsg_WaitForDownloadShelfVisibilityChange::WriteReplyParams( |
| 926 reply_message_, true); |
| 927 automation_->Send(reply_message_); |
| 928 automation_->RemoveObserver(this); |
| 929 delete this; |
| 930 } |
| 931 } else { |
| 932 NOTREACHED(); |
| 933 } |
| 934 } |
| 935 |
| 902 AutomationProviderBookmarkModelObserver::AutomationProviderBookmarkModelObserver
( | 936 AutomationProviderBookmarkModelObserver::AutomationProviderBookmarkModelObserver
( |
| 903 AutomationProvider* provider, | 937 AutomationProvider* provider, |
| 904 IPC::Message* reply_message, | 938 IPC::Message* reply_message, |
| 905 BookmarkModel* model) { | 939 BookmarkModel* model) { |
| 906 automation_provider_ = provider; | 940 automation_provider_ = provider; |
| 907 reply_message_ = reply_message; | 941 reply_message_ = reply_message; |
| 908 model_ = model; | 942 model_ = model; |
| 909 model_->AddObserver(this); | 943 model_->AddObserver(this); |
| 910 } | 944 } |
| 911 | 945 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 : automation_(automation), | 1003 : automation_(automation), |
| 970 reply_message_(reply_message), | 1004 reply_message_(reply_message), |
| 971 controller_(controller) { | 1005 controller_(controller) { |
| 972 Source<NavigationController> source(controller_); | 1006 Source<NavigationController> source(controller_); |
| 973 registrar_.Add(this, NotificationType::LOAD_STOP, source); | 1007 registrar_.Add(this, NotificationType::LOAD_STOP, source); |
| 974 // Pages requiring auth don't send LOAD_STOP. | 1008 // Pages requiring auth don't send LOAD_STOP. |
| 975 registrar_.Add(this, NotificationType::AUTH_NEEDED, source); | 1009 registrar_.Add(this, NotificationType::AUTH_NEEDED, source); |
| 976 } | 1010 } |
| 977 | 1011 |
| 978 OmniboxAcceptNotificationObserver::~OmniboxAcceptNotificationObserver() { | 1012 OmniboxAcceptNotificationObserver::~OmniboxAcceptNotificationObserver() { |
| 979 automation_->RemoveNavigationStatusListener(this); | 1013 automation_->RemoveObserver(this); |
| 980 } | 1014 } |
| 981 | 1015 |
| 982 void OmniboxAcceptNotificationObserver::Observe( | 1016 void OmniboxAcceptNotificationObserver::Observe( |
| 983 NotificationType type, | 1017 NotificationType type, |
| 984 const NotificationSource& source, | 1018 const NotificationSource& source, |
| 985 const NotificationDetails& details) { | 1019 const NotificationDetails& details) { |
| 986 if (type == NotificationType::LOAD_STOP || | 1020 if (type == NotificationType::LOAD_STOP || |
| 987 type == NotificationType::AUTH_NEEDED) { | 1021 type == NotificationType::AUTH_NEEDED) { |
| 988 AutomationMsg_SendJSONRequest::WriteReplyParams( | 1022 AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 989 reply_message_, std::string("{}"), false); | 1023 reply_message_, std::string("{}"), false); |
| 990 automation_->Send(reply_message_); | 1024 automation_->Send(reply_message_); |
| 991 delete this; | 1025 delete this; |
| 992 } else { | 1026 } else { |
| 993 NOTREACHED(); | 1027 NOTREACHED(); |
| 994 } | 1028 } |
| 995 } | 1029 } |
| 996 | 1030 |
| OLD | NEW |