<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[202998] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/202998">202998</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2016-07-08 11:52:26 -0700 (Fri, 08 Jul 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>REGRESSION (<a href="http://trac.webkit.org/projects/webkit/changeset/196321">r196321</a>): Adobe Reader DC + Safari : Zoom level pulldown is not displayed at the correct position
https://bugs.webkit.org/show_bug.cgi?id=159531
rdar://problem/26382579

Reviewed by Tim Horton.

There's code in the Adobe Acrobat framework that checks if the main bundle identifier is &quot;com.apple.WebKit.PluginProcess&quot;
and assumes that it's running inside the Adobe Reader app if it's something else. Since we're now using the XPC service
for all plug-ins, the bundle identifier is &quot;com.apple.WebKit.Plugin.64&quot;, so the Acrobat framework assumes it's running in the app
and doesn't use any special tricks to show the popup menu.

Work around this by shimming CFStringCompare, and looking for the exact conditions when this can happen and return kCFCompareEqualTo
when all conditions are true.

* PluginProcess/mac/PluginProcessMac.mm:
(WebKit::isAdobeAcrobatAddress):
(WebKit::stringCompare):
(WebKit::initializeShim):
(WebKit::PluginProcess::platformInitializeProcess):
* PluginProcess/mac/PluginProcessShim.h:
* PluginProcess/mac/PluginProcessShim.mm:
(WebKit::shimCFStringCompare):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PluginProcessmacPluginProcessMacmm">trunk/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm</a></li>
<li><a href="#trunkSourceWebKit2PluginProcessmacPluginProcessShimh">trunk/Source/WebKit2/PluginProcess/mac/PluginProcessShim.h</a></li>
<li><a href="#trunkSourceWebKit2PluginProcessmacPluginProcessShimmm">trunk/Source/WebKit2/PluginProcess/mac/PluginProcessShim.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (202997 => 202998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-07-08 18:48:25 UTC (rev 202997)
+++ trunk/Source/WebKit2/ChangeLog        2016-07-08 18:52:26 UTC (rev 202998)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2016-07-07  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        REGRESSION (r196321): Adobe Reader DC + Safari : Zoom level pulldown is not displayed at the correct position
+        https://bugs.webkit.org/show_bug.cgi?id=159531
+        rdar://problem/26382579
+
+        Reviewed by Tim Horton.
+
+        There's code in the Adobe Acrobat framework that checks if the main bundle identifier is &quot;com.apple.WebKit.PluginProcess&quot;
+        and assumes that it's running inside the Adobe Reader app if it's something else. Since we're now using the XPC service
+        for all plug-ins, the bundle identifier is &quot;com.apple.WebKit.Plugin.64&quot;, so the Acrobat framework assumes it's running in the app
+        and doesn't use any special tricks to show the popup menu.
+        
+        Work around this by shimming CFStringCompare, and looking for the exact conditions when this can happen and return kCFCompareEqualTo
+        when all conditions are true.
+        
+        * PluginProcess/mac/PluginProcessMac.mm:
+        (WebKit::isAdobeAcrobatAddress):
+        (WebKit::stringCompare):
+        (WebKit::initializeShim):
+        (WebKit::PluginProcess::platformInitializeProcess):
+        * PluginProcess/mac/PluginProcessShim.h:
+        * PluginProcess/mac/PluginProcessShim.mm:
+        (WebKit::shimCFStringCompare):
+
</ins><span class="cx"> 2016-07-08  Brady Eidson  &lt;beidson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed: Fix case-sensitive filesystem build.
</span></span></pre></div>
<a id="trunkSourceWebKit2PluginProcessmacPluginProcessMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm (202997 => 202998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm        2016-07-08 18:48:25 UTC (rev 202997)
+++ trunk/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm        2016-07-08 18:52:26 UTC (rev 202998)
</span><span class="lines">@@ -238,7 +238,7 @@
</span><span class="cx">     PluginProcess::singleton().setModalWindowIsShowing(modalWindowIsShowing);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static unsigned modalCount = 0;
</del><ins>+static unsigned modalCount;
</ins><span class="cx"> 
</span><span class="cx"> static void beginModal()
</span><span class="cx"> {
</span><span class="lines">@@ -271,11 +271,70 @@
</span><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if defined(__i386__)
</del><ins>+static bool oldPluginProcessNameShouldEqualNewPluginProcessNameForAdobeReader;
+
+static bool isAdobeAcrobatAddress(const void* address)
+{
+    Dl_info imageInfo;
+    if (!dladdr(address, &amp;imageInfo))
+        return false;
+
+    const char* pathSuffix = &quot;/Contents/Frameworks/Acrobat.framework/Acrobat&quot;;
+
+    int pathSuffixLength = strlen(pathSuffix);
+    int imageFilePathLength = strlen(imageInfo.dli_fname);
+
+    if (imageFilePathLength &lt; pathSuffixLength)
+        return false;
+
+    if (strcmp(imageInfo.dli_fname + (imageFilePathLength - pathSuffixLength), pathSuffix))
+        return false;
+
+    return true;
+}
+
+static bool stringCompare(CFStringRef a, CFStringRef b, CFStringCompareFlags options, void* returnAddress, CFComparisonResult&amp; result)
+{
+    if (pthread_main_np() != 1)
+        return false;
+
+    if (!oldPluginProcessNameShouldEqualNewPluginProcessNameForAdobeReader)
+        return false;
+
+    if (options != kCFCompareCaseInsensitive)
+        return false;
+
+    const char* aCString = CFStringGetCStringPtr(a, kCFStringEncodingASCII);
+    if (!aCString)
+        return false;
+
+    const char* bCString = CFStringGetCStringPtr(b, kCFStringEncodingASCII);
+    if (!bCString)
+        return false;
+
+    if (strcmp(aCString, &quot;com.apple.WebKit.PluginProcess&quot;))
+        return false;
+
+    if (strcmp(bCString, &quot;com.apple.WebKit.Plugin.64&quot;))
+        return false;
+
+    // Check if the LHS string comes from the Acrobat framework.
+    if (!isAdobeAcrobatAddress(a))
+        return false;
+
+    // Check if the return adress is part of the Acrobat framework as well.
+    if (!isAdobeAcrobatAddress(returnAddress))
+        return false;
+
+    result = kCFCompareEqualTo;
+    return true;
+}
+
</ins><span class="cx"> static void initializeShim()
</span><span class="cx"> {
</span><span class="cx">     // Initialize the shim for 32-bit only.
</span><span class="cx">     const PluginProcessShimCallbacks callbacks = {
</span><ins>+#if defined(__i386__)
</ins><span class="cx">         shouldCallRealDebugger,
</span><span class="cx">         isWindowActive,
</span><span class="cx">         getCurrentEventButtonState,
</span><span class="lines">@@ -286,12 +345,13 @@
</span><span class="cx">         setModal,
</span><span class="cx">         openCFURLRef,
</span><span class="cx">         shouldMapMemoryExecutable,
</span><ins>+#endif
+        stringCompare,
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     PluginProcessShimInitializeFunc initFunc = reinterpret_cast&lt;PluginProcessShimInitializeFunc&gt;(dlsym(RTLD_DEFAULT, &quot;WebKitPluginProcessShimInitialize&quot;));
</span><span class="cx">     initFunc(callbacks);
</span><span class="cx"> }
</span><del>-#endif
</del><span class="cx"> 
</span><span class="cx"> static void (*NSConcreteTask_launch)(NSTask *, SEL);
</span><span class="cx"> 
</span><span class="lines">@@ -447,9 +507,7 @@
</span><span class="cx"> 
</span><span class="cx"> void PluginProcess::platformInitializeProcess(const ChildProcessInitializationParameters&amp; parameters)
</span><span class="cx"> {
</span><del>-#if defined(__i386__)
</del><span class="cx">     initializeShim();
</span><del>-#endif
</del><span class="cx"> 
</span><span class="cx">     initializeCocoaOverrides();
</span><span class="cx"> 
</span><span class="lines">@@ -467,6 +525,9 @@
</span><span class="cx"> 
</span><span class="cx">     m_pluginBundleIdentifier = CFBundleGetIdentifier(pluginBundle.get());
</span><span class="cx"> 
</span><ins>+    if (m_pluginBundleIdentifier == &quot;com.adobe.acrobat.pdfviewerNPAPI&quot;)
+        oldPluginProcessNameShouldEqualNewPluginProcessNameForAdobeReader = true;
+
</ins><span class="cx"> #if defined(__i386__)
</span><span class="cx">     if (m_pluginBundleIdentifier == &quot;com.microsoft.SilverlightPlugin&quot;) {
</span><span class="cx">         // Set this so that any calls to mach_vm_map for pages reserved by malloc will be executable.
</span></span></pre></div>
<a id="trunkSourceWebKit2PluginProcessmacPluginProcessShimh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/PluginProcess/mac/PluginProcessShim.h (202997 => 202998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/PluginProcess/mac/PluginProcessShim.h        2016-07-08 18:48:25 UTC (rev 202997)
+++ trunk/Source/WebKit2/PluginProcess/mac/PluginProcessShim.h        2016-07-08 18:52:26 UTC (rev 202998)
</span><span class="lines">@@ -23,8 +23,7 @@
</span><span class="cx">  * THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#ifndef PluginProcessShim_h
-#define PluginProcessShim_h
</del><ins>+#pragma once
</ins><span class="cx"> 
</span><span class="cx"> @class NSWindow;
</span><span class="cx"> 
</span><span class="lines">@@ -33,6 +32,7 @@
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> struct PluginProcessShimCallbacks {
</span><ins>+#if defined(__i386__)
</ins><span class="cx">     bool (*shouldCallRealDebugger)();
</span><span class="cx">     bool (*isWindowActive)(WindowRef, bool&amp; result);
</span><span class="cx">     UInt32 (*getCurrentEventButtonState)();
</span><span class="lines">@@ -43,10 +43,10 @@
</span><span class="cx">     void (*setModal)(bool);
</span><span class="cx">     bool (*openCFURLRef)(CFURLRef, int32_t&amp; returnValue, CFURLRef* launchedURL);
</span><span class="cx">     bool (*shouldMapMemoryExecutable)(int flags);
</span><ins>+#endif
+    bool (*stringCompare)(CFStringRef a, CFStringRef b, CFStringCompareFlags options, void* returnAddress, CFComparisonResult&amp; result);
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> typedef void (*PluginProcessShimInitializeFunc)(const PluginProcessShimCallbacks&amp;);
</span><span class="cx"> 
</span><span class="cx"> }
</span><del>-
-#endif // PluginProcessShim_h
</del></span></pre></div>
<a id="trunkSourceWebKit2PluginProcessmacPluginProcessShimmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/PluginProcess/mac/PluginProcessShim.mm (202997 => 202998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/PluginProcess/mac/PluginProcessShim.mm        2016-07-08 18:48:25 UTC (rev 202997)
+++ trunk/Source/WebKit2/PluginProcess/mac/PluginProcessShim.mm        2016-07-08 18:52:26 UTC (rev 202998)
</span><span class="lines">@@ -136,6 +136,7 @@
</span><span class="cx"> DYLD_INTERPOSE(shimHideWindow, HideWindow);
</span><span class="cx"> DYLD_INTERPOSE(shimLSOpenCFURLRef, LSOpenCFURLRef);
</span><span class="cx"> DYLD_INTERPOSE(shimMachVMMap, mach_vm_map);
</span><ins>+DYLD_INTERPOSE(shimCFStringCompare, CFStringCompare);
</ins><span class="cx"> 
</span><span class="cx"> #pragma clang diagnostic pop
</span><span class="cx"> 
</span><span class="lines">@@ -330,6 +331,20 @@
</span><span class="cx"> DYLD_INTERPOSE(shim_shmget, shmget);
</span><span class="cx"> DYLD_INTERPOSE(shim_shmctl, shmctl);
</span><span class="cx"> 
</span><ins>+static CFComparisonResult shimCFStringCompare(CFStringRef a, CFStringRef b, CFStringCompareFlags options)
+{
+    if (pluginProcessShimCallbacks.stringCompare) {
+        CFComparisonResult result;
+        if (pluginProcessShimCallbacks.stringCompare(a, b, options, __builtin_return_address(0), result))
+            return result;
+    }
+
+    return CFStringCompare(a, b, options);
+}
+
+DYLD_INTERPOSE(shimCFStringCompare, CFStringCompare);
+
+
</ins><span class="cx"> __attribute__((visibility(&quot;default&quot;)))
</span><span class="cx"> void WebKitPluginProcessShimInitialize(const PluginProcessShimCallbacks&amp; callbacks)
</span><span class="cx"> {
</span></span></pre>
</div>
</div>

</body>
</html>