Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / android / compositor / layer_title_cache.cc
blobac8c77622d4f9940735615358fc2690aa7dfd3c9
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/android/compositor/layer_title_cache.h"
7 #include <android/bitmap.h>
9 #include "base/memory/scoped_ptr.h"
10 #include "cc/layers/layer.h"
11 #include "cc/layers/ui_resource_layer.h"
12 #include "chrome/browser/android/compositor/decoration_title.h"
13 #include "jni/LayerTitleCache_jni.h"
14 #include "ui/android/resources/resource_manager.h"
15 #include "ui/gfx/android/java_bitmap.h"
16 #include "ui/gfx/geometry/point_f.h"
17 #include "ui/gfx/geometry/rect_f.h"
18 #include "ui/gfx/geometry/size.h"
20 namespace chrome {
21 namespace android {
23 // static
24 LayerTitleCache* LayerTitleCache::FromJavaObject(jobject jobj) {
25 if (!jobj)
26 return NULL;
27 return reinterpret_cast<LayerTitleCache*>(Java_LayerTitleCache_getNativePtr(
28 base::android::AttachCurrentThread(), jobj));
31 LayerTitleCache::LayerTitleCache(JNIEnv* env,
32 jobject obj,
33 jint fade_width,
34 jint favicon_start_padding,
35 jint favicon_end_padding,
36 jint spinner_resource_id,
37 jint spinner_incognito_resource_id)
38 : weak_java_title_cache_(env, obj),
39 fade_width_(fade_width),
40 favicon_start_padding_(favicon_start_padding),
41 favicon_end_padding_(favicon_end_padding),
42 spinner_resource_id_(spinner_resource_id),
43 spinner_incognito_resource_id_(spinner_incognito_resource_id),
44 resource_manager_(nullptr) {
47 void LayerTitleCache::Destroy(JNIEnv* env, jobject obj) {
48 delete this;
51 void LayerTitleCache::UpdateLayer(JNIEnv* env,
52 jobject obj,
53 jint tab_id,
54 jint title_resource_id,
55 jint favicon_resource_id,
56 bool is_incognito,
57 bool is_rtl) {
58 DecorationTitle* title_layer = layer_cache_.Lookup(tab_id);
59 if (title_layer == NULL) {
60 layer_cache_.AddWithID(
61 new DecorationTitle(
62 this, resource_manager_, title_resource_id, favicon_resource_id,
63 spinner_resource_id_, spinner_incognito_resource_id_, fade_width_,
64 favicon_start_padding_, favicon_end_padding_, is_incognito, is_rtl),
65 tab_id);
66 } else {
67 if (title_resource_id != -1 && favicon_resource_id != -1) {
68 title_layer->Update(title_resource_id, favicon_resource_id, fade_width_,
69 favicon_start_padding_, favicon_end_padding_,
70 is_incognito, is_rtl);
71 } else {
72 layer_cache_.Remove(tab_id);
77 void LayerTitleCache::ClearExcept(JNIEnv* env, jobject obj, jint except_id) {
78 IDMap<DecorationTitle, IDMapOwnPointer>::iterator iter(&layer_cache_);
79 for (; !iter.IsAtEnd(); iter.Advance()) {
80 const int id = iter.GetCurrentKey();
81 if (id != except_id)
82 layer_cache_.Remove(id);
86 DecorationTitle* LayerTitleCache::GetTitleLayer(int tab_id) {
87 return layer_cache_.Lookup(tab_id);
90 void LayerTitleCache::SetResourceManager(
91 ui::ResourceManager* resource_manager) {
92 resource_manager_ = resource_manager;
94 IDMap<DecorationTitle, IDMapOwnPointer>::iterator iter(&layer_cache_);
95 for (; !iter.IsAtEnd(); iter.Advance()) {
96 iter.GetCurrentValue()->SetResourceManager(resource_manager_);
100 LayerTitleCache::~LayerTitleCache() {
103 bool RegisterLayerTitleCache(JNIEnv* env) {
104 return RegisterNativesImpl(env);
107 // ----------------------------------------------------------------------------
108 // Native JNI methods
109 // ----------------------------------------------------------------------------
111 jlong Init(JNIEnv* env,
112 const JavaParamRef<jobject>& obj,
113 jint fade_width,
114 jint favicon_start_padding,
115 jint favicon_end_padding,
116 jint spinner_resource_id,
117 jint spinner_incognito_resource_id) {
118 LayerTitleCache* cache = new LayerTitleCache(
119 env, obj, fade_width, favicon_start_padding, favicon_end_padding,
120 spinner_resource_id, spinner_incognito_resource_id);
121 return reinterpret_cast<intptr_t>(cache);
124 } // namespace android
125 } // namespace chrome