Skip to content

Commit

Permalink
Stop abusing private APIs for "Inspect Element" menu item
Browse files Browse the repository at this point in the history
 When WebKit2 first announced, there was no way for an
 app to take an NSMenu, modify it, and return the result
 when a context menu is presented.

 WebKit1 had a delegate method for that named:
 -webView:contextMenuItemsForElement:defaultMenuItems:

 WebKit2 added this delegate method, in private, but it
 was not available until the next update of macOS.

 'Til then, we had to fake "Inspect Element" because we
 did not have access to the default implementation that
 is available through the delegate method.

 Apple now flags the function names that were used to do that.

 This will break "Inspect Element" on one version of macOS.
 Which one I don't even recall.
 But it is worth it to make the review process smoother.
  • Loading branch information
emsquared committed Mar 4, 2019
1 parent fafe384 commit ab24aef
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
33 changes: 26 additions & 7 deletions Sources/App/Classes/Controllers/TXMenuController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1401,16 +1401,35 @@ - (void)copyLogAsHtml:(id)sender

- (void)openWebInspector:(id)sender
{
TVCLogView *webView = self.selectedViewControllerBackingView;
/*
When WebKit2 first announced, there was no way for an
app to take an NSMenu, modify it, and return the result
when a context menu is presented.
if (webView == nil) {
return;
}
WebKit1 had a delegate method for that named:
-webView:contextMenuItemsForElement:defaultMenuItems:
WebKit2 added this delegate method, in private, but it
was not available until the next update of macOS.
'Til then, we had to fake "Inspect Element" because we
did not have access to the default implementation that
is available through the delegate method.
Apple now flags the function names that were used to do that.
This will break "Inspect Element" on one version of macOS.
Which one I don't even recall.
But it is worth it to make the review process smoother.
NSAssert(webView.isUsingWebKit2,
@"Missing implementation");
Sorry.
*/

[(TVCLogViewInternalWK2 *)webView.webView openWebInspector];
(void)
[TDCAlert alertWithMessage:TXTLS(@"Prompts[kig-m1]")
title:TXTLS(@"Prompts[ujw-64]")
defaultButton:TXTLS(@"Prompts[c7s-dq]")
alternateButton:nil];
}

- (void)markScrollback:(id)sender
Expand Down
2 changes: 0 additions & 2 deletions Sources/App/Classes/Headers/Private/TVCLogViewInternalWK2.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ NS_ASSUME_NONNULL_BEGIN

+ (void)emptyCaches;
+ (void)emptyCaches:(void (^ _Nullable)(void))completionHandler;

- (void)openWebInspector;
@end

NS_ASSUME_NONNULL_END
21 changes: 0 additions & 21 deletions Sources/App/Classes/Views/Channel View/TVCLogViewInternalWK2.m
Original file line number Diff line number Diff line change
Expand Up @@ -305,27 +305,6 @@ + (void)emptyCaches:(void (^ _Nullable)(void))completionHandler
}
}

- (void)openWebInspector
{
WKPageRef pageRef = NULL;

if (TEXTUAL_RUNNING_ON_SIERRA) {
pageRef = [self _pageForTesting];
} else if (TEXTUAL_RUNNING_ON_ELCAPITAN) {
WKView *webViewParent = (id)self.subviews[0];

pageRef = [webViewParent pageRef];
}

if (pageRef == NULL) {
return;
}

WKInspectorRef inspectorRef = WKPageGetInspector(pageRef);

WKInspectorShow(inspectorRef);
}

- (void)findString:(NSString *)searchString movingForward:(BOOL)movingForward
{
NSParameterAssert(searchString != nil);
Expand Down
3 changes: 3 additions & 0 deletions Sources/App/Resources/Language Files/en.lproj/Prompts.strings
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,6 @@

"rn7-08" = "Unable to access iCloud";
"wjn-f1" = "Make sure you're logged in and that “iCloud Drive” or “Documents & Data” is enabled.";

"ujw-64" = "The “Inspect Element” feature of WebKit2 cannot be accessed on this version of macOS.";
"kig-m1" = "Disable WebKit2 or upgrade to a newer version of macOS.";

0 comments on commit ab24aef

Please sign in to comment.