OLD | NEW |
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/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" | 91 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" |
92 #include "chrome/browser/ui/browser_init.h" | 92 #include "chrome/browser/ui/browser_init.h" |
93 #include "chrome/browser/ui/browser_window.h" | 93 #include "chrome/browser/ui/browser_window.h" |
94 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 94 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
95 #include "chrome/browser/ui/find_bar/find_bar.h" | 95 #include "chrome/browser/ui/find_bar/find_bar.h" |
96 #include "chrome/browser/ui/login/login_prompt.h" | 96 #include "chrome/browser/ui/login/login_prompt.h" |
97 #include "chrome/browser/ui/omnibox/location_bar.h" | 97 #include "chrome/browser/ui/omnibox/location_bar.h" |
98 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 98 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
99 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" | 99 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" |
100 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 100 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
101 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" | |
102 #include "chrome/common/automation_messages.h" | 101 #include "chrome/common/automation_messages.h" |
103 #include "chrome/common/chrome_constants.h" | 102 #include "chrome/common/chrome_constants.h" |
104 #include "chrome/common/chrome_notification_types.h" | 103 #include "chrome/common/chrome_notification_types.h" |
105 #include "chrome/common/chrome_paths.h" | 104 #include "chrome/common/chrome_paths.h" |
106 #include "chrome/common/chrome_switches.h" | 105 #include "chrome/common/chrome_switches.h" |
107 #include "chrome/common/extensions/extension.h" | 106 #include "chrome/common/extensions/extension.h" |
108 #include "chrome/common/extensions/url_pattern.h" | 107 #include "chrome/common/extensions/url_pattern.h" |
109 #include "chrome/common/extensions/url_pattern_set.h" | 108 #include "chrome/common/extensions/url_pattern_set.h" |
110 #include "chrome/common/pref_names.h" | 109 #include "chrome/common/pref_names.h" |
111 #include "chrome/common/render_messages.h" | 110 #include "chrome/common/render_messages.h" |
(...skipping 2421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2533 browser_handler_map["RemoveNTPMostVisitedThumbnail"] = | 2532 browser_handler_map["RemoveNTPMostVisitedThumbnail"] = |
2534 &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail; | 2533 &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail; |
2535 browser_handler_map["UnpinNTPMostVisitedThumbnail"] = | 2534 browser_handler_map["UnpinNTPMostVisitedThumbnail"] = |
2536 &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail; | 2535 &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail; |
2537 browser_handler_map["RestoreAllNTPMostVisitedThumbnails"] = | 2536 browser_handler_map["RestoreAllNTPMostVisitedThumbnails"] = |
2538 &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails; | 2537 &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails; |
2539 | 2538 |
2540 browser_handler_map["KillRendererProcess"] = | 2539 browser_handler_map["KillRendererProcess"] = |
2541 &TestingAutomationProvider::KillRendererProcess; | 2540 &TestingAutomationProvider::KillRendererProcess; |
2542 | 2541 |
2543 browser_handler_map["GetNTPThumbnailMode"] = | |
2544 &TestingAutomationProvider::GetNTPThumbnailMode; | |
2545 browser_handler_map["SetNTPThumbnailMode"] = | |
2546 &TestingAutomationProvider::SetNTPThumbnailMode; | |
2547 browser_handler_map["GetNTPMenuMode"] = | |
2548 &TestingAutomationProvider::GetNTPMenuMode; | |
2549 browser_handler_map["SetNTPMenuMode"] = | |
2550 &TestingAutomationProvider::SetNTPMenuMode; | |
2551 | |
2552 browser_handler_map["LaunchApp"] = &TestingAutomationProvider::LaunchApp; | 2542 browser_handler_map["LaunchApp"] = &TestingAutomationProvider::LaunchApp; |
2553 browser_handler_map["SetAppLaunchType"] = | 2543 browser_handler_map["SetAppLaunchType"] = |
2554 &TestingAutomationProvider::SetAppLaunchType; | 2544 &TestingAutomationProvider::SetAppLaunchType; |
2555 #if defined(OS_CHROMEOS) | 2545 #if defined(OS_CHROMEOS) |
2556 browser_handler_map["CaptureProfilePhoto"] = | 2546 browser_handler_map["CaptureProfilePhoto"] = |
2557 &TestingAutomationProvider::CaptureProfilePhoto; | 2547 &TestingAutomationProvider::CaptureProfilePhoto; |
2558 browser_handler_map["GetTimeInfo"] = &TestingAutomationProvider::GetTimeInfo; | 2548 browser_handler_map["GetTimeInfo"] = &TestingAutomationProvider::GetTimeInfo; |
2559 #endif // defined(OS_CHROMEOS) | 2549 #endif // defined(OS_CHROMEOS) |
2560 | 2550 |
2561 // Look for command in handlers that take a Browser handle. | 2551 // Look for command in handlers that take a Browser handle. |
(...skipping 3035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5597 std::string prompt_text; | 5587 std::string prompt_text; |
5598 if (args->GetString("prompt_text", &prompt_text)) | 5588 if (args->GetString("prompt_text", &prompt_text)) |
5599 dialog->SetOverridePromptText(UTF8ToUTF16(prompt_text)); | 5589 dialog->SetOverridePromptText(UTF8ToUTF16(prompt_text)); |
5600 dialog->native_dialog()->AcceptAppModalDialog(); | 5590 dialog->native_dialog()->AcceptAppModalDialog(); |
5601 } else { | 5591 } else { |
5602 dialog->native_dialog()->CancelAppModalDialog(); | 5592 dialog->native_dialog()->CancelAppModalDialog(); |
5603 } | 5593 } |
5604 reply.SendSuccess(NULL); | 5594 reply.SendSuccess(NULL); |
5605 } | 5595 } |
5606 | 5596 |
5607 // Sample JSON input: { "command": "GetNTPThumbnailMode" } | |
5608 // For output, refer to GetNTPThumbnailMode() in | |
5609 // chrome/test/pyautolib/pyauto.py. | |
5610 void TestingAutomationProvider::GetNTPThumbnailMode( | |
5611 Browser* browser, | |
5612 DictionaryValue* args, | |
5613 IPC::Message* reply_message) { | |
5614 const int shown_sections = ShownSectionsHandler::GetShownSections( | |
5615 browser->profile()->GetPrefs()); | |
5616 | |
5617 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | |
5618 return_value->SetBoolean("apps", shown_sections & APPS ? true : false); | |
5619 return_value->SetBoolean("most_visited", | |
5620 shown_sections & THUMB ? true : false); | |
5621 | |
5622 AutomationJSONReply reply(this, reply_message); | |
5623 reply.SendSuccess(return_value.get()); | |
5624 } | |
5625 | |
5626 // Sample JSON input: { "command": "SetNTPThumbnailMode", "section": "apps", | |
5627 // "turn_on": true } | |
5628 // Refer to SetNTPThumbnailMode() in chrome/test/pyautolib/pyauto.py for | |
5629 // all possible input values. | |
5630 // Sample JSON output: {} | |
5631 void TestingAutomationProvider::SetNTPThumbnailMode( | |
5632 Browser* browser, | |
5633 DictionaryValue* args, | |
5634 IPC::Message* reply_message) { | |
5635 AutomationJSONReply reply(this, reply_message); | |
5636 std::string section_name; | |
5637 bool turn_on; | |
5638 if (!args->GetString("section", §ion_name) || | |
5639 !args->GetBoolean("turn_on", &turn_on)) { | |
5640 reply.SendError("Invalid or missing args"); | |
5641 return; | |
5642 } | |
5643 | |
5644 PrefService* prefs = browser->profile()->GetPrefs(); | |
5645 Section section; | |
5646 if (section_name.compare("apps") == 0) { | |
5647 section = APPS; | |
5648 } else if (section_name.compare("most_visited") == 0) { | |
5649 section = THUMB; | |
5650 } else if (section_name.compare("recently_closed") == 0) { | |
5651 reply.SendError("Thumbnail mode does not apply to the recently closed " | |
5652 "section."); | |
5653 return; | |
5654 } else { | |
5655 reply.SendError(StringPrintf("Unexpected section name: '%s'", | |
5656 section_name.c_str())); | |
5657 return; | |
5658 } | |
5659 | |
5660 if (turn_on) { | |
5661 ShownSectionsHandler::SetShownSection(prefs, section); | |
5662 } else { | |
5663 int shown_sections = ShownSectionsHandler::GetShownSections(prefs); | |
5664 // Change the bit for the relevant section in the bitmask to 0. | |
5665 shown_sections &= ~(0xFFFFFFFF & section); | |
5666 prefs->SetInteger(prefs::kNTPShownSections, shown_sections); | |
5667 } | |
5668 | |
5669 reply.SendSuccess(NULL); | |
5670 } | |
5671 | |
5672 // Sample JSON input: { "command": "GetNTPMenuMode" } | |
5673 // For output, refer to GetNTPMenuMode() in | |
5674 // chrome/test/pyautolib/pyauto.py. | |
5675 void TestingAutomationProvider::GetNTPMenuMode( | |
5676 Browser* browser, | |
5677 DictionaryValue* args, | |
5678 IPC::Message* reply_message) { | |
5679 const int shown_sections = ShownSectionsHandler::GetShownSections( | |
5680 browser->profile()->GetPrefs()); | |
5681 | |
5682 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | |
5683 return_value->SetBoolean("apps", shown_sections & MENU_APPS ? true : false); | |
5684 return_value->SetBoolean("most_visited", | |
5685 shown_sections & MENU_THUMB ? true : false); | |
5686 return_value->SetBoolean("recently_closed", | |
5687 shown_sections & MENU_RECENT ? true : false); | |
5688 | |
5689 AutomationJSONReply reply(this, reply_message); | |
5690 reply.SendSuccess(return_value.get()); | |
5691 } | |
5692 | |
5693 // Sample JSON input: { "command": "SetNTPMenuMode", "section": "apps", | |
5694 // "turn_on": false } | |
5695 // Refer to SetNTPMenuMode() in chrome/test/pyautolib/pyauto.py for all possible | |
5696 // input values. | |
5697 // Sample JSON output: {} | |
5698 void TestingAutomationProvider::SetNTPMenuMode( | |
5699 Browser* browser, | |
5700 DictionaryValue* args, | |
5701 IPC::Message* reply_message) { | |
5702 AutomationJSONReply reply(this, reply_message); | |
5703 std::string section_name; | |
5704 bool turn_on; | |
5705 if (!args->GetString("section", §ion_name) || | |
5706 !args->GetBoolean("turn_on", &turn_on)) { | |
5707 reply.SendError("Invalid or missing args"); | |
5708 return; | |
5709 } | |
5710 | |
5711 PrefService* prefs = browser->profile()->GetPrefs(); | |
5712 Section section; | |
5713 if (section_name.compare("apps") == 0) { | |
5714 section = MENU_APPS; | |
5715 } else if (section_name.compare("most_visited") == 0) { | |
5716 section = MENU_THUMB; | |
5717 } else if (section_name.compare("recently_closed") == 0) { | |
5718 section = MENU_RECENT; | |
5719 } else { | |
5720 reply.SendError(StringPrintf("Unexpected section name: '%s'", | |
5721 section_name.c_str())); | |
5722 return; | |
5723 } | |
5724 | |
5725 int shown_sections = ShownSectionsHandler::GetShownSections(prefs); | |
5726 if (turn_on) { | |
5727 // Change the bit for the relevant section in the bitmask to 1. | |
5728 shown_sections |= section; | |
5729 } else { | |
5730 // Change the bit for the relevant section in the bitmask to 0. | |
5731 shown_sections &= ~(0xFFFFFFFF & section); | |
5732 } | |
5733 prefs->SetInteger(prefs::kNTPShownSections, shown_sections); | |
5734 | |
5735 reply.SendSuccess(NULL); | |
5736 } | |
5737 | |
5738 // Sample JSON input: { "command": "LaunchApp", | 5597 // Sample JSON input: { "command": "LaunchApp", |
5739 // "id": "ahfgeienlihckogmohjhadlkjgocpleb" } | 5598 // "id": "ahfgeienlihckogmohjhadlkjgocpleb" } |
5740 // Sample JSON output: {} | 5599 // Sample JSON output: {} |
5741 void TestingAutomationProvider::LaunchApp( | 5600 void TestingAutomationProvider::LaunchApp( |
5742 Browser* browser, | 5601 Browser* browser, |
5743 DictionaryValue* args, | 5602 DictionaryValue* args, |
5744 IPC::Message* reply_message) { | 5603 IPC::Message* reply_message) { |
5745 std::string id; | 5604 std::string id; |
5746 if (!args->GetString("id", &id)) { | 5605 if (!args->GetString("id", &id)) { |
5747 AutomationJSONReply(this, reply_message).SendError( | 5606 AutomationJSONReply(this, reply_message).SendError( |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6527 | 6386 |
6528 Send(reply_message_); | 6387 Send(reply_message_); |
6529 redirect_query_ = 0; | 6388 redirect_query_ = 0; |
6530 reply_message_ = NULL; | 6389 reply_message_ = NULL; |
6531 } | 6390 } |
6532 | 6391 |
6533 void TestingAutomationProvider::OnRemoveProvider() { | 6392 void TestingAutomationProvider::OnRemoveProvider() { |
6534 if (g_browser_process) | 6393 if (g_browser_process) |
6535 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6394 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6536 } | 6395 } |
OLD | NEW |