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

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

Issue 10115018: Convert the infobars interactive_ui_test to a browser_test. Remove the ExtensionProxy class which… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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.h" 5 #include "chrome/browser/automation/automation_provider.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 10 matching lines...) Expand all
21 #include "base/stl_util.h" 21 #include "base/stl_util.h"
22 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
23 #include "base/string_util.h" 23 #include "base/string_util.h"
24 #include "base/synchronization/waitable_event.h" 24 #include "base/synchronization/waitable_event.h"
25 #include "base/threading/thread.h" 25 #include "base/threading/thread.h"
26 #include "base/utf_string_conversions.h" 26 #include "base/utf_string_conversions.h"
27 #include "base/values.h" 27 #include "base/values.h"
28 #include "chrome/app/chrome_command_ids.h" 28 #include "chrome/app/chrome_command_ids.h"
29 #include "chrome/browser/autocomplete/autocomplete_edit.h" 29 #include "chrome/browser/autocomplete/autocomplete_edit.h"
30 #include "chrome/browser/automation/automation_browser_tracker.h" 30 #include "chrome/browser/automation/automation_browser_tracker.h"
31 #include "chrome/browser/automation/automation_extension_tracker.h"
32 #include "chrome/browser/automation/automation_provider_list.h" 31 #include "chrome/browser/automation/automation_provider_list.h"
33 #include "chrome/browser/automation/automation_provider_observers.h" 32 #include "chrome/browser/automation/automation_provider_observers.h"
34 #include "chrome/browser/automation/automation_resource_message_filter.h" 33 #include "chrome/browser/automation/automation_resource_message_filter.h"
35 #include "chrome/browser/automation/automation_tab_tracker.h" 34 #include "chrome/browser/automation/automation_tab_tracker.h"
36 #include "chrome/browser/automation/automation_window_tracker.h" 35 #include "chrome/browser/automation/automation_window_tracker.h"
37 #include "chrome/browser/bookmarks/bookmark_model.h" 36 #include "chrome/browser/bookmarks/bookmark_model.h"
38 #include "chrome/browser/bookmarks/bookmark_storage.h" 37 #include "chrome/browser/bookmarks/bookmark_storage.h"
39 #include "chrome/browser/browser_process.h" 38 #include "chrome/browser/browser_process.h"
40 #include "chrome/browser/browsing_data_remover.h" 39 #include "chrome/browser/browsing_data_remover.h"
41 #include "chrome/browser/character_encoding.h" 40 #include "chrome/browser/character_encoding.h"
42 #include "chrome/browser/content_settings/host_content_settings_map.h" 41 #include "chrome/browser/content_settings/host_content_settings_map.h"
43 #include "chrome/browser/extensions/crx_installer.h"
44 #include "chrome/browser/extensions/extension_browser_event_router.h"
45 #include "chrome/browser/extensions/extension_host.h"
46 #include "chrome/browser/extensions/extension_install_ui.h"
47 #include "chrome/browser/extensions/extension_message_service.h"
48 #include "chrome/browser/extensions/extension_service.h"
49 #include "chrome/browser/extensions/extension_system.h"
50 #include "chrome/browser/extensions/extension_tab_util.h"
51 #include "chrome/browser/extensions/extension_toolbar_model.h"
52 #include "chrome/browser/extensions/unpacked_installer.h"
53 #include "chrome/browser/extensions/user_script_master.h"
54 #include "chrome/browser/net/url_request_mock_util.h" 42 #include "chrome/browser/net/url_request_mock_util.h"
55 #include "chrome/browser/prefs/pref_service.h" 43 #include "chrome/browser/prefs/pref_service.h"
56 #include "chrome/browser/printing/print_job.h" 44 #include "chrome/browser/printing/print_job.h"
57 #include "chrome/browser/profiles/profile_manager.h" 45 #include "chrome/browser/profiles/profile_manager.h"
58 #include "chrome/browser/ssl/ssl_blocking_page.h" 46 #include "chrome/browser/ssl/ssl_blocking_page.h"
59 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" 47 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
60 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" 48 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h"
61 #include "chrome/browser/ui/browser_list.h" 49 #include "chrome/browser/ui/browser_list.h"
62 #include "chrome/browser/ui/browser_window.h" 50 #include "chrome/browser/ui/browser_window.h"
63 #include "chrome/browser/ui/find_bar/find_bar.h" 51 #include "chrome/browser/ui/find_bar/find_bar.h"
64 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 52 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
65 #include "chrome/browser/ui/find_bar/find_notification_details.h" 53 #include "chrome/browser/ui/find_bar/find_notification_details.h"
66 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 54 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
67 #include "chrome/browser/ui/login/login_prompt.h" 55 #include "chrome/browser/ui/login/login_prompt.h"
68 #include "chrome/browser/ui/omnibox/location_bar.h" 56 #include "chrome/browser/ui/omnibox/location_bar.h"
69 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 57 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
70 #include "chrome/common/automation_constants.h" 58 #include "chrome/common/automation_constants.h"
71 #include "chrome/common/automation_messages.h" 59 #include "chrome/common/automation_messages.h"
72 #include "chrome/common/chrome_constants.h" 60 #include "chrome/common/chrome_constants.h"
73 #include "chrome/common/chrome_paths.h" 61 #include "chrome/common/chrome_paths.h"
74 #include "chrome/common/chrome_switches.h" 62 #include "chrome/common/chrome_switches.h"
75 #include "chrome/common/chrome_version_info.h" 63 #include "chrome/common/chrome_version_info.h"
76 #include "chrome/common/extensions/extension.h"
77 #include "chrome/common/pref_names.h" 64 #include "chrome/common/pref_names.h"
78 #include "chrome/common/render_messages.h" 65 #include "chrome/common/render_messages.h"
79 #include "chrome/common/url_constants.h" 66 #include "chrome/common/url_constants.h"
80 #include "content/public/browser/browser_thread.h" 67 #include "content/public/browser/browser_thread.h"
81 #include "content/public/browser/download_item.h" 68 #include "content/public/browser/download_item.h"
82 #include "content/public/browser/render_view_host.h" 69 #include "content/public/browser/render_view_host.h"
83 #include "content/public/browser/trace_controller.h" 70 #include "content/public/browser/trace_controller.h"
84 #include "content/public/browser/web_contents.h" 71 #include "content/public/browser/web_contents.h"
85 #include "content/public/browser/web_contents_view.h" 72 #include "content/public/browser/web_contents_view.h"
86 #include "net/proxy/proxy_config_service_fixed.h" 73 #include "net/proxy/proxy_config_service_fixed.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 use_initial_load_observers_(true), 162 use_initial_load_observers_(true),
176 is_connected_(false), 163 is_connected_(false),
177 initial_tab_loads_complete_(false), 164 initial_tab_loads_complete_(false),
178 network_library_initialized_(true), 165 network_library_initialized_(true),
179 login_webui_ready_(true) { 166 login_webui_ready_(true) {
180 TRACE_EVENT_BEGIN_ETW("AutomationProvider::AutomationProvider", 0, ""); 167 TRACE_EVENT_BEGIN_ETW("AutomationProvider::AutomationProvider", 0, "");
181 168
182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
183 170
184 browser_tracker_.reset(new AutomationBrowserTracker(this)); 171 browser_tracker_.reset(new AutomationBrowserTracker(this));
185 extension_tracker_.reset(new AutomationExtensionTracker(this));
186 tab_tracker_.reset(new AutomationTabTracker(this)); 172 tab_tracker_.reset(new AutomationTabTracker(this));
187 window_tracker_.reset(new AutomationWindowTracker(this)); 173 window_tracker_.reset(new AutomationWindowTracker(this));
188 new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this, profile)); 174 new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this, profile));
189 metric_event_duration_observer_.reset(new MetricEventDurationObserver()); 175 metric_event_duration_observer_.reset(new MetricEventDurationObserver());
190 extension_test_result_observer_.reset(
191 new ExtensionTestResultNotificationObserver(this));
192 176
193 TRACE_EVENT_END_ETW("AutomationProvider::AutomationProvider", 0, ""); 177 TRACE_EVENT_END_ETW("AutomationProvider::AutomationProvider", 0, "");
194 } 178 }
195 179
196 AutomationProvider::~AutomationProvider() { 180 AutomationProvider::~AutomationProvider() {
197 if (channel_.get()) 181 if (channel_.get())
198 channel_->Close(); 182 channel_->Close();
199 } 183 }
200 184
201 bool AutomationProvider::InitializeChannel(const std::string& channel_id) { 185 bool AutomationProvider::InitializeChannel(const std::string& channel_id) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 OnNetworkLibraryInit(); 289 OnNetworkLibraryInit();
306 OnLoginWebuiReady(); 290 OnLoginWebuiReady();
307 } 291 }
308 292
309 int AutomationProvider::GetIndexForNavigationController( 293 int AutomationProvider::GetIndexForNavigationController(
310 const NavigationController* controller, const Browser* parent) const { 294 const NavigationController* controller, const Browser* parent) const {
311 DCHECK(parent); 295 DCHECK(parent);
312 return parent->GetIndexOfController(controller); 296 return parent->GetIndexOfController(controller);
313 } 297 }
314 298
315 int AutomationProvider::AddExtension(const Extension* extension) {
316 DCHECK(extension);
317 return extension_tracker_->Add(extension);
318 }
319
320 // TODO(phajdan.jr): move to TestingAutomationProvider. 299 // TODO(phajdan.jr): move to TestingAutomationProvider.
321 DictionaryValue* AutomationProvider::GetDictionaryFromDownloadItem( 300 DictionaryValue* AutomationProvider::GetDictionaryFromDownloadItem(
322 const DownloadItem* download) { 301 const DownloadItem* download) {
323 std::map<DownloadItem::DownloadState, std::string> state_to_string; 302 std::map<DownloadItem::DownloadState, std::string> state_to_string;
324 state_to_string[DownloadItem::IN_PROGRESS] = std::string("IN_PROGRESS"); 303 state_to_string[DownloadItem::IN_PROGRESS] = std::string("IN_PROGRESS");
325 state_to_string[DownloadItem::CANCELLED] = std::string("CANCELLED"); 304 state_to_string[DownloadItem::CANCELLED] = std::string("CANCELLED");
326 state_to_string[DownloadItem::REMOVING] = std::string("REMOVING"); 305 state_to_string[DownloadItem::REMOVING] = std::string("REMOVING");
327 state_to_string[DownloadItem::INTERRUPTED] = std::string("INTERRUPTED"); 306 state_to_string[DownloadItem::INTERRUPTED] = std::string("INTERRUPTED");
328 state_to_string[DownloadItem::COMPLETE] = std::string("COMPLETE"); 307 state_to_string[DownloadItem::COMPLETE] = std::string("COMPLETE");
329 308
(...skipping 17 matching lines...) Expand all
347 dl_item_value->SetBoolean("is_temporary", download->IsTemporary()); 326 dl_item_value->SetBoolean("is_temporary", download->IsTemporary());
348 dl_item_value->SetBoolean("is_otr", download->IsOtr()); // incognito 327 dl_item_value->SetBoolean("is_otr", download->IsOtr()); // incognito
349 dl_item_value->SetString("state", state_to_string[download->GetState()]); 328 dl_item_value->SetString("state", state_to_string[download->GetState()]);
350 dl_item_value->SetString("safety_state", 329 dl_item_value->SetString("safety_state",
351 safety_state_to_string[download->GetSafetyState()]); 330 safety_state_to_string[download->GetSafetyState()]);
352 dl_item_value->SetInteger("PercentComplete", download->PercentComplete()); 331 dl_item_value->SetInteger("PercentComplete", download->PercentComplete());
353 332
354 return dl_item_value; 333 return dl_item_value;
355 } 334 }
356 335
357 const Extension* AutomationProvider::GetExtension(int extension_handle) {
358 return extension_tracker_->GetResource(extension_handle);
359 }
360
361 const Extension* AutomationProvider::GetEnabledExtension(int extension_handle) {
362 const Extension* extension =
363 extension_tracker_->GetResource(extension_handle);
364 ExtensionService* service = profile_->GetExtensionService();
365 if (extension && service &&
366 service->GetExtensionById(extension->id(), false))
367 return extension;
368 return NULL;
369 }
370
371 const Extension* AutomationProvider::GetDisabledExtension(
372 int extension_handle) {
373 const Extension* extension =
374 extension_tracker_->GetResource(extension_handle);
375 ExtensionService* service = profile_->GetExtensionService();
376 if (extension && service &&
377 service->GetExtensionById(extension->id(), true) &&
378 !service->GetExtensionById(extension->id(), false))
379 return extension;
380 return NULL;
381 }
382
383 void AutomationProvider::OnChannelConnected(int pid) { 336 void AutomationProvider::OnChannelConnected(int pid) {
384 is_connected_ = true; 337 is_connected_ = true;
385 338
386 // Send a hello message with our current automation protocol version. 339 // Send a hello message with our current automation protocol version.
387 VLOG(2) << "Testing channel connected, sending hello message"; 340 VLOG(2) << "Testing channel connected, sending hello message";
388 channel_->Send(new AutomationMsg_Hello(GetProtocolVersion())); 341 channel_->Send(new AutomationMsg_Hello(GetProtocolVersion()));
389 342
390 SendInitialLoadMessage(); 343 SendInitialLoadMessage();
391 } 344 }
392 345
(...skipping 24 matching lines...) Expand all
417 IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync) 370 IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync)
418 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest) 371 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest)
419 IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding, OverrideEncoding) 372 IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding, OverrideEncoding)
420 IPC_MESSAGE_HANDLER(AutomationMsg_SelectAll, SelectAll) 373 IPC_MESSAGE_HANDLER(AutomationMsg_SelectAll, SelectAll)
421 IPC_MESSAGE_HANDLER(AutomationMsg_Cut, Cut) 374 IPC_MESSAGE_HANDLER(AutomationMsg_Cut, Cut)
422 IPC_MESSAGE_HANDLER(AutomationMsg_Copy, Copy) 375 IPC_MESSAGE_HANDLER(AutomationMsg_Copy, Copy)
423 IPC_MESSAGE_HANDLER(AutomationMsg_Paste, Paste) 376 IPC_MESSAGE_HANDLER(AutomationMsg_Paste, Paste)
424 IPC_MESSAGE_HANDLER(AutomationMsg_ReloadAsync, ReloadAsync) 377 IPC_MESSAGE_HANDLER(AutomationMsg_ReloadAsync, ReloadAsync)
425 IPC_MESSAGE_HANDLER(AutomationMsg_StopAsync, StopAsync) 378 IPC_MESSAGE_HANDLER(AutomationMsg_StopAsync, StopAsync)
426 IPC_MESSAGE_HANDLER(AutomationMsg_SetPageFontSize, OnSetPageFontSize) 379 IPC_MESSAGE_HANDLER(AutomationMsg_SetPageFontSize, OnSetPageFontSize)
427 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForExtensionTestResult,
428 WaitForExtensionTestResult)
429 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InstallExtension,
430 InstallExtension)
431 IPC_MESSAGE_HANDLER(AutomationMsg_UninstallExtension,
432 UninstallExtension)
433 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_EnableExtension,
434 EnableExtension)
435 IPC_MESSAGE_HANDLER(AutomationMsg_DisableExtension,
436 DisableExtension)
437 IPC_MESSAGE_HANDLER_DELAY_REPLY(
438 AutomationMsg_ExecuteExtensionActionInActiveTabAsync,
439 ExecuteExtensionActionInActiveTabAsync)
440 IPC_MESSAGE_HANDLER(AutomationMsg_MoveExtensionBrowserAction,
441 MoveExtensionBrowserAction)
442 IPC_MESSAGE_HANDLER(AutomationMsg_GetExtensionProperty,
443 GetExtensionProperty)
444 IPC_MESSAGE_HANDLER(AutomationMsg_SaveAsAsync, SaveAsAsync) 380 IPC_MESSAGE_HANDLER(AutomationMsg_SaveAsAsync, SaveAsAsync)
445 IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBrowsingData, RemoveBrowsingData) 381 IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBrowsingData, RemoveBrowsingData)
446 IPC_MESSAGE_HANDLER(AutomationMsg_JavaScriptStressTestControl, 382 IPC_MESSAGE_HANDLER(AutomationMsg_JavaScriptStressTestControl,
447 JavaScriptStressTestControl) 383 JavaScriptStressTestControl)
448 IPC_MESSAGE_HANDLER(AutomationMsg_BeginTracing, BeginTracing) 384 IPC_MESSAGE_HANDLER(AutomationMsg_BeginTracing, BeginTracing)
449 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_EndTracing, EndTracing) 385 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_EndTracing, EndTracing)
450 IPC_MESSAGE_HANDLER(AutomationMsg_GetTracingOutput, GetTracingOutput) 386 IPC_MESSAGE_HANDLER(AutomationMsg_GetTracingOutput, GetTracingOutput)
451 #if defined(OS_WIN) && !defined(USE_AURA) 387 #if defined(OS_WIN) && !defined(USE_AURA)
452 // These are for use with external tabs. 388 // These are for use with external tabs.
453 IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab) 389 IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab)
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 return NULL; 747 return NULL;
812 } 748 }
813 749
814 RenderViewHost* view_host = web_contents->GetRenderViewHost(); 750 RenderViewHost* view_host = web_contents->GetRenderViewHost();
815 return view_host; 751 return view_host;
816 } 752 }
817 753
818 return NULL; 754 return NULL;
819 } 755 }
820 756
821 void AutomationProvider::WaitForExtensionTestResult(
822 IPC::Message* reply_message) {
823 DCHECK(!reply_message_);
824 reply_message_ = reply_message;
825 // Call MaybeSendResult, because the result might have come in before
826 // we were waiting on it.
827 extension_test_result_observer_->MaybeSendResult();
828 }
829
830 void AutomationProvider::InstallExtension(
831 const FilePath& extension_path, bool with_ui,
832 IPC::Message* reply_message) {
833 ExtensionService* service = profile_->GetExtensionService();
834 ExtensionProcessManager* manager = profile_->GetExtensionProcessManager();
835 if (service && manager) {
836 // The observer will delete itself when done.
837 new ExtensionReadyNotificationObserver(
838 manager,
839 service,
840 this,
841 AutomationMsg_InstallExtension::ID,
842 reply_message);
843
844 if (extension_path.MatchesExtension(FILE_PATH_LITERAL(".crx"))) {
845 ExtensionInstallUI* client =
846 (with_ui ? new ExtensionInstallUI(profile_) : NULL);
847 scoped_refptr<CrxInstaller> installer(
848 CrxInstaller::Create(service, client));
849 if (!with_ui)
850 installer->set_allow_silent_install(true);
851 installer->set_install_cause(extension_misc::INSTALL_CAUSE_AUTOMATION);
852 installer->InstallCrx(extension_path);
853 } else {
854 scoped_refptr<extensions::UnpackedInstaller> installer(
855 extensions::UnpackedInstaller::Create(service));
856 installer->set_prompt_for_plugins(with_ui);
857 installer->Load(extension_path);
858 }
859 } else {
860 AutomationMsg_InstallExtension::WriteReplyParams(reply_message, 0);
861 Send(reply_message);
862 }
863 }
864
865 void AutomationProvider::UninstallExtension(int extension_handle,
866 bool* success) {
867 *success = false;
868 const Extension* extension = GetExtension(extension_handle);
869 ExtensionService* service = profile_->GetExtensionService();
870 if (extension && service) {
871 ExtensionUnloadNotificationObserver observer;
872 service->UninstallExtension(extension->id(), false, NULL);
873 // The extension unload notification should have been sent synchronously
874 // with the uninstall. Just to be safe, check that it was received.
875 *success = observer.did_receive_unload_notification();
876 }
877 }
878
879 void AutomationProvider::EnableExtension(int extension_handle,
880 IPC::Message* reply_message) {
881 const Extension* extension = GetDisabledExtension(extension_handle);
882 ExtensionService* service = profile_->GetExtensionService();
883 ExtensionProcessManager* manager = profile_->GetExtensionProcessManager();
884 // Only enable if this extension is disabled.
885 if (extension && service && manager) {
886 // The observer will delete itself when done.
887 new ExtensionReadyNotificationObserver(
888 manager,
889 service,
890 this,
891 AutomationMsg_EnableExtension::ID,
892 reply_message);
893 service->EnableExtension(extension->id());
894 } else {
895 AutomationMsg_EnableExtension::WriteReplyParams(reply_message, false);
896 Send(reply_message);
897 }
898 }
899
900 void AutomationProvider::DisableExtension(int extension_handle,
901 bool* success) {
902 *success = false;
903 const Extension* extension = GetEnabledExtension(extension_handle);
904 ExtensionService* service = profile_->GetExtensionService();
905 if (extension && service) {
906 ExtensionUnloadNotificationObserver observer;
907 service->DisableExtension(extension->id(), Extension::DISABLE_USER_ACTION);
908 // The extension unload notification should have been sent synchronously
909 // with the disable. Just to be safe, check that it was received.
910 *success = observer.did_receive_unload_notification();
911 }
912 }
913
914 void AutomationProvider::ExecuteExtensionActionInActiveTabAsync(
915 int extension_handle, int browser_handle,
916 IPC::Message* reply_message) {
917 bool success = false;
918 const Extension* extension = GetEnabledExtension(extension_handle);
919 ExtensionService* service = profile_->GetExtensionService();
920 ExtensionMessageService* message_service =
921 ExtensionSystem::Get(profile_)->message_service();
922 Browser* browser = browser_tracker_->GetResource(browser_handle);
923 if (extension && service && message_service && browser) {
924 int tab_id = ExtensionTabUtil::GetTabId(browser->GetSelectedWebContents());
925 if (extension->page_action()) {
926 service->browser_event_router()->PageActionExecuted(
927 browser->profile(), extension->id(), "action", tab_id, "", 1);
928 success = true;
929 } else if (extension->browser_action()) {
930 service->browser_event_router()->BrowserActionExecuted(
931 browser->profile(), extension->id(), browser);
932 success = true;
933 }
934 }
935 AutomationMsg_ExecuteExtensionActionInActiveTabAsync::WriteReplyParams(
936 reply_message, success);
937 Send(reply_message);
938 }
939
940 void AutomationProvider::MoveExtensionBrowserAction(
941 int extension_handle, int index, bool* success) {
942 *success = false;
943 const Extension* extension = GetEnabledExtension(extension_handle);
944 ExtensionService* service = profile_->GetExtensionService();
945 if (extension && service) {
946 ExtensionToolbarModel* toolbar = service->toolbar_model();
947 if (toolbar) {
948 if (index >= 0 && index < static_cast<int>(toolbar->size())) {
949 toolbar->MoveBrowserAction(extension, index);
950 *success = true;
951 } else {
952 DLOG(WARNING) << "Attempted to move browser action to invalid index.";
953 }
954 }
955 }
956 }
957
958 void AutomationProvider::GetExtensionProperty(
959 int extension_handle,
960 AutomationMsg_ExtensionProperty type,
961 bool* success,
962 std::string* value) {
963 *success = false;
964 const Extension* extension = GetExtension(extension_handle);
965 ExtensionService* service = profile_->GetExtensionService();
966 if (extension && service) {
967 ExtensionToolbarModel* toolbar = service->toolbar_model();
968 int found_index = -1;
969 int index = 0;
970 switch (type) {
971 case AUTOMATION_MSG_EXTENSION_ID:
972 *value = extension->id();
973 *success = true;
974 break;
975 case AUTOMATION_MSG_EXTENSION_NAME:
976 *value = extension->name();
977 *success = true;
978 break;
979 case AUTOMATION_MSG_EXTENSION_VERSION:
980 *value = extension->VersionString();
981 *success = true;
982 break;
983 case AUTOMATION_MSG_EXTENSION_BROWSER_ACTION_INDEX:
984 if (toolbar) {
985 for (ExtensionList::const_iterator iter = toolbar->begin();
986 iter != toolbar->end(); iter++) {
987 // Skip this extension if we are in incognito mode
988 // and it is not incognito-enabled.
989 if (profile_->IsOffTheRecord() &&
990 !service->IsIncognitoEnabled((*iter)->id()))
991 continue;
992 if (*iter == extension) {
993 found_index = index;
994 break;
995 }
996 index++;
997 }
998 *value = base::IntToString(found_index);
999 *success = true;
1000 }
1001 break;
1002 default:
1003 LOG(WARNING) << "Trying to get undefined extension property";
1004 break;
1005 }
1006 }
1007 }
1008
1009 void AutomationProvider::SaveAsAsync(int tab_handle) { 757 void AutomationProvider::SaveAsAsync(int tab_handle) {
1010 NavigationController* tab = NULL; 758 NavigationController* tab = NULL;
1011 WebContents* web_contents = GetWebContentsForHandle(tab_handle, &tab); 759 WebContents* web_contents = GetWebContentsForHandle(tab_handle, &tab);
1012 if (web_contents) 760 if (web_contents)
1013 web_contents->OnSavePage(); 761 web_contents->OnSavePage();
1014 } 762 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider.h ('k') | chrome/browser/automation/automation_provider_observers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698