Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Unified Diff: chrome/browser/android/webapps/add_to_homescreen_helper.cc

Issue 1288903002: Refactor ShortcutHelper and merge in BookmarkUtils (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/webapps/add_to_homescreen_helper.cc
diff --git a/chrome/browser/android/shortcut_helper.cc b/chrome/browser/android/webapps/add_to_homescreen_helper.cc
similarity index 53%
copy from chrome/browser/android/shortcut_helper.cc
copy to chrome/browser/android/webapps/add_to_homescreen_helper.cc
index 58d80c2037aef34d49aa40af849dba064553a7b9..81785a1e55656e7299ce2ff0221efad803de24ac 100644
--- a/chrome/browser/android/shortcut_helper.cc
+++ b/chrome/browser/android/webapps/add_to_homescreen_helper.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/android/shortcut_helper.h"
+#include "chrome/browser/android/webapps/add_to_homescreen_helper.h"
#include <jni.h>
@@ -12,11 +12,12 @@
#include "base/location.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/android/shortcut_helper.h"
#include "chrome/browser/banners/app_banner_settings_helper.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/manifest.h"
-#include "jni/ShortcutHelper_jni.h"
+#include "jni/AddToHomescreenHelper_jni.h"
#include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/color_analysis.h"
#include "url/gurl.h"
@@ -26,53 +27,55 @@ using content::Manifest;
jlong Initialize(JNIEnv* env, jobject obj, jobject java_web_contents) {
content::WebContents* web_contents =
content::WebContents::FromJavaWebContents(java_web_contents);
- ShortcutHelper* shortcut_helper = new ShortcutHelper(env, obj, web_contents);
- return reinterpret_cast<intptr_t>(shortcut_helper);
+ AddToHomescreenHelper* add_to_homescreen_helper = new AddToHomescreenHelper(
+ env, obj, web_contents);
+ return reinterpret_cast<intptr_t>(add_to_homescreen_helper);
}
-ShortcutHelper::ShortcutHelper(JNIEnv* env,
- jobject obj,
- content::WebContents* web_contents)
+AddToHomescreenHelper::AddToHomescreenHelper(JNIEnv* env,
+ jobject obj,
+ content::WebContents* web_contents)
: add_shortcut_pending_(false),
- data_fetcher_(new ShortcutDataFetcher(web_contents, this)) {
+ data_fetcher_(new AddToHomescreenDataFetcher(web_contents, this)) {
java_ref_.Reset(env, obj);
}
-ShortcutHelper::~ShortcutHelper() {
+AddToHomescreenHelper::~AddToHomescreenHelper() {
data_fetcher_->set_weak_observer(nullptr);
data_fetcher_ = nullptr;
}
-void ShortcutHelper::OnUserTitleAvailable(const base::string16& user_title) {
+void AddToHomescreenHelper::OnUserTitleAvailable(
+ const base::string16& user_title) {
JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jstring> j_user_title =
base::android::ConvertUTF16ToJavaString(env, user_title);
- Java_ShortcutHelper_onUserTitleAvailable(env,
- java_ref_.obj(),
- j_user_title.obj());
+ Java_AddToHomescreenHelper_onUserTitleAvailable(env,
+ java_ref_.obj(),
+ j_user_title.obj());
}
-void ShortcutHelper::OnDataAvailable(const ShortcutInfo& info,
- const SkBitmap& icon) {
+void AddToHomescreenHelper::OnDataAvailable(const ShortcutInfo& info,
+ const SkBitmap& icon) {
JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jobject> java_bitmap;
if (icon.getSize())
java_bitmap = gfx::ConvertToJavaBitmap(&icon);
- Java_ShortcutHelper_onIconAvailable(env,
- java_ref_.obj(),
- java_bitmap.obj());
+ Java_AddToHomescreenHelper_onIconAvailable(env,
+ java_ref_.obj(),
+ java_bitmap.obj());
if (add_shortcut_pending_)
AddShortcut(info, icon);
}
-void ShortcutHelper::Destroy(JNIEnv* env, jobject obj) {
+void AddToHomescreenHelper::Destroy(JNIEnv* env, jobject obj) {
delete this;
}
-SkBitmap ShortcutHelper::FinalizeLauncherIcon(const SkBitmap& bitmap,
- const GURL& url) {
+SkBitmap AddToHomescreenHelper::FinalizeLauncherIcon(const SkBitmap& bitmap,
+ const GURL& url) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
// Determine a single color to use for the favicon if the favicon that is
@@ -91,18 +94,18 @@ SkBitmap ShortcutHelper::FinalizeLauncherIcon(const SkBitmap& bitmap,
java_bitmap = gfx::ConvertToJavaBitmap(&bitmap);
base::android::ScopedJavaLocalRef<jobject> ref =
- Java_ShortcutHelper_finalizeLauncherIcon(env,
- java_url.obj(),
- java_bitmap.obj(),
- dominant_red,
- dominant_green,
- dominant_blue);
+ Java_AddToHomescreenHelper_finalizeLauncherIcon(env,
+ java_url.obj(),
+ java_bitmap.obj(),
+ dominant_red,
+ dominant_green,
+ dominant_blue);
return gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(ref.obj()));
}
-void ShortcutHelper::AddShortcut(JNIEnv* env,
- jobject obj,
- jstring j_user_title) {
+void AddToHomescreenHelper::AddShortcut(JNIEnv* env,
+ jobject obj,
+ jstring j_user_title) {
add_shortcut_pending_ = true;
base::string16 user_title =
@@ -117,8 +120,8 @@ void ShortcutHelper::AddShortcut(JNIEnv* env,
}
}
-void ShortcutHelper::AddShortcut(const ShortcutInfo& info,
- const SkBitmap& icon) {
+void AddToHomescreenHelper::AddShortcut(const ShortcutInfo& info,
+ const SkBitmap& icon) {
DCHECK(add_shortcut_pending_);
if (!add_shortcut_pending_)
return;
@@ -134,45 +137,11 @@ void ShortcutHelper::AddShortcut(const ShortcutInfo& info,
icon));
}
-bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
+bool AddToHomescreenHelper::RegisterAddToHomescreenHelper(JNIEnv* env) {
return RegisterNativesImpl(env);
}
-// static
-void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap(
- const ShortcutInfo& info,
- const SkBitmap& icon_bitmap) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
-
- // Send the data to the Java side to create the shortcut.
- JNIEnv* env = base::android::AttachCurrentThread();
- ScopedJavaLocalRef<jstring> java_url =
- base::android::ConvertUTF8ToJavaString(env, info.url.spec());
- ScopedJavaLocalRef<jstring> java_user_title =
- base::android::ConvertUTF16ToJavaString(env, info.user_title);
- ScopedJavaLocalRef<jstring> java_name =
- base::android::ConvertUTF16ToJavaString(env, info.name);
- ScopedJavaLocalRef<jstring> java_short_name =
- base::android::ConvertUTF16ToJavaString(env, info.short_name);
- ScopedJavaLocalRef<jobject> java_bitmap;
- if (icon_bitmap.getSize())
- java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap);
-
- Java_ShortcutHelper_addShortcut(
- env,
- base::android::GetApplicationContext(),
- java_url.obj(),
- java_user_title.obj(),
- java_name.obj(),
- java_short_name.obj(),
- java_bitmap.obj(),
- info.display == blink::WebDisplayModeStandalone,
- info.orientation,
- info.source,
- info.theme_color);
-}
-
-void ShortcutHelper::RecordAddToHomescreen() {
+void AddToHomescreenHelper::RecordAddToHomescreen() {
// Record that the shortcut has been added, so no banners will be shown
// for this app.
content::WebContents* web_contents = data_fetcher_->web_contents();

Powered by Google App Engine
This is Rietveld 408576698