Commit 3de3e3db authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Remove unnecessary usage of GTM from //ios

Convert usage of GTMStringEncoding that were used to convert
to/from base64 (possibly the web safe variant) to use //base
instead (which provides an encoder/decoder).

Remove dependencies on //third_party/google_toolbox_for_mac
from //ios/chrome that are no longer used (i.e. the code do
not use GTM and the include are stale).

Removing those dependencies may enable Chrome on iOS to drop
the dependency on //third_party/google_toolbox_for_mac.

Bug: none
Tbr: rsesek@chromium.org
Change-Id: I82939c005c762a9914ece809ec3e7767ed8db729
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1899458
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarDavid Jean <djean@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712595}
parent f1326b9e
......@@ -311,7 +311,6 @@ source_set("main") {
"//ios/chrome/browser/crash_report",
"//ios/chrome/common",
"//ios/testing/perf:startup",
"//third_party/google_toolbox_for_mac",
]
}
......
include_rules = [
"+third_party/google_toolbox_for_mac",
]
specific_include_rules = {
"metrics_mediator\.mm": [
"+third_party/google_toolbox_for_mac/src/Foundation/GTMTimeUtils.h",
],
}
......@@ -116,7 +116,6 @@ include_rules = [
"+services/network/public/cpp",
"+third_party/breakpad/breakpad/src/client/ios",
"+third_party/breakpad/breakpad/src/common",
"+third_party/google_toolbox_for_mac",
"+third_party/libaddressinput",
"+third_party/libxml/chromium/xml_writer.h",
"+third_party/metrics_proto",
......
......@@ -28,7 +28,6 @@ source_set("geolocation") {
"//ios/chrome/browser",
"//ios/chrome/browser/ui/util",
"//ios/public/provider/chrome/browser",
"//third_party/google_toolbox_for_mac",
"//ui/base",
"//url",
]
......
......@@ -6,35 +6,40 @@
#include <stdint.h>
#import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h"
#include "base/base64url.h"
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
NSString* const kGMOLocationDescriptorFormat =
@"role: CURRENT_LOCATION\n"
@"producer: DEVICE_LOCATION\n"
@"timestamp: %lld\n"
@"radius: %ld\n"
@"latlng <\n"
@" latitude_e7: %.f\n"
@" longitude_e7: %.f\n"
@">";
namespace {
// Returns the LocationDescriptor as an ASCII proto encoded in web safe base64.
std::string LocationDescriptorAsWebSafeBase64(int64_t timestamp,
long radius,
double latitude,
double longitude) {
const std::string location_descriptor =
base::StringPrintf("role: CURRENT_LOCATION\n"
"producer: DEVICE_LOCATION\n"
"timestamp: %lld\n"
"radius: %ld\n"
"latlng <\n"
" latitude_e7: %.f\n"
" longitude_e7: %.f\n"
">",
timestamp, radius, latitude, longitude);
@implementation CLLocation (XGeoHeader)
- (NSString*)cr_serializeStringToWebSafeBase64String:(NSString*)data {
GTMStringEncoding* encoder =
[GTMStringEncoding rfc4648Base64WebsafeStringEncoding];
NSString* base64 =
[encoder encode:[data dataUsingEncoding:NSUTF8StringEncoding]
error:nullptr];
if (base64) {
return base64;
}
return @"";
std::string encoded_descriptor;
base::Base64UrlEncode(location_descriptor,
base::Base64UrlEncodePolicy::INCLUDE_PADDING,
&encoded_descriptor);
return encoded_descriptor;
}
} // namespace
@implementation CLLocation (XGeoHeader)
// Returns the timestamp of this location in microseconds since the UNIX epoch.
// Returns 0 if the timestamp is unavailable or invalid.
......@@ -58,22 +63,16 @@ NSString* const kGMOLocationDescriptorFormat =
return -1L;
}
// Returns the LocationDescriptor as an ASCII proto.
- (NSString*)cr_locationDescriptor {
// Construct the location descriptor using its format string.
return [NSString stringWithFormat:kGMOLocationDescriptorFormat,
[self cr_timestampInMicroseconds],
[self cr_accuracyInMillimeters],
floor(self.coordinate.latitude * 1e7),
floor(self.coordinate.longitude * 1e7)];
}
- (NSString*)cr_xGeoString {
NSString* locationDescriptor = [self cr_locationDescriptor];
const std::string encoded_location_descriptor =
LocationDescriptorAsWebSafeBase64([self cr_timestampInMicroseconds],
[self cr_accuracyInMillimeters],
floor(self.coordinate.latitude * 1e7),
floor(self.coordinate.longitude * 1e7));
// The "a" indicates that it is an ASCII proto.
return [NSString
stringWithFormat:@"a %@", [self cr_serializeStringToWebSafeBase64String:
locationDescriptor]];
return base::SysUTF8ToNSString(
base::StringPrintf("a %s", encoded_location_descriptor.c_str()));
}
@end
......@@ -174,7 +174,6 @@ source_set("browser_view") {
"//ios/web/public",
"//ios/web/public/deprecated",
"//ios/web/public/deprecated:deprecated_web_util",
"//third_party/google_toolbox_for_mac",
"//ui/base",
"//ui/gfx",
"//url",
......
......@@ -8,7 +8,6 @@ source_set("image_util") {
"image_util.mm",
]
deps = [
"//third_party/google_toolbox_for_mac",
"//ui/base",
]
configs += [ "//build/config/compiler:enable_arc" ]
......
......@@ -6,8 +6,6 @@
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/image_util/image_util.h"
#include "third_party/google_toolbox_for_mac/src/iPhone/GTMUIImage+Resize.h"
#include "ui/gfx/color_analysis.h"
#include "ui/gfx/image/image.h"
......
......@@ -83,7 +83,6 @@ source_set("location_bar") {
"//ios/web/public:public",
"//ios/web/public/security",
"//skia",
"//third_party/google_toolbox_for_mac",
"//ui/base",
"//ui/base",
"//ui/gfx",
......
......@@ -169,7 +169,6 @@ source_set("omnibox_internal") {
"//ios/web",
"//net",
"//skia",
"//third_party/google_toolbox_for_mac",
"//ui/base",
"//ui/gfx",
"//ui/gfx/geometry",
......
......@@ -32,7 +32,6 @@
#include "ios/chrome/grit/ios_strings.h"
#include "ios/chrome/grit/ios_theme_resources.h"
#include "skia/ext/skia_utils_ios.h"
#include "third_party/google_toolbox_for_mac/src/iPhone/GTMFadeTruncatingLabel.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image.h"
......
specific_include_rules = {
"tab_view\.mm": [
"+third_party/google_toolbox_for_mac/src/iPhone/GTMFadeTruncatingLabel.h",
],
}
......@@ -48,7 +48,6 @@
#include "ios/chrome/grit/ios_strings.h"
#import "ios/web/public/web_state.h"
#import "ios/web/public/web_state_observer_bridge.h"
#include "third_party/google_toolbox_for_mac/src/iPhone/GTMFadeTruncatingLabel.h"
#include "ui/gfx/image/image.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......
......@@ -9,14 +9,13 @@
#import "ios/chrome/browser/ui/tabs/tab_view_delegate.h"
@class GTMFadeTruncatingLabel;
@protocol TabViewDelegate;
// View class that draws a Chrome-style tab.
@interface TabView : UIControl
@property(nonatomic, weak) id<TabViewDelegate> delegate;
@property(nonatomic, readonly, strong) GTMFadeTruncatingLabel* titleLabel;
@property(nonatomic, readonly, strong) UILabel* titleLabel;
@property(nonatomic, strong) UIImage* favicon;
@property(nonatomic, assign, getter=isCollapsed) BOOL collapsed;
@property(nonatomic, strong) UIImage* background;
......
......@@ -406,17 +406,17 @@ UIImage* DefaultFaviconImage() {
faviconColorName = @"tabstrip_inactive_tab_text_color";
}
_faviconView.tintColor = [UIColor colorNamed:faviconColorName];
self.titleLabel.textColor = _faviconView.tintColor;
_titleLabel.textColor = _faviconView.tintColor;
// Update font weight and accessibility label.
UIFontWeight fontWeight =
selected ? UIFontWeightSemibold : UIFontWeightMedium;
self.titleLabel.font = [UIFont systemFontOfSize:kFontSize weight:fontWeight];
_titleLabel.font = [UIFont systemFontOfSize:kFontSize weight:fontWeight];
// It would make more sense to set active/inactive on tab_view itself, but
// tab_view is not an an accessible element, and making it one would add
// several complicated layers to UIA. Instead, simply set active/inactive
// here to be used by UIA.
[self.titleLabel setAccessibilityValue:(selected ? @"active" : @"inactive")];
[_titleLabel setAccessibilityValue:(selected ? @"active" : @"inactive")];
}
#pragma mark - DropAndNavigateDelegate
......@@ -435,4 +435,10 @@ UIImage* DefaultFaviconImage() {
[_delegate tabViewTapped:self];
}
#pragma mark - Properties
- (UILabel*)titleLabel {
return _titleLabel;
}
@end
......@@ -61,7 +61,6 @@ source_set("tts") {
"//ios/web",
"//ios/web/public/deprecated",
"//net",
"//third_party/google_toolbox_for_mac",
"//url",
]
}
......@@ -84,6 +83,5 @@ source_set("unit_tests") {
"//ios/web/common",
"//ios/web/public/test",
"//testing/gtest",
"//third_party/google_toolbox_for_mac",
]
}
......@@ -7,13 +7,13 @@
#include "ios/web/public/test/web_test_with_web_state.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
#import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const char kExpectedDecodedData[] = "testaudo32oio";
NSString* const kHTMLFormat =
@"<html><head><script>%@</script></head><body></body></html>";
NSString* const kValidVoiceSearchScript =
......@@ -89,14 +89,16 @@ class TextToSpeechListenerTest : public web::WebTestWithWebState {
};
TEST_F(TextToSpeechListenerTest, ValidAudioDataTest) {
GTMStringEncoding* encoder = [GTMStringEncoding rfc4648Base64StringEncoding];
NSString* html =
[NSString stringWithFormat:kHTMLFormat, kValidVoiceSearchScript];
NSData* expected_audio_data =
[encoder decode:@"dGVzdGF1ZG8zMm9pbw==" error:nullptr];
TestExtraction(html, expected_audio_data);
[NSData dataWithBytes:&kExpectedDecodedData[0]
length:sizeof(kExpectedDecodedData) - 1];
TestExtraction(
[NSString stringWithFormat:kHTMLFormat, kValidVoiceSearchScript],
expected_audio_data);
}
TEST_F(TextToSpeechListenerTest, InvalidAudioDataTest) {
TestExtraction([NSString stringWithFormat:kHTMLFormat, @""], nil);
NSData* expected_audio_data = nil;
TestExtraction([NSString stringWithFormat:kHTMLFormat, @""],
expected_audio_data);
}
......@@ -4,10 +4,11 @@
#import "ios/chrome/browser/voice/text_to_speech_parser.h"
#include "base/base64.h"
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/web/public/deprecated/crw_js_injection_receiver.h"
#import "ios/web/public/web_state.h"
#import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -88,14 +89,18 @@ NSData* ExtractVoiceSearchAudioDataFromPageHTML(NSString* page_html) {
NSRange search_range =
NSMakeRange(raw_base64_encoded_audio_string.length - search_range_length,
search_range_length);
NSString* base64_encoded_audio_string = [raw_base64_encoded_audio_string
stringByReplacingOccurrencesOfString:kTrailingEqualEncoding
withString:@"="
options:0
range:search_range];
const std::string base64_encoded_audio_string =
base::SysNSStringToUTF8([raw_base64_encoded_audio_string
stringByReplacingOccurrencesOfString:kTrailingEqualEncoding
withString:@"="
options:0
range:search_range]);
GTMStringEncoding* base64 = [GTMStringEncoding rfc4648Base64StringEncoding];
return [base64 decode:base64_encoded_audio_string error:nullptr];
std::string decoded_data;
if (!base::Base64Decode(base64_encoded_audio_string, &decoded_data))
return nil;
return [NSData dataWithBytes:decoded_data.c_str() length:decoded_data.size()];
}
void ExtractVoiceSearchAudioDataFromWebState(
......
......@@ -6,8 +6,8 @@
#import "ios/chrome/browser/voice/text_to_speech_parser.h"
#include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h"
#include "testing/platform_test.h"
#import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -17,6 +17,7 @@
NSData* ExtractVoiceSearchAudioDataFromPageHTML(NSString* pageHTML);
namespace {
const char kExpectedDecodedData[] = "testaudo32oio";
NSString* const kValidVoiceSearchHTML =
@"<script>(function(){var _a_tts='dGVzdGF1ZG8zMm9pbw==';var _m_tts= {}}";
NSString* const kInvalidVoiceSearchHTML = @"no TTS data";
......@@ -28,15 +29,16 @@ TEST_F(TextToSpeechParser, ExtractAudioDataValid) {
NSData* result =
ExtractVoiceSearchAudioDataFromPageHTML(kValidVoiceSearchHTML);
EXPECT_TRUE(result != nil);
EXPECT_NSNE(result, nil);
GTMStringEncoding* base64 = [GTMStringEncoding rfc4648Base64StringEncoding];
NSData* expectedData = [base64 decode:@"dGVzdGF1ZG8zMm9pbw==" error:nullptr];
EXPECT_TRUE([expectedData isEqualToData:result]);
NSData* expectedData =
[NSData dataWithBytes:&kExpectedDecodedData[0]
length:sizeof(kExpectedDecodedData) - 1];
EXPECT_NSEQ(expectedData, result);
}
TEST_F(TextToSpeechParser, ExtractAudioDataNotFound) {
NSData* result =
ExtractVoiceSearchAudioDataFromPageHTML(kInvalidVoiceSearchHTML);
EXPECT_TRUE(result == nil);
EXPECT_NSEQ(result, nil);
}
......@@ -27,7 +27,6 @@ include_rules = [
"+net/url_request",
"+services/network/public/cpp",
"+third_party/breakpad/breakpad/src/client/ios",
"+third_party/google_toolbox_for_mac",
"+ui",
# Strings and resources.
......
include_rules = [
"+ios/third_party/earl_grey2/src",
"+net",
"+third_party/google_toolbox_for_mac",
"+third_party/ocmock",
]
specific_include_rules = {
"ocmock_complex_type_helper\.h": [
"+third_party/google_toolbox_for_mac/src/Foundation/GTMLightweightProxy.h",
],
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment