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

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

Issue 8804011: WebDriver extension support in TestingAutomationProvider. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix comments and minor issues Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #include "chrome/browser/ui/browser_window.h" 64 #include "chrome/browser/ui/browser_window.h"
65 #include "chrome/browser/ui/find_bar/find_notification_details.h" 65 #include "chrome/browser/ui/find_bar/find_notification_details.h"
66 #include "chrome/browser/ui/login/login_prompt.h" 66 #include "chrome/browser/ui/login/login_prompt.h"
67 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 67 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
68 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 68 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
69 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" 69 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h"
70 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 70 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
71 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" 71 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h"
72 #include "chrome/common/automation_messages.h" 72 #include "chrome/common/automation_messages.h"
73 #include "chrome/common/chrome_notification_types.h" 73 #include "chrome/common/chrome_notification_types.h"
74 #include "chrome/common/chrome_view_type.h"
74 #include "chrome/common/content_settings_types.h" 75 #include "chrome/common/content_settings_types.h"
75 #include "chrome/common/extensions/extension.h" 76 #include "chrome/common/extensions/extension.h"
76 #include "content/browser/download/save_package.h" 77 #include "content/browser/download/save_package.h"
77 #include "content/browser/renderer_host/render_view_host.h" 78 #include "content/browser/renderer_host/render_view_host.h"
78 #include "content/browser/tab_contents/navigation_controller.h" 79 #include "content/browser/tab_contents/navigation_controller.h"
79 #include "content/browser/tab_contents/tab_contents.h" 80 #include "content/browser/tab_contents/tab_contents.h"
80 #include "content/public/browser/notification_service.h" 81 #include "content/public/browser/notification_service.h"
81 #include "content/public/browser/render_process_host.h" 82 #include "content/public/browser/render_process_host.h"
82 #include "content/public/common/process_type.h" 83 #include "content/public/common/process_type.h"
83 #include "googleurl/src/gurl.h" 84 #include "googleurl/src/gurl.h"
(...skipping 2557 matching lines...) Expand 10 before | Expand all | Expand 10 after
2641 reply_message_.release()).SendSuccess(NULL); 2642 reply_message_.release()).SendSuccess(NULL);
2642 delete this; 2643 delete this;
2643 } 2644 }
2644 } else { 2645 } else {
2645 LOG(WARNING) << "Ignoring unexpected event type: " 2646 LOG(WARNING) << "Ignoring unexpected event type: "
2646 << *request_details.ptr() << " (expected: " << event_type_ 2647 << *request_details.ptr() << " (expected: " << event_type_
2647 << ")"; 2648 << ")";
2648 } 2649 }
2649 } 2650 }
2650 2651
2651 AllTabsStoppedLoadingObserver::AllTabsStoppedLoadingObserver( 2652 AllViewsStoppedLoadingObserver::AllViewsStoppedLoadingObserver(
2652 AutomationProvider* automation, 2653 AutomationProvider* automation,
2653 IPC::Message* reply_message) 2654 IPC::Message* reply_message,
2655 ExtensionProcessManager* extension_process_manager)
2654 : automation_(automation->AsWeakPtr()), 2656 : automation_(automation->AsWeakPtr()),
2655 reply_message_(reply_message) { 2657 reply_message_(reply_message),
2658 extension_process_manager_(extension_process_manager) {
2656 registrar_.Add(this, 2659 registrar_.Add(this,
2657 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, 2660 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN,
2658 content::NotificationService::AllSources()); 2661 content::NotificationService::AllSources());
2662 registrar_.Add(this,
2663 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
2664 content::NotificationService::AllSources());
2659 for (BrowserList::const_iterator iter = BrowserList::begin(); 2665 for (BrowserList::const_iterator iter = BrowserList::begin();
2660 iter != BrowserList::end(); 2666 iter != BrowserList::end();
2661 ++iter) { 2667 ++iter) {
2662 Browser* browser = *iter; 2668 Browser* browser = *iter;
2663 for (int i = 0; i < browser->tab_count(); ++i) { 2669 for (int i = 0; i < browser->tab_count(); ++i) {
2664 TabContentsWrapper* contents_wrapper = 2670 TabContentsWrapper* contents_wrapper =
2665 browser->GetTabContentsWrapperAt(i); 2671 browser->GetTabContentsWrapperAt(i);
2666 StartObserving(contents_wrapper->automation_tab_helper()); 2672 StartObserving(contents_wrapper->automation_tab_helper());
2667 if (contents_wrapper->automation_tab_helper()->has_pending_loads()) 2673 if (contents_wrapper->automation_tab_helper()->has_pending_loads())
2668 pending_tabs_.insert(contents_wrapper->tab_contents()); 2674 pending_tabs_.insert(contents_wrapper->tab_contents());
2669 } 2675 }
2670 } 2676 }
2671 CheckIfNoMorePendingLoads(); 2677 CheckIfNoMorePendingLoads();
2672 } 2678 }
2673 2679
2674 AllTabsStoppedLoadingObserver::~AllTabsStoppedLoadingObserver() { 2680 AllViewsStoppedLoadingObserver::~AllViewsStoppedLoadingObserver() {
2675 } 2681 }
2676 2682
2677 void AllTabsStoppedLoadingObserver::OnFirstPendingLoad( 2683 void AllViewsStoppedLoadingObserver::OnFirstPendingLoad(
2678 TabContents* tab_contents) { 2684 TabContents* tab_contents) {
2679 pending_tabs_.insert(tab_contents); 2685 pending_tabs_.insert(tab_contents);
2680 } 2686 }
2681 2687
2682 void AllTabsStoppedLoadingObserver::OnNoMorePendingLoads( 2688 void AllViewsStoppedLoadingObserver::OnNoMorePendingLoads(
2683 TabContents* tab_contents) { 2689 TabContents* tab_contents) {
2684 if (!automation_) { 2690 if (!automation_) {
2685 delete this; 2691 delete this;
2686 return; 2692 return;
2687 } 2693 }
2688 2694
2689 TabSet::iterator iter = pending_tabs_.find(tab_contents); 2695 TabSet::iterator iter = pending_tabs_.find(tab_contents);
2690 if (iter == pending_tabs_.end()) { 2696 if (iter == pending_tabs_.end()) {
2691 LOG(ERROR) << "Received OnNoMorePendingLoads for tab without " 2697 LOG(ERROR) << "Received OnNoMorePendingLoads for tab without "
2692 << "OnFirstPendingLoad."; 2698 << "OnFirstPendingLoad.";
2693 return; 2699 return;
2694 } 2700 }
2695 pending_tabs_.erase(iter); 2701 pending_tabs_.erase(iter);
2696 CheckIfNoMorePendingLoads(); 2702 CheckIfNoMorePendingLoads();
2697 } 2703 }
2698 2704
2699 void AllTabsStoppedLoadingObserver::Observe( 2705 void AllViewsStoppedLoadingObserver::Observe(
2700 int type, 2706 int type,
2701 const content::NotificationSource& source, 2707 const content::NotificationSource& source,
2702 const content::NotificationDetails& details) { 2708 const content::NotificationDetails& details) {
2703 if (!automation_) { 2709 if (!automation_) {
2710 delete this;
2711 return;
2712 }
2713 if (type == chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING) {
2714 CheckIfNoMorePendingLoads();
2715 } else if (type == chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN) {
2704 AutomationJSONReply(automation_, 2716 AutomationJSONReply(automation_,
2705 reply_message_.release()).SendSuccess(NULL); 2717 reply_message_.release()).SendSuccess(NULL);
2706 delete this; 2718 delete this;
2707 } 2719 }
2708 } 2720 }
2709 2721
2710 void AllTabsStoppedLoadingObserver::CheckIfNoMorePendingLoads() { 2722 void AllViewsStoppedLoadingObserver::CheckIfNoMorePendingLoads() {
2711 if (!automation_) { 2723 if (!automation_) {
2712 delete this; 2724 delete this;
2713 return; 2725 return;
2714 } 2726 }
2715 2727
2716 if (pending_tabs_.empty()) { 2728 if (pending_tabs_.empty() &&
2729 DidExtensionHostsStopLoading(extension_process_manager_)) {
2717 AutomationJSONReply(automation_, 2730 AutomationJSONReply(automation_,
2718 reply_message_.release()).SendSuccess(NULL); 2731 reply_message_.release()).SendSuccess(NULL);
2719 delete this; 2732 delete this;
2720 } 2733 }
2721 } 2734 }
2722 2735
2723 NewTabObserver::NewTabObserver(AutomationProvider* automation, 2736 NewTabObserver::NewTabObserver(AutomationProvider* automation,
2724 IPC::Message* reply_message) 2737 IPC::Message* reply_message)
2725 : automation_(automation->AsWeakPtr()), 2738 : automation_(automation->AsWeakPtr()),
2726 reply_message_(reply_message) { 2739 reply_message_(reply_message) {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
3047 } 3060 }
3048 } 3061 }
3049 3062
3050 // static 3063 // static
3051 void PolicyUpdatesObserver::PostTask(content::BrowserThread::ID id, 3064 void PolicyUpdatesObserver::PostTask(content::BrowserThread::ID id,
3052 const base::Closure& callback) { 3065 const base::Closure& callback) {
3053 content::BrowserThread::PostTask(id, FROM_HERE, callback); 3066 content::BrowserThread::PostTask(id, FROM_HERE, callback);
3054 } 3067 }
3055 3068
3056 #endif // defined(ENABLE_CONFIGURATION_POLICY) 3069 #endif // defined(ENABLE_CONFIGURATION_POLICY)
3070
3071 ExtensionPopupObserver::ExtensionPopupObserver(
3072 AutomationProvider* automation,
3073 IPC::Message* reply_message,
3074 const std::string& extension_id)
3075 : automation_(automation->AsWeakPtr()),
3076 reply_message_(reply_message),
3077 extension_id_(extension_id) {
3078 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
3079 content::NotificationService::AllSources());
3080 }
3081
3082 ExtensionPopupObserver::~ExtensionPopupObserver() {
3083 }
3084
3085 void ExtensionPopupObserver::Observe(
3086 int type,
3087 const content::NotificationSource& source,
3088 const content::NotificationDetails& details) {
3089 if (!automation_) {
3090 delete this;
3091 return;
3092 }
3093
3094 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
3095 if (host->extension_id() == extension_id_ &&
3096 host->extension_host_type() == chrome::VIEW_TYPE_EXTENSION_POPUP) {
3097 AutomationJSONReply(automation_, reply_message_.release())
3098 .SendSuccess(NULL);
3099 delete this;
3100 }
3101 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider_observers.h ('k') | chrome/browser/automation/testing_automation_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698