diff options
author | thestig <thestig@chromium.org> | 2015-09-29 16:12:08 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-29 23:12:57 +0000 |
commit | f805644696b5e1ad2522aa843dbdba38d5a0dae8 (patch) | |
tree | 37cbf9badb2e4846459e61bcd8db159bd14e55cb | |
parent | fd51070d151eff452ecca7c57a38f733ac100342 (diff) | |
download | chromium_src-f805644696b5e1ad2522aa843dbdba38d5a0dae8.zip chromium_src-f805644696b5e1ad2522aa843dbdba38d5a0dae8.tar.gz chromium_src-f805644696b5e1ad2522aa843dbdba38d5a0dae8.tar.bz2 |
Mark more files/functions as non-mobile.
- Split desktop only code into their own files.
- Split NavigateParams into its own file.
- Stop build ui_tests_utils.h on mobile.
BUG=159847
Review URL: https://codereview.chromium.org/1377653002
Cr-Commit-Position: refs/heads/master@{#351430}
46 files changed, 892 insertions, 665 deletions
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn index 1219a47..8e06e93 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -1106,6 +1106,8 @@ source_set("test_support") { if (is_android) { sources -= [ + "password_manager/password_manager_test_base.cc", + "password_manager/password_manager_test_base.h", "sessions/session_service_test_helper.cc", "sessions/session_service_test_helper.h", "ui/webui/signin/login_ui_test_utils.cc", diff --git a/chrome/browser/android/tab_android.cc b/chrome/browser/android/tab_android.cc index 7c5b0b7..ed7721b 100644 --- a/chrome/browser/android/tab_android.cc +++ b/chrome/browser/android/tab_android.cc @@ -400,7 +400,7 @@ void TabAndroid::OnFaviconAvailable(const gfx::Image& image) { if (favicon.empty()) return; - JNIEnv *env = base::android::AttachCurrentThread(); + JNIEnv* env = base::android::AttachCurrentThread(); Java_Tab_onFaviconAvailable(env, weak_java_tab_.get(env).obj(), gfx::ConvertToJavaBitmap(&favicon).obj()); } @@ -568,7 +568,7 @@ TabAndroid::TabLoadStatus TabAndroid::LoadUrl( if (prerender_manager) { bool prefetched_page_loaded = HasPrerenderedUrl(gurl); // Getting the load status before MaybeUsePrerenderedPage() b/c it resets. - chrome::NavigateParams params(NULL, web_contents()); + chrome::NavigateParams params(web_contents()); InstantSearchPrerenderer* prerenderer = InstantSearchPrerenderer::GetForProfile(GetProfile()); if (prerenderer) { @@ -683,7 +683,6 @@ void TabAndroid::SetPendingPrint() { ScopedJavaLocalRef<jobject> TabAndroid::GetFavicon(JNIEnv* env, jobject obj) { - ScopedJavaLocalRef<jobject> bitmap; favicon::FaviconDriver* favicon_driver = favicon::ContentFaviconDriver::FromWebContents(web_contents_.get()); diff --git a/chrome/browser/autocomplete/autocomplete_browsertest.cc b/chrome/browser/autocomplete/autocomplete_browsertest.cc index 3063925..5046dff 100644 --- a/chrome/browser/autocomplete/autocomplete_browsertest.cc +++ b/chrome/browser/autocomplete/autocomplete_browsertest.cc @@ -22,6 +22,7 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/search_test_utils.h" #include "chrome/test/base/test_switches.h" #include "chrome/test/base/ui_test_utils.h" #include "components/history/core/browser/history_service.h" @@ -53,7 +54,7 @@ base::string16 AutocompleteResultAsString(const AutocompleteResult& result) { class AutocompleteBrowserTest : public ExtensionBrowserTest { protected: void WaitForTemplateURLServiceToLoad() { - ui_test_utils::WaitForTemplateURLServiceToLoad( + search_test_utils::WaitForTemplateURLServiceToLoad( TemplateURLServiceFactory::GetForProfile(browser()->profile())); } diff --git a/chrome/browser/autocomplete/shortcuts_backend_unittest.cc b/chrome/browser/autocomplete/shortcuts_backend_unittest.cc index d01df8f..4ac93bc 100644 --- a/chrome/browser/autocomplete/shortcuts_backend_unittest.cc +++ b/chrome/browser/autocomplete/shortcuts_backend_unittest.cc @@ -11,8 +11,8 @@ #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" +#include "chrome/test/base/search_test_utils.h" #include "chrome/test/base/testing_profile.h" -#include "chrome/test/base/ui_test_utils.h" #include "components/omnibox/browser/shortcuts_database.h" #include "components/search_engines/template_url_service.h" #include "content/public/test/test_browser_thread.h" @@ -126,7 +126,7 @@ void ShortcutsBackendTest::SetUp() { &profile_, &TemplateURLServiceFactory::BuildInstanceFor); TemplateURLService* template_url_service = TemplateURLServiceFactory::GetForProfile(&profile_); - ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); + search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); } void ShortcutsBackendTest::TearDown() { diff --git a/chrome/browser/chrome_content_browser_client_unittest.cc b/chrome/browser/chrome_content_browser_client_unittest.cc index 7cd0ed6..1d5455d 100644 --- a/chrome/browser/chrome_content_browser_client_unittest.cc +++ b/chrome/browser/chrome_content_browser_client_unittest.cc @@ -10,10 +10,6 @@ #include "base/metrics/field_trial.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/search_engines/template_url_service_factory.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/test/base/browser_with_test_window_test.h" -#include "chrome/test/base/ui_test_utils.h" #include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/search_engines/template_url_service.h" #include "components/variations/entropy_provider.h" @@ -27,6 +23,13 @@ #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" +#if !defined(OS_ANDROID) && !defined(OS_IOS) +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/test/base/browser_with_test_window_test.h" +#include "chrome/test/base/search_test_utils.h" +#endif + using ChromeContentBrowserClientTest = testing::Test; TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) { @@ -85,7 +88,7 @@ TEST_F(ChromeContentBrowserClientWindowTest, OpenURL) { EXPECT_EQ(previous_count + 2, browser()->tab_strip_model()->count()); } -#endif // !defined(OS_ANDROID) && !defined(OS_IOS) +#endif // !defined(OS_ANDROID) && !defined(OS_IOS) #if defined(ENABLE_WEBRTC) @@ -112,6 +115,7 @@ class DisableWebRtcEncryptionFlagTest : public testing::Test { base::CommandLine from_command_line_; base::CommandLine to_command_line_; + private: DISALLOW_COPY_AND_ASSIGN(DisableWebRtcEncryptionFlagTest); }; @@ -335,7 +339,7 @@ class InstantNTPURLRewriteTest : public BrowserWithTestWindowTest { profile(), &TemplateURLServiceFactory::BuildInstanceFor); TemplateURLService* template_url_service = TemplateURLServiceFactory::GetForProfile(browser()->profile()); - ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); + search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); TemplateURLData data; data.SetShortName(base::ASCIIToUTF16("foo.com")); diff --git a/chrome/browser/extensions/api/omnibox/omnibox_api_browsertest.cc b/chrome/browser/extensions/api/omnibox/omnibox_api_browsertest.cc index e646b7e..ae9e76f 100644 --- a/chrome/browser/extensions/api/omnibox/omnibox_api_browsertest.cc +++ b/chrome/browser/extensions/api/omnibox/omnibox_api_browsertest.cc @@ -10,7 +10,7 @@ #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/location_bar/location_bar.h" -#include "chrome/test/base/ui_test_utils.h" +#include "chrome/test/base/search_test_utils.h" #include "components/metrics/proto/omnibox_event.pb.h" #include "components/omnibox/browser/autocomplete_controller.h" #include "components/omnibox/browser/autocomplete_input.h" @@ -31,7 +31,7 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, DISABLED_Basic) { // The results depend on the TemplateURLService being loaded. Make sure it is // loaded so that the autocomplete results are consistent. Profile* profile = browser()->profile(); - ui_test_utils::WaitForTemplateURLServiceToLoad( + search_test_utils::WaitForTemplateURLServiceToLoad( TemplateURLServiceFactory::GetForProfile(profile)); AutocompleteController* autocomplete_controller = @@ -161,7 +161,7 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, DISABLED_Basic) { IN_PROC_BROWSER_TEST_F(OmniboxApiTest, OnInputEntered) { ASSERT_TRUE(RunExtensionTest("omnibox")) << message_; Profile* profile = browser()->profile(); - ui_test_utils::WaitForTemplateURLServiceToLoad( + search_test_utils::WaitForTemplateURLServiceToLoad( TemplateURLServiceFactory::GetForProfile(profile)); LocationBar* location_bar = GetLocationBar(browser()); @@ -216,7 +216,7 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, DISABLED_IncognitoSplitMode) { // The results depend on the TemplateURLService being loaded. Make sure it is // loaded so that the autocomplete results are consistent. - ui_test_utils::WaitForTemplateURLServiceToLoad( + search_test_utils::WaitForTemplateURLServiceToLoad( TemplateURLServiceFactory::GetForProfile(browser()->profile())); LocationBar* location_bar = GetLocationBar(incognito_browser); diff --git a/chrome/browser/extensions/api/omnibox/omnibox_api_interactive_test.cc b/chrome/browser/extensions/api/omnibox/omnibox_api_interactive_test.cc index 79c4ad8..1d1f00b 100644 --- a/chrome/browser/extensions/api/omnibox/omnibox_api_interactive_test.cc +++ b/chrome/browser/extensions/api/omnibox/omnibox_api_interactive_test.cc @@ -5,7 +5,7 @@ #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" #include "chrome/browser/extensions/api/omnibox/omnibox_api_testbase.h" #include "chrome/browser/search_engines/template_url_service_factory.h" -#include "chrome/test/base/ui_test_utils.h" +#include "chrome/test/base/search_test_utils.h" #include "components/metrics/proto/omnibox_event.pb.h" #include "extensions/test/result_catcher.h" @@ -18,7 +18,7 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, PopupStaysClosed) { // The results depend on the TemplateURLService being loaded. Make sure it is // loaded so that the autocomplete results are consistent. Profile* profile = browser()->profile(); - ui_test_utils::WaitForTemplateURLServiceToLoad( + search_test_utils::WaitForTemplateURLServiceToLoad( TemplateURLServiceFactory::GetForProfile(profile)); LocationBar* location_bar = GetLocationBar(browser()); diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc index 80f6129..d965602 100644 --- a/chrome/browser/policy/policy_browsertest.cc +++ b/chrome/browser/policy/policy_browsertest.cc @@ -85,6 +85,7 @@ #include "chrome/common/url_constants.h" #include "chrome/grit/generated_resources.h" #include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/search_test_utils.h" #include "chrome/test/base/test_switches.h" #include "chrome/test/base/ui_test_utils.h" #include "components/content_settings/core/common/content_settings.h" @@ -1016,7 +1017,7 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) { TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( browser()->profile()); - ui_test_utils::WaitForTemplateURLServiceToLoad(service); + search_test_utils::WaitForTemplateURLServiceToLoad(service); TemplateURL* default_search = service->GetDefaultSearchProvider(); ASSERT_TRUE(default_search); EXPECT_NE(kKeyword, default_search->keyword()); @@ -1217,7 +1218,7 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, ReplaceSearchTerms) { TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( browser()->profile()); - ui_test_utils::WaitForTemplateURLServiceToLoad(service); + search_test_utils::WaitForTemplateURLServiceToLoad(service); TemplateURL* default_search = service->GetDefaultSearchProvider(); ASSERT_TRUE(default_search); EXPECT_NE(kKeyword, default_search->keyword()); @@ -4004,6 +4005,6 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, UnifiedDesktopEnabledByDefault) { UpdateProviderPolicy(policies); EXPECT_FALSE(display_manager->unified_desktop_enabled()); } -#endif // defined(OS_CHROMEOS) +#endif // defined(OS_CHROMEOS) } // namespace policy diff --git a/chrome/browser/policy/policy_prefs_browsertest.cc b/chrome/browser/policy/policy_prefs_browsertest.cc index cfbd3c8..2a0cc03 100644 --- a/chrome/browser/policy/policy_prefs_browsertest.cc +++ b/chrome/browser/policy/policy_prefs_browsertest.cc @@ -29,6 +29,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/search_test_utils.h" #include "chrome/test/base/ui_test_utils.h" #include "components/policy/core/browser/browser_policy_connector.h" #include "components/policy/core/common/external_data_fetcher.h" @@ -498,7 +499,7 @@ class PolicyPrefsTest : public InProcessBrowserTest { } void SetUpOnMainThread() override { - ui_test_utils::WaitForTemplateURLServiceToLoad( + search_test_utils::WaitForTemplateURLServiceToLoad( TemplateURLServiceFactory::GetForProfile(browser()->profile())); } diff --git a/chrome/browser/profiles/profile_window_browsertest.cc b/chrome/browser/profiles/profile_window_browsertest.cc index eb83cf1..1868752 100644 --- a/chrome/browser/profiles/profile_window_browsertest.cc +++ b/chrome/browser/profiles/profile_window_browsertest.cc @@ -18,6 +18,7 @@ #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/toolbar/wrench_menu_model.h" #include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/search_test_utils.h" #include "chrome/test/base/ui_test_utils.h" #include "components/history/core/browser/history_db_task.h" #include "components/history/core/browser/history_service.h" @@ -128,7 +129,7 @@ Browser* ProfileWindowBrowserTest::OpenGuestBrowser() { // When |browser| closes a BrowsingDataRemover will be created and executed. // It needs a loaded TemplateUrlService or else it hangs on to a // CallbackList::Subscription forever. - ui_test_utils::WaitForTemplateURLServiceToLoad( + search_test_utils::WaitForTemplateURLServiceToLoad( TemplateURLServiceFactory::GetForProfile(guest)); return browser; diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc b/chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc index ee2f6f7..ee0d4e5 100644 --- a/chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc +++ b/chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc @@ -21,6 +21,7 @@ #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/render_messages.h" #include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/search_test_utils.h" #include "chrome/test/base/ui_test_utils.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h" #include "components/search_engines/template_url_data.h" @@ -478,7 +479,7 @@ class SearchByImageBrowserTest : public InProcessBrowserTest { TemplateURLService* model = TemplateURLServiceFactory::GetForProfile(browser()->profile()); ASSERT_TRUE(model); - ui_test_utils::WaitForTemplateURLServiceToLoad(model); + search_test_utils::WaitForTemplateURLServiceToLoad(model); ASSERT_TRUE(model->loaded()); TemplateURLData data; diff --git a/chrome/browser/search/instant_unittest_base.cc b/chrome/browser/search/instant_unittest_base.cc index 93a8b24..3ba7101 100644 --- a/chrome/browser/search/instant_unittest_base.cc +++ b/chrome/browser/search/instant_unittest_base.cc @@ -15,7 +15,7 @@ #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" #include "chrome/test/base/browser_with_test_window_test.h" -#include "chrome/test/base/ui_test_utils.h" +#include "chrome/test/base/search_test_utils.h" #include "components/google/core/browser/google_pref_names.h" #include "components/google/core/browser/google_url_tracker.h" #include "components/search/search.h" @@ -93,7 +93,7 @@ void InstantUnitTestBase::SetUpHelper() { BrowserWithTestWindowTest::SetUp(); template_url_service_ = TemplateURLServiceFactory::GetForProfile(profile()); - ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service_); + search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service_); UIThreadSearchTermsData::SetGoogleBaseURL("https://www.google.com/"); SetUserSelectedDefaultSearchProvider("{google:baseURL}"); diff --git a/chrome/browser/search/search_unittest.cc b/chrome/browser/search/search_unittest.cc index c7ed494..8807c05 100644 --- a/chrome/browser/search/search_unittest.cc +++ b/chrome/browser/search/search_unittest.cc @@ -18,7 +18,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/browser_with_test_window_test.h" -#include "chrome/test/base/ui_test_utils.h" +#include "chrome/test/base/search_test_utils.h" #include "components/google/core/browser/google_switches.h" #include "components/search/search.h" #include "components/search_engines/search_engines_switches.h" @@ -50,7 +50,7 @@ class SearchTest : public BrowserWithTestWindowTest { profile(), &TemplateURLServiceFactory::BuildInstanceFor); TemplateURLService* template_url_service = TemplateURLServiceFactory::GetForProfile(profile()); - ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); + search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); SetSearchProvider(true, false); } diff --git a/chrome/browser/sync/test/integration/sync_test.cc b/chrome/browser/sync/test/integration/sync_test.cc index 9522fd1..aed9291 100644 --- a/chrome/browser/sync/test/integration/sync_test.cc +++ b/chrome/browser/sync/test/integration/sync_test.cc @@ -51,6 +51,7 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/test/base/search_test_utils.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/ui_test_utils.h" #include "components/bookmarks/test/bookmark_test_helpers.h" @@ -455,7 +456,7 @@ bool SyncTest::SetupClients() { BookmarkModelFactory::GetForProfile(verifier())); ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile( verifier(), ServiceAccessType::EXPLICIT_ACCESS)); - ui_test_utils::WaitForTemplateURLServiceToLoad( + search_test_utils::WaitForTemplateURLServiceToLoad( TemplateURLServiceFactory::GetForProfile(verifier())); } // Error cases are all handled by LOG(FATAL) messages. So there is not really @@ -519,7 +520,7 @@ void SyncTest::InitializeInstance(int index) { BookmarkModelFactory::GetForProfile(GetProfile(index))); ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile( GetProfile(index), ServiceAccessType::EXPLICIT_ACCESS)); - ui_test_utils::WaitForTemplateURLServiceToLoad( + search_test_utils::WaitForTemplateURLServiceToLoad( TemplateURLServiceFactory::GetForProfile(GetProfile(index))); } diff --git a/chrome/browser/ui/autofill/card_unmask_prompt_view_browsertest.cc b/chrome/browser/ui/autofill/card_unmask_prompt_view_browsertest.cc index 0492435..e9e4ce2 100644 --- a/chrome/browser/ui/autofill/card_unmask_prompt_view_browsertest.cc +++ b/chrome/browser/ui/autofill/card_unmask_prompt_view_browsertest.cc @@ -16,6 +16,7 @@ #include "components/autofill/core/browser/card_unmask_delegate.h" #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl.h" #include "components/user_prefs/user_prefs.h" +#include "content/public/browser/browser_context.h" #include "content/public/browser/web_contents.h" #include "content/public/test/test_utils.h" diff --git a/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc b/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc index 0aa4a74..ced26fc 100644 --- a/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc +++ b/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc @@ -24,6 +24,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/search_test_utils.h" #include "chrome/test/base/test_switches.h" #include "chrome/test/base/ui_test_utils.h" #include "components/app_modal/javascript_app_modal_dialog.h" @@ -422,7 +423,7 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( browser()->profile()); - ui_test_utils::WaitForTemplateURLServiceToLoad(service); + search_test_utils::WaitForTemplateURLServiceToLoad(service); LocationBar* location_bar = browser()->window()->GetLocationBar(); ui_test_utils::SendToOmniboxAndSubmit(location_bar, search_string); OmniboxEditModel* model = location_bar->GetOmniboxView()->model(); diff --git a/chrome/browser/ui/bookmarks/bookmark_context_menu_controller.cc b/chrome/browser/ui/bookmarks/bookmark_context_menu_controller.cc index cd4afd2..9ca97a5 100644 --- a/chrome/browser/ui/bookmarks/bookmark_context_menu_controller.cc +++ b/chrome/browser/ui/bookmarks/bookmark_context_menu_controller.cc @@ -14,6 +14,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/bookmarks/bookmark_editor.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h" +#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" diff --git a/chrome/browser/ui/bookmarks/bookmark_context_menu_controller_unittest.cc b/chrome/browser/ui/bookmarks/bookmark_context_menu_controller_unittest.cc index ddc4dbb..a1d7a17 100644 --- a/chrome/browser/ui/bookmarks/bookmark_context_menu_controller_unittest.cc +++ b/chrome/browser/ui/bookmarks/bookmark_context_menu_controller_unittest.cc @@ -13,6 +13,7 @@ #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h" +#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_profile.h" #include "components/bookmarks/browser/bookmark_model.h" diff --git a/chrome/browser/ui/bookmarks/bookmark_ui_utils_unittest.cc b/chrome/browser/ui/bookmarks/bookmark_ui_utils_desktop_unittest.cc index b0a51f9..e297064 100644 --- a/chrome/browser/ui/bookmarks/bookmark_ui_utils_unittest.cc +++ b/chrome/browser/ui/bookmarks/bookmark_ui_utils_desktop_unittest.cc @@ -2,17 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/bookmarks/bookmark_utils.h" - #include "base/strings/utf_string_conversions.h" +#include "chrome/browser/ui/bookmarks/bookmark_utils.h" +#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" #include "chrome/test/base/testing_profile.h" #include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/test/test_bookmark_client.h" #include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" -#if !defined(OS_ANDROID) && !defined(OS_IOS) - using base::ASCIIToUTF16; using bookmarks::BookmarkModel; using bookmarks::BookmarkNode; @@ -125,4 +123,3 @@ TEST_F(BookmarkUIUtilsTest, HasBookmarkURLsAllowedInIncognitoMode) { } } // namespace -#endif diff --git a/chrome/browser/ui/bookmarks/bookmark_utils.cc b/chrome/browser/ui/bookmarks/bookmark_utils.cc index 2c5fbc1..dde64ac 100644 --- a/chrome/browser/ui/bookmarks/bookmark_utils.cc +++ b/chrome/browser/ui/bookmarks/bookmark_utils.cc @@ -7,21 +7,11 @@ #include "base/basictypes.h" #include "base/logging.h" #include "base/prefs/pref_service.h" -#include "base/strings/string_number_conversions.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search/search.h" -#include "chrome/browser/ui/app_list/app_list_util.h" -#include "chrome/browser/ui/bookmarks/bookmark_editor.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_navigator.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/simple_message_box.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" -#include "chrome/grit/chromium_strings.h" -#include "chrome/grit/generated_resources.h" #include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_node_data.h" #include "components/search/search.h" @@ -30,7 +20,6 @@ #include "content/public/browser/web_contents.h" #include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/dragdrop/drop_target_event.h" -#include "ui/base/l10n/l10n_util.h" #if defined(ENABLE_EXTENSIONS) #include "chrome/browser/extensions/api/commands/command_service.h" @@ -55,8 +44,6 @@ using bookmarks::BookmarkNode; namespace chrome { -int num_bookmark_urls_before_prompting = 15; - namespace { // The ways in which extensions may customize the bookmark shortcut. @@ -66,112 +53,6 @@ enum BookmarkShortcutDisposition { BOOKMARK_SHORTCUT_DISPOSITION_OVERRIDE_REQUESTED }; -// Iterator that iterates through a set of BookmarkNodes returning the URLs -// for nodes that are urls, or the URLs for the children of non-url urls. -// This does not recurse through all descendants, only immediate children. -// The following illustrates -// typical usage: -// OpenURLIterator iterator(nodes); -// while (iterator.has_next()) { -// const GURL* url = iterator.NextURL(); -// // do something with |urll|. -// } -class OpenURLIterator { - public: - explicit OpenURLIterator(const std::vector<const BookmarkNode*>& nodes) - : child_index_(0), - next_(NULL), - parent_(nodes.begin()), - end_(nodes.end()) { - FindNext(); - } - - bool has_next() { return next_ != NULL;} - - const GURL* NextURL() { - if (!has_next()) { - NOTREACHED(); - return NULL; - } - - const GURL* next = next_; - FindNext(); - return next; - } - - private: - // Seach next node which has URL. - void FindNext() { - for (; parent_ < end_; ++parent_, child_index_ = 0) { - if ((*parent_)->is_url()) { - next_ = &(*parent_)->url(); - ++parent_; - child_index_ = 0; - return; - } else { - for (; child_index_ < (*parent_)->child_count(); ++child_index_) { - const BookmarkNode* child = (*parent_)->GetChild(child_index_); - if (child->is_url()) { - next_ = &child->url(); - ++child_index_; - return; - } - } - } - } - next_ = NULL; - } - - int child_index_; - const GURL* next_; - std::vector<const BookmarkNode*>::const_iterator parent_; - const std::vector<const BookmarkNode*>::const_iterator end_; - - DISALLOW_COPY_AND_ASSIGN(OpenURLIterator); -}; - -bool ShouldOpenAll(gfx::NativeWindow parent, - const std::vector<const BookmarkNode*>& nodes) { - int child_count = 0; - OpenURLIterator iterator(nodes); - while (iterator.has_next()) { - iterator.NextURL(); - child_count++; - } - - if (child_count < num_bookmark_urls_before_prompting) - return true; - - return ShowMessageBox(parent, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), - l10n_util::GetStringFUTF16(IDS_BOOKMARK_BAR_SHOULD_OPEN_ALL, - base::IntToString16(child_count)), - MESSAGE_BOX_TYPE_QUESTION) == MESSAGE_BOX_RESULT_YES; -} - -// Returns the total number of descendants nodes. -int ChildURLCountTotal(const BookmarkNode* node) { - int result = 0; - for (int i = 0; i < node->child_count(); ++i) { - const BookmarkNode* child = node->GetChild(i); - result++; - if (child->is_folder()) - result += ChildURLCountTotal(child); - } - return result; -} - -// Returns in |urls|, the url and title pairs for each open tab in browser. -void GetURLsForOpenTabs(Browser* browser, - std::vector<std::pair<GURL, base::string16> >* urls) { - for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { - std::pair<GURL, base::string16> entry; - GetURLAndTitleToBookmark(browser->tab_strip_model()->GetWebContentsAt(i), - &(entry.first), &(entry.second)); - urls->push_back(entry); - } -} - // Indicates how the bookmark shortcut has been changed by extensions associated // with |profile|, if at all. BookmarkShortcutDisposition GetBookmarkShortcutDisposition(Profile* profile) { @@ -217,100 +98,6 @@ gfx::ImageSkia GetFolderIcon(gfx::VectorIconId id) { } // namespace -void OpenAll(gfx::NativeWindow parent, - content::PageNavigator* navigator, - const std::vector<const BookmarkNode*>& nodes, - WindowOpenDisposition initial_disposition, - content::BrowserContext* browser_context) { - if (!ShouldOpenAll(parent, nodes)) - return; - - // Opens all |nodes| of type URL and any children of |nodes| that are of type - // URL. |navigator| is the PageNavigator used to open URLs. After the first - // url is opened |opened_first_url| is set to true and |navigator| is set to - // the PageNavigator of the last active tab. This is done to handle a window - // disposition of new window, in which case we want subsequent tabs to open in - // that window. - bool opened_first_url = false; - WindowOpenDisposition disposition = initial_disposition; - OpenURLIterator iterator(nodes); - while (iterator.has_next()) { - const GURL* url = iterator.NextURL(); - // When |initial_disposition| is OFF_THE_RECORD, a node which can't be - // opened in incognito window, it is detected using |browser_context|, is - // not opened. - if (initial_disposition == OFF_THE_RECORD && - !IsURLAllowedInIncognito(*url, browser_context)) - continue; - - content::WebContents* opened_tab = navigator->OpenURL( - content::OpenURLParams(*url, content::Referrer(), disposition, - ui::PAGE_TRANSITION_AUTO_BOOKMARK, false)); - - if (!opened_first_url) { - opened_first_url = true; - disposition = NEW_BACKGROUND_TAB; - // We opened the first URL which may have opened a new window or clobbered - // the current page, reset the navigator just to be sure. |opened_tab| may - // be NULL in tests. - if (opened_tab) - navigator = opened_tab; - } - } -} - -void OpenAll(gfx::NativeWindow parent, - content::PageNavigator* navigator, - const BookmarkNode* node, - WindowOpenDisposition initial_disposition, - content::BrowserContext* browser_context) { - std::vector<const BookmarkNode*> nodes; - nodes.push_back(node); - OpenAll(parent, navigator, nodes, initial_disposition, browser_context); -} - -bool ConfirmDeleteBookmarkNode(const BookmarkNode* node, - gfx::NativeWindow window) { - DCHECK(node && node->is_folder() && !node->empty()); - return ShowMessageBox(window, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), - l10n_util::GetStringFUTF16Int(IDS_BOOKMARK_EDITOR_CONFIRM_DELETE, - ChildURLCountTotal(node)), - MESSAGE_BOX_TYPE_QUESTION) == MESSAGE_BOX_RESULT_YES; -} - -void ShowBookmarkAllTabsDialog(Browser* browser) { - Profile* profile = browser->profile(); - BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); - DCHECK(model && model->loaded()); - - const BookmarkNode* parent = model->GetParentForNewNodes(); - BookmarkEditor::EditDetails details = - BookmarkEditor::EditDetails::AddFolder(parent, parent->child_count()); - GetURLsForOpenTabs(browser, &(details.urls)); - DCHECK(!details.urls.empty()); - - BookmarkEditor::Show(browser->window()->GetNativeWindow(), profile, details, - BookmarkEditor::SHOW_TREE); -} - -bool HasBookmarkURLs(const std::vector<const BookmarkNode*>& selection) { - OpenURLIterator iterator(selection); - return iterator.has_next(); -} - -bool HasBookmarkURLsAllowedInIncognitoMode( - const std::vector<const BookmarkNode*>& selection, - content::BrowserContext* browser_context) { - OpenURLIterator iterator(selection); - while (iterator.has_next()) { - const GURL* url = iterator.NextURL(); - if (IsURLAllowedInIncognito(*url, browser_context)) - return true; - } - return false; -} - GURL GetURLToBookmark(content::WebContents* web_contents) { DCHECK(web_contents); return search::IsInstantNTP(web_contents) ? GURL(kChromeUINewTabURL) diff --git a/chrome/browser/ui/bookmarks/bookmark_utils.h b/chrome/browser/ui/bookmarks/bookmark_utils.h index 0df90b4..2a0e2f7 100644 --- a/chrome/browser/ui/bookmarks/bookmark_utils.h +++ b/chrome/browser/ui/bookmarks/bookmark_utils.h @@ -12,7 +12,6 @@ #include "ui/base/window_open_disposition.h" #include "ui/gfx/native_widget_types.h" -class Browser; class GURL; class PrefService; class Profile; @@ -24,7 +23,6 @@ struct BookmarkNodeData; namespace content { class BrowserContext; -class PageNavigator; class WebContents; } @@ -38,48 +36,6 @@ class DropTargetEvent; namespace chrome { -// Number of bookmarks we'll open before prompting the user to see if they -// really want to open all. -// -// NOTE: treat this as a const. It is not const so unit tests can change the -// value. -extern int num_bookmark_urls_before_prompting; - -// Opens all the bookmarks in |nodes| that are of type url and all the child -// bookmarks that are of type url for folders in |nodes|. |initial_disposition| -// dictates how the first URL is opened, all subsequent URLs are opened as -// background tabs. |navigator| is used to open the URLs. -void OpenAll(gfx::NativeWindow parent, - content::PageNavigator* navigator, - const std::vector<const bookmarks::BookmarkNode*>& nodes, - WindowOpenDisposition initial_disposition, - content::BrowserContext* browser_context); - -// Convenience for OpenAll() with a single BookmarkNode. -void OpenAll(gfx::NativeWindow parent, - content::PageNavigator* navigator, - const bookmarks::BookmarkNode* node, - WindowOpenDisposition initial_disposition, - content::BrowserContext* browser_context); - -// Asks the user before deleting a non-empty bookmark folder. -bool ConfirmDeleteBookmarkNode(const bookmarks::BookmarkNode* node, - gfx::NativeWindow window); - -// Shows the bookmark all tabs dialog. -void ShowBookmarkAllTabsDialog(Browser* browser); - -// Returns true if OpenAll() can open at least one bookmark of type url -// in |selection|. -bool HasBookmarkURLs( - const std::vector<const bookmarks::BookmarkNode*>& selection); - -// Returns true if OpenAll() can open at least one bookmark of type url -// in |selection| with incognito mode. -bool HasBookmarkURLsAllowedInIncognitoMode( - const std::vector<const bookmarks::BookmarkNode*>& selection, - content::BrowserContext* browser_context); - // Returns the bookmarkable URL for |web_contents|. // This is normally the current URL, but when the page is the Instant Extended // New Tab Page, the precise current URL may reflect various flags or other diff --git a/chrome/browser/ui/bookmarks/bookmark_utils_desktop.cc b/chrome/browser/ui/bookmarks/bookmark_utils_desktop.cc new file mode 100644 index 0000000..132aeb5 --- /dev/null +++ b/chrome/browser/ui/bookmarks/bookmark_utils_desktop.cc @@ -0,0 +1,271 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" + +#include "base/basictypes.h" +#include "base/logging.h" +#include "base/prefs/pref_service.h" +#include "base/strings/string_number_conversions.h" +#include "chrome/browser/bookmarks/bookmark_model_factory.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" +#include "chrome/browser/ui/app_list/app_list_util.h" +#include "chrome/browser/ui/bookmarks/bookmark_editor.h" +#include "chrome/browser/ui/bookmarks/bookmark_utils.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_navigator.h" +#include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/simple_message_box.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/url_constants.h" +#include "chrome/grit/chromium_strings.h" +#include "chrome/grit/generated_resources.h" +#include "components/bookmarks/browser/bookmark_model.h" +#include "components/bookmarks/browser/bookmark_node_data.h" +#include "components/search/search.h" +#include "components/url_formatter/url_formatter.h" +#include "components/user_prefs/user_prefs.h" +#include "content/public/browser/web_contents.h" +#include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/dragdrop/drop_target_event.h" +#include "ui/base/l10n/l10n_util.h" + +#if defined(ENABLE_EXTENSIONS) +#include "chrome/browser/extensions/api/commands/command_service.h" +#include "extensions/browser/extension_registry.h" +#include "extensions/common/extension_set.h" +#endif + +#if defined(TOOLKIT_VIEWS) +#include "ui/gfx/color_palette.h" +#include "ui/gfx/paint_vector_icon.h" +#include "ui/gfx/vector_icons_public.h" +#endif + +#if defined(OS_WIN) +#include "chrome/grit/theme_resources.h" +#include "ui/base/resource/material_design/material_design_controller.h" +#include "ui/base/resource/resource_bundle.h" +#endif + +using bookmarks::BookmarkModel; +using bookmarks::BookmarkNode; + +namespace chrome { + +int num_bookmark_urls_before_prompting = 15; + +namespace { + +// Iterator that iterates through a set of BookmarkNodes returning the URLs +// for nodes that are urls, or the URLs for the children of non-url urls. +// This does not recurse through all descendants, only immediate children. +// The following illustrates +// typical usage: +// OpenURLIterator iterator(nodes); +// while (iterator.has_next()) { +// const GURL* url = iterator.NextURL(); +// // do something with |urll|. +// } +class OpenURLIterator { + public: + explicit OpenURLIterator(const std::vector<const BookmarkNode*>& nodes) + : child_index_(0), + next_(NULL), + parent_(nodes.begin()), + end_(nodes.end()) { + FindNext(); + } + + bool has_next() { return next_ != NULL;} + + const GURL* NextURL() { + if (!has_next()) { + NOTREACHED(); + return NULL; + } + + const GURL* next = next_; + FindNext(); + return next; + } + + private: + // Seach next node which has URL. + void FindNext() { + for (; parent_ < end_; ++parent_, child_index_ = 0) { + if ((*parent_)->is_url()) { + next_ = &(*parent_)->url(); + ++parent_; + child_index_ = 0; + return; + } else { + for (; child_index_ < (*parent_)->child_count(); ++child_index_) { + const BookmarkNode* child = (*parent_)->GetChild(child_index_); + if (child->is_url()) { + next_ = &child->url(); + ++child_index_; + return; + } + } + } + } + next_ = NULL; + } + + int child_index_; + const GURL* next_; + std::vector<const BookmarkNode*>::const_iterator parent_; + const std::vector<const BookmarkNode*>::const_iterator end_; + + DISALLOW_COPY_AND_ASSIGN(OpenURLIterator); +}; + +#if !defined(OS_ANDROID) && !defined(OS_IOS) +bool ShouldOpenAll(gfx::NativeWindow parent, + const std::vector<const BookmarkNode*>& nodes) { + int child_count = 0; + OpenURLIterator iterator(nodes); + while (iterator.has_next()) { + iterator.NextURL(); + child_count++; + } + + if (child_count < num_bookmark_urls_before_prompting) + return true; + + return ShowMessageBox(parent, + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), + l10n_util::GetStringFUTF16(IDS_BOOKMARK_BAR_SHOULD_OPEN_ALL, + base::IntToString16(child_count)), + MESSAGE_BOX_TYPE_QUESTION) == MESSAGE_BOX_RESULT_YES; +} +#endif + +// Returns the total number of descendants nodes. +int ChildURLCountTotal(const BookmarkNode* node) { + int result = 0; + for (int i = 0; i < node->child_count(); ++i) { + const BookmarkNode* child = node->GetChild(i); + result++; + if (child->is_folder()) + result += ChildURLCountTotal(child); + } + return result; +} + +#if !defined(OS_ANDROID) && !defined(OS_IOS) +// Returns in |urls|, the url and title pairs for each open tab in browser. +void GetURLsForOpenTabs(Browser* browser, + std::vector<std::pair<GURL, base::string16> >* urls) { + for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { + std::pair<GURL, base::string16> entry; + GetURLAndTitleToBookmark(browser->tab_strip_model()->GetWebContentsAt(i), + &(entry.first), &(entry.second)); + urls->push_back(entry); + } +} +#endif + +} // namespace + +#if !defined(OS_ANDROID) && !defined(OS_IOS) +void OpenAll(gfx::NativeWindow parent, + content::PageNavigator* navigator, + const std::vector<const BookmarkNode*>& nodes, + WindowOpenDisposition initial_disposition, + content::BrowserContext* browser_context) { + if (!ShouldOpenAll(parent, nodes)) + return; + + // Opens all |nodes| of type URL and any children of |nodes| that are of type + // URL. |navigator| is the PageNavigator used to open URLs. After the first + // url is opened |opened_first_url| is set to true and |navigator| is set to + // the PageNavigator of the last active tab. This is done to handle a window + // disposition of new window, in which case we want subsequent tabs to open in + // that window. + bool opened_first_url = false; + WindowOpenDisposition disposition = initial_disposition; + OpenURLIterator iterator(nodes); + while (iterator.has_next()) { + const GURL* url = iterator.NextURL(); + // When |initial_disposition| is OFF_THE_RECORD, a node which can't be + // opened in incognito window, it is detected using |browser_context|, is + // not opened. + if (initial_disposition == OFF_THE_RECORD && + !IsURLAllowedInIncognito(*url, browser_context)) + continue; + + content::WebContents* opened_tab = navigator->OpenURL( + content::OpenURLParams(*url, content::Referrer(), disposition, + ui::PAGE_TRANSITION_AUTO_BOOKMARK, false)); + + if (!opened_first_url) { + opened_first_url = true; + disposition = NEW_BACKGROUND_TAB; + // We opened the first URL which may have opened a new window or clobbered + // the current page, reset the navigator just to be sure. |opened_tab| may + // be NULL in tests. + if (opened_tab) + navigator = opened_tab; + } + } +} + +void OpenAll(gfx::NativeWindow parent, + content::PageNavigator* navigator, + const BookmarkNode* node, + WindowOpenDisposition initial_disposition, + content::BrowserContext* browser_context) { + std::vector<const BookmarkNode*> nodes; + nodes.push_back(node); + OpenAll(parent, navigator, nodes, initial_disposition, browser_context); +} + +bool ConfirmDeleteBookmarkNode(const BookmarkNode* node, + gfx::NativeWindow window) { + DCHECK(node && node->is_folder() && !node->empty()); + return ShowMessageBox(window, + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), + l10n_util::GetStringFUTF16Int(IDS_BOOKMARK_EDITOR_CONFIRM_DELETE, + ChildURLCountTotal(node)), + MESSAGE_BOX_TYPE_QUESTION) == MESSAGE_BOX_RESULT_YES; +} + +void ShowBookmarkAllTabsDialog(Browser* browser) { + Profile* profile = browser->profile(); + BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); + DCHECK(model && model->loaded()); + + const BookmarkNode* parent = model->GetParentForNewNodes(); + BookmarkEditor::EditDetails details = + BookmarkEditor::EditDetails::AddFolder(parent, parent->child_count()); + GetURLsForOpenTabs(browser, &(details.urls)); + DCHECK(!details.urls.empty()); + + BookmarkEditor::Show(browser->window()->GetNativeWindow(), profile, details, + BookmarkEditor::SHOW_TREE); +} + +bool HasBookmarkURLs(const std::vector<const BookmarkNode*>& selection) { + OpenURLIterator iterator(selection); + return iterator.has_next(); +} + +bool HasBookmarkURLsAllowedInIncognitoMode( + const std::vector<const BookmarkNode*>& selection, + content::BrowserContext* browser_context) { + OpenURLIterator iterator(selection); + while (iterator.has_next()) { + const GURL* url = iterator.NextURL(); + if (IsURLAllowedInIncognito(*url, browser_context)) + return true; + } + return false; +} +#endif // !defined(OS_ANDROID) && !defined(OS_IOS) + +} // namespace chrome diff --git a/chrome/browser/ui/bookmarks/bookmark_utils_desktop.h b/chrome/browser/ui/bookmarks/bookmark_utils_desktop.h new file mode 100644 index 0000000..062817b --- /dev/null +++ b/chrome/browser/ui/bookmarks/bookmark_utils_desktop.h @@ -0,0 +1,70 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UTILS_DESKTOP_H_ +#define CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UTILS_DESKTOP_H_ + +#include <vector> + +#include "ui/base/window_open_disposition.h" +#include "ui/gfx/native_widget_types.h" + +class Browser; + +namespace bookmarks { +class BookmarkNode; +} + +namespace content { +class BrowserContext; +class PageNavigator; +} + +namespace chrome { + +// Number of bookmarks we'll open before prompting the user to see if they +// really want to open all. +// +// NOTE: treat this as a const. It is not const so unit tests can change the +// value. +extern int num_bookmark_urls_before_prompting; + +// Opens all the bookmarks in |nodes| that are of type url and all the child +// bookmarks that are of type url for folders in |nodes|. |initial_disposition| +// dictates how the first URL is opened, all subsequent URLs are opened as +// background tabs. |navigator| is used to open the URLs. +void OpenAll(gfx::NativeWindow parent, + content::PageNavigator* navigator, + const std::vector<const bookmarks::BookmarkNode*>& nodes, + WindowOpenDisposition initial_disposition, + content::BrowserContext* browser_context); + +// Convenience for OpenAll() with a single BookmarkNode. +void OpenAll(gfx::NativeWindow parent, + content::PageNavigator* navigator, + const bookmarks::BookmarkNode* node, + WindowOpenDisposition initial_disposition, + content::BrowserContext* browser_context); + +// Asks the user before deleting a non-empty bookmark folder. +bool ConfirmDeleteBookmarkNode(const bookmarks::BookmarkNode* node, + gfx::NativeWindow window); + +// Shows the bookmark all tabs dialog. +void ShowBookmarkAllTabsDialog(Browser* browser); + +// Returns true if OpenAll() can open at least one bookmark of type url +// in |selection|. +bool HasBookmarkURLs( + const std::vector<const bookmarks::BookmarkNode*>& selection); + +// Returns true if OpenAll() can open at least one bookmark of type url +// in |selection| with incognito mode. +bool HasBookmarkURLsAllowedInIncognitoMode( + const std::vector<const bookmarks::BookmarkNode*>& selection, + content::BrowserContext* browser_context); + +} // namespace chrome + +#endif // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UTILS_DESKTOP_H_ diff --git a/chrome/browser/ui/browser_commands.cc b/chrome/browser/ui/browser_commands.cc index 0e26db0..2d71419 100644 --- a/chrome/browser/ui/browser_commands.cc +++ b/chrome/browser/ui/browser_commands.cc @@ -27,6 +27,7 @@ #include "chrome/browser/translate/chrome_translate_client.h" #include "chrome/browser/ui/accelerator_utils.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h" +#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_command_controller.h" #include "chrome/browser/ui/browser_dialogs.h" diff --git a/chrome/browser/ui/browser_navigator.cc b/chrome/browser/ui/browser_navigator.cc index b9b4683..b040cc0 100644 --- a/chrome/browser/ui/browser_navigator.cc +++ b/chrome/browser/ui/browser_navigator.cc @@ -399,108 +399,10 @@ bool SwapInPrerender(const GURL& url, chrome::NavigateParams* params) { prerender_manager->MaybeUsePrerenderedPage(url, params); } -chrome::HostDesktopType GetHostDesktop(Browser* browser) { - if (browser) - return browser->host_desktop_type(); - return chrome::GetActiveDesktop(); -} - } // namespace -namespace chrome { - -NavigateParams::NavigateParams(Browser* a_browser, - const GURL& a_url, - ui::PageTransition a_transition) - : url(a_url), - frame_tree_node_id(-1), - uses_post(false), - target_contents(NULL), - source_contents(NULL), - disposition(CURRENT_TAB), - trusted_source(false), - transition(a_transition), - is_renderer_initiated(false), - tabstrip_index(-1), - tabstrip_add_types(TabStripModel::ADD_ACTIVE), - window_action(NO_ACTION), - user_gesture(true), - path_behavior(RESPECT), - ref_behavior(IGNORE_REF), - browser(a_browser), - initiating_profile(NULL), - host_desktop_type(GetHostDesktop(a_browser)), - should_replace_current_entry(false), - created_with_opener(false) { -} -NavigateParams::NavigateParams(Browser* a_browser, - WebContents* a_target_contents) - : frame_tree_node_id(-1), - uses_post(false), - target_contents(a_target_contents), - source_contents(NULL), - disposition(CURRENT_TAB), - trusted_source(false), - transition(ui::PAGE_TRANSITION_LINK), - is_renderer_initiated(false), - tabstrip_index(-1), - tabstrip_add_types(TabStripModel::ADD_ACTIVE), - window_action(NO_ACTION), - user_gesture(true), - path_behavior(RESPECT), - ref_behavior(IGNORE_REF), - browser(a_browser), - initiating_profile(NULL), - host_desktop_type(GetHostDesktop(a_browser)), - should_replace_current_entry(false), - created_with_opener(false) { -} - -NavigateParams::NavigateParams(Profile* a_profile, - const GURL& a_url, - ui::PageTransition a_transition) - : url(a_url), - frame_tree_node_id(-1), - uses_post(false), - target_contents(NULL), - source_contents(NULL), - disposition(NEW_FOREGROUND_TAB), - trusted_source(false), - transition(a_transition), - is_renderer_initiated(false), - tabstrip_index(-1), - tabstrip_add_types(TabStripModel::ADD_ACTIVE), - window_action(SHOW_WINDOW), - user_gesture(true), - path_behavior(RESPECT), - ref_behavior(IGNORE_REF), - browser(NULL), - initiating_profile(a_profile), - host_desktop_type(chrome::GetActiveDesktop()), - should_replace_current_entry(false), - created_with_opener(false) { -} - -NavigateParams::~NavigateParams() {} - -void FillNavigateParamsFromOpenURLParams(chrome::NavigateParams* nav_params, - const content::OpenURLParams& params) { - nav_params->referrer = params.referrer; - nav_params->source_site_instance = params.source_site_instance; - nav_params->frame_tree_node_id = params.frame_tree_node_id; - nav_params->redirect_chain = params.redirect_chain; - nav_params->extra_headers = params.extra_headers; - nav_params->disposition = params.disposition; - nav_params->trusted_source = false; - nav_params->is_renderer_initiated = params.is_renderer_initiated; - nav_params->transferred_global_request_id = - params.transferred_global_request_id; - nav_params->should_replace_current_entry = - params.should_replace_current_entry; - nav_params->uses_post = params.uses_post; - nav_params->browser_initiated_post_data = params.browser_initiated_post_data; -} +namespace chrome { void Navigate(NavigateParams* params) { Browser* source_browser = params->browser; diff --git a/chrome/browser/ui/browser_navigator.h b/chrome/browser/ui/browser_navigator.h index 07754c7..4b0dba1 100644 --- a/chrome/browser/ui/browser_navigator.h +++ b/chrome/browser/ui/browser_navigator.h @@ -5,250 +5,17 @@ #ifndef CHROME_BROWSER_UI_BROWSER_NAVIGATOR_H_ #define CHROME_BROWSER_UI_BROWSER_NAVIGATOR_H_ -#include <string> +// TODO(thestig) Forward declare this and do IWYU. +#include "chrome/browser/ui/browser_navigator_params.h" -#include "base/memory/ref_counted.h" -#include "base/memory/ref_counted_memory.h" -#include "chrome/browser/ui/host_desktop.h" -#include "content/public/browser/browser_context.h" -#include "content/public/browser/global_request_id.h" -#include "content/public/browser/page_navigator.h" -#include "content/public/browser/site_instance.h" -#include "content/public/common/referrer.h" -#include "ui/base/page_transition_types.h" -#include "ui/base/window_open_disposition.h" -#include "ui/gfx/geometry/rect.h" -#include "url/gurl.h" - -class Browser; -class Profile; +class GURL; namespace content { -class WebContents; +class BrowserContext; } namespace chrome { -// Parameters that tell Navigate() what to do. -// -// Some basic examples: -// -// Simple Navigate to URL in current tab: -// chrome::NavigateParams params(browser, GURL("http://www.google.com/"), -// ui::PAGE_TRANSITION_LINK); -// chrome::Navigate(¶ms); -// -// Open bookmark in new background tab: -// chrome::NavigateParams params(browser, url, -// ui::PAGE_TRANSITION_AUTO_BOOKMARK); -// params.disposition = NEW_BACKGROUND_TAB; -// chrome::Navigate(¶ms); -// -// Opens a popup WebContents: -// chrome::NavigateParams params(browser, popup_contents); -// params.source_contents = source_contents; -// chrome::Navigate(¶ms); -// -// See browser_navigator_browsertest.cc for more examples. -// -struct NavigateParams { - NavigateParams(Browser* browser, - const GURL& a_url, - ui::PageTransition a_transition); - NavigateParams(Browser* browser, - content::WebContents* a_target_contents); - NavigateParams(Profile* profile, - const GURL& a_url, - ui::PageTransition a_transition); - ~NavigateParams(); - - // The URL/referrer to be loaded. Ignored if |target_contents| is non-NULL. - GURL url; - content::Referrer referrer; - - // The browser-global ID of the frame to navigate, or -1 for the main frame. - int frame_tree_node_id; - - // Any redirect URLs that occurred for this navigation before |url|. - // Usually empty. - std::vector<GURL> redirect_chain; - - // Indicates whether this navigation will be sent using POST. - // The POST method is limited support for basic POST data by leveraging - // NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST. - // It is not for things like file uploads. - bool uses_post; - - // The post data when the navigation uses POST. - scoped_refptr<base::RefCountedMemory> browser_initiated_post_data; - - // Extra headers to add to the request for this page. Headers are - // represented as "<name>: <value>" and separated by \r\n. The entire string - // is terminated by \r\n. May be empty if no extra headers are needed. - std::string extra_headers; - - // [in] A WebContents to be navigated or inserted into the target - // Browser's tabstrip. If NULL, |url| or the homepage will be used - // instead. When non-NULL, Navigate() assumes it has already been - // navigated to its intended destination and will not load any URL in it - // (i.e. |url| is ignored). - // Default is NULL. - // [out] The WebContents in which the navigation occurred or that was - // inserted. Guaranteed non-NULL except for note below: - // Note: If this field is set to NULL by the caller and Navigate() creates - // a new WebContents, this field will remain NULL and the - // WebContents deleted if the WebContents it created is - // not added to a TabStripModel before Navigate() returns. - content::WebContents* target_contents; - - // [in] The WebContents that initiated the Navigate() request if such - // context is necessary. Default is NULL, i.e. no context. - // [out] If NULL, this value will be set to the selected WebContents in - // the originating browser prior to the operation performed by - // Navigate(). However, if the originating page is from a different - // profile (e.g. an OFF_THE_RECORD page originating from a non-OTR - // window), then |source_contents| is reset to NULL. - content::WebContents* source_contents; - - // The disposition requested by the navigation source. Default is - // CURRENT_TAB. What follows is a set of coercions that happen to this value - // when other factors are at play: - // - // [in]: Condition: [out]: - // NEW_BACKGROUND_TAB target browser tabstrip is empty NEW_FOREGROUND_TAB - // CURRENT_TAB " " " NEW_FOREGROUND_TAB - // OFF_THE_RECORD target browser profile is incog. NEW_FOREGROUND_TAB - // - // If disposition is NEW_BACKGROUND_TAB, TabStripModel::ADD_ACTIVE is - // removed from |tabstrip_add_types| automatically. - // If disposition is one of NEW_WINDOW, NEW_POPUP, NEW_FOREGROUND_TAB or - // SINGLETON_TAB, then TabStripModel::ADD_ACTIVE is automatically added to - // |tabstrip_add_types|. - WindowOpenDisposition disposition; - - // Sets browser->is_trusted_source. Default is false. - bool trusted_source; - - // The transition type of the navigation. Default is - // ui::PAGE_TRANSITION_LINK when target_contents is specified in the - // constructor. - ui::PageTransition transition; - - // Whether this navigation was initiated by the renderer process. Default is - // false. - bool is_renderer_initiated; - - // The index the caller would like the tab to be positioned at in the - // TabStrip. The actual index will be determined by the TabHandler in - // accordance with |add_types|. Defaults to -1 (allows the TabHandler to - // decide). - int tabstrip_index; - - // A bitmask of values defined in TabStripModel::AddTabTypes. Helps - // determine where to insert a new tab and whether or not it should be - // selected, among other properties. Default is ADD_ACTIVE. - int tabstrip_add_types; - - // If non-empty, the new tab is an app tab. - std::string extension_app_id; - - // If non-empty, specifies the desired initial position and size of the - // window if |disposition| == NEW_POPUP. - // TODO(beng): Figure out if this can be used to create Browser windows - // for other callsites that use set_override_bounds, or - // remove this comment. - gfx::Rect window_bounds; - - // Determines if and how the target window should be made visible at the end - // of the call to Navigate(). - enum WindowAction { - // Do not show or activate the browser window after navigating. - NO_ACTION, - // Show and activate the browser window after navigating. - SHOW_WINDOW, - // Show the browser window after navigating but do not activate. - SHOW_WINDOW_INACTIVE - }; - // Default is NO_ACTION (don't show or activate the window). - // If disposition is NEW_WINDOW or NEW_POPUP, and |window_action| is set to - // NO_ACTION, |window_action| will be set to SHOW_WINDOW. - WindowAction window_action; - - // If false then the navigation was not initiated by a user gesture. - // Default is true. - bool user_gesture; - - // What to do with the path component of the URL for singleton navigations. - enum PathBehavior { - // Two URLs with differing paths are different. - RESPECT, - // Ignore path when finding existing tab, navigate to new URL. - IGNORE_AND_NAVIGATE, - // Ignore path when finding existing tab, don't navigate tab. - IGNORE_AND_STAY_PUT, - }; - // Default is RESPECT. - PathBehavior path_behavior; - - // What to do with the ref component of the URL for singleton navigations. - enum RefBehavior { - // Two URLs with differing refs are same. - IGNORE_REF, - // Two URLs with differing refs are different. - RESPECT_REF, - }; - // Default is IGNORE. - RefBehavior ref_behavior; - - // [in] Specifies a Browser object where the navigation could occur or the - // tab could be added. Navigate() is not obliged to use this Browser if - // it is not compatible with the operation being performed. This can be - // NULL, in which case |initiating_profile| must be provided. - // [out] Specifies the Browser object where the navigation occurred or the - // tab was added. Guaranteed non-NULL unless the disposition did not - // require a navigation, in which case this is set to NULL - // (SUPPRESS_OPEN, SAVE_TO_DISK, IGNORE_ACTION). - // Note: If |show_window| is set to false and a new Browser is created by - // Navigate(), the caller is responsible for showing it so that its - // window can assume responsibility for the Browser's lifetime (Browser - // objects are deleted when the user closes a visible browser window). - Browser* browser; - - // The profile that is initiating the navigation. If there is a non-NULL - // browser passed in via |browser|, it's profile will be used instead. - Profile* initiating_profile; - - // Refers to a navigation that was parked in the browser in order to be - // transferred to another RVH. Only used in case of a redirection of a request - // to a different site that created a new RVH. - content::GlobalRequestID transferred_global_request_id; - - // Refers to which desktop this navigation should occur on. May be passed - // explicitly or inferred from an existing Browser instance. - chrome::HostDesktopType host_desktop_type; - - // Indicates whether this navigation should replace the current - // navigation entry. - bool should_replace_current_entry; - - // Indicates whether |target_contents| is being created with a window.opener. - bool created_with_opener; - - // SiteInstance of the frame that initiated the navigation or null if we - // don't know it. This should be assigned from the OpenURLParams of the - // WebContentsDelegate::OpenURLFromTab implementation and is used to determine - // the SiteInstance that will be used for the resulting frame in the case of - // an about:blank or a data url navigation. - scoped_refptr<content::SiteInstance> source_site_instance; - - private: - NavigateParams(); -}; - -// Copies fields from |params| struct to |nav_params| struct. -void FillNavigateParamsFromOpenURLParams(chrome::NavigateParams* nav_params, - const content::OpenURLParams& params); - // Navigates according to the configuration specified in |params|. void Navigate(NavigateParams* params); diff --git a/chrome/browser/ui/browser_navigator_params.cc b/chrome/browser/ui/browser_navigator_params.cc new file mode 100644 index 0000000..74e086c --- /dev/null +++ b/chrome/browser/ui/browser_navigator_params.cc @@ -0,0 +1,152 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/browser_navigator_params.h" + +#include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "content/public/browser/navigation_controller.h" +#include "content/public/browser/page_navigator.h" + +#if !defined(OS_ANDROID) +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/host_desktop.h" +#endif + +using content::GlobalRequestID; +using content::NavigationController; +using content::WebContents; + +namespace chrome { + +#if !defined(OS_ANDROID) +namespace { + +HostDesktopType GetHostDesktop(Browser* browser) { + if (browser) + return browser->host_desktop_type(); + return GetActiveDesktop(); +} + +} // namespace +#endif + +#if defined(OS_ANDROID) +NavigateParams::NavigateParams(WebContents* a_target_contents) + : frame_tree_node_id(-1), + uses_post(false), + target_contents(a_target_contents), + source_contents(nullptr), + disposition(CURRENT_TAB), + trusted_source(false), + transition(ui::PAGE_TRANSITION_LINK), + is_renderer_initiated(false), + tabstrip_index(-1), + tabstrip_add_types(TabStripModel::ADD_ACTIVE), + window_action(NO_ACTION), + user_gesture(true), + path_behavior(RESPECT), + ref_behavior(IGNORE_REF), + initiating_profile(nullptr), + host_desktop_type(GetActiveDesktop()), + should_replace_current_entry(false), + created_with_opener(false) { +} +#else +NavigateParams::NavigateParams(Browser* a_browser, + const GURL& a_url, + ui::PageTransition a_transition) + : url(a_url), + frame_tree_node_id(-1), + uses_post(false), + target_contents(NULL), + source_contents(NULL), + disposition(CURRENT_TAB), + trusted_source(false), + transition(a_transition), + is_renderer_initiated(false), + tabstrip_index(-1), + tabstrip_add_types(TabStripModel::ADD_ACTIVE), + window_action(NO_ACTION), + user_gesture(true), + path_behavior(RESPECT), + ref_behavior(IGNORE_REF), + browser(a_browser), + initiating_profile(NULL), + host_desktop_type(GetHostDesktop(a_browser)), + should_replace_current_entry(false), + created_with_opener(false) { +} + +NavigateParams::NavigateParams(Browser* a_browser, + WebContents* a_target_contents) + : frame_tree_node_id(-1), + uses_post(false), + target_contents(a_target_contents), + source_contents(NULL), + disposition(CURRENT_TAB), + trusted_source(false), + transition(ui::PAGE_TRANSITION_LINK), + is_renderer_initiated(false), + tabstrip_index(-1), + tabstrip_add_types(TabStripModel::ADD_ACTIVE), + window_action(NO_ACTION), + user_gesture(true), + path_behavior(RESPECT), + ref_behavior(IGNORE_REF), + browser(a_browser), + initiating_profile(NULL), + host_desktop_type(GetHostDesktop(a_browser)), + should_replace_current_entry(false), + created_with_opener(false) { +} +#endif // !defined(OS_ANDROID) + +NavigateParams::NavigateParams(Profile* a_profile, + const GURL& a_url, + ui::PageTransition a_transition) + : url(a_url), + frame_tree_node_id(-1), + uses_post(false), + target_contents(NULL), + source_contents(NULL), + disposition(NEW_FOREGROUND_TAB), + trusted_source(false), + transition(a_transition), + is_renderer_initiated(false), + tabstrip_index(-1), + tabstrip_add_types(TabStripModel::ADD_ACTIVE), + window_action(SHOW_WINDOW), + user_gesture(true), + path_behavior(RESPECT), + ref_behavior(IGNORE_REF), +#if !defined(OS_ANDROID) + browser(NULL), +#endif + initiating_profile(a_profile), + host_desktop_type(GetActiveDesktop()), + should_replace_current_entry(false), + created_with_opener(false) { +} + +NavigateParams::~NavigateParams() {} + +void FillNavigateParamsFromOpenURLParams(NavigateParams* nav_params, + const content::OpenURLParams& params) { + nav_params->referrer = params.referrer; + nav_params->source_site_instance = params.source_site_instance; + nav_params->frame_tree_node_id = params.frame_tree_node_id; + nav_params->redirect_chain = params.redirect_chain; + nav_params->extra_headers = params.extra_headers; + nav_params->disposition = params.disposition; + nav_params->trusted_source = false; + nav_params->is_renderer_initiated = params.is_renderer_initiated; + nav_params->transferred_global_request_id = + params.transferred_global_request_id; + nav_params->should_replace_current_entry = + params.should_replace_current_entry; + nav_params->uses_post = params.uses_post; + nav_params->browser_initiated_post_data = params.browser_initiated_post_data; +} + +} // namespace chrome diff --git a/chrome/browser/ui/browser_navigator_params.h b/chrome/browser/ui/browser_navigator_params.h new file mode 100644 index 0000000..d011c0e --- /dev/null +++ b/chrome/browser/ui/browser_navigator_params.h @@ -0,0 +1,261 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_BROWSER_NAVIGATOR_PARAMS_H_ +#define CHROME_BROWSER_UI_BROWSER_NAVIGATOR_PARAMS_H_ + +#include <string> +#include <vector> + +#include "base/memory/ref_counted.h" +#include "base/memory/ref_counted_memory.h" +#include "chrome/browser/ui/host_desktop.h" +#include "content/public/browser/global_request_id.h" +#include "content/public/browser/site_instance.h" +#include "content/public/common/referrer.h" +#include "ui/base/page_transition_types.h" +#include "ui/base/window_open_disposition.h" +#include "ui/gfx/geometry/rect.h" +#include "url/gurl.h" + +class Browser; +class Profile; + +namespace content { +class WebContents; +struct OpenURLParams; +} + +namespace chrome { + +// Parameters that tell Navigate() what to do. +// +// Some basic examples: +// +// Simple Navigate to URL in current tab: +// chrome::NavigateParams params(browser, GURL("http://www.google.com/"), +// ui::PAGE_TRANSITION_LINK); +// chrome::Navigate(¶ms); +// +// Open bookmark in new background tab: +// chrome::NavigateParams params(browser, url, +// ui::PAGE_TRANSITION_AUTO_BOOKMARK); +// params.disposition = NEW_BACKGROUND_TAB; +// chrome::Navigate(¶ms); +// +// Opens a popup WebContents: +// chrome::NavigateParams params(browser, popup_contents); +// params.source_contents = source_contents; +// chrome::Navigate(¶ms); +// +// See browser_navigator_browsertest.cc for more examples. + +// TODO(thestig): Split or ifdef out more fields that are not used on Android. +struct NavigateParams { +#if defined(OS_ANDROID) + explicit NavigateParams(content::WebContents* a_target_contents); +#else + NavigateParams(Browser* browser, + const GURL& a_url, + ui::PageTransition a_transition); + NavigateParams(Browser* browser, + content::WebContents* a_target_contents); +#endif + NavigateParams(Profile* profile, + const GURL& a_url, + ui::PageTransition a_transition); + ~NavigateParams(); + + // The URL/referrer to be loaded. Ignored if |target_contents| is non-NULL. + GURL url; + content::Referrer referrer; + + // The browser-global ID of the frame to navigate, or -1 for the main frame. + int frame_tree_node_id; + + // Any redirect URLs that occurred for this navigation before |url|. + // Usually empty. + std::vector<GURL> redirect_chain; + + // Indicates whether this navigation will be sent using POST. + // The POST method is limited support for basic POST data by leveraging + // NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST. + // It is not for things like file uploads. + bool uses_post; + + // The post data when the navigation uses POST. + scoped_refptr<base::RefCountedMemory> browser_initiated_post_data; + + // Extra headers to add to the request for this page. Headers are + // represented as "<name>: <value>" and separated by \r\n. The entire string + // is terminated by \r\n. May be empty if no extra headers are needed. + std::string extra_headers; + + // [in] A WebContents to be navigated or inserted into the target + // Browser's tabstrip. If NULL, |url| or the homepage will be used + // instead. When non-NULL, Navigate() assumes it has already been + // navigated to its intended destination and will not load any URL in it + // (i.e. |url| is ignored). + // Default is NULL. + // [out] The WebContents in which the navigation occurred or that was + // inserted. Guaranteed non-NULL except for note below: + // Note: If this field is set to NULL by the caller and Navigate() creates + // a new WebContents, this field will remain NULL and the + // WebContents deleted if the WebContents it created is + // not added to a TabStripModel before Navigate() returns. + content::WebContents* target_contents; + + // [in] The WebContents that initiated the Navigate() request if such + // context is necessary. Default is NULL, i.e. no context. + // [out] If NULL, this value will be set to the selected WebContents in + // the originating browser prior to the operation performed by + // Navigate(). However, if the originating page is from a different + // profile (e.g. an OFF_THE_RECORD page originating from a non-OTR + // window), then |source_contents| is reset to NULL. + content::WebContents* source_contents; + + // The disposition requested by the navigation source. Default is + // CURRENT_TAB. What follows is a set of coercions that happen to this value + // when other factors are at play: + // + // [in]: Condition: [out]: + // NEW_BACKGROUND_TAB target browser tabstrip is empty NEW_FOREGROUND_TAB + // CURRENT_TAB " " " NEW_FOREGROUND_TAB + // OFF_THE_RECORD target browser profile is incog. NEW_FOREGROUND_TAB + // + // If disposition is NEW_BACKGROUND_TAB, TabStripModel::ADD_ACTIVE is + // removed from |tabstrip_add_types| automatically. + // If disposition is one of NEW_WINDOW, NEW_POPUP, NEW_FOREGROUND_TAB or + // SINGLETON_TAB, then TabStripModel::ADD_ACTIVE is automatically added to + // |tabstrip_add_types|. + WindowOpenDisposition disposition; + + // Sets browser->is_trusted_source. Default is false. + bool trusted_source; + + // The transition type of the navigation. Default is + // ui::PAGE_TRANSITION_LINK when target_contents is specified in the + // constructor. + ui::PageTransition transition; + + // Whether this navigation was initiated by the renderer process. Default is + // false. + bool is_renderer_initiated; + + // The index the caller would like the tab to be positioned at in the + // TabStrip. The actual index will be determined by the TabHandler in + // accordance with |add_types|. Defaults to -1 (allows the TabHandler to + // decide). + int tabstrip_index; + + // A bitmask of values defined in TabStripModel::AddTabTypes. Helps + // determine where to insert a new tab and whether or not it should be + // selected, among other properties. Default is ADD_ACTIVE. + int tabstrip_add_types; + + // If non-empty, the new tab is an app tab. + std::string extension_app_id; + + // If non-empty, specifies the desired initial position and size of the + // window if |disposition| == NEW_POPUP. + // TODO(beng): Figure out if this can be used to create Browser windows + // for other callsites that use set_override_bounds, or + // remove this comment. + gfx::Rect window_bounds; + + // Determines if and how the target window should be made visible at the end + // of the call to Navigate(). + enum WindowAction { + // Do not show or activate the browser window after navigating. + NO_ACTION, + // Show and activate the browser window after navigating. + SHOW_WINDOW, + // Show the browser window after navigating but do not activate. + SHOW_WINDOW_INACTIVE + }; + // Default is NO_ACTION (don't show or activate the window). + // If disposition is NEW_WINDOW or NEW_POPUP, and |window_action| is set to + // NO_ACTION, |window_action| will be set to SHOW_WINDOW. + WindowAction window_action; + + // If false then the navigation was not initiated by a user gesture. + // Default is true. + bool user_gesture; + + // What to do with the path component of the URL for singleton navigations. + enum PathBehavior { + // Two URLs with differing paths are different. + RESPECT, + // Ignore path when finding existing tab, navigate to new URL. + IGNORE_AND_NAVIGATE, + // Ignore path when finding existing tab, don't navigate tab. + IGNORE_AND_STAY_PUT, + }; + // Default is RESPECT. + PathBehavior path_behavior; + + // What to do with the ref component of the URL for singleton navigations. + enum RefBehavior { + // Two URLs with differing refs are same. + IGNORE_REF, + // Two URLs with differing refs are different. + RESPECT_REF, + }; + // Default is IGNORE. + RefBehavior ref_behavior; + +#if !defined(OS_ANDROID) + // [in] Specifies a Browser object where the navigation could occur or the + // tab could be added. Navigate() is not obliged to use this Browser if + // it is not compatible with the operation being performed. This can be + // NULL, in which case |initiating_profile| must be provided. + // [out] Specifies the Browser object where the navigation occurred or the + // tab was added. Guaranteed non-NULL unless the disposition did not + // require a navigation, in which case this is set to NULL + // (SUPPRESS_OPEN, SAVE_TO_DISK, IGNORE_ACTION). + // Note: If |show_window| is set to false and a new Browser is created by + // Navigate(), the caller is responsible for showing it so that its + // window can assume responsibility for the Browser's lifetime (Browser + // objects are deleted when the user closes a visible browser window). + Browser* browser; +#endif + + // The profile that is initiating the navigation. If there is a non-NULL + // browser passed in via |browser|, it's profile will be used instead. + Profile* initiating_profile; + + // Refers to a navigation that was parked in the browser in order to be + // transferred to another RVH. Only used in case of a redirection of a request + // to a different site that created a new RVH. + content::GlobalRequestID transferred_global_request_id; + + // Refers to which desktop this navigation should occur on. May be passed + // explicitly or inferred from an existing Browser instance. + chrome::HostDesktopType host_desktop_type; + + // Indicates whether this navigation should replace the current + // navigation entry. + bool should_replace_current_entry; + + // Indicates whether |target_contents| is being created with a window.opener. + bool created_with_opener; + + // SiteInstance of the frame that initiated the navigation or null if we + // don't know it. This should be assigned from the OpenURLParams of the + // WebContentsDelegate::OpenURLFromTab implementation and is used to determine + // the SiteInstance that will be used for the resulting frame in the case of + // an about:blank or a data url navigation. + scoped_refptr<content::SiteInstance> source_site_instance; + + private: + NavigateParams(); +}; + +// Copies fields from |params| struct to |nav_params| struct. +void FillNavigateParamsFromOpenURLParams(chrome::NavigateParams* nav_params, + const content::OpenURLParams& params); + +} // namespace chrome + +#endif // CHROME_BROWSER_UI_BROWSER_NAVIGATOR_PARAMS_H_ diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm index 6f0a942..6e3f50a 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm @@ -19,6 +19,7 @@ #import "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/ui/bookmarks/bookmark_editor.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h" +#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/chrome_pages.h" diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.mm index d5734c0..0a14142 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.mm @@ -9,6 +9,7 @@ #import "chrome/browser/app_controller_mac.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h" +#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_finder.h" #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" diff --git a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc index a74309e..4f2ec26 100644 --- a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc +++ b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc @@ -27,6 +27,7 @@ #include "chrome/common/url_constants.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/interactive_test_utils.h" +#include "chrome/test/base/search_test_utils.h" #include "chrome/test/base/ui_test_utils.h" #include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_utils.h" @@ -267,7 +268,7 @@ class OmniboxViewTest : public InProcessBrowserTest, TemplateURLServiceFactory::GetForProfile(profile); ASSERT_TRUE(model); - ui_test_utils::WaitForTemplateURLServiceToLoad(model); + search_test_utils::WaitForTemplateURLServiceToLoad(model); ASSERT_TRUE(model->loaded()); diff --git a/chrome/browser/ui/search/instant_test_utils.cc b/chrome/browser/ui/search/instant_test_utils.cc index 1402129..56841fc 100644 --- a/chrome/browser/ui/search/instant_test_utils.cc +++ b/chrome/browser/ui/search/instant_test_utils.cc @@ -14,7 +14,7 @@ #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/base/interactive_test_utils.h" -#include "chrome/test/base/ui_test_utils.h" +#include "chrome/test/base/search_test_utils.h" #include "components/omnibox/browser/omnibox_view.h" #include "components/search_engines/template_url_service.h" #include "components/variations/entropy_provider.h" @@ -49,7 +49,7 @@ void InstantTestBase::SetupInstant(Browser* browser) { TemplateURLService* service = TemplateURLServiceFactory::GetForProfile(browser_->profile()); - ui_test_utils::WaitForTemplateURLServiceToLoad(service); + search_test_utils::WaitForTemplateURLServiceToLoad(service); TemplateURLData data; // Necessary to use exact URL for both the main URL and the alternate URL for @@ -72,7 +72,7 @@ void InstantTestBase::SetupInstant(Browser* browser) { void InstantTestBase::SetInstantURL(const std::string& url) { TemplateURLService* service = TemplateURLServiceFactory::GetForProfile(browser_->profile()); - ui_test_utils::WaitForTemplateURLServiceToLoad(service); + search_test_utils::WaitForTemplateURLServiceToLoad(service); TemplateURLData data; data.SetShortName(base::ASCIIToUTF16("name")); diff --git a/chrome/browser/ui/search/new_tab_page_interceptor_browsertest.cc b/chrome/browser/ui/search/new_tab_page_interceptor_browsertest.cc index 3684620..656fa28 100644 --- a/chrome/browser/ui/search/new_tab_page_interceptor_browsertest.cc +++ b/chrome/browser/ui/search/new_tab_page_interceptor_browsertest.cc @@ -12,6 +12,7 @@ #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/search_test_utils.h" #include "chrome/test/base/ui_test_utils.h" #include "components/search_engines/template_url_service.h" #include "content/public/browser/navigation_controller.h" @@ -48,7 +49,7 @@ class NewTabPageInterceptorTest : public InProcessBrowserTest { void ChangeDefaultSearchProvider(const char* new_tab_path) { TemplateURLService* template_url_service = TemplateURLServiceFactory::GetForProfile(browser()->profile()); - ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); + search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); UIThreadSearchTermsData::SetGoogleBaseURL("https://mock.http/"); std::string base_url("{google:baseURL}"); TemplateURLData data; diff --git a/chrome/browser/ui/search/search_ipc_router_unittest.cc b/chrome/browser/ui/search/search_ipc_router_unittest.cc index 24c3c11..a9507a7 100644 --- a/chrome/browser/ui/search/search_ipc_router_unittest.cc +++ b/chrome/browser/ui/search/search_ipc_router_unittest.cc @@ -24,7 +24,7 @@ #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/browser_with_test_window_test.h" -#include "chrome/test/base/ui_test_utils.h" +#include "chrome/test/base/search_test_utils.h" #include "components/omnibox/common/omnibox_focus_state.h" #include "components/search_engines/template_url_service.h" #include "content/public/browser/navigation_controller.h" @@ -105,7 +105,7 @@ class SearchIPCRouterTest : public BrowserWithTestWindowTest { &TemplateURLServiceFactory::BuildInstanceFor); TemplateURLService* template_url_service = TemplateURLServiceFactory::GetForProfile(profile()); - ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); + search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); TemplateURLData data; data.SetShortName(base::ASCIIToUTF16("foo.com")); diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc index 2cc9c3d..dbe7120 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc @@ -32,6 +32,7 @@ #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h" +#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc index c659c61..56449a6 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc @@ -17,6 +17,7 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h" +#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_window.h" diff --git a/chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc b/chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc index f3a9d6e..f247947 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc @@ -17,7 +17,7 @@ #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/bookmarks/bookmark_utils.h" +#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_profile.h" #include "components/bookmarks/browser/bookmark_model.h" diff --git a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc index 092c1ef..802d9f2 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc @@ -14,6 +14,7 @@ #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h" +#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" #include "chrome/browser/ui/browser_dialogs.h" #include "chrome/grit/generated_resources.h" #include "chrome/grit/locale_settings.h" diff --git a/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc b/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc index 3c17088..832b6ff 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc @@ -12,6 +12,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h" +#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" #include "chrome/browser/ui/views/event_utils.h" @@ -399,7 +400,7 @@ void BookmarkMenuDelegate::WillRemoveBookmarks( // to support different parents, but this would need to prune any nodes whose // parent has been removed. As all nodes currently have the same parent, there // is the DCHECK. - DCHECK(changed_parent_menus.size() <= 1); + DCHECK_LE(changed_parent_menus.size(), 1U); // Remove any descendants of the removed nodes in |node_to_menu_map_|. for (NodeToMenuMap::iterator i(node_to_menu_map_.begin()); diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 07e15ff..f5f07dc 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -138,8 +138,8 @@ 'browser/ui/browser_dialogs.h', 'browser/ui/browser_mac.cc', 'browser/ui/browser_mac.h', - 'browser/ui/browser_navigator.cc', - 'browser/ui/browser_navigator.h', + 'browser/ui/browser_navigator_params.cc', + 'browser/ui/browser_navigator_params.h', 'browser/ui/browser_otr_state_android.cc', 'browser/ui/browser_ui_prefs.cc', 'browser/ui/browser_ui_prefs.h', @@ -1487,6 +1487,8 @@ 'browser/ui/bookmarks/bookmark_tab_helper.h', 'browser/ui/bookmarks/bookmark_tab_helper_delegate.cc', 'browser/ui/bookmarks/bookmark_tab_helper_delegate.h', + 'browser/ui/bookmarks/bookmark_utils_desktop.cc', + 'browser/ui/bookmarks/bookmark_utils_desktop.h', 'browser/ui/bookmarks/enhanced_bookmark_key_service.cc', 'browser/ui/bookmarks/enhanced_bookmark_key_service.h', 'browser/ui/bookmarks/enhanced_bookmark_key_service_factory.cc', @@ -1507,6 +1509,8 @@ 'browser/ui/browser_iterator.h', 'browser/ui/browser_list.cc', 'browser/ui/browser_list.h', + 'browser/ui/browser_navigator.cc', + 'browser/ui/browser_navigator.h', 'browser/ui/browser_otr_state.cc', 'browser/ui/browser_otr_state.h', 'browser/ui/browser_tab_restore_service_delegate.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 73e7306..2b6a7cf 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -274,7 +274,7 @@ 'browser/ui/autofill/test_popup_controller_common.cc', 'browser/ui/autofill/test_popup_controller_common.h', 'browser/ui/bookmarks/bookmark_editor_unittest.cc', - 'browser/ui/bookmarks/bookmark_ui_utils_unittest.cc', + 'browser/ui/bookmarks/bookmark_ui_utils_desktop_unittest.cc', 'browser/ui/bookmarks/recently_used_folders_combo_model_unittest.cc', 'browser/ui/chrome_select_file_policy_unittest.cc', # It is safe to list */cocoa/* files in the "common" file list @@ -1822,6 +1822,8 @@ 'test/base/scoped_bundle_swizzler_mac.mm', 'test/base/scoped_testing_local_state.cc', 'test/base/scoped_testing_local_state.h', + 'test/base/search_test_utils.cc', + 'test/base/search_test_utils.h', 'test/base/test_browser_window.cc', 'test/base/test_browser_window.h', 'test/base/test_launcher_utils.cc', @@ -1894,6 +1896,8 @@ }], ['OS=="android"', { 'sources!': [ + 'browser/password_manager/password_manager_test_base.cc', + 'browser/password_manager/password_manager_test_base.h', 'browser/sessions/session_service_test_helper.cc', 'browser/sessions/session_service_test_helper.h', 'browser/ui/exclusive_access/fullscreen_controller_state_test.cc', @@ -1909,6 +1913,8 @@ 'test/base/in_process_browser_test.h', 'test/base/test_browser_window.cc', 'test/base/test_browser_window.h', + 'test/base/ui_test_utils.cc', + 'test/base/ui_test_utils.h', ], }], ['chromeos==1', { @@ -2638,6 +2644,7 @@ ['OS=="android" or OS=="ios"', { 'sources!': [ 'browser/devtools/device/webrtc/devtools_bridge_instances_request_unittest.cc', + 'browser/ui/bookmarks/bookmark_ui_utils_desktop_unittest.cc', 'browser/ui/sync/sync_promo_ui_unittest.cc', ], }, { # 'OS!="android" and OS!="ios"' diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn index aeaeee4..666b2aa 100644 --- a/chrome/test/BUILD.gn +++ b/chrome/test/BUILD.gn @@ -56,6 +56,8 @@ source_set("test_support") { "base/scoped_bundle_swizzler_mac.mm", "base/scoped_testing_local_state.cc", "base/scoped_testing_local_state.h", + "base/search_test_utils.cc", + "base/search_test_utils.h", "base/test_browser_window.cc", "base/test_browser_window.h", "base/test_launcher_utils.cc", @@ -171,6 +173,8 @@ source_set("test_support") { "base/in_process_browser_test.h", "base/test_browser_window.cc", "base/test_browser_window.h", + "base/ui_test_utils.cc", + "base/ui_test_utils.h", ] } @@ -1872,6 +1876,7 @@ if (!is_android) { if (is_android || is_ios) { sources -= [ "../browser/devtools/device/webrtc/devtools_bridge_instances_request_unittest.cc", + "../browser/ui/bookmarks/bookmark_ui_utils_desktop_unittest.cc", "../browser/ui/sync/sync_promo_ui_unittest.cc", ] } else { diff --git a/chrome/test/base/search_test_utils.cc b/chrome/test/base/search_test_utils.cc new file mode 100644 index 0000000..8c52119 --- /dev/null +++ b/chrome/test/base/search_test_utils.cc @@ -0,0 +1,28 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/base/search_test_utils.h" + +#include "base/memory/ref_counted.h" +#include "components/search_engines/template_url_service.h" +#include "content/public/test/test_utils.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace search_test_utils { + +void WaitForTemplateURLServiceToLoad(TemplateURLService* service) { + if (service->loaded()) + return; + scoped_refptr<content::MessageLoopRunner> message_loop_runner = + new content::MessageLoopRunner; + scoped_ptr<TemplateURLService::Subscription> subscription = + service->RegisterOnLoadedCallback( + message_loop_runner->QuitClosure()); + service->Load(); + message_loop_runner->Run(); + + ASSERT_TRUE(service->loaded()); +} + +} // namespace search_test_utils diff --git a/chrome/test/base/search_test_utils.h b/chrome/test/base/search_test_utils.h new file mode 100644 index 0000000..144f623 --- /dev/null +++ b/chrome/test/base/search_test_utils.h @@ -0,0 +1,17 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_TEST_BASE_SEARCH_TEST_UTILS_H_ +#define CHROME_TEST_BASE_SEARCH_TEST_UTILS_H_ + +class TemplateURLService; + +namespace search_test_utils { + +// Blocks until |service| finishes loading. +void WaitForTemplateURLServiceToLoad(TemplateURLService* service); + +} // namespace search_test_utils + +#endif // CHROME_TEST_BASE_SEARCH_TEST_UTILS_H_ diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc index 6a9f0b2..9355756 100644 --- a/chrome/test/base/ui_test_utils.cc +++ b/chrome/test/base/ui_test_utils.cc @@ -47,7 +47,6 @@ #include "components/history/core/browser/history_service_observer.h" #include "components/omnibox/browser/autocomplete_controller.h" #include "components/omnibox/browser/omnibox_view.h" -#include "components/search_engines/template_url_service.h" #include "content/public/browser/download_item.h" #include "content/public/browser/download_manager.h" #include "content/public/browser/geolocation_provider.h" @@ -76,7 +75,6 @@ #include "ui/aura/window_event_dispatcher.h" #endif -using content::NativeWebKeyboardEvent; using content::NavigationController; using content::NavigationEntry; using content::OpenURLParams; @@ -149,7 +147,6 @@ void NavigateToURL(chrome::NavigateParams* params) { content::WaitForLoadStop(params->target_contents); } - void NavigateToURLWithPost(Browser* browser, const GURL& url) { chrome::NavigateParams params(browser, url, ui::PAGE_TRANSITION_FORM_SUBMIT); @@ -326,20 +323,6 @@ int FindInPage(WebContents* tab, return observer.number_of_matches(); } -void WaitForTemplateURLServiceToLoad(TemplateURLService* service) { - if (service->loaded()) - return; - scoped_refptr<content::MessageLoopRunner> message_loop_runner = - new content::MessageLoopRunner; - scoped_ptr<TemplateURLService::Subscription> subscription = - service->RegisterOnLoadedCallback( - message_loop_runner->QuitClosure()); - service->Load(); - message_loop_runner->Run(); - - ASSERT_TRUE(service->loaded()); -} - void DownloadURL(Browser* browser, const GURL& download_url) { base::ScopedTempDir downloads_directory; ASSERT_TRUE(downloads_directory.CreateUniqueTempDir()); @@ -371,12 +354,12 @@ void SendToOmniboxAndSubmit(LocationBar* location_bar, } } -Browser* GetBrowserNotInSet(std::set<Browser*> excluded_browsers) { +Browser* GetBrowserNotInSet(const std::set<Browser*>& excluded_browsers) { for (chrome::BrowserIterator it; !it.done(); it.Next()) { if (excluded_browsers.find(*it) == excluded_browsers.end()) return *it; } - return NULL; + return nullptr; } namespace { diff --git a/chrome/test/base/ui_test_utils.h b/chrome/test/base/ui_test_utils.h index e5a359a..cd95c4b 100644 --- a/chrome/test/base/ui_test_utils.h +++ b/chrome/test/base/ui_test_utils.h @@ -29,7 +29,6 @@ class Browser; class LocationBar; class Profile; -class TemplateURLService; namespace app_modal { class AppModalDialog; @@ -143,9 +142,6 @@ int FindInPage(content::WebContents* tab, int* ordinal, gfx::Rect* selection_rect); -// Blocks until |service| finishes loading. -void WaitForTemplateURLServiceToLoad(TemplateURLService* service); - // Blocks until the |history_service|'s history finishes loading. void WaitForHistoryToLoad(history::HistoryService* history_service); @@ -157,7 +153,7 @@ void SendToOmniboxAndSubmit(LocationBar* location_bar, const std::string& input); // Gets the first browser that is not in the specified set. -Browser* GetBrowserNotInSet(std::set<Browser*> excluded_browsers); +Browser* GetBrowserNotInSet(const std::set<Browser*>& excluded_browsers); // Gets the size and value of the cookie string for |url| in the given tab. // Can be called from any thread. |