Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/tab_android.h" | 5 #include "chrome/browser/android/tab_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "base/feature_list.h" | |
| 11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 14 #include "blimp/client/public/blimp_client_context.h" | 15 #include "blimp/client/public/blimp_client_context.h" |
| 15 #include "blimp/client/public/contents/blimp_contents.h" | 16 #include "blimp/client/public/contents/blimp_contents.h" |
| 16 #include "blimp/client/public/contents/blimp_contents_view.h" | 17 #include "blimp/client/public/contents/blimp_contents_view.h" |
| 17 #include "blimp/client/public/contents/blimp_navigation_controller.h" | 18 #include "blimp/client/public/contents/blimp_navigation_controller.h" |
| 18 #include "cc/layers/layer.h" | 19 #include "cc/layers/layer.h" |
| 19 #include "chrome/browser/android/blimp/blimp_client_context_factory.h" | 20 #include "chrome/browser/android/blimp/blimp_client_context_factory.h" |
| 20 #include "chrome/browser/android/compositor/tab_content_manager.h" | 21 #include "chrome/browser/android/compositor/tab_content_manager.h" |
| 21 #include "chrome/browser/android/metrics/uma_utils.h" | 22 #include "chrome/browser/android/metrics/uma_utils.h" |
| 22 #include "chrome/browser/android/offline_pages/offline_page_bridge.h" | 23 #include "chrome/browser/android/offline_pages/offline_page_bridge.h" |
| 23 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 24 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
| 24 #include "chrome/browser/android/offline_pages/offline_page_utils.h" | 25 #include "chrome/browser/android/offline_pages/offline_page_utils.h" |
| 26 #include "chrome/browser/android/search_geolocation_disclosure_infobar_delegate. h" | |
| 25 #include "chrome/browser/android/tab_web_contents_delegate_android.h" | 27 #include "chrome/browser/android/tab_web_contents_delegate_android.h" |
| 26 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 28 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 27 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 29 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
| 28 #include "chrome/browser/browser_about_handler.h" | 30 #include "chrome/browser/browser_about_handler.h" |
| 29 #include "chrome/browser/chrome_notification_types.h" | 31 #include "chrome/browser/chrome_notification_types.h" |
| 30 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 32 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 31 #include "chrome/browser/infobars/infobar_service.h" | 33 #include "chrome/browser/infobars/infobar_service.h" |
| 34 #include "chrome/browser/permissions/permission_manager.h" | |
| 32 #include "chrome/browser/prerender/prerender_contents.h" | 35 #include "chrome/browser/prerender/prerender_contents.h" |
| 33 #include "chrome/browser/prerender/prerender_manager.h" | 36 #include "chrome/browser/prerender/prerender_manager.h" |
| 34 #include "chrome/browser/prerender/prerender_manager_factory.h" | 37 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 35 #include "chrome/browser/printing/print_view_manager_basic.h" | 38 #include "chrome/browser/printing/print_view_manager_basic.h" |
| 36 #include "chrome/browser/profiles/profile.h" | 39 #include "chrome/browser/profiles/profile.h" |
| 37 #include "chrome/browser/profiles/profile_android.h" | 40 #include "chrome/browser/profiles/profile_android.h" |
| 38 #include "chrome/browser/profiles/profile_manager.h" | 41 #include "chrome/browser/profiles/profile_manager.h" |
| 39 #include "chrome/browser/search/instant_service.h" | 42 #include "chrome/browser/search/instant_service.h" |
| 40 #include "chrome/browser/search/instant_service_factory.h" | 43 #include "chrome/browser/search/instant_service_factory.h" |
| 41 #include "chrome/browser/search/search.h" | 44 #include "chrome/browser/search/search.h" |
| 45 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
| 42 #include "chrome/browser/sessions/session_tab_helper.h" | 46 #include "chrome/browser/sessions/session_tab_helper.h" |
| 43 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 47 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 44 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h" | 48 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h" |
| 45 #include "chrome/browser/tab_contents/tab_util.h" | 49 #include "chrome/browser/tab_contents/tab_util.h" |
| 46 #include "chrome/browser/ui/android/content_settings/popup_blocked_infobar_deleg ate.h" | 50 #include "chrome/browser/ui/android/content_settings/popup_blocked_infobar_deleg ate.h" |
| 47 #include "chrome/browser/ui/android/context_menu_helper.h" | 51 #include "chrome/browser/ui/android/context_menu_helper.h" |
| 48 #include "chrome/browser/ui/android/infobars/infobar_container_android.h" | 52 #include "chrome/browser/ui/android/infobars/infobar_container_android.h" |
| 49 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 53 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
| 50 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 54 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 51 #include "chrome/browser/ui/android/view_android_helper.h" | 55 #include "chrome/browser/ui/android/view_android_helper.h" |
| 52 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" | 56 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
| 53 #include "chrome/browser/ui/search/instant_search_prerenderer.h" | 57 #include "chrome/browser/ui/search/instant_search_prerenderer.h" |
| 54 #include "chrome/browser/ui/search/search_tab_helper.h" | 58 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 55 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 59 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 56 #include "chrome/browser/ui/tab_helpers.h" | 60 #include "chrome/browser/ui/tab_helpers.h" |
| 61 #include "chrome/common/chrome_features.h" | |
| 57 #include "chrome/common/render_messages.h" | 62 #include "chrome/common/render_messages.h" |
| 58 #include "chrome/common/search/instant_types.h" | 63 #include "chrome/common/search/instant_types.h" |
| 59 #include "chrome/common/url_constants.h" | 64 #include "chrome/common/url_constants.h" |
| 60 #include "components/bookmarks/browser/bookmark_model.h" | 65 #include "components/bookmarks/browser/bookmark_model.h" |
| 61 #include "components/bookmarks/browser/bookmark_node.h" | 66 #include "components/bookmarks/browser/bookmark_node.h" |
| 62 #include "components/bookmarks/browser/bookmark_utils.h" | 67 #include "components/bookmarks/browser/bookmark_utils.h" |
| 63 #include "components/bookmarks/managed/managed_bookmark_service.h" | 68 #include "components/bookmarks/managed/managed_bookmark_service.h" |
| 64 #include "components/dom_distiller/core/url_utils.h" | 69 #include "components/dom_distiller/core/url_utils.h" |
| 65 #include "components/favicon/content/content_favicon_driver.h" | 70 #include "components/favicon/content/content_favicon_driver.h" |
| 66 #include "components/navigation_interception/intercept_navigation_delegate.h" | 71 #include "components/navigation_interception/intercept_navigation_delegate.h" |
| 67 #include "components/navigation_interception/navigation_params.h" | 72 #include "components/navigation_interception/navigation_params.h" |
| 68 #include "components/offline_pages/offline_page_feature.h" | 73 #include "components/offline_pages/offline_page_feature.h" |
| 69 #include "components/offline_pages/offline_page_item.h" | 74 #include "components/offline_pages/offline_page_item.h" |
| 70 #include "components/offline_pages/offline_page_model.h" | 75 #include "components/offline_pages/offline_page_model.h" |
| 76 #include "components/search_engines/template_url.h" | |
| 77 #include "components/search_engines/template_url_service.h" | |
| 71 #include "components/sessions/content/content_live_tab.h" | 78 #include "components/sessions/content/content_live_tab.h" |
| 72 #include "components/sessions/core/tab_restore_service.h" | 79 #include "components/sessions/core/tab_restore_service.h" |
| 73 #include "components/url_formatter/url_fixer.h" | 80 #include "components/url_formatter/url_fixer.h" |
| 74 #include "content/public/browser/android/compositor.h" | 81 #include "content/public/browser/android/compositor.h" |
| 75 #include "content/public/browser/browser_thread.h" | 82 #include "content/public/browser/browser_thread.h" |
| 76 #include "content/public/browser/interstitial_page.h" | 83 #include "content/public/browser/interstitial_page.h" |
| 77 #include "content/public/browser/navigation_entry.h" | 84 #include "content/public/browser/navigation_entry.h" |
| 78 #include "content/public/browser/notification_service.h" | 85 #include "content/public/browser/notification_service.h" |
| 86 #include "content/public/browser/permission_type.h" | |
| 79 #include "content/public/browser/render_frame_host.h" | 87 #include "content/public/browser/render_frame_host.h" |
| 80 #include "content/public/browser/render_process_host.h" | 88 #include "content/public/browser/render_process_host.h" |
| 81 #include "content/public/browser/render_view_host.h" | 89 #include "content/public/browser/render_view_host.h" |
| 82 #include "content/public/browser/user_metrics.h" | 90 #include "content/public/browser/user_metrics.h" |
| 83 #include "content/public/browser/web_contents.h" | 91 #include "content/public/browser/web_contents.h" |
| 84 #include "content/public/common/browser_controls_state.h" | 92 #include "content/public/common/browser_controls_state.h" |
| 85 #include "content/public/common/resource_request_body.h" | 93 #include "content/public/common/resource_request_body.h" |
| 86 #include "jni/Tab_jni.h" | 94 #include "jni/Tab_jni.h" |
| 87 #include "net/base/escape.h" | 95 #include "net/base/escape.h" |
| 88 #include "skia/ext/image_operations.h" | 96 #include "skia/ext/image_operations.h" |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 search_tab_helper->SupportsInstant()) { | 638 search_tab_helper->SupportsInstant()) { |
| 631 EmbeddedSearchRequestParams request_params(gurl); | 639 EmbeddedSearchRequestParams request_params(gurl); |
| 632 search_tab_helper->Submit(search_terms, request_params); | 640 search_tab_helper->Submit(search_terms, request_params); |
| 633 return DEFAULT_PAGE_LOAD; | 641 return DEFAULT_PAGE_LOAD; |
| 634 } | 642 } |
| 635 load_params.is_renderer_initiated = is_renderer_initiated; | 643 load_params.is_renderer_initiated = is_renderer_initiated; |
| 636 load_params.should_replace_current_entry = should_replace_current_entry; | 644 load_params.should_replace_current_entry = should_replace_current_entry; |
| 637 load_params.intent_received_timestamp = intent_received_timestamp; | 645 load_params.intent_received_timestamp = intent_received_timestamp; |
| 638 load_params.has_user_gesture = has_user_gesture; | 646 load_params.has_user_gesture = has_user_gesture; |
| 639 web_contents()->GetController().LoadURLWithParams(load_params); | 647 web_contents()->GetController().LoadURLWithParams(load_params); |
| 648 | |
| 649 MaybeShowDefaultSearchGeolocationDisclosure(gurl); | |
|
gone
2016/11/04 23:21:48
Is it possible to add this to a WebContentsObserve
benwells
2016/11/07 08:36:06
Done.
| |
| 640 } | 650 } |
| 641 return DEFAULT_PAGE_LOAD; | 651 return DEFAULT_PAGE_LOAD; |
| 642 } | 652 } |
| 643 | 653 |
| 644 void TabAndroid::SetActiveNavigationEntryTitleForUrl( | 654 void TabAndroid::SetActiveNavigationEntryTitleForUrl( |
| 645 JNIEnv* env, | 655 JNIEnv* env, |
| 646 const JavaParamRef<jobject>& obj, | 656 const JavaParamRef<jobject>& obj, |
| 647 const JavaParamRef<jstring>& jurl, | 657 const JavaParamRef<jstring>& jurl, |
| 648 const JavaParamRef<jstring>& jtitle) { | 658 const JavaParamRef<jstring>& jtitle) { |
| 649 DCHECK(web_contents()); | 659 DCHECK(web_contents()); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 882 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 892 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 883 TRACE_EVENT0("native", "TabAndroid::Init"); | 893 TRACE_EVENT0("native", "TabAndroid::Init"); |
| 884 // This will automatically bind to the Java object and pass ownership there. | 894 // This will automatically bind to the Java object and pass ownership there. |
| 885 new TabAndroid(env, obj); | 895 new TabAndroid(env, obj); |
| 886 } | 896 } |
| 887 | 897 |
| 888 // static | 898 // static |
| 889 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 899 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
| 890 return RegisterNativesImpl(env); | 900 return RegisterNativesImpl(env); |
| 891 } | 901 } |
| 902 | |
| 903 void TabAndroid::MaybeShowDefaultSearchGeolocationDisclosure(GURL gurl) { | |
| 904 if (base::FeatureList::IsEnabled(features::kConsistentOmniboxGeolocation)) { | |
| 905 TemplateURLService* template_url_service = | |
| 906 TemplateURLServiceFactory::GetForProfile(GetProfile()); | |
| 907 // Only show the disclosure for default search navigations from the omnibox. | |
| 908 bool is_search_url = | |
| 909 template_url_service->IsSearchResultsPageFromDefaultSearchProvider( | |
| 910 gurl); | |
| 911 if (!is_search_url) | |
| 912 return; | |
| 913 | |
| 914 // Only show the disclosure if Google is the default search engine. | |
| 915 TemplateURL* default_search = | |
| 916 template_url_service->GetDefaultSearchProvider(); | |
| 917 if (!default_search || | |
| 918 !default_search->url_ref().HasGoogleBaseURLs( | |
| 919 template_url_service->search_terms_data())) { | |
| 920 return; | |
| 921 } | |
| 922 | |
| 923 // Perform Java side checks for whether the disclosure should be shown. | |
| 924 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 925 if (!Java_Tab_couldShowDefaultSearchGeolocationDisclosure( | |
| 926 env, weak_java_tab_.get(env))) { | |
| 927 return; | |
| 928 } | |
| 929 | |
| 930 // Only show the disclosure if the geolocation permission is set to ASK | |
| 931 // (i.e. has not been explicitly set or revoked). | |
| 932 blink::mojom::PermissionStatus status = | |
| 933 PermissionManager::Get(GetProfile()) | |
| 934 ->GetPermissionStatus(content::PermissionType::GEOLOCATION, gurl, | |
| 935 gurl); | |
| 936 if (status != blink::mojom::PermissionStatus::ASK) | |
| 937 return; | |
| 938 | |
| 939 // All good, let's show the disclosure. | |
| 940 SearchGeolocationDisclosureInfoBarDelegate::Create(web_contents()); | |
| 941 } | |
| 942 } | |
| OLD | NEW |