Chromium Code Reviews| 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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 content::NotificationService::AllSources()); | 379 content::NotificationService::AllSources()); |
| 380 } | 380 } |
| 381 | 381 |
| 382 TabStripNotificationObserver::~TabStripNotificationObserver() { | 382 TabStripNotificationObserver::~TabStripNotificationObserver() { |
| 383 } | 383 } |
| 384 | 384 |
| 385 void TabStripNotificationObserver::Observe( | 385 void TabStripNotificationObserver::Observe( |
| 386 int type, | 386 int type, |
| 387 const content::NotificationSource& source, | 387 const content::NotificationSource& source, |
| 388 const content::NotificationDetails& details) { | 388 const content::NotificationDetails& details) { |
| 389 if (type == notification_) { | 389 DCHECK_EQ(notification_, type); |
| 390 if (type == chrome::NOTIFICATION_TAB_PARENTED) { | 390 if (type == chrome::NOTIFICATION_TAB_PARENTED) { |
| 391 ObserveTab(&(content::Source<TabContents>(source).ptr()-> | 391 ObserveTab(&content::Source<TabContents>(source)->web_contents()-> |
| 392 web_contents()->GetController())); | 392 GetController()); |
| 393 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 393 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
| 394 ObserveTab(&(content::Source<content::WebContents>(source).ptr()-> | 394 ObserveTab(&content::Source<content::WebContents>(source)->GetController()); |
| 395 GetController())); | |
| 396 } else { | |
| 397 ObserveTab(content::Source<NavigationController>(source).ptr()); | |
| 398 } | |
| 399 delete this; | |
| 400 } else { | 395 } else { |
| 401 NOTREACHED(); | 396 ObserveTab(content::Source<NavigationController>(source).ptr()); |
| 402 } | 397 } |
| 398 delete this; | |
| 403 } | 399 } |
| 404 | 400 |
| 405 TabAppendedNotificationObserver::TabAppendedNotificationObserver( | 401 TabAppendedNotificationObserver::TabAppendedNotificationObserver( |
| 406 Browser* parent, | 402 Browser* parent, |
| 407 AutomationProvider* automation, | 403 AutomationProvider* automation, |
| 408 IPC::Message* reply_message, | 404 IPC::Message* reply_message, |
| 409 bool use_json_interface) | 405 bool use_json_interface) |
| 410 : TabStripNotificationObserver(chrome::NOTIFICATION_TAB_PARENTED, | 406 : TabStripNotificationObserver(chrome::NOTIFICATION_TAB_PARENTED, |
| 411 automation), | 407 automation), |
| 412 parent_(parent), | 408 parent_(parent), |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 434 | 430 |
| 435 IPC::Message* TabAppendedNotificationObserver::ReleaseReply() { | 431 IPC::Message* TabAppendedNotificationObserver::ReleaseReply() { |
| 436 return reply_message_.release(); | 432 return reply_message_.release(); |
| 437 } | 433 } |
| 438 | 434 |
| 439 TabClosedNotificationObserver::TabClosedNotificationObserver( | 435 TabClosedNotificationObserver::TabClosedNotificationObserver( |
| 440 AutomationProvider* automation, | 436 AutomationProvider* automation, |
| 441 bool wait_until_closed, | 437 bool wait_until_closed, |
| 442 IPC::Message* reply_message, | 438 IPC::Message* reply_message, |
| 443 bool use_json_interface) | 439 bool use_json_interface) |
| 444 : TabStripNotificationObserver( | 440 : TabStripNotificationObserver((wait_until_closed ? |
| 445 wait_until_closed | 441 static_cast<int>(content::NOTIFICATION_WEB_CONTENTS_DESTROYED) : |
| 446 ? static_cast<int>(content::NOTIFICATION_WEB_CONTENTS_DESTROYED) | 442 static_cast<int>(chrome::NOTIFICATION_TAB_CLOSING)), automation), |
| 447 : static_cast<int>(chrome::NOTIFICATION_TAB_CLOSING), | |
| 448 automation), | |
| 449 reply_message_(reply_message), | 443 reply_message_(reply_message), |
| 450 use_json_interface_(use_json_interface), | 444 use_json_interface_(use_json_interface), |
| 451 for_browser_command_(false) { | 445 for_browser_command_(false) { |
| 452 } | 446 } |
| 453 | 447 |
| 454 TabClosedNotificationObserver::~TabClosedNotificationObserver() {} | 448 TabClosedNotificationObserver::~TabClosedNotificationObserver() {} |
| 455 | 449 |
| 456 void TabClosedNotificationObserver::ObserveTab( | 450 void TabClosedNotificationObserver::ObserveTab( |
| 457 NavigationController* controller) { | 451 NavigationController* controller) { |
| 458 if (!automation_) | 452 if (!automation_) |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, | 797 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
| 804 content::NotificationService::AllBrowserContextsAndSources()); | 798 content::NotificationService::AllBrowserContextsAndSources()); |
| 805 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 799 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 806 content::NotificationService::AllBrowserContextsAndSources()); | 800 content::NotificationService::AllBrowserContextsAndSources()); |
| 807 } | 801 } |
| 808 | 802 |
| 809 BrowserOpenedNotificationObserver::~BrowserOpenedNotificationObserver() { | 803 BrowserOpenedNotificationObserver::~BrowserOpenedNotificationObserver() { |
| 810 } | 804 } |
| 811 | 805 |
| 812 void BrowserOpenedNotificationObserver::Observe( | 806 void BrowserOpenedNotificationObserver::Observe( |
| 813 int type, const content::NotificationSource& source, | 807 int type, |
| 808 const content::NotificationSource& source, | |
| 814 const content::NotificationDetails& details) { | 809 const content::NotificationDetails& details) { |
| 815 if (!automation_) { | 810 if (!automation_) { |
| 816 delete this; | 811 delete this; |
| 817 return; | 812 return; |
| 818 } | 813 } |
| 819 | 814 |
| 820 if (type == chrome::NOTIFICATION_BROWSER_OPENED) { | 815 if (type == chrome::NOTIFICATION_BROWSER_OPENED) { |
| 821 // Store the new browser ID and continue waiting for a new tab within it | 816 // Store the new browser ID and continue waiting for a new tab within it |
| 822 // to stop loading. | 817 // to stop loading. |
| 823 new_window_id_ = ExtensionTabUtil::GetWindowId( | 818 new_window_id_ = ExtensionTabUtil::GetWindowId( |
| 824 content::Source<Browser>(source).ptr()); | 819 content::Source<Browser>(source).ptr()); |
| 825 } else if (type == content::NOTIFICATION_LOAD_STOP) { | 820 } else { |
| 821 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type); | |
| 826 // Only send the result if the loaded tab is in the new window. | 822 // Only send the result if the loaded tab is in the new window. |
| 827 NavigationController* controller = | 823 NavigationController* controller = |
| 828 content::Source<NavigationController>(source).ptr(); | 824 content::Source<NavigationController>(source).ptr(); |
| 829 TabContents* tab = | 825 TabContents* tab = |
| 830 TabContents::FromWebContents(controller->GetWebContents()); | 826 TabContents::FromWebContents(controller->GetWebContents()); |
| 831 int window_id = tab ? tab->restore_tab_helper()->window_id().id() : -1; | 827 int window_id = tab ? tab->restore_tab_helper()->window_id().id() : -1; |
| 832 if (window_id == new_window_id_) { | 828 if (window_id == new_window_id_) { |
| 833 if (use_json_interface_) { | 829 if (use_json_interface_) { |
| 834 AutomationJSONReply(automation_, | 830 AutomationJSONReply(automation_, |
| 835 reply_message_.release()).SendSuccess(NULL); | 831 reply_message_.release()).SendSuccess(NULL); |
| 836 } else { | 832 } else { |
| 837 if (for_browser_command_) { | 833 if (for_browser_command_) { |
| 838 AutomationMsg_WindowExecuteCommand::WriteReplyParams( | 834 AutomationMsg_WindowExecuteCommand::WriteReplyParams( |
| 839 reply_message_.get(), true); | 835 reply_message_.get(), true); |
| 840 } | 836 } |
| 841 automation_->Send(reply_message_.release()); | 837 automation_->Send(reply_message_.release()); |
| 842 } | 838 } |
| 843 delete this; | 839 delete this; |
| 844 return; | 840 return; |
| 845 } | 841 } |
| 846 } else { | |
| 847 NOTREACHED(); | |
| 848 } | 842 } |
| 849 } | 843 } |
| 850 | 844 |
| 851 void BrowserOpenedNotificationObserver::set_for_browser_command( | 845 void BrowserOpenedNotificationObserver::set_for_browser_command( |
| 852 bool for_browser_command) { | 846 bool for_browser_command) { |
| 853 for_browser_command_ = for_browser_command; | 847 for_browser_command_ = for_browser_command; |
| 854 } | 848 } |
| 855 | 849 |
| 856 BrowserClosedNotificationObserver::BrowserClosedNotificationObserver( | 850 BrowserClosedNotificationObserver::BrowserClosedNotificationObserver( |
| 857 Browser* browser, | 851 Browser* browser, |
| 858 AutomationProvider* automation, | 852 AutomationProvider* automation, |
| 859 IPC::Message* reply_message, | 853 IPC::Message* reply_message, |
| 860 bool use_json_interface) | 854 bool use_json_interface) |
| 861 : automation_(automation->AsWeakPtr()), | 855 : automation_(automation->AsWeakPtr()), |
| 862 reply_message_(reply_message), | 856 reply_message_(reply_message), |
| 863 use_json_interface_(use_json_interface), | 857 use_json_interface_(use_json_interface), |
| 864 for_browser_command_(false) { | 858 for_browser_command_(false) { |
| 865 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED, | 859 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED, |
| 866 content::Source<Browser>(browser)); | 860 content::Source<Browser>(browser)); |
| 867 } | 861 } |
| 868 | 862 |
| 869 BrowserClosedNotificationObserver::~BrowserClosedNotificationObserver() {} | 863 BrowserClosedNotificationObserver::~BrowserClosedNotificationObserver() {} |
| 870 | 864 |
| 871 void BrowserClosedNotificationObserver::Observe( | 865 void BrowserClosedNotificationObserver::Observe( |
| 872 int type, const content::NotificationSource& source, | 866 int type, const content::NotificationSource& source, |
| 873 const content::NotificationDetails& details) { | 867 const content::NotificationDetails& details) { |
| 874 DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSED); | 868 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_CLOSED, type); |
| 875 | 869 |
| 876 if (!automation_) { | 870 if (!automation_) { |
| 877 delete this; | 871 delete this; |
| 878 return; | 872 return; |
| 879 } | 873 } |
| 880 | 874 |
| 881 int browser_count = static_cast<int>(BrowserList::size()); | 875 int browser_count = static_cast<int>(BrowserList::size()); |
| 882 // We get the notification before the browser is removed from the BrowserList. | 876 // We get the notification before the browser is removed from the BrowserList. |
| 883 bool app_closing = browser_count == 1; | 877 bool app_closing = browser_count == 1; |
| 884 | 878 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1167 | 1161 |
| 1168 void DomOperationObserver::Observe( | 1162 void DomOperationObserver::Observe( |
| 1169 int type, const content::NotificationSource& source, | 1163 int type, const content::NotificationSource& source, |
| 1170 const content::NotificationDetails& details) { | 1164 const content::NotificationDetails& details) { |
| 1171 if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { | 1165 if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { |
| 1172 content::Details<DomOperationNotificationDetails> dom_op_details(details); | 1166 content::Details<DomOperationNotificationDetails> dom_op_details(details); |
| 1173 if (dom_op_details->automation_id == automation_id_) | 1167 if (dom_op_details->automation_id == automation_id_) |
| 1174 OnDomOperationCompleted(dom_op_details->json); | 1168 OnDomOperationCompleted(dom_op_details->json); |
| 1175 } else if (type == chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN) { | 1169 } else if (type == chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN) { |
| 1176 OnModalDialogShown(); | 1170 OnModalDialogShown(); |
| 1177 } else if (type == chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED) { | 1171 } else { |
| 1172 DCHECK_EQ(chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, type); | |
| 1178 WebContents* web_contents = content::Source<WebContents>(source).ptr(); | 1173 WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
| 1179 if (web_contents) { | 1174 if (web_contents) { |
| 1180 TabContents* tab_contents = TabContents::FromWebContents(web_contents); | 1175 TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
| 1181 if (tab_contents && | 1176 if (tab_contents && tab_contents->content_settings() && |
| 1182 tab_contents->content_settings() && | |
| 1183 tab_contents->content_settings()->IsContentBlocked( | 1177 tab_contents->content_settings()->IsContentBlocked( |
| 1184 CONTENT_SETTINGS_TYPE_JAVASCRIPT)) { | 1178 CONTENT_SETTINGS_TYPE_JAVASCRIPT)) |
| 1185 OnJavascriptBlocked(); | 1179 OnJavascriptBlocked(); |
| 1186 } | |
| 1187 } | 1180 } |
| 1188 } | 1181 } |
| 1189 } | 1182 } |
| 1190 | 1183 |
| 1191 DomOperationMessageSender::DomOperationMessageSender( | 1184 DomOperationMessageSender::DomOperationMessageSender( |
| 1192 AutomationProvider* automation, | 1185 AutomationProvider* automation, |
| 1193 IPC::Message* reply_message, | 1186 IPC::Message* reply_message, |
| 1194 bool use_json_interface) | 1187 bool use_json_interface) |
| 1195 : DomOperationObserver(0), | 1188 : DomOperationObserver(0), |
| 1196 automation_(automation->AsWeakPtr()), | 1189 automation_(automation->AsWeakPtr()), |
| (...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2186 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 2179 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 2187 content::NotificationService::AllSources()); | 2180 content::NotificationService::AllSources()); |
| 2188 } | 2181 } |
| 2189 } | 2182 } |
| 2190 | 2183 |
| 2191 AppLaunchObserver::~AppLaunchObserver() {} | 2184 AppLaunchObserver::~AppLaunchObserver() {} |
| 2192 | 2185 |
| 2193 void AppLaunchObserver::Observe(int type, | 2186 void AppLaunchObserver::Observe(int type, |
| 2194 const content::NotificationSource& source, | 2187 const content::NotificationSource& source, |
| 2195 const content::NotificationDetails& details) { | 2188 const content::NotificationDetails& details) { |
| 2196 if (type == content::NOTIFICATION_LOAD_STOP) { | 2189 if (type == chrome::NOTIFICATION_BROWSER_WINDOW_READY) { |
| 2197 if (launch_container_ == extension_misc::LAUNCH_TAB) { | 2190 new_window_id_ = |
| 2198 // The app has been launched in the new tab. | 2191 ExtensionTabUtil::GetWindowId(content::Source<Browser>(source).ptr()); |
| 2199 if (automation_) { | 2192 return; |
| 2200 AutomationJSONReply(automation_, | 2193 } |
| 2201 reply_message_.release()).SendSuccess(NULL); | 2194 |
| 2202 } | 2195 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type); |
| 2203 delete this; | 2196 TabContents* tab = TabContents::FromWebContents( |
| 2204 return; | 2197 content::Source<NavigationController>(source)->GetWebContents()); |
| 2205 } else { | 2198 if ((launch_container_ == extension_misc::LAUNCH_TAB) || |
| 2206 // The app has launched only if the loaded tab is in the new window. | 2199 (tab && |
| 2207 NavigationController* controller = | 2200 (tab->restore_tab_helper()->window_id().id() == new_window_id_))) { |
|
Peter Kasting
2012/08/29 01:21:38
Note: There is a slight behavior change here in th
| |
| 2208 content::Source<NavigationController>(source).ptr(); | 2201 if (automation_) { |
| 2209 TabContents* tab = | 2202 AutomationJSONReply(automation_, |
| 2210 TabContents::FromWebContents(controller->GetWebContents()); | 2203 reply_message_.release()).SendSuccess(NULL); |
| 2211 int window_id = tab ? tab->restore_tab_helper()->window_id().id() : -1; | |
| 2212 if (window_id == new_window_id_) { | |
| 2213 if (automation_) { | |
| 2214 AutomationJSONReply(automation_, | |
| 2215 reply_message_.release()).SendSuccess(NULL); | |
| 2216 } | |
| 2217 delete this; | |
| 2218 return; | |
| 2219 } | |
| 2220 } | 2204 } |
| 2221 } else if (type == chrome::NOTIFICATION_BROWSER_WINDOW_READY) { | 2205 delete this; |
| 2222 new_window_id_ = ExtensionTabUtil::GetWindowId( | |
| 2223 content::Source<Browser>(source).ptr()); | |
| 2224 } else { | |
| 2225 NOTREACHED(); | |
| 2226 } | 2206 } |
| 2227 } | 2207 } |
| 2228 | 2208 |
| 2229 namespace { | 2209 namespace { |
| 2230 | 2210 |
| 2231 // Returns whether all active notifications have an associated process ID. | 2211 // Returns whether all active notifications have an associated process ID. |
| 2232 bool AreActiveNotificationProcessesReady() { | 2212 bool AreActiveNotificationProcessesReady() { |
| 2233 NotificationUIManager* manager = g_browser_process->notification_ui_manager(); | 2213 NotificationUIManager* manager = g_browser_process->notification_ui_manager(); |
| 2234 const BalloonCollection::Balloons& balloons = | 2214 const BalloonCollection::Balloons& balloons = |
| 2235 manager->balloon_collection()->GetActiveBalloons(); | 2215 manager->balloon_collection()->GetActiveBalloons(); |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2851 if (!profile) { | 2831 if (!profile) { |
| 2852 AutomationJSONReply(automation_, | 2832 AutomationJSONReply(automation_, |
| 2853 reply_message_.release()).SendError("Profile could not be created."); | 2833 reply_message_.release()).SendError("Profile could not be created."); |
| 2854 return; | 2834 return; |
| 2855 } | 2835 } |
| 2856 } else if (type == chrome::NOTIFICATION_BROWSER_OPENED) { | 2836 } else if (type == chrome::NOTIFICATION_BROWSER_OPENED) { |
| 2857 // Store the new browser ID and continue waiting for a new tab within it | 2837 // Store the new browser ID and continue waiting for a new tab within it |
| 2858 // to stop loading. | 2838 // to stop loading. |
| 2859 new_window_id_ = ExtensionTabUtil::GetWindowId( | 2839 new_window_id_ = ExtensionTabUtil::GetWindowId( |
| 2860 content::Source<Browser>(source).ptr()); | 2840 content::Source<Browser>(source).ptr()); |
| 2861 } else if (type == content::NOTIFICATION_LOAD_STOP) { | 2841 } else { |
| 2842 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type); | |
| 2862 // Only send the result if the loaded tab is in the new window. | 2843 // Only send the result if the loaded tab is in the new window. |
| 2863 NavigationController* controller = | 2844 NavigationController* controller = |
| 2864 content::Source<NavigationController>(source).ptr(); | 2845 content::Source<NavigationController>(source).ptr(); |
| 2865 TabContents* tab = | 2846 TabContents* tab = |
| 2866 TabContents::FromWebContents(controller->GetWebContents()); | 2847 TabContents::FromWebContents(controller->GetWebContents()); |
| 2867 int window_id = tab ? tab->restore_tab_helper()->window_id().id() : -1; | 2848 int window_id = tab ? tab->restore_tab_helper()->window_id().id() : -1; |
| 2868 if (window_id == new_window_id_) { | 2849 if (window_id == new_window_id_) { |
| 2869 if (automation_) { | 2850 if (automation_) { |
| 2870 AutomationJSONReply(automation_, reply_message_.release()) | 2851 AutomationJSONReply(automation_, reply_message_.release()) |
| 2871 .SendSuccess(NULL); | 2852 .SendSuccess(NULL); |
| 2872 } | 2853 } |
| 2873 delete this; | 2854 delete this; |
| 2874 } | 2855 } |
| 2875 } else { | |
| 2876 NOTREACHED(); | |
| 2877 } | 2856 } |
| 2878 } | 2857 } |
| 2879 | 2858 |
| 2880 ExtensionPopupObserver::ExtensionPopupObserver( | 2859 ExtensionPopupObserver::ExtensionPopupObserver( |
| 2881 AutomationProvider* automation, | 2860 AutomationProvider* automation, |
| 2882 IPC::Message* reply_message, | 2861 IPC::Message* reply_message, |
| 2883 const std::string& extension_id) | 2862 const std::string& extension_id) |
| 2884 : automation_(automation->AsWeakPtr()), | 2863 : automation_(automation->AsWeakPtr()), |
| 2885 reply_message_(reply_message), | 2864 reply_message_(reply_message), |
| 2886 extension_id_(extension_id) { | 2865 extension_id_(extension_id) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2979 if (automation_) { | 2958 if (automation_) { |
| 2980 AutomationJSONReply(automation_, reply_message_.release()) | 2959 AutomationJSONReply(automation_, reply_message_.release()) |
| 2981 .SendSuccess(NULL); | 2960 .SendSuccess(NULL); |
| 2982 } | 2961 } |
| 2983 delete this; | 2962 delete this; |
| 2984 } | 2963 } |
| 2985 } else { | 2964 } else { |
| 2986 NOTREACHED(); | 2965 NOTREACHED(); |
| 2987 } | 2966 } |
| 2988 } | 2967 } |
| OLD | NEW |