Browse Source

fix: disable more private macOS APIs in MAS build (5-0-x) (#20988)

* fix: add patch to disable remote layer APIs

* fix: add patch to disable remote accessibility APIs

* fix: add patch to disable private window frame APIs

* fix: add patch to disable NSURLFileTypeMappings API
Cheng Zhao 5 years ago
parent
commit
2053da9f83

+ 4 - 0
patches/common/chromium/.patches

@@ -45,6 +45,10 @@ allow_webview_file_url.patch
 enable_osr_components.patch
 ignore_rc_check.patch
 enable_widevine.patch
+mas_disable_remote_layer.patch
+mas_disable_remote_accessibility.patch
+mas_disable_custom_window_frame.patch
+mas_disable_spi_file_type_mappings.patch
 chrome_key_systems.patch
 allow_nested_error_trackers.patch
 blink_initialization_order.patch

+ 150 - 0
patches/common/chromium/mas_disable_custom_window_frame.patch

@@ -0,0 +1,150 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Cheng Zhao <[email protected]>
+Date: Thu, 20 Sep 2018 17:48:49 -0700
+Subject: mas_disable_custom_window_frame.patch
+
+Disable private window frame APIs (NSNextStepFrame and NSThemeFrame) for MAS
+build.
+
+diff --git a/ui/views_bridge_mac/browser_native_widget_window_mac.mm b/ui/views_bridge_mac/browser_native_widget_window_mac.mm
+index e391bf976bf6..41e45901d180 100644
+--- a/ui/views_bridge_mac/browser_native_widget_window_mac.mm
++++ b/ui/views_bridge_mac/browser_native_widget_window_mac.mm
+@@ -9,6 +9,8 @@
+ #include "ui/views_bridge_mac/bridged_native_widget_impl.h"
+ #include "ui/views_bridge_mac/mojo/bridged_native_widget_host.mojom.h"
+ 
++#ifndef MAS_BUILD
++
+ @interface NSWindow (PrivateBrowserNativeWidgetAPI)
+ + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle;
+ @end
+@@ -69,10 +71,14 @@ - (NSRect)_draggableFrame NS_DEPRECATED_MAC(10_10, 10_11) {
+ 
+ @end
+ 
++#endif  // MAS_BUILD
++
+ @implementation BrowserNativeWidgetWindow
+ 
+ // NSWindow (PrivateAPI) overrides.
+ 
++#ifndef MAS_BUILD
++
+ + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle {
+   // - NSThemeFrame and its subclasses will be nil if it's missing at runtime.
+   if ([BrowserWindowFrame class])
+@@ -87,6 +93,8 @@ - (BOOL)_usesCustomDrawing {
+   return NO;
+ }
+ 
++#endif  // MAS_BUILD
++
+ // Handle "Move focus to the window toolbar" configured in System Preferences ->
+ // Keyboard -> Shortcuts -> Keyboard. Usually Ctrl+F5. The argument (|unknown|)
+ // tends to just be nil.
+diff --git a/ui/views_bridge_mac/native_widget_mac_frameless_nswindow.mm b/ui/views_bridge_mac/native_widget_mac_frameless_nswindow.mm
+index 583003b9789d..57b285fe98fb 100644
+--- a/ui/views_bridge_mac/native_widget_mac_frameless_nswindow.mm
++++ b/ui/views_bridge_mac/native_widget_mac_frameless_nswindow.mm
+@@ -4,6 +4,8 @@
+ 
+ #import "ui/views_bridge_mac/native_widget_mac_frameless_nswindow.h"
+ 
++#ifndef MAS_BUILD
++
+ @interface NSWindow (PrivateAPI)
+ + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle;
+ @end
+@@ -18,8 +20,12 @@ - (CGFloat)_titlebarHeight {
+ }
+ @end
+ 
++#endif  // MAS_BUILD
++
+ @implementation NativeWidgetMacFramelessNSWindow
+ 
++#ifndef MAS_BUILD
++
+ + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle {
+   if ([NativeWidgetMacFramelessNSWindowFrame class]) {
+     return [NativeWidgetMacFramelessNSWindowFrame class];
+@@ -27,4 +33,6 @@ + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle {
+   return [super frameViewClassForStyleMask:windowStyle];
+ }
+ 
++#endif   // MAS_BUILD
++
+ @end
+diff --git a/ui/views_bridge_mac/native_widget_mac_nswindow.h b/ui/views_bridge_mac/native_widget_mac_nswindow.h
+index 30b091bb60ed..8e54c6057250 100644
+--- a/ui/views_bridge_mac/native_widget_mac_nswindow.h
++++ b/ui/views_bridge_mac/native_widget_mac_nswindow.h
+@@ -17,6 +17,8 @@ class BridgedNativeWidgetImpl;
+ 
+ @protocol WindowTouchBarDelegate;
+ 
++#ifndef MAS_BUILD
++
+ // Weak lets Chrome launch even if a future macOS doesn't have the below classes
+ 
+ WEAK_IMPORT_ATTRIBUTE
+@@ -33,6 +35,8 @@ VIEWS_EXPORT
+ @interface NativeWidgetMacNSWindowTitledFrame : NSThemeFrame
+ @end
+ 
++#endif  // MAS_BUILD
++
+ // The NSWindow used by BridgedNativeWidget. Provides hooks into AppKit that
+ // can only be accomplished by overriding methods.
+ VIEWS_EXPORT
+diff --git a/ui/views_bridge_mac/native_widget_mac_nswindow.mm b/ui/views_bridge_mac/native_widget_mac_nswindow.mm
+index fac57d31027e..259833c8e910 100644
+--- a/ui/views_bridge_mac/native_widget_mac_nswindow.mm
++++ b/ui/views_bridge_mac/native_widget_mac_nswindow.mm
+@@ -15,7 +15,9 @@
+ #import "ui/views_bridge_mac/window_touch_bar_delegate.h"
+ 
+ @interface NSWindow (Private)
++#ifndef MAS_BUILD
+ + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle;
++#endif
+ - (BOOL)hasKeyAppearance;
+ - (long long)_resizeDirectionForMouseLocation:(CGPoint)location;
+ 
+@@ -56,6 +58,8 @@ - (void)cr_mouseDownOnFrameView:(NSEvent*)event {
+ }
+ @end
+ 
++#ifndef MAS_BUILD
++
+ @implementation NativeWidgetMacNSWindowTitledFrame
+ - (void)mouseDown:(NSEvent*)event {
+   [self cr_mouseDownOnFrameView:event];
+@@ -76,6 +80,8 @@ - (BOOL)usesCustomDrawing {
+ }
+ @end
+ 
++#endif  // MAS_BUILD
++
+ @implementation NativeWidgetMacNSWindow {
+  @private
+   base::scoped_nsobject<CommandDispatcher> commandDispatcher_;
+@@ -148,6 +154,8 @@ - (id)rootAccessibilityObject {
+ 
+ // NSWindow overrides.
+ 
++#ifndef MAS_BUILD
++
+ + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle {
+   if (windowStyle & NSWindowStyleMaskTitled) {
+     if (Class customFrame = [NativeWidgetMacNSWindowTitledFrame class])
+@@ -159,6 +167,8 @@ + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle {
+   return [super frameViewClassForStyleMask:windowStyle];
+ }
+ 
++#endif  // MAS_BUILD
++
+ - (BOOL)_isTitleHidden {
+   bool shouldShowWindowTitle = YES;
+   if (bridgeImpl_)

+ 308 - 0
patches/common/chromium/mas_disable_remote_accessibility.patch

@@ -0,0 +1,308 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Cheng Zhao <[email protected]>
+Date: Thu, 20 Sep 2018 17:48:49 -0700
+Subject: mas_disable_remote_accessibility.patch
+
+Disable remote accessibility APIs (NSAccessibilityRemoteUIElement) for MAS
+build.
+
+diff --git a/content/browser/ns_view_bridge_factory_impl.mm b/content/browser/ns_view_bridge_factory_impl.mm
+index 118fb68e451d..382ab5c19018 100644
+--- a/content/browser/ns_view_bridge_factory_impl.mm
++++ b/content/browser/ns_view_bridge_factory_impl.mm
+@@ -48,6 +48,7 @@ explicit RenderWidgetHostNSViewBridgeOwner(
+ 
+   // RenderWidgetHostNSViewClientHelper implementation.
+   id GetRootBrowserAccessibilityElement() override {
++#ifndef MAS_BUILD
+     if (!remote_accessibility_element_) {
+       int64_t browser_pid = 0;
+       std::vector<uint8_t> element_token;
+@@ -58,13 +59,18 @@ id GetRootBrowserAccessibilityElement() override {
+           ui::RemoteAccessibility::GetRemoteElementFromToken(element_token);
+     }
+     return remote_accessibility_element_.get();
++#else
++    return nil;
++#endif
+   }
+   id GetFocusedBrowserAccessibilityElement() override {
+     return GetRootBrowserAccessibilityElement();
+   }
+   void SetAccessibilityWindow(NSWindow* window) override {
++#ifndef MAS_BUILD
+     client_->SetRemoteAccessibilityWindowToken(
+         ui::RemoteAccessibility::GetTokenForLocalElement(window));
++#endif
+   }
+ 
+   void ForwardKeyboardEvent(const NativeWebKeyboardEvent& key_event,
+@@ -125,8 +131,10 @@ void SmartMagnify(const blink::WebGestureEvent& web_event) override {
+ 
+   mojom::RenderWidgetHostNSViewClientAssociatedPtr client_;
+   std::unique_ptr<RenderWidgetHostNSViewBridgeLocal> bridge_;
++#ifndef MAS_BUILD
+   base::scoped_nsobject<NSAccessibilityRemoteUIElement>
+       remote_accessibility_element_;
++#endif
+ 
+   DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostNSViewBridgeOwner);
+ };
+diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
+index 4c9994c3e1bf..9f320d6203f0 100644
+--- a/content/browser/renderer_host/render_widget_host_view_mac.h
++++ b/content/browser/renderer_host/render_widget_host_view_mac.h
+@@ -37,7 +37,9 @@ class ScopedPasswordInputEnabler;
+ 
+ @protocol RenderWidgetHostViewMacDelegate;
+ 
++#ifndef MAS_BUILD
+ @class NSAccessibilityRemoteUIElement;
++#endif
+ @class RenderWidgetHostViewCocoa;
+ 
+ namespace content {
+@@ -637,10 +639,12 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
+   // EnsureSurfaceSynchronizedForWebTest().
+   uint32_t latest_capture_sequence_number_ = 0u;
+ 
++#ifndef MAS_BUILD
+   // Remote accessibility objects corresponding to the NSWindow that this is
+   // displayed to the user in.
+   base::scoped_nsobject<NSAccessibilityRemoteUIElement>
+       remote_window_accessible_;
++#endif
+ 
+   // Used to force the NSApplication's focused accessibility element to be the
+   // content::BrowserAccessibilityCocoa accessibility tree when the NSView for
+diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
+index 82e72fd8bd92..d37a8c425006 100644
+--- a/content/browser/renderer_host/render_widget_host_view_mac.mm
++++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
+@@ -263,8 +263,10 @@
+ void RenderWidgetHostViewMac::MigrateNSViewBridge(
+     NSViewBridgeFactoryHost* bridge_factory_host,
+     uint64_t parent_ns_view_id) {
++#ifndef MAS_BUILD
+   // Destroy the previous remote accessibility element.
+   remote_window_accessible_.reset();
++#endif
+ 
+   // Disconnect from the previous bridge (this will have the effect of
+   // destroying the associated bridge), and close the binding (to allow it
+@@ -1402,8 +1404,10 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
+ 
+ gfx::NativeViewAccessible
+ RenderWidgetHostViewMac::AccessibilityGetNativeViewAccessibleForWindow() {
++#ifndef MAS_BUILD
+   if (remote_window_accessible_)
+     return remote_window_accessible_.get();
++#endif
+   return [cocoa_view() window];
+ }
+ 
+@@ -1447,9 +1451,11 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
+ }
+ 
+ void RenderWidgetHostViewMac::SetAccessibilityWindow(NSWindow* window) {
++#ifndef MAS_BUILD
+   // When running in-process, just use the NSView's NSWindow as its own
+   // accessibility element.
+   remote_window_accessible_.reset();
++#endif
+ }
+ 
+ bool RenderWidgetHostViewMac::SyncIsWidgetForMainFrame(
+@@ -1929,19 +1935,23 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
+ 
+ void RenderWidgetHostViewMac::SyncGetRootAccessibilityElement(
+     SyncGetRootAccessibilityElementCallback callback) {
++#ifndef MAS_BUILD
+   id element_id = GetRootBrowserAccessibilityElement();
+   std::move(callback).Run(
+       getpid(), ui::RemoteAccessibility::GetTokenForLocalElement(element_id));
++#endif
+ }
+ 
+ void RenderWidgetHostViewMac::SetRemoteAccessibilityWindowToken(
+     const std::vector<uint8_t>& window_token) {
++#ifndef MAS_BUILD
+   if (window_token.empty()) {
+     remote_window_accessible_.reset();
+   } else {
+     remote_window_accessible_ =
+         ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
+   }
++#endif
+ }
+ 
+ ///////////////////////////////////////////////////////////////////////////////
+diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn
+index 195435b5cc3a..86ef61629a35 100644
+--- a/ui/base/BUILD.gn
++++ b/ui/base/BUILD.gn
+@@ -293,6 +293,13 @@ jumbo_component("base") {
+     "window_open_disposition.h",
+   ]
+ 
++  if (is_mas_build) {
++    sources -= [
++      "cocoa/remote_accessibility_api.h",
++      "cocoa/remote_accessibility_api.mm",
++    ]
++  }
++
+   if (is_posix) {
+     sources += [ "l10n/l10n_util_posix.cc" ]
+   }
+diff --git a/ui/base/cocoa/remote_accessibility_api.h b/ui/base/cocoa/remote_accessibility_api.h
+index 2a58aebabb23..3424b6011e80 100644
+--- a/ui/base/cocoa/remote_accessibility_api.h
++++ b/ui/base/cocoa/remote_accessibility_api.h
+@@ -11,6 +11,8 @@
+ #include "base/mac/scoped_nsobject.h"
+ #include "ui/base/ui_base_export.h"
+ 
++#ifndef MAS_BUILD
++
+ @interface NSAccessibilityRemoteUIElement : NSObject
+ + (void)registerRemoteUIProcessIdentifier:(int)pid;
+ + (NSData*)remoteTokenForLocalUIElement:(id)element;
+@@ -32,4 +34,6 @@ class UI_BASE_EXPORT RemoteAccessibility {
+ 
+ }  // namespace ui
+ 
++#endif  // MAS_BUILD
++
+ #endif  // UI_BASE_COCOA_REMOTE_ACCESSIBILITY_API_H_
+diff --git a/ui/views/cocoa/bridged_native_widget_host_impl.h b/ui/views/cocoa/bridged_native_widget_host_impl.h
+index f37b520f49ed..5d4fa32bbee2 100644
+--- a/ui/views/cocoa/bridged_native_widget_host_impl.h
++++ b/ui/views/cocoa/bridged_native_widget_host_impl.h
+@@ -28,7 +28,9 @@
+ #include "ui/views_bridge_mac/mojo/bridged_native_widget_host.mojom.h"
+ 
+ @class NativeWidgetMacNSWindow;
++#ifndef MAS_BUILD
+ @class NSAccessibilityRemoteUIElement;
++#endif
+ @class NSView;
+ 
+ namespace ui {
+@@ -392,11 +394,13 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
+   // process.
+   views_bridge_mac::mojom::BridgedNativeWidgetAssociatedPtr bridge_ptr_;
+ 
++#ifndef MAS_BUILD
+   // Remote accessibility objects corresponding to the NSWindow and its root
+   // NSView.
+   base::scoped_nsobject<NSAccessibilityRemoteUIElement>
+       remote_window_accessible_;
+   base::scoped_nsobject<NSAccessibilityRemoteUIElement> remote_view_accessible_;
++#endif
+ 
+   // Used to force the NSApplication's focused accessibility element to be the
+   // views::Views accessibility tree when the NSView for this is focused.
+diff --git a/ui/views/cocoa/bridged_native_widget_host_impl.mm b/ui/views/cocoa/bridged_native_widget_host_impl.mm
+index 8004f676b09c..fa6229777533 100644
+--- a/ui/views/cocoa/bridged_native_widget_host_impl.mm
++++ b/ui/views/cocoa/bridged_native_widget_host_impl.mm
+@@ -345,14 +345,22 @@ void UpdateCALayerParams(gfx::CALayerParams* ca_layer_params) {
+ BridgedNativeWidgetHostImpl::GetNativeViewAccessibleForNSView() const {
+   if (bridge_impl_)
+     return bridge_impl_->ns_view();
++#ifndef MAS_BUILD
+   return remote_view_accessible_.get();
++#else
++  return nullptr;
++#endif
+ }
+ 
+ gfx::NativeViewAccessible
+ BridgedNativeWidgetHostImpl::GetNativeViewAccessibleForNSWindow() const {
+   if (bridge_impl_)
+     return bridge_impl_->ns_window();
++#ifndef MAS_BUILD
+   return remote_window_accessible_.get();
++#else
++  return nullptr;
++#endif
+ }
+ 
+ views_bridge_mac::mojom::BridgedNativeWidget*
+@@ -1138,6 +1146,7 @@ void UpdateCALayerParams(gfx::CALayerParams* ca_layer_params) {
+ void BridgedNativeWidgetHostImpl::SetRemoteAccessibilityTokens(
+     const std::vector<uint8_t>& window_token,
+     const std::vector<uint8_t>& view_token) {
++#ifndef MAS_BUILD
+   remote_window_accessible_ =
+       ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
+   remote_view_accessible_ =
+@@ -1145,14 +1154,17 @@ void UpdateCALayerParams(gfx::CALayerParams* ca_layer_params) {
+   [remote_view_accessible_ setWindowUIElement:remote_window_accessible_.get()];
+   [remote_view_accessible_
+       setTopLevelUIElement:remote_window_accessible_.get()];
++#endif
+ }
+ 
+ bool BridgedNativeWidgetHostImpl::GetRootViewAccessibilityToken(
+     int64_t* pid,
+     std::vector<uint8_t>* token) {
++#ifndef MAS_BUILD
+   *pid = getpid();
+   id element_id = GetNativeViewAccessible();
+   *token = ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
++#endif
+   return true;
+ }
+ 
+diff --git a/ui/views_bridge_mac/bridge_factory_impl.mm b/ui/views_bridge_mac/bridge_factory_impl.mm
+index 614379e22a82..d3e3c10a4925 100644
+--- a/ui/views_bridge_mac/bridge_factory_impl.mm
++++ b/ui/views_bridge_mac/bridge_factory_impl.mm
+@@ -42,6 +42,7 @@
+ 
+   // BridgedNativeWidgetHostHelper:
+   id GetNativeViewAccessible() override {
++#ifndef MAS_BUILD
+     if (!remote_accessibility_element_) {
+       int64_t browser_pid = 0;
+       std::vector<uint8_t> element_token;
+@@ -52,6 +53,9 @@ id GetNativeViewAccessible() override {
+           ui::RemoteAccessibility::GetRemoteElementFromToken(element_token);
+     }
+     return remote_accessibility_element_.get();
++#else
++    return nil;
++#endif
+   }
+   void DispatchKeyEvent(ui::KeyEvent* event) override {
+     bool event_handled = false;
+@@ -89,8 +93,10 @@ void GetWordAt(const gfx::Point& location_in_content,
+   mojom::TextInputHostAssociatedPtr text_input_host_ptr_;
+ 
+   std::unique_ptr<BridgedNativeWidgetImpl> bridge_impl_;
++#ifndef MAS_BUILD
+   base::scoped_nsobject<NSAccessibilityRemoteUIElement>
+       remote_accessibility_element_;
++#endif
+ };
+ 
+ }  // namespace
+diff --git a/ui/views_bridge_mac/bridged_native_widget_impl.mm b/ui/views_bridge_mac/bridged_native_widget_impl.mm
+index f1d96295cf69..ec5603eccee0 100644
+--- a/ui/views_bridge_mac/bridged_native_widget_impl.mm
++++ b/ui/views_bridge_mac/bridged_native_widget_impl.mm
+@@ -529,10 +529,12 @@ NSUInteger CountBridgedWindows(NSArray* child_windows) {
+   // this should be treated as an error and caught early.
+   CHECK(bridged_view_);
+ 
++#ifndef MAS_BUILD
+   // Send the accessibility tokens for the NSView now that it exists.
+   host_->SetRemoteAccessibilityTokens(
+       ui::RemoteAccessibility::GetTokenForLocalElement(window_),
+       ui::RemoteAccessibility::GetTokenForLocalElement(bridged_view_));
++#endif
+ 
+   // Beware: This view was briefly removed (in favor of a bare CALayer) in
+   // crrev/c/1236675. The ordering of unassociated layers relative to NSView

+ 186 - 0
patches/common/chromium/mas_disable_remote_layer.patch

@@ -0,0 +1,186 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Cheng Zhao <[email protected]>
+Date: Thu, 20 Sep 2018 17:48:49 -0700
+Subject: mas_disable_remote_layer.patch
+
+Disable remote layer APIs (CAContext and CALayerHost) for MAS build.
+
+diff --git a/gpu/ipc/service/image_transport_surface_overlay_mac.h b/gpu/ipc/service/image_transport_surface_overlay_mac.h
+index 5d68c4f9944b..d4869147f74f 100644
+--- a/gpu/ipc/service/image_transport_surface_overlay_mac.h
++++ b/gpu/ipc/service/image_transport_surface_overlay_mac.h
+@@ -16,7 +16,9 @@
+ #include "ui/gl/gl_surface.h"
+ #include "ui/gl/gpu_switching_observer.h"
+ 
++#ifndef MAS_BUILD
+ @class CAContext;
++#endif
+ @class CALayer;
+ 
+ namespace ui {
+@@ -84,7 +86,9 @@ class ImageTransportSurfaceOverlayMac : public gl::GLSurface,
+   base::WeakPtr<ImageTransportSurfaceDelegate> delegate_;
+ 
+   bool use_remote_layer_api_;
++#ifndef MAS_BUILD
+   base::scoped_nsobject<CAContext> ca_context_;
++#endif
+   std::unique_ptr<ui::CALayerTreeCoordinator> ca_layer_tree_coordinator_;
+ 
+   gfx::Size pixel_size_;
+diff --git a/gpu/ipc/service/image_transport_surface_overlay_mac.mm b/gpu/ipc/service/image_transport_surface_overlay_mac.mm
+index 3884df87a49f..0604876a93ec 100644
+--- a/gpu/ipc/service/image_transport_surface_overlay_mac.mm
++++ b/gpu/ipc/service/image_transport_surface_overlay_mac.mm
+@@ -56,6 +56,7 @@
+ }
+ 
+ bool ImageTransportSurfaceOverlayMac::Initialize(gl::GLSurfaceFormat format) {
++#ifndef MAS_BUILD
+   // Create the CAContext to send this to the GPU process, and the layer for
+   // the context.
+   if (use_remote_layer_api_) {
+@@ -64,6 +65,7 @@
+         [CAContext contextWithCGSConnection:connection_id options:@{}] retain]);
+     [ca_context_ setLayer:ca_layer_tree_coordinator_->GetCALayerForDisplay()];
+   }
++#endif
+   return true;
+ }
+ 
+@@ -122,7 +124,9 @@
+                          "GLImpl", static_cast<int>(gl::GetGLImplementation()),
+                          "width", pixel_size_.width());
+     if (use_remote_layer_api_) {
++#ifndef MAS_BUILD
+       params.ca_layer_params.ca_context_id = [ca_context_ contextId];
++#endif
+     } else {
+       IOSurfaceRef io_surface =
+           ca_layer_tree_coordinator_->GetIOSurfaceForDisplay();
+diff --git a/ui/accelerated_widget_mac/display_ca_layer_tree.mm b/ui/accelerated_widget_mac/display_ca_layer_tree.mm
+index 60abe639bd9c..c38eed5fbdef 100644
+--- a/ui/accelerated_widget_mac/display_ca_layer_tree.mm
++++ b/ui/accelerated_widget_mac/display_ca_layer_tree.mm
+@@ -98,6 +98,7 @@ - (void)setContentsChanged;
+ }
+ 
+ void DisplayCALayerTree::GotCALayerFrame(uint32_t ca_context_id) {
++#ifndef MAS_BUILD
+   // Early-out if the remote layer has not changed.
+   if ([remote_layer_ contextId] == ca_context_id)
+     return;
+@@ -122,6 +123,9 @@ - (void)setContentsChanged;
+     [io_surface_layer_ removeFromSuperlayer];
+     io_surface_layer_.reset();
+   }
++#else
++  NOTREACHED() << "Remote layer is being used in MAS build";
++#endif
+ }
+ 
+ void DisplayCALayerTree::GotIOSurfaceFrame(
+diff --git a/ui/base/cocoa/remote_layer_api.h b/ui/base/cocoa/remote_layer_api.h
+index 291a11b4d13b..c35919922fa2 100644
+--- a/ui/base/cocoa/remote_layer_api.h
++++ b/ui/base/cocoa/remote_layer_api.h
+@@ -13,6 +13,7 @@
+ 
+ #include "ui/base/ui_base_export.h"
+ 
++#ifndef MAS_BUILD
+ // The CGSConnectionID is used to create the CAContext in the process that is
+ // going to share the CALayers that it is rendering to another process to
+ // display.
+@@ -50,6 +51,8 @@ typedef uint32_t CAContextID;
+ 
+ #endif // __OBJC__
+ 
++#endif // MAS_BUILD
++
+ namespace ui {
+ 
+ // This function will check if all of the interfaces listed above are supported
+diff --git a/ui/base/cocoa/remote_layer_api.mm b/ui/base/cocoa/remote_layer_api.mm
+index bbaf9f466f49..8c846ce9523a 100644
+--- a/ui/base/cocoa/remote_layer_api.mm
++++ b/ui/base/cocoa/remote_layer_api.mm
+@@ -12,6 +12,7 @@
+ namespace ui {
+ 
+ bool RemoteLayerAPISupported() {
++#ifndef MAS_BUILD
+   static bool disabled_at_command_line =
+       base::CommandLine::ForCurrentProcess()->HasSwitch(
+           switches::kDisableRemoteCoreAnimation);
+@@ -46,6 +47,9 @@ bool RemoteLayerAPISupported() {
+ 
+   // If everything is there, we should be able to use the API.
+   return true;
++#else
++  return false;
++#endif  // MAS_BUILD
+ }
+ 
+ }  // namespace
+diff --git a/ui/views/cocoa/bridged_native_widget_host_impl.h b/ui/views/cocoa/bridged_native_widget_host_impl.h
+index 2214108d4c75..f37b520f49ed 100644
+--- a/ui/views/cocoa/bridged_native_widget_host_impl.h
++++ b/ui/views/cocoa/bridged_native_widget_host_impl.h
+@@ -426,11 +426,13 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
+   // Display link for getting vsync info for |display_|.
+   scoped_refptr<ui::DisplayLinkMac> display_link_;
+ 
++#ifndef MAS_BUILD
+   // Structure to avoid sending IOSurface mach ports over mojo.
+   // https://crbug.com/942213
+   class IOSurfaceToRemoteLayerInterceptor;
+   std::unique_ptr<IOSurfaceToRemoteLayerInterceptor>
+       io_surface_to_remote_layer_interceptor_;
++#endif
+ 
+   // The geometry of the window and its contents view, in screen coordinates.
+   gfx::Rect window_bounds_in_screen_;
+diff --git a/ui/views/cocoa/bridged_native_widget_host_impl.mm b/ui/views/cocoa/bridged_native_widget_host_impl.mm
+index 37206fa1e261..8004f676b09c 100644
+--- a/ui/views/cocoa/bridged_native_widget_host_impl.mm
++++ b/ui/views/cocoa/bridged_native_widget_host_impl.mm
+@@ -208,6 +208,8 @@ bool PositionWindowInScreenCoordinates(Widget* widget,
+ 
+ }  // namespace
+ 
++#ifndef MAS_BUILD
++
+ // A gfx::CALayerParams may pass the content to be drawn across processes via
+ // either an IOSurface (sent as mach port) or a CAContextID (which is an
+ // integer). For historical reasons, software compositing uses IOSurfaces.
+@@ -262,6 +264,8 @@ void UpdateCALayerParams(gfx::CALayerParams* ca_layer_params) {
+   base::scoped_nsobject<CALayer> io_surface_layer_;
+ };
+ 
++#endif  // MAS_BUILD
++
+ // static
+ BridgedNativeWidgetHostImpl* BridgedNativeWidgetHostImpl::GetFromNativeWindow(
+     gfx::NativeWindow native_window) {
+@@ -1413,6 +1417,7 @@ void UpdateCALayerParams(gfx::CALayerParams* ca_layer_params) {
+   const gfx::CALayerParams* ca_layer_params =
+       compositor_->widget()->GetCALayerParams();
+   if (ca_layer_params) {
++#ifndef MAS_BUILD
+     // Replace IOSurface mach ports with CAContextIDs only when using the
+     // out-of-process bridge (to reduce risk, because this workaround is being
+     // merged to late-life-cycle release branches) and when an IOSurface
+@@ -1429,8 +1434,11 @@ void UpdateCALayerParams(gfx::CALayerParams* ca_layer_params) {
+           &updated_ca_layer_params);
+       bridge_ptr_->SetCALayerParams(updated_ca_layer_params);
+     } else {
++#endif  // MAS_BUILD
+       bridge()->SetCALayerParams(*ca_layer_params);
++#ifndef MAS_BUILD
+     }
++#endif  // MAS_BUILD
+   }
+ 
+   // Take this opportunity to update the VSync parameters, if needed.

+ 47 - 0
patches/common/chromium/mas_disable_spi_file_type_mappings.patch

@@ -0,0 +1,47 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Cheng Zhao <[email protected]>
+Date: Thu, 20 Sep 2018 17:48:49 -0700
+Subject: mas_disable_spi_file_type_mappings.patch
+
+Disable NSURLFileTypeMappings API for MAS build.
+
+diff --git a/net/base/platform_mime_util_mac.mm b/net/base/platform_mime_util_mac.mm
+index a510c87ea7d9..b5f8ed974402 100644
+--- a/net/base/platform_mime_util_mac.mm
++++ b/net/base/platform_mime_util_mac.mm
+@@ -18,7 +18,7 @@
+ #include <CoreServices/CoreServices.h>
+ #endif  // defined(OS_IOS)
+ 
+-#if !defined(OS_IOS)
++#if !defined(OS_IOS) && !defined(MAS_BUILD)
+ // SPI declaration; see the commentary in GetPlatformExtensionsForMimeType.
+ // iOS must not use any private API, per Apple guideline.
+ 
+@@ -26,7 +26,7 @@ @interface NSURLFileTypeMappings : NSObject
+ + (NSURLFileTypeMappings*)sharedMappings;
+ - (NSArray*)extensionsForMIMEType:(NSString*)mimeType;
+ @end
+-#endif  // !defined(OS_IOS)
++#endif  // !defined(OS_IOS) && !defined(MAS_BUILD)
+ 
+ namespace net {
+ 
+@@ -75,7 +75,7 @@ - (NSArray*)extensionsForMIMEType:(NSString*)mimeType;
+ void PlatformMimeUtil::GetPlatformExtensionsForMimeType(
+     const std::string& mime_type,
+     std::unordered_set<base::FilePath::StringType>* extensions) const {
+-#if defined(OS_IOS)
++#if defined(OS_IOS) || defined(MAS_BUILD)
+   NSArray* extensions_list = nil;
+ #else
+   // There is no API for this that uses UTIs. The WebKitSystemInterface call
+@@ -90,7 +90,7 @@ - (NSArray*)extensionsForMIMEType:(NSString*)mimeType;
+   NSArray* extensions_list =
+       [[NSURLFileTypeMappings sharedMappings]
+           extensionsForMIMEType:base::SysUTF8ToNSString(mime_type)];
+-#endif  // defined(OS_IOS)
++#endif  // defined(OS_IOS)  || defined(MAS_BUILD)
+ 
+   if (extensions_list) {
+     for (NSString* extension in extensions_list)