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/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 2510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2521 &TestingAutomationProvider::EnableSyncForDatatypes; | 2521 &TestingAutomationProvider::EnableSyncForDatatypes; |
2522 browser_handler_map["DisableSyncForDatatypes"] = | 2522 browser_handler_map["DisableSyncForDatatypes"] = |
2523 &TestingAutomationProvider::DisableSyncForDatatypes; | 2523 &TestingAutomationProvider::DisableSyncForDatatypes; |
2524 | 2524 |
2525 browser_handler_map["GetNTPInfo"] = | 2525 browser_handler_map["GetNTPInfo"] = |
2526 &TestingAutomationProvider::GetNTPInfo; | 2526 &TestingAutomationProvider::GetNTPInfo; |
2527 browser_handler_map["MoveNTPMostVisitedThumbnail"] = | 2527 browser_handler_map["MoveNTPMostVisitedThumbnail"] = |
2528 &TestingAutomationProvider::MoveNTPMostVisitedThumbnail; | 2528 &TestingAutomationProvider::MoveNTPMostVisitedThumbnail; |
2529 browser_handler_map["RemoveNTPMostVisitedThumbnail"] = | 2529 browser_handler_map["RemoveNTPMostVisitedThumbnail"] = |
2530 &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail; | 2530 &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail; |
2531 browser_handler_map["UnpinNTPMostVisitedThumbnail"] = | |
2532 &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail; | |
2533 browser_handler_map["RestoreAllNTPMostVisitedThumbnails"] = | 2531 browser_handler_map["RestoreAllNTPMostVisitedThumbnails"] = |
2534 &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails; | 2532 &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails; |
2535 | 2533 |
2536 browser_handler_map["KillRendererProcess"] = | 2534 browser_handler_map["KillRendererProcess"] = |
2537 &TestingAutomationProvider::KillRendererProcess; | 2535 &TestingAutomationProvider::KillRendererProcess; |
2538 | 2536 |
2539 browser_handler_map["LaunchApp"] = &TestingAutomationProvider::LaunchApp; | 2537 browser_handler_map["LaunchApp"] = &TestingAutomationProvider::LaunchApp; |
2540 browser_handler_map["SetAppLaunchType"] = | 2538 browser_handler_map["SetAppLaunchType"] = |
2541 &TestingAutomationProvider::SetAppLaunchType; | 2539 &TestingAutomationProvider::SetAppLaunchType; |
2542 | 2540 |
(...skipping 3067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5610 } | 5608 } |
5611 if (!args->GetInteger("old_index", &old_index)) { | 5609 if (!args->GetInteger("old_index", &old_index)) { |
5612 reply.SendError("Missing or invalid 'old_index' key"); | 5610 reply.SendError("Missing or invalid 'old_index' key"); |
5613 return; | 5611 return; |
5614 } | 5612 } |
5615 history::TopSites* top_sites = browser->profile()->GetTopSites(); | 5613 history::TopSites* top_sites = browser->profile()->GetTopSites(); |
5616 if (!top_sites) { | 5614 if (!top_sites) { |
5617 reply.SendError("TopSites service is not initialized."); | 5615 reply.SendError("TopSites service is not initialized."); |
5618 return; | 5616 return; |
5619 } | 5617 } |
5620 GURL swapped; | |
5621 // If thumbnail A is switching positions with a pinned thumbnail B, B | |
5622 // should be pinned in the old index of A. | |
5623 if (top_sites->GetPinnedURLAtIndex(index, &swapped)) { | |
5624 top_sites->AddPinnedURL(swapped, old_index); | |
5625 } | |
5626 top_sites->AddPinnedURL(GURL(url), index); | |
5627 reply.SendSuccess(NULL); | 5618 reply.SendSuccess(NULL); |
5628 } | 5619 } |
5629 | 5620 |
5630 void TestingAutomationProvider::RemoveNTPMostVisitedThumbnail( | 5621 void TestingAutomationProvider::RemoveNTPMostVisitedThumbnail( |
5631 Browser* browser, | 5622 Browser* browser, |
5632 DictionaryValue* args, | 5623 DictionaryValue* args, |
5633 IPC::Message* reply_message) { | 5624 IPC::Message* reply_message) { |
5634 AutomationJSONReply reply(this, reply_message); | 5625 AutomationJSONReply reply(this, reply_message); |
5635 std::string url; | 5626 std::string url; |
5636 if (!args->GetString("url", &url)) { | 5627 if (!args->GetString("url", &url)) { |
5637 reply.SendError("Missing or invalid 'url' key."); | 5628 reply.SendError("Missing or invalid 'url' key."); |
5638 return; | 5629 return; |
5639 } | 5630 } |
5640 history::TopSites* top_sites = browser->profile()->GetTopSites(); | 5631 history::TopSites* top_sites = browser->profile()->GetTopSites(); |
5641 if (!top_sites) { | 5632 if (!top_sites) { |
5642 reply.SendError("TopSites service is not initialized."); | 5633 reply.SendError("TopSites service is not initialized."); |
5643 return; | 5634 return; |
5644 } | 5635 } |
5645 top_sites->AddBlacklistedURL(GURL(url)); | 5636 top_sites->AddBlacklistedURL(GURL(url)); |
5646 reply.SendSuccess(NULL); | 5637 reply.SendSuccess(NULL); |
5647 } | 5638 } |
5648 | 5639 |
5649 void TestingAutomationProvider::UnpinNTPMostVisitedThumbnail( | |
5650 Browser* browser, | |
5651 DictionaryValue* args, | |
5652 IPC::Message* reply_message) { | |
5653 AutomationJSONReply reply(this, reply_message); | |
5654 std::string url; | |
5655 if (!args->GetString("url", &url)) { | |
5656 reply.SendError("Missing or invalid 'url' key."); | |
5657 return; | |
5658 } | |
5659 history::TopSites* top_sites = browser->profile()->GetTopSites(); | |
5660 if (!top_sites) { | |
5661 reply.SendError("TopSites service is not initialized."); | |
5662 return; | |
5663 } | |
5664 top_sites->RemovePinnedURL(GURL(url)); | |
5665 reply.SendSuccess(NULL); | |
5666 } | |
5667 | |
5668 void TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails( | 5640 void TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails( |
5669 Browser* browser, | 5641 Browser* browser, |
5670 DictionaryValue* args, | 5642 DictionaryValue* args, |
5671 IPC::Message* reply_message) { | 5643 IPC::Message* reply_message) { |
5672 AutomationJSONReply reply(this, reply_message); | 5644 AutomationJSONReply reply(this, reply_message); |
5673 history::TopSites* top_sites = browser->profile()->GetTopSites(); | 5645 history::TopSites* top_sites = browser->profile()->GetTopSites(); |
5674 if (!top_sites) { | 5646 if (!top_sites) { |
5675 reply.SendError("TopSites service is not initialized."); | 5647 reply.SendError("TopSites service is not initialized."); |
5676 return; | 5648 return; |
5677 } | 5649 } |
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6985 *browser_handle = browser_tracker_->Add(browser); | 6957 *browser_handle = browser_tracker_->Add(browser); |
6986 *success = true; | 6958 *success = true; |
6987 } | 6959 } |
6988 } | 6960 } |
6989 } | 6961 } |
6990 | 6962 |
6991 void TestingAutomationProvider::OnRemoveProvider() { | 6963 void TestingAutomationProvider::OnRemoveProvider() { |
6992 if (g_browser_process) | 6964 if (g_browser_process) |
6993 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6965 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6994 } | 6966 } |
OLD | NEW |