Skip to content

Commit

Permalink
Make monochrome use the same copy of licenses as chrome
Browse files Browse the repository at this point in the history
1. Compare chrome and webview licenses, and add the Chromium project license;
2. Get the Brotli decompression function and put it in component/about_ui/;
3. make monochrome call the function via JNI.

Bug: 688077
Change-Id: I125dce46f85d3b268d9cee6d19249905f79f0209
Reviewed-on: https://chromium-review.googlesource.com/497870
Commit-Queue: Yipeng Wang <yipengw@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: Kunihiko Sakamoto <ksakamoto@chromium.org>
Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
Reviewed-by: Dan Beam <dbeam@chromium.org>
Reviewed-by: Richard Coles <torne@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#478052}
  • Loading branch information
Yipeng Wang authored and Commit Bot committed Jun 8, 2017
1 parent b5da597 commit 5671d4f
Show file tree
Hide file tree
Showing 23 changed files with 358 additions and 106 deletions.
4 changes: 0 additions & 4 deletions android_webview/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,7 @@ android_assets("pak_file_assets") {
# These assets are needed by both monochrome and stand alone WebView, but not by
# Chrome.
android_assets("monochrome_webview_assets") {
sources = [
webview_license_path,
]
deps = [
":generate_webview_license_notice",
"//third_party/icu:icu_assets",
"//v8:v8_external_startup_data_assets",
]
Expand Down
15 changes: 15 additions & 0 deletions android_webview/apk/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/android/rules.gni")

# Since Monochrome has its own content provider, these two files are put
# in two different targets.
android_library("webview_license_provider_java") {
java_files = [ "//android_webview/apk/java/src/com/android/webview/chromium/LicenseContentProvider.java" ]
}

android_library("webview_license_activity_java") {
java_files = [ "//android_webview/apk/java/src/com/android/webview/chromium/LicenseActivity.java" ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@
* other than LicenseContentProvider.
*/
public class LicenseActivity extends Activity {
private static final String LICENSES_URI_SUFFIX = "LicenseContentProvider/webview_licenses";
private static final String LICENSES_CONTENT_TYPE = "text/html";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String packageName = getPackageName();
final Intent intent = new Intent(Intent.ACTION_VIEW);
final String licenseUri = String.format("content://%s.%s",
packageName, LicenseContentProvider.LICENSES_URI_SUFFIX);
intent.setDataAndType(
Uri.parse(licenseUri), LicenseContentProvider.LICENSES_CONTENT_TYPE);
final String licenseUri =
String.format("content://%s.%s", packageName, LICENSES_URI_SUFFIX);
intent.setDataAndType(Uri.parse(licenseUri), LICENSES_CONTENT_TYPE);
intent.addCategory(Intent.CATEGORY_DEFAULT);
final int titleId = getResources().getIdentifier(
"license_activity_title", "string", packageName);
final int titleId =
getResources().getIdentifier("license_activity_title", "string", packageName);
if (titleId != 0) {
intent.putExtra(Intent.EXTRA_TITLE, getString(titleId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public String getType(Uri uri) {
}

@Override
public int update(Uri uri, ContentValues values, String where,
String[] whereArgs) {
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
throw new UnsupportedOperationException();
}

Expand All @@ -84,8 +83,8 @@ public Uri insert(Uri uri, ContentValues values) {
}

@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
throw new UnsupportedOperationException();
}
}
}
2 changes: 0 additions & 2 deletions android_webview/glue/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ android_library("glue") {
"java/src/com/android/webview/chromium/DrawGLFunctor.java",
"java/src/com/android/webview/chromium/GeolocationPermissionsAdapter.java",
"java/src/com/android/webview/chromium/GraphicsUtils.java",
"java/src/com/android/webview/chromium/LicenseActivity.java",
"java/src/com/android/webview/chromium/LicenseContentProvider.java",
"java/src/com/android/webview/chromium/MonochromeLibraryPreloader.java",
"java/src/com/android/webview/chromium/ServiceWorkerClientAdapter.java",
"java/src/com/android/webview/chromium/ServiceWorkerControllerAdapter.java",
Expand Down
2 changes: 2 additions & 0 deletions chrome/android/chrome_public_apk_tmpl.gni
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ template("monochrome_public_apk_tmpl") {
}
deps += [
"//android_webview:monochrome_webview_assets",
"//android_webview/apk:webview_license_activity_java",
"//android_webview/glue",
"//chrome/android:chrome_public_non_pak_assets",
"//chrome/android:monochrome_pak_assets",
"//chrome/android/monochrome:monochrome_license_provider_java",
]

if (!is_java_debug) {
Expand Down
16 changes: 16 additions & 0 deletions chrome/android/monochrome/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/android/rules.gni")

android_library("monochrome_license_provider_java") {
java_files =
[ "java/src/com/android/webview/chromium/LicenseContentProvider.java" ]

deps = [
"//base:base_java",
"//chrome/android:chrome_java",
"//components/about_ui/android:aboutui_java",
]
}
3 changes: 3 additions & 0 deletions chrome/android/monochrome/java/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+components/about_ui/android/java",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package com.android.webview.chromium;

import android.annotation.TargetApi;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.util.Log;

import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.ProcessInitException;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.components.aboutui.CreditUtils;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
* Content provider for the OSS licenses file.
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public class LicenseContentProvider
extends ContentProvider implements ContentProvider.PipeDataWriter<String> {
public static final String LICENSES_URI_SUFFIX = "LicenseContentProvider/webview_licenses";
public static final String LICENSES_CONTENT_TYPE = "text/html";
private static final String TAG = "LicenseCP";

@Override
public boolean onCreate() {
return true;
}

@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
if (uri != null && uri.toString().endsWith(LICENSES_URI_SUFFIX)) {
return openPipeHelper(null, null, null, "webview_licenses.notice", this);
}
return null;
}

@Override
public void writeDataToPipe(
ParcelFileDescriptor output, Uri uri, String mimeType, Bundle opts, String filename) {
try (OutputStream out = new FileOutputStream(output.getFileDescriptor());) {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
try {
ChromeBrowserInitializer.getInstance(getContext())
.handleSynchronousStartup();
} catch (ProcessInitException e) {
Log.e(TAG, "Fail to initialize the Chrome Browser.", e);
}
}
});
out.write(CreditUtils.nativeGetJavaWrapperCredits());
} catch (IOException e) {
Log.e(TAG, "Failed to write the license file", e);
}
}

@Override
public String getType(Uri uri) {
if (uri != null && uri.toString().endsWith(LICENSES_URI_SUFFIX)) {
return LICENSES_CONTENT_TYPE;
}
return null;
}

@Override
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
throw new UnsupportedOperationException();
}

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
throw new UnsupportedOperationException();
}

@Override
public Uri insert(Uri uri, ContentValues values) {
throw new UnsupportedOperationException();
}

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
throw new UnsupportedOperationException();
}
}
1 change: 1 addition & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ split_static_library("ui") {
"//chrome/common:instant_mojom",
"//chrome/common/net",
"//chrome/installer/util:with_no_strings",
"//components/about_ui",
"//components/app_modal",
"//components/autofill/content/browser:risk_proto",
"//components/autofill/core/browser",
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/webui/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+components/about_ui"
"+components/invalidation",
"+components/onc",
"+components/proximity_auth",
Expand Down
29 changes: 6 additions & 23 deletions chrome/browser/ui/webui/about_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "chrome/grit/browser_resources.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/about_ui/credit_utils.h"
#include "components/grit/components_resources.h"
#include "components/strings/grit/components_locale_settings.h"
#include "content/public/browser/browser_thread.h"
Expand Down Expand Up @@ -691,32 +692,14 @@ void AboutUIHTMLSource::StartDataRequest(
idr = IDR_KEYBOARD_UTILS_JS;
#endif

base::StringPiece raw_response =
ResourceBundle::GetSharedInstance().GetRawDataResource(idr);
if (idr == IDR_ABOUT_UI_CREDITS_HTML) {
const uint8_t* next_encoded_byte =
reinterpret_cast<const uint8_t*>(raw_response.data());
size_t input_size_remaining = raw_response.size();
BrotliDecoderState* decoder =
BrotliDecoderCreateInstance(nullptr /* no custom allocator */,
nullptr /* no custom deallocator */,
nullptr /* no custom memory handle */);
CHECK(!!decoder);
while (!BrotliDecoderIsFinished(decoder)) {
size_t output_size_remaining = 0;
CHECK(BrotliDecoderDecompressStream(
decoder, &input_size_remaining, &next_encoded_byte,
&output_size_remaining, nullptr,
nullptr) != BROTLI_DECODER_RESULT_ERROR);
const uint8_t* output_buffer =
BrotliDecoderTakeOutput(decoder, &output_size_remaining);
response.insert(response.end(), output_buffer,
output_buffer + output_size_remaining);
}
BrotliDecoderDestroyInstance(decoder);
response = about_ui::GetCredits(true /*include_scripts*/);
} else {
response = raw_response.as_string();
response = ResourceBundle::GetSharedInstance()
.GetRawDataResource(idr)
.as_string();
}

#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
} else if (source_name_ == chrome::kChromeUIDiscardsHost) {
response = AboutDiscards(path);
Expand Down
21 changes: 21 additions & 0 deletions components/about_ui/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

static_library("about_ui") {
sources = [
"credit_utils.cc",
"credit_utils.h",
]
deps = [
"//base",
"//components/resources:components_resources",
"//third_party/brotli:dec",
"//ui/base",
"//ui/resources",
]

if (is_android) {
deps += [ "//components/about_ui/android:about_ui_jni_headers" ]
}
}
6 changes: 6 additions & 0 deletions components/about_ui/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include_rules = [
"+components/grit/components_resources.h",
"+jni",
"+third_party/brotli",
"+ui/base",
]
18 changes: 18 additions & 0 deletions components/about_ui/android/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/android/rules.gni")

generate_jni("about_ui_jni_headers") {
sources = [
"java/src/org/chromium/components/aboutui/CreditUtils.java",
]
jni_package = "components/about_ui"
}

android_library("aboutui_java") {
java_files = [ "java/src/org/chromium/components/aboutui/CreditUtils.java" ]
deps = [
"//base:base_java",
]
}
2 changes: 2 additions & 0 deletions components/about_ui/android/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
agrieve@chromium.org
torne@chromium.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.components.aboutui;

import org.chromium.base.annotations.JNINamespace;

/** Credits-related utilities. */
@JNINamespace("about_ui")
public class CreditUtils {
private CreditUtils() {}

/** Returns a string containing the content of about_credits.html. */
public static native byte[] nativeGetJavaWrapperCredits();
}
Loading

0 comments on commit 5671d4f

Please sign in to comment.