Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1117)

Side by Side Diff: chrome/browser/automation/automation_provider_observers.cc

Issue 10890023: Miscellaneous cleanups from several months ago I never got around to landing. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 content::NotificationService::AllSources()); 376 content::NotificationService::AllSources());
377 } 377 }
378 378
379 TabStripNotificationObserver::~TabStripNotificationObserver() { 379 TabStripNotificationObserver::~TabStripNotificationObserver() {
380 } 380 }
381 381
382 void TabStripNotificationObserver::Observe( 382 void TabStripNotificationObserver::Observe(
383 int type, 383 int type,
384 const content::NotificationSource& source, 384 const content::NotificationSource& source,
385 const content::NotificationDetails& details) { 385 const content::NotificationDetails& details) {
386 if (type == notification_) { 386 DCHECK_EQ(notification_, type);
387 if (type == chrome::NOTIFICATION_TAB_PARENTED) { 387 if (type == chrome::NOTIFICATION_TAB_PARENTED) {
388 ObserveTab(&(content::Source<TabContents>(source).ptr()-> 388 ObserveTab(&content::Source<TabContents>(source)->web_contents()->
389 web_contents()->GetController())); 389 GetController());
390 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { 390 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
391 ObserveTab(&(content::Source<content::WebContents>(source).ptr()-> 391 ObserveTab(&content::Source<content::WebContents>(source)->GetController());
392 GetController()));
393 } else {
394 ObserveTab(content::Source<NavigationController>(source).ptr());
395 }
396 delete this;
397 } else { 392 } else {
398 NOTREACHED(); 393 ObserveTab(content::Source<NavigationController>(source).ptr());
399 } 394 }
395 delete this;
400 } 396 }
401 397
402 TabAppendedNotificationObserver::TabAppendedNotificationObserver( 398 TabAppendedNotificationObserver::TabAppendedNotificationObserver(
403 Browser* parent, 399 Browser* parent,
404 AutomationProvider* automation, 400 AutomationProvider* automation,
405 IPC::Message* reply_message, 401 IPC::Message* reply_message,
406 bool use_json_interface) 402 bool use_json_interface)
407 : TabStripNotificationObserver(chrome::NOTIFICATION_TAB_PARENTED, 403 : TabStripNotificationObserver(chrome::NOTIFICATION_TAB_PARENTED,
408 automation), 404 automation),
409 parent_(parent), 405 parent_(parent),
(...skipping 21 matching lines...) Expand all
431 427
432 IPC::Message* TabAppendedNotificationObserver::ReleaseReply() { 428 IPC::Message* TabAppendedNotificationObserver::ReleaseReply() {
433 return reply_message_.release(); 429 return reply_message_.release();
434 } 430 }
435 431
436 TabClosedNotificationObserver::TabClosedNotificationObserver( 432 TabClosedNotificationObserver::TabClosedNotificationObserver(
437 AutomationProvider* automation, 433 AutomationProvider* automation,
438 bool wait_until_closed, 434 bool wait_until_closed,
439 IPC::Message* reply_message, 435 IPC::Message* reply_message,
440 bool use_json_interface) 436 bool use_json_interface)
441 : TabStripNotificationObserver( 437 : TabStripNotificationObserver((wait_until_closed ?
442 wait_until_closed 438 static_cast<int>(content::NOTIFICATION_WEB_CONTENTS_DESTROYED) :
443 ? static_cast<int>(content::NOTIFICATION_WEB_CONTENTS_DESTROYED) 439 static_cast<int>(chrome::NOTIFICATION_TAB_CLOSING)), automation),
444 : static_cast<int>(chrome::NOTIFICATION_TAB_CLOSING),
445 automation),
446 reply_message_(reply_message), 440 reply_message_(reply_message),
447 use_json_interface_(use_json_interface), 441 use_json_interface_(use_json_interface),
448 for_browser_command_(false) { 442 for_browser_command_(false) {
449 } 443 }
450 444
451 TabClosedNotificationObserver::~TabClosedNotificationObserver() {} 445 TabClosedNotificationObserver::~TabClosedNotificationObserver() {}
452 446
453 void TabClosedNotificationObserver::ObserveTab( 447 void TabClosedNotificationObserver::ObserveTab(
454 NavigationController* controller) { 448 NavigationController* controller) {
455 if (!automation_) 449 if (!automation_)
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, 794 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED,
801 content::NotificationService::AllBrowserContextsAndSources()); 795 content::NotificationService::AllBrowserContextsAndSources());
802 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, 796 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
803 content::NotificationService::AllBrowserContextsAndSources()); 797 content::NotificationService::AllBrowserContextsAndSources());
804 } 798 }
805 799
806 BrowserOpenedNotificationObserver::~BrowserOpenedNotificationObserver() { 800 BrowserOpenedNotificationObserver::~BrowserOpenedNotificationObserver() {
807 } 801 }
808 802
809 void BrowserOpenedNotificationObserver::Observe( 803 void BrowserOpenedNotificationObserver::Observe(
810 int type, const content::NotificationSource& source, 804 int type,
805 const content::NotificationSource& source,
811 const content::NotificationDetails& details) { 806 const content::NotificationDetails& details) {
812 if (!automation_) { 807 if (!automation_) {
813 delete this; 808 delete this;
814 return; 809 return;
815 } 810 }
816 811
817 if (type == chrome::NOTIFICATION_BROWSER_OPENED) { 812 if (type == chrome::NOTIFICATION_BROWSER_OPENED) {
818 // Store the new browser ID and continue waiting for a new tab within it 813 // Store the new browser ID and continue waiting for a new tab within it
819 // to stop loading. 814 // to stop loading.
820 new_window_id_ = ExtensionTabUtil::GetWindowId( 815 new_window_id_ = ExtensionTabUtil::GetWindowId(
821 content::Source<Browser>(source).ptr()); 816 content::Source<Browser>(source).ptr());
822 } else if (type == content::NOTIFICATION_LOAD_STOP) { 817 } else {
818 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type);
823 // Only send the result if the loaded tab is in the new window. 819 // Only send the result if the loaded tab is in the new window.
824 NavigationController* controller = 820 NavigationController* controller =
825 content::Source<NavigationController>(source).ptr(); 821 content::Source<NavigationController>(source).ptr();
826 TabContents* tab = 822 TabContents* tab =
827 TabContents::FromWebContents(controller->GetWebContents()); 823 TabContents::FromWebContents(controller->GetWebContents());
828 int window_id = tab ? tab->session_tab_helper()->window_id().id() : -1; 824 int window_id = tab ? tab->session_tab_helper()->window_id().id() : -1;
829 if (window_id == new_window_id_) { 825 if (window_id == new_window_id_) {
830 if (use_json_interface_) { 826 if (use_json_interface_) {
831 AutomationJSONReply(automation_, 827 AutomationJSONReply(automation_,
832 reply_message_.release()).SendSuccess(NULL); 828 reply_message_.release()).SendSuccess(NULL);
833 } else { 829 } else {
834 if (for_browser_command_) { 830 if (for_browser_command_) {
835 AutomationMsg_WindowExecuteCommand::WriteReplyParams( 831 AutomationMsg_WindowExecuteCommand::WriteReplyParams(
836 reply_message_.get(), true); 832 reply_message_.get(), true);
837 } 833 }
838 automation_->Send(reply_message_.release()); 834 automation_->Send(reply_message_.release());
839 } 835 }
840 delete this; 836 delete this;
841 return; 837 return;
842 } 838 }
843 } else {
844 NOTREACHED();
845 } 839 }
846 } 840 }
847 841
848 void BrowserOpenedNotificationObserver::set_for_browser_command( 842 void BrowserOpenedNotificationObserver::set_for_browser_command(
849 bool for_browser_command) { 843 bool for_browser_command) {
850 for_browser_command_ = for_browser_command; 844 for_browser_command_ = for_browser_command;
851 } 845 }
852 846
853 BrowserClosedNotificationObserver::BrowserClosedNotificationObserver( 847 BrowserClosedNotificationObserver::BrowserClosedNotificationObserver(
854 Browser* browser, 848 Browser* browser,
855 AutomationProvider* automation, 849 AutomationProvider* automation,
856 IPC::Message* reply_message, 850 IPC::Message* reply_message,
857 bool use_json_interface) 851 bool use_json_interface)
858 : automation_(automation->AsWeakPtr()), 852 : automation_(automation->AsWeakPtr()),
859 reply_message_(reply_message), 853 reply_message_(reply_message),
860 use_json_interface_(use_json_interface), 854 use_json_interface_(use_json_interface),
861 for_browser_command_(false) { 855 for_browser_command_(false) {
862 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED, 856 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED,
863 content::Source<Browser>(browser)); 857 content::Source<Browser>(browser));
864 } 858 }
865 859
866 BrowserClosedNotificationObserver::~BrowserClosedNotificationObserver() {} 860 BrowserClosedNotificationObserver::~BrowserClosedNotificationObserver() {}
867 861
868 void BrowserClosedNotificationObserver::Observe( 862 void BrowserClosedNotificationObserver::Observe(
869 int type, const content::NotificationSource& source, 863 int type, const content::NotificationSource& source,
870 const content::NotificationDetails& details) { 864 const content::NotificationDetails& details) {
871 DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSED); 865 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_CLOSED, type);
872 866
873 if (!automation_) { 867 if (!automation_) {
874 delete this; 868 delete this;
875 return; 869 return;
876 } 870 }
877 871
878 int browser_count = static_cast<int>(BrowserList::size()); 872 int browser_count = static_cast<int>(BrowserList::size());
879 // We get the notification before the browser is removed from the BrowserList. 873 // We get the notification before the browser is removed from the BrowserList.
880 bool app_closing = browser_count == 1; 874 bool app_closing = browser_count == 1;
881 875
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 1158
1165 void DomOperationObserver::Observe( 1159 void DomOperationObserver::Observe(
1166 int type, const content::NotificationSource& source, 1160 int type, const content::NotificationSource& source,
1167 const content::NotificationDetails& details) { 1161 const content::NotificationDetails& details) {
1168 if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { 1162 if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) {
1169 content::Details<DomOperationNotificationDetails> dom_op_details(details); 1163 content::Details<DomOperationNotificationDetails> dom_op_details(details);
1170 if (dom_op_details->automation_id == automation_id_) 1164 if (dom_op_details->automation_id == automation_id_)
1171 OnDomOperationCompleted(dom_op_details->json); 1165 OnDomOperationCompleted(dom_op_details->json);
1172 } else if (type == chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN) { 1166 } else if (type == chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN) {
1173 OnModalDialogShown(); 1167 OnModalDialogShown();
1174 } else if (type == chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED) { 1168 } else {
1169 DCHECK_EQ(chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, type);
1175 WebContents* web_contents = content::Source<WebContents>(source).ptr(); 1170 WebContents* web_contents = content::Source<WebContents>(source).ptr();
1176 if (web_contents) { 1171 if (web_contents) {
1177 TabContents* tab_contents = TabContents::FromWebContents(web_contents); 1172 TabContents* tab_contents = TabContents::FromWebContents(web_contents);
1178 if (tab_contents && 1173 if (tab_contents && tab_contents->content_settings() &&
1179 tab_contents->content_settings() &&
1180 tab_contents->content_settings()->IsContentBlocked( 1174 tab_contents->content_settings()->IsContentBlocked(
1181 CONTENT_SETTINGS_TYPE_JAVASCRIPT)) { 1175 CONTENT_SETTINGS_TYPE_JAVASCRIPT))
1182 OnJavascriptBlocked(); 1176 OnJavascriptBlocked();
1183 }
1184 } 1177 }
1185 } 1178 }
1186 } 1179 }
1187 1180
1188 DomOperationMessageSender::DomOperationMessageSender( 1181 DomOperationMessageSender::DomOperationMessageSender(
1189 AutomationProvider* automation, 1182 AutomationProvider* automation,
1190 IPC::Message* reply_message, 1183 IPC::Message* reply_message,
1191 bool use_json_interface) 1184 bool use_json_interface)
1192 : DomOperationObserver(0), 1185 : DomOperationObserver(0),
1193 automation_(automation->AsWeakPtr()), 1186 automation_(automation->AsWeakPtr()),
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, 2078 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
2086 content::NotificationService::AllSources()); 2079 content::NotificationService::AllSources());
2087 } 2080 }
2088 } 2081 }
2089 2082
2090 AppLaunchObserver::~AppLaunchObserver() {} 2083 AppLaunchObserver::~AppLaunchObserver() {}
2091 2084
2092 void AppLaunchObserver::Observe(int type, 2085 void AppLaunchObserver::Observe(int type,
2093 const content::NotificationSource& source, 2086 const content::NotificationSource& source,
2094 const content::NotificationDetails& details) { 2087 const content::NotificationDetails& details) {
2095 if (type == content::NOTIFICATION_LOAD_STOP) { 2088 if (type == chrome::NOTIFICATION_BROWSER_WINDOW_READY) {
2096 if (launch_container_ == extension_misc::LAUNCH_TAB) { 2089 new_window_id_ =
2097 // The app has been launched in the new tab. 2090 ExtensionTabUtil::GetWindowId(content::Source<Browser>(source).ptr());
2098 if (automation_) { 2091 return;
2099 AutomationJSONReply(automation_, 2092 }
2100 reply_message_.release()).SendSuccess(NULL); 2093
2101 } 2094 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type);
2102 delete this; 2095 TabContents* tab = TabContents::FromWebContents(
2103 return; 2096 content::Source<NavigationController>(source)->GetWebContents());
2104 } else { 2097 if ((launch_container_ == extension_misc::LAUNCH_TAB) ||
2105 // The app has launched only if the loaded tab is in the new window. 2098 (tab &&
2106 NavigationController* controller = 2099 (tab->session_tab_helper()->window_id().id() == new_window_id_))) {
2107 content::Source<NavigationController>(source).ptr(); 2100 if (automation_) {
2108 TabContents* tab = 2101 AutomationJSONReply(automation_,
2109 TabContents::FromWebContents(controller->GetWebContents()); 2102 reply_message_.release()).SendSuccess(NULL);
2110 int window_id = tab ? tab->session_tab_helper()->window_id().id() : -1;
2111 if (window_id == new_window_id_) {
2112 if (automation_) {
2113 AutomationJSONReply(automation_,
2114 reply_message_.release()).SendSuccess(NULL);
2115 }
2116 delete this;
2117 return;
2118 }
2119 } 2103 }
2120 } else if (type == chrome::NOTIFICATION_BROWSER_WINDOW_READY) { 2104 delete this;
2121 new_window_id_ = ExtensionTabUtil::GetWindowId(
2122 content::Source<Browser>(source).ptr());
2123 } else {
2124 NOTREACHED();
2125 } 2105 }
2126 } 2106 }
2127 2107
2128 namespace { 2108 namespace {
2129 2109
2130 // Returns whether all active notifications have an associated process ID. 2110 // Returns whether all active notifications have an associated process ID.
2131 bool AreActiveNotificationProcessesReady() { 2111 bool AreActiveNotificationProcessesReady() {
2132 NotificationUIManager* manager = g_browser_process->notification_ui_manager(); 2112 NotificationUIManager* manager = g_browser_process->notification_ui_manager();
2133 const BalloonCollection::Balloons& balloons = 2113 const BalloonCollection::Balloons& balloons =
2134 manager->balloon_collection()->GetActiveBalloons(); 2114 manager->balloon_collection()->GetActiveBalloons();
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
2750 if (!profile) { 2730 if (!profile) {
2751 AutomationJSONReply(automation_, 2731 AutomationJSONReply(automation_,
2752 reply_message_.release()).SendError("Profile could not be created."); 2732 reply_message_.release()).SendError("Profile could not be created.");
2753 return; 2733 return;
2754 } 2734 }
2755 } else if (type == chrome::NOTIFICATION_BROWSER_OPENED) { 2735 } else if (type == chrome::NOTIFICATION_BROWSER_OPENED) {
2756 // Store the new browser ID and continue waiting for a new tab within it 2736 // Store the new browser ID and continue waiting for a new tab within it
2757 // to stop loading. 2737 // to stop loading.
2758 new_window_id_ = ExtensionTabUtil::GetWindowId( 2738 new_window_id_ = ExtensionTabUtil::GetWindowId(
2759 content::Source<Browser>(source).ptr()); 2739 content::Source<Browser>(source).ptr());
2760 } else if (type == content::NOTIFICATION_LOAD_STOP) { 2740 } else {
2741 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type);
2761 // Only send the result if the loaded tab is in the new window. 2742 // Only send the result if the loaded tab is in the new window.
2762 NavigationController* controller = 2743 NavigationController* controller =
2763 content::Source<NavigationController>(source).ptr(); 2744 content::Source<NavigationController>(source).ptr();
2764 TabContents* tab = 2745 TabContents* tab =
2765 TabContents::FromWebContents(controller->GetWebContents()); 2746 TabContents::FromWebContents(controller->GetWebContents());
2766 int window_id = tab ? tab->session_tab_helper()->window_id().id() : -1; 2747 int window_id = tab ? tab->session_tab_helper()->window_id().id() : -1;
2767 if (window_id == new_window_id_) { 2748 if (window_id == new_window_id_) {
2768 if (automation_) { 2749 if (automation_) {
2769 AutomationJSONReply(automation_, reply_message_.release()) 2750 AutomationJSONReply(automation_, reply_message_.release())
2770 .SendSuccess(NULL); 2751 .SendSuccess(NULL);
2771 } 2752 }
2772 delete this; 2753 delete this;
2773 } 2754 }
2774 } else {
2775 NOTREACHED();
2776 } 2755 }
2777 } 2756 }
2778 2757
2779 ExtensionPopupObserver::ExtensionPopupObserver( 2758 ExtensionPopupObserver::ExtensionPopupObserver(
2780 AutomationProvider* automation, 2759 AutomationProvider* automation,
2781 IPC::Message* reply_message, 2760 IPC::Message* reply_message,
2782 const std::string& extension_id) 2761 const std::string& extension_id)
2783 : automation_(automation->AsWeakPtr()), 2762 : automation_(automation->AsWeakPtr()),
2784 reply_message_(reply_message), 2763 reply_message_(reply_message),
2785 extension_id_(extension_id) { 2764 extension_id_(extension_id) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2878 if (automation_) { 2857 if (automation_) {
2879 AutomationJSONReply(automation_, reply_message_.release()) 2858 AutomationJSONReply(automation_, reply_message_.release())
2880 .SendSuccess(NULL); 2859 .SendSuccess(NULL);
2881 } 2860 }
2882 delete this; 2861 delete this;
2883 } 2862 }
2884 } else { 2863 } else {
2885 NOTREACHED(); 2864 NOTREACHED();
2886 } 2865 }
2887 } 2866 }
OLDNEW
« no previous file with comments | « chrome/browser/alternate_nav_url_fetcher.cc ('k') | chrome/browser/download/download_request_limiter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698