-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path8.xm
159 lines (120 loc) · 4.23 KB
/
8.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
@class Application, BrowserController, TabController, TabDocument, TiltedTabView;
@interface Application
// Returns the current Application
+ (instancetype)sharedApplication;
// Called when the app resumes from the background
- (void)applicationDidBecomeActive:(UIApplication *)application;
// Called when the app finishes launching
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
// Implemented by this tweak
// Brings up the keyboard
- (void)typeTab;
@end
@interface BrowserController
// Returns the current BrowserController
+ (instancetype)sharedBrowserController;
// Brings up the keyboard, use of arg1 us unknown
- (void)navigationBarURLWasTapped:(id)arg1;
// Called on iPad?
- (void)addTabFromButtonBar;
// Returns the current TabController
- (TabController *)tabController;
// Gets the state of private browsing
- (BOOL)privateBrowsingEnabled;
//Determins of the tab view is currently showing
- (BOOL)isShowingTabView;
@end
@interface TabController
// Called when the + button in the TiltedTabView on iPhone is pressed
- (void)_addNewActiveTiltedTabViewTab;
// Returns the currently displayed TabDocument
- (TabDocument *)activeTabDocument;
// Returns the currently loaded TabDocuments
- (NSArray *)currentTabDocuments;
// Returns the tilted tab view if running on an iPhone
- (TiltedTabView *)tiltedTabView;
@end
@interface TabDocument
// Returns if the document is blank or not
- (BOOL)isBlankDocument;
@end
@class TabDocument, TiltedTabView, BrowserController, BrowserControllerWK2, Application, TabController;
@interface TabController (Legacy)
- (NSArray *)_currentTabs;
@end
@interface TiltedTabView
- (NSArray *)items;
@end
// iOS 8.0-8.4.1 code
%group 8
%hook Application
%new
- (void)typeTab {
// Adds a method for typing into the search field to Safari's app delegate
BrowserController *bc = MSHookIvar<BrowserController *>(self, "_controller");
if (bc.tabController.activeTabDocument.isBlankDocument) {
[bc navigationBarURLWasTapped:0];
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
%orig;
[(Application *)[UIApplication sharedApplication] typeTab];
return YES;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
%orig;
BrowserController *bc = MSHookIvar<BrowserController *>(self, "_controller");
if (!bc.privateBrowsingEnabled) {
[(Application *)[UIApplication sharedApplication] typeTab];
}
}
%end
%hook TabController
- (void)setActiveTabDocument:(TabDocument *)blankTab animated:(BOOL)animated {
%orig;
// Main hook for normal browsing
BrowserController *bc = MSHookIvar<BrowserController *>(self, "_browserController");
if (!bc.privateBrowsingEnabled) {
[(Application *)[UIApplication sharedApplication] typeTab];
}
}
// Done as a workaround to a bug with the private browsing TiltedTabView
- (void)_addNewActiveTiltedTabViewTab {
Application *appDel = (Application *)[UIApplication sharedApplication];
BrowserController *bc = MSHookIvar<BrowserController *>(appDel, "_controller");
// Called when you press the add tab UIBarButtonItem on iPhone
%orig;
if (bc.privateBrowsingEnabled) {
[(Application *)[UIApplication sharedApplication] typeTab];
}
}
%end
%hook BrowserControllerWK2
- (void)addTabFromButtonBar {
Application *appDel = (Application *)[UIApplication sharedApplication];
BrowserController *bc = MSHookIvar<BrowserController *>(appDel, "_controller");
// Called when you press the add tab UIBarButtonItem on iPad
%orig;
if (bc.privateBrowsingEnabled) {
[(Application *)[UIApplication sharedApplication] typeTab];
}
}
%end
%hook TabOverview
- (void)_addTab {
%orig;
// Also iPad
Application *appDel = (Application *)[UIApplication sharedApplication];
BrowserController *bc = MSHookIvar<BrowserController *>(appDel, "_controller");
if (bc.privateBrowsingEnabled) {
[(Application *)[UIApplication sharedApplication] typeTab];
}
}
%end
%end
%ctor {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 &&
[[[UIDevice currentDevice] systemVersion] floatValue] < 9.0) {
%init(8);
}
}