Add ICU message format support
[chromium-blink-merge.git] / ios / web / web_state / js / crw_js_plugin_placeholder_manager.mm
blob6378d87b55f375b7d480c20e9da5dff83ad242b2
1 // Copyright 2013 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 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h"
7 #include "base/logging.h"
8 #include "base/strings/sys_string_conversions.h"
9 #include "ios/web/public/web_client.h"
11 @implementation CRWJSPluginPlaceholderManager
13 namespace {
15 // Returns a string with \ and ' escaped, and wrapped in '.
16 // This is used instead of GetQuotedJSONString because that will convert
17 // UTF-16 to UTF-8, which can cause problems when injecting scripts depending
18 // on the page encoding (see crbug.com/302741).
19 NSString* EscapedQuotedString(NSString* string) {
20   string = [string stringByReplacingOccurrencesOfString:@"\\"
21                                              withString:@"\\\\"];
22   string = [string stringByReplacingOccurrencesOfString:@"'"
23                                              withString:@"\\'"];
24   return [NSString stringWithFormat:@"'%@'", string];
29 #pragma mark -
30 #pragma mark ProtectedMethods
32 - (NSString*)scriptPath {
33   return @"plugin_placeholder";
36 - (NSString*)presenceBeacon {
37   return @"__gCrWeb.plugin";
40 - (NSString*)staticInjectionContent {
41   NSString* baseContent = [super staticInjectionContent];
42   DCHECK(web::GetWebClient());
43   NSString* pluginNotSupportedText = base::SysUTF16ToNSString(
44       web::GetWebClient()->GetPluginNotSupportedText());
45   NSString* placeholderCall = [NSString stringWithFormat:
46       @"__gCrWeb.plugin.addPluginPlaceholders(%@);",
47           EscapedQuotedString(pluginNotSupportedText)];
48   return [baseContent stringByAppendingString:placeholderCall];
51 @end