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