summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/translate/ios/browser/js_language_detection_manager.mm5
-rw-r--r--ios/web/ios_web.gyp2
-rw-r--r--ios/web/public/web_state/js/crw_js_early_script_manager.h23
-rw-r--r--ios/web/web_state/js/crw_js_early_script_manager.mm59
4 files changed, 86 insertions, 3 deletions
diff --git a/components/translate/ios/browser/js_language_detection_manager.mm b/components/translate/ios/browser/js_language_detection_manager.mm
index d352899..4a65b81 100644
--- a/components/translate/ios/browser/js_language_detection_manager.mm
+++ b/components/translate/ios/browser/js_language_detection_manager.mm
@@ -8,8 +8,7 @@
#include "base/mac/scoped_nsobject.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
-#import "ios/web/public/web_state/js/crw_js_base_manager.h"
-#import "ios/web/public/web_state/js/crw_js_message_manager.h"
+#import "ios/web/public/web_state/js/crw_js_early_script_manager.h"
namespace language_detection {
// Note: This should stay in sync with the constant in language_detection.js.
@@ -29,7 +28,7 @@ const size_t kMaxIndexChars = 65535;
}
- (NSArray*)directDependencies {
- return @[ [CRWJSBaseManager class], [CRWJSMessageManager class], ];
+ return @[ [CRWJSEarlyScriptManager class] ];
}
#pragma mark - Public methods
diff --git a/ios/web/ios_web.gyp b/ios/web/ios_web.gyp
index 7e67484..f387fcc 100644
--- a/ios/web/ios_web.gyp
+++ b/ios/web/ios_web.gyp
@@ -42,6 +42,7 @@
'public/web_client.cc',
'public/web_client.h',
'public/web_state/js/crw_js_base_manager.h',
+ 'public/web_state/js/crw_js_early_script_manager.h',
'public/web_state/js/crw_js_injection_evaluator.h',
'public/web_state/js/crw_js_injection_manager.h',
'public/web_state/js/crw_js_injection_receiver.h',
@@ -53,6 +54,7 @@
'web_state/js/crw_js_base_manager.mm',
'web_state/js/crw_js_common_manager.h',
'web_state/js/crw_js_common_manager.mm',
+ 'web_state/js/crw_js_early_script_manager.mm',
'web_state/js/crw_js_injection_manager.mm',
'web_state/js/crw_js_injection_receiver.mm',
'web_state/js/crw_js_message_dynamic_manager.h',
diff --git a/ios/web/public/web_state/js/crw_js_early_script_manager.h b/ios/web/public/web_state/js/crw_js_early_script_manager.h
new file mode 100644
index 0000000..356c2f0
--- /dev/null
+++ b/ios/web/public/web_state/js/crw_js_early_script_manager.h
@@ -0,0 +1,23 @@
+// Copyright 2014 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.
+
+#ifndef IOS_WEB_PUBLIC_WEB_STATE_JS_CRW_JS_EARLY_SCRIPT_MANAGER_H_
+#define IOS_WEB_PUBLIC_WEB_STATE_JS_CRW_JS_EARLY_SCRIPT_MANAGER_H_
+
+#import "ios/web/public/web_state/js/crw_js_injection_manager.h"
+
+// Manager to handle all the scripts that need to be injected before the page
+// scripts take effect. Includes the base scripts and any feature scripts
+// that might need to perform global actions such as overriding HTML methods.
+@interface CRWJSEarlyScriptManager : CRWJSInjectionManager
+
+// Adds a |JsInjectionManager| class that should be injected ASAP to pages.
+- (void)addDependency:(Class)scriptManager;
+
+// Removes a class added previously with |addDependency|.
+- (void)removeDependency:(Class)scriptManager;
+
+@end
+
+#endif // IOS_WEB_PUBLIC_WEB_STATE_JS_CRW_JS_EARLY_SCRIPT_MANAGER_H_
diff --git a/ios/web/web_state/js/crw_js_early_script_manager.mm b/ios/web/web_state/js/crw_js_early_script_manager.mm
new file mode 100644
index 0000000..d8a87f3
--- /dev/null
+++ b/ios/web/web_state/js/crw_js_early_script_manager.mm
@@ -0,0 +1,59 @@
+// Copyright 2014 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 "ios/web/public/web_state/js/crw_js_early_script_manager.h"
+
+#import "base/mac/scoped_nsobject.h"
+#import "ios/web/public/web_state/js/crw_js_base_manager.h"
+#include "ios/web/public/web_state/js/crw_js_injection_receiver.h"
+#import "ios/web/public/web_state/js/crw_js_message_manager.h"
+
+@interface CRWJSEarlyScriptManager () {
+ base::scoped_nsobject<NSMutableSet> _dependencies;
+}
+@end
+
+@implementation CRWJSEarlyScriptManager
+
+#pragma mark - Protected Methods
+
+- (id)initWithReceiver:(CRWJSInjectionReceiver*)receiver {
+ self = [super initWithReceiver:receiver];
+ if (self) {
+ _dependencies.reset([[NSMutableSet alloc] initWithArray:@[
+ // TODO(eugenebut): update with correct dependencies when they are
+ // upstreamed.
+ [CRWJSBaseManager class],
+ [CRWJSMessageManager class],
+ ]]);
+ }
+ return self;
+}
+
+- (NSString*)staticInjectionContent {
+ // Early Script Manager does not supply any scripts of its own. Rather it uses
+ // its dependencies to ensure all relevant script content is injected into
+ // pages.
+ return @"";
+}
+
+- (NSString*)presenceBeacon {
+ return @"__gCrWeb";
+}
+
+- (NSArray*)directDependencies {
+ return [_dependencies allObjects];
+}
+
+- (void)addDependency:(Class)scriptManager {
+ [_dependencies addObject:scriptManager];
+}
+
+- (void)removeDependency:(Class)scriptManager {
+ [_dependencies removeObject:scriptManager];
+}
+
+#pragma mark -
+
+@end