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/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #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_view.h" | |
17 #include "blimp/client/public/contents/blimp_navigation_controller.h" | |
18 #include "cc/layers/layer.h" | 14 #include "cc/layers/layer.h" |
19 #include "chrome/browser/android/blimp/blimp_client_context_factory.h" | |
20 #include "chrome/browser/android/compositor/tab_content_manager.h" | 15 #include "chrome/browser/android/compositor/tab_content_manager.h" |
21 #include "chrome/browser/android/metrics/uma_utils.h" | 16 #include "chrome/browser/android/metrics/uma_utils.h" |
22 #include "chrome/browser/android/offline_pages/offline_page_bridge.h" | 17 #include "chrome/browser/android/offline_pages/offline_page_bridge.h" |
23 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 18 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
24 #include "chrome/browser/android/offline_pages/offline_page_utils.h" | 19 #include "chrome/browser/android/offline_pages/offline_page_utils.h" |
25 #include "chrome/browser/android/tab_web_contents_delegate_android.h" | 20 #include "chrome/browser/android/tab_web_contents_delegate_android.h" |
26 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
27 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 22 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
28 #include "chrome/browser/browser_about_handler.h" | 23 #include "chrome/browser/browser_about_handler.h" |
29 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 356 |
362 if (favicon_driver) | 357 if (favicon_driver) |
363 favicon_driver->AddObserver(this); | 358 favicon_driver->AddObserver(this); |
364 | 359 |
365 synced_tab_delegate_->SetWebContents(web_contents()); | 360 synced_tab_delegate_->SetWebContents(web_contents()); |
366 | 361 |
367 // Verify that the WebContents this tab represents matches the expected | 362 // Verify that the WebContents this tab represents matches the expected |
368 // off the record state. | 363 // off the record state. |
369 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); | 364 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); |
370 | 365 |
371 if (!blimp_contents_) | 366 content_layer_->InsertChild(web_contents_->GetNativeView()->GetLayer(), 0); |
372 content_layer_->InsertChild(web_contents_->GetNativeView()->GetLayer(), 0); | |
373 } | |
374 | |
375 base::android::ScopedJavaLocalRef<jobject> TabAndroid::InitBlimpContents( | |
376 JNIEnv* env, | |
377 const JavaParamRef<jobject>& obj, | |
378 const JavaParamRef<jobject>& j_profile, | |
379 jlong window_android_ptr) { | |
380 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile.obj()); | |
381 DCHECK(!profile->IsOffTheRecord()); | |
382 blimp::client::BlimpClientContext* context = | |
383 BlimpClientContextFactory::GetForBrowserContext(profile); | |
384 DCHECK(context); | |
385 ui::WindowAndroid* window = | |
386 reinterpret_cast<ui::WindowAndroid*>(window_android_ptr); | |
387 blimp_contents_ = context->CreateBlimpContents(window); | |
388 // If creating a BlimpContents failed, fall back to WebContents-based by | |
389 // doing an early out here. | |
390 if (!blimp_contents_) | |
391 return nullptr; | |
392 | |
393 // Let's detach the layer from WebContents first, just to be sure. | |
394 if (web_contents_ && web_contents_->GetNativeView() && | |
395 web_contents_->GetNativeView()->GetLayer()) { | |
396 cc::Layer* web_contents_layer = web_contents_->GetNativeView()->GetLayer(); | |
397 if (web_contents_layer->parent() == content_layer_.get()) | |
398 web_contents_layer->RemoveFromParent(); | |
399 } | |
400 | |
401 // Attach the layer holding the tab contents to the |content_layer_|. | |
402 content_layer_->InsertChild( | |
403 blimp_contents_->GetView()->GetNativeView()->GetLayer(), 0); | |
404 | |
405 return blimp_contents_->GetJavaObject(); | |
406 } | 367 } |
407 | 368 |
408 void TabAndroid::UpdateDelegates( | 369 void TabAndroid::UpdateDelegates( |
409 JNIEnv* env, | 370 JNIEnv* env, |
410 const JavaParamRef<jobject>& obj, | 371 const JavaParamRef<jobject>& obj, |
411 const JavaParamRef<jobject>& jweb_contents_delegate, | 372 const JavaParamRef<jobject>& jweb_contents_delegate, |
412 const JavaParamRef<jobject>& jcontext_menu_populator) { | 373 const JavaParamRef<jobject>& jcontext_menu_populator) { |
413 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( | 374 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( |
414 jcontext_menu_populator); | 375 jcontext_menu_populator); |
415 web_contents_delegate_ = | 376 web_contents_delegate_ = |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 if (!fixed_url.is_valid()) | 482 if (!fixed_url.is_valid()) |
522 return PAGE_LOAD_FAILED; | 483 return PAGE_LOAD_FAILED; |
523 | 484 |
524 if (!HandleNonNavigationAboutURL(fixed_url)) { | 485 if (!HandleNonNavigationAboutURL(fixed_url)) { |
525 // Record UMA "ShowHistory" here. That way it'll pick up both user | 486 // Record UMA "ShowHistory" here. That way it'll pick up both user |
526 // typing chrome://history as well as selecting from the drop down menu. | 487 // typing chrome://history as well as selecting from the drop down menu. |
527 if (fixed_url.spec() == chrome::kChromeUIHistoryURL) { | 488 if (fixed_url.spec() == chrome::kChromeUIHistoryURL) { |
528 content::RecordAction(base::UserMetricsAction("ShowHistory")); | 489 content::RecordAction(base::UserMetricsAction("ShowHistory")); |
529 } | 490 } |
530 | 491 |
531 if (blimp_contents()) { | |
532 blimp_contents()->GetNavigationController().LoadURL(fixed_url); | |
533 return DEFAULT_PAGE_LOAD; | |
534 } | |
535 | |
536 content::NavigationController::LoadURLParams load_params(fixed_url); | 492 content::NavigationController::LoadURLParams load_params(fixed_url); |
537 if (j_extra_headers) { | 493 if (j_extra_headers) { |
538 load_params.extra_headers = base::android::ConvertJavaStringToUTF8( | 494 load_params.extra_headers = base::android::ConvertJavaStringToUTF8( |
539 env, | 495 env, |
540 j_extra_headers); | 496 j_extra_headers); |
541 } | 497 } |
542 if (j_post_data) { | 498 if (j_post_data) { |
543 load_params.load_type = | 499 load_params.load_type = |
544 content::NavigationController::LOAD_TYPE_HTTP_POST; | 500 content::NavigationController::LOAD_TYPE_HTTP_POST; |
545 load_params.post_data = | 501 load_params.post_data = |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 759 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
804 TRACE_EVENT0("native", "TabAndroid::Init"); | 760 TRACE_EVENT0("native", "TabAndroid::Init"); |
805 // This will automatically bind to the Java object and pass ownership there. | 761 // This will automatically bind to the Java object and pass ownership there. |
806 new TabAndroid(env, obj); | 762 new TabAndroid(env, obj); |
807 } | 763 } |
808 | 764 |
809 // static | 765 // static |
810 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 766 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
811 return RegisterNativesImpl(env); | 767 return RegisterNativesImpl(env); |
812 } | 768 } |
OLD | NEW |