| Index: chrome/browser/android/tab_android.cc
|
| diff --git a/chrome/browser/android/tab_android.cc b/chrome/browser/android/tab_android.cc
|
| index 7410dde72b60061ed30e2da1cb1549b5f3914c9b..cf4f3441badb200c698c96fa1f3fa4ec7be6912a 100644
|
| --- a/chrome/browser/android/tab_android.cc
|
| +++ b/chrome/browser/android/tab_android.cc
|
| @@ -5,11 +5,18 @@
|
| #include "chrome/browser/android/tab_android.h"
|
|
|
| #include "base/android/jni_android.h"
|
| +#include "base/android/jni_array.h"
|
| #include "base/android/jni_string.h"
|
| #include "base/debug/trace_event.h"
|
| #include "chrome/browser/android/chrome_web_contents_delegate_android.h"
|
| +#include "chrome/browser/browser_about_handler.h"
|
| #include "chrome/browser/chrome_notification_types.h"
|
| #include "chrome/browser/content_settings/tab_specific_content_settings.h"
|
| +#include "chrome/browser/google/google_url_tracker.h"
|
| +#include "chrome/browser/google/google_util.h"
|
| +#include "chrome/browser/prerender/prerender_contents.h"
|
| +#include "chrome/browser/prerender/prerender_manager.h"
|
| +#include "chrome/browser/prerender/prerender_manager_factory.h"
|
| #include "chrome/browser/printing/print_view_manager_basic.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/profiles/profile_android.h"
|
| @@ -25,11 +32,15 @@
|
| #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
|
| #include "chrome/browser/ui/tab_helpers.h"
|
| #include "chrome/browser/ui/toolbar/toolbar_model_impl.h"
|
| +#include "chrome/common/net/url_fixer_upper.h"
|
| +#include "chrome/common/url_constants.h"
|
| #include "content/public/browser/android/content_view_core.h"
|
| #include "content/public/browser/navigation_entry.h"
|
| #include "content/public/browser/notification_service.h"
|
| +#include "content/public/browser/user_metrics.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "jni/Tab_jni.h"
|
| +#include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
|
|
|
| TabAndroid* TabAndroid::FromWebContents(content::WebContents* web_contents) {
|
| CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(web_contents);
|
| @@ -181,6 +192,25 @@ bool TabAndroid::ShouldWelcomePageLinkToTermsOfService() {
|
| return false;
|
| }
|
|
|
| +bool TabAndroid::HasPrerenderedUrl(GURL gurl) {
|
| + prerender::PrerenderManager* prerender_manager = GetPrerenderManager();
|
| + if (!prerender_manager)
|
| + return false;
|
| +
|
| + std::vector<content::WebContents*> contents =
|
| + prerender_manager->GetAllPrerenderingContents();
|
| + prerender::PrerenderContents* prerender_contents;
|
| + for (size_t i = 0; i < contents.size(); ++i) {
|
| + prerender_contents = prerender_manager->
|
| + GetPrerenderContents(contents.at(i));
|
| + if (prerender_contents->prerender_url() == gurl &&
|
| + prerender_contents->has_finished_loading()) {
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| void TabAndroid::SwapTabContents(content::WebContents* old_contents,
|
| content::WebContents* new_contents,
|
| bool did_start_load,
|
| @@ -343,6 +373,86 @@ base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetProfileAndroid(
|
| return profile_android->GetJavaObject();
|
| }
|
|
|
| +TabAndroid::TabLoadStatus TabAndroid::LoadUrl(JNIEnv* env,
|
| + jobject obj,
|
| + jstring url,
|
| + jstring j_extra_headers,
|
| + jbyteArray j_post_data,
|
| + jint page_transition,
|
| + jstring j_referrer_url,
|
| + jint referrer_policy) {
|
| + content::ContentViewCore* content_view = GetContentViewCore();
|
| + if (!content_view)
|
| + return PAGE_LOAD_FAILED;
|
| +
|
| + GURL gurl(base::android::ConvertJavaStringToUTF8(env, url));
|
| + if (gurl.is_empty())
|
| + return PAGE_LOAD_FAILED;
|
| +
|
| + // If the page was prerendered, use it.
|
| + // Note in incognito mode, we don't have a PrerenderManager.
|
| +
|
| + prerender::PrerenderManager* prerender_manager =
|
| + prerender::PrerenderManagerFactory::GetForProfile(GetProfile());
|
| + 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());
|
| + if (prerender_manager->MaybeUsePrerenderedPage(gurl, ¶ms)) {
|
| + return prefetched_page_loaded ?
|
| + FULL_PRERENDERED_PAGE_LOAD : PARTIAL_PRERENDERED_PAGE_LOAD;
|
| + }
|
| + }
|
| +
|
| + GURL fixed_url(URLFixerUpper::FixupURL(gurl.possibly_invalid_spec(),
|
| + std::string()));
|
| + if (!fixed_url.is_valid())
|
| + return PAGE_LOAD_FAILED;
|
| +
|
| + if (!HandleNonNavigationAboutURL(fixed_url)) {
|
| + // Notify the GoogleURLTracker of searches, it might want to change the
|
| + // actual Google site used (for instance when in the UK, google.co.uk, when
|
| + // in the US google.com).
|
| + // Note that this needs to happen before we initiate the navigation as the
|
| + // GoogleURLTracker uses the navigation pending notification to trigger the
|
| + // infobar.
|
| + if (google_util::IsGoogleSearchUrl(fixed_url) &&
|
| + (page_transition & content::PAGE_TRANSITION_GENERATED)) {
|
| + GoogleURLTracker::GoogleURLSearchCommitted(GetProfile());
|
| + }
|
| +
|
| + // Record UMA "ShowHistory" here. That way it'll pick up both user
|
| + // typing chrome://history as well as selecting from the drop down menu.
|
| + if (fixed_url.spec() == chrome::kChromeUIHistoryURL) {
|
| + content::RecordAction(base::UserMetricsAction("ShowHistory"));
|
| + }
|
| +
|
| + content::NavigationController::LoadURLParams load_params(fixed_url);
|
| + if (j_extra_headers) {
|
| + load_params.extra_headers = base::android::ConvertJavaStringToUTF8(
|
| + env,
|
| + j_extra_headers);
|
| + }
|
| + if (j_post_data) {
|
| + load_params.load_type =
|
| + content::NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST;
|
| + std::vector<uint8> post_data;
|
| + base::android::JavaByteArrayToByteVector(env, j_post_data, &post_data);
|
| + load_params.browser_initiated_post_data =
|
| + base::RefCountedBytes::TakeVector(&post_data);
|
| + }
|
| + load_params.transition_type =
|
| + content::PageTransitionFromInt(page_transition);
|
| + if (j_referrer_url) {
|
| + load_params.referrer = content::Referrer(
|
| + GURL(base::android::ConvertJavaStringToUTF8(env, j_referrer_url)),
|
| + static_cast<blink::WebReferrerPolicy>(referrer_policy));
|
| + }
|
| + content_view->LoadUrl(load_params);
|
| + }
|
| + return DEFAULT_PAGE_LOAD;
|
| +}
|
| +
|
| ToolbarModel::SecurityLevel TabAndroid::GetSecurityLevel(JNIEnv* env,
|
| jobject obj) {
|
| return ToolbarModelImpl::GetSecurityLevelForWebContents(web_contents());
|
| @@ -382,6 +492,13 @@ bool TabAndroid::Print(JNIEnv* env, jobject obj) {
|
| return true;
|
| }
|
|
|
| +prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const {
|
| + Profile* profile = GetProfile();
|
| + if (!profile)
|
| + return NULL;
|
| + return prerender::PrerenderManagerFactory::GetForProfile(profile);
|
| +}
|
| +
|
| static void Init(JNIEnv* env, jobject obj) {
|
| TRACE_EVENT0("native", "TabAndroid::Init");
|
| // This will automatically bind to the Java object and pass ownership there.
|
|
|