OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "ios/web/public/web_client.h" |
| 10 |
| 11 @implementation CRWJSPluginPlaceholderManager |
| 12 |
| 13 namespace { |
| 14 |
| 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]; |
| 25 } |
| 26 |
| 27 } |
| 28 |
| 29 #pragma mark - |
| 30 #pragma mark ProtectedMethods |
| 31 |
| 32 - (NSString*)scriptPath { |
| 33 return @"plugin_placeholder"; |
| 34 } |
| 35 |
| 36 - (NSString*)presenceBeacon { |
| 37 return @"__gCrWeb.plugin"; |
| 38 } |
| 39 |
| 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]; |
| 49 } |
| 50 |
| 51 @end |
OLD | NEW |