Commit b41a2b9d authored by Mats Palmgren's avatar Mats Palmgren
Browse files

Bug 1687239 part 2 - Remove plugin support from layout/. r=emilio

Note that there's still a little plugin related code in
widget/ and gfx/ etc after this.  That can be removed
once we remove plugin support from dom/ etc.
The removal from layout/ should be pretty complete though.

Differential Revision: https://phabricator.services.mozilla.com/D102140
parent 334efb39
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ enum AccType {
  eHyperTextType,
  eImageType,
  eOuterDocType,
  ePluginType,
  eTextLeafType,

  /**
+0 −130
Original line number Diff line number Diff line
@@ -62,7 +62,6 @@
#include "nsIObserverService.h"
#include "nsMenuPopupFrame.h"
#include "nsLayoutUtils.h"
#include "nsPluginFrame.h"
#include "nsTreeBodyFrame.h"
#include "nsTreeColumns.h"
#include "nsTreeUtils.h"
@@ -87,10 +86,6 @@
#  include "XULTreeGridAccessibleWrap.h"
#endif

#if defined(XP_WIN) || defined(MOZ_ACCESSIBILITY_ATK)
#  include "nsNPAPIPluginInstance.h"
#endif

using namespace mozilla;
using namespace mozilla::a11y;
using namespace mozilla::dom;
@@ -398,111 +393,6 @@ Accessible* nsAccessibilityService::GetRootDocumentAccessible(
  return nullptr;
}

#ifdef XP_WIN
static StaticAutoPtr<nsTArray<nsCOMPtr<nsIContent> > > sPendingPlugins;
static StaticAutoPtr<nsTArray<nsCOMPtr<nsITimer> > > sPluginTimers;

class PluginTimerCallBack final : public nsITimerCallback, public nsINamed {
  ~PluginTimerCallBack() {}

 public:
  explicit PluginTimerCallBack(nsIContent* aContent) : mContent(aContent) {}

  NS_DECL_ISUPPORTS

  NS_IMETHOD Notify(nsITimer* aTimer) final {
    if (!mContent->IsInUncomposedDoc()) return NS_OK;

    PresShell* presShell = mContent->OwnerDoc()->GetPresShell();
    if (presShell) {
      DocAccessible* doc = presShell->GetDocAccessible();
      if (doc) {
        // Make sure that if we created an accessible for the plugin that wasn't
        // a plugin accessible we remove it before creating the right
        // accessible.
        doc->RecreateAccessible(mContent);
        sPluginTimers->RemoveElement(aTimer);
        return NS_OK;
      }
    }

    // We couldn't get a doc accessible so presumably the document went away.
    // In this case don't leak our ref to the content or timer.
    sPendingPlugins->RemoveElement(mContent);
    sPluginTimers->RemoveElement(aTimer);
    return NS_OK;
  }

  NS_IMETHOD GetName(nsACString& aName) final {
    aName.AssignLiteral("PluginTimerCallBack");
    return NS_OK;
  }

 private:
  nsCOMPtr<nsIContent> mContent;
};

NS_IMPL_ISUPPORTS(PluginTimerCallBack, nsITimerCallback, nsINamed)
#endif

already_AddRefed<Accessible> nsAccessibilityService::CreatePluginAccessible(
    nsPluginFrame* aFrame, nsIContent* aContent, Accessible* aContext) {
  // nsPluginFrame means a plugin, so we need to use the accessibility support
  // of the plugin.
  if (aFrame->GetRect().IsEmpty()) return nullptr;

#if defined(XP_WIN) || defined(MOZ_ACCESSIBILITY_ATK)
  RefPtr<nsNPAPIPluginInstance> pluginInstance = aFrame->GetPluginInstance();
  if (pluginInstance) {
#  ifdef XP_WIN
    if (!sPendingPlugins->Contains(aContent) &&
        (Preferences::GetBool("accessibility.delay_plugins") ||
         Compatibility::IsJAWS() || Compatibility::IsWE())) {
      RefPtr<PluginTimerCallBack> cb = new PluginTimerCallBack(aContent);
      nsCOMPtr<nsITimer> timer;
      NS_NewTimerWithCallback(
          getter_AddRefs(timer), cb,
          Preferences::GetUint("accessibility.delay_plugin_time"),
          nsITimer::TYPE_ONE_SHOT);
      sPluginTimers->AppendElement(timer);
      sPendingPlugins->AppendElement(aContent);
      return nullptr;
    }

    // We need to remove aContent from the pending plugins here to avoid
    // reentrancy.  When the timer fires it calls
    // DocAccessible::ContentInserted() which does the work async.
    sPendingPlugins->RemoveElement(aContent);

    // Note: pluginPort will be null if windowless.
    HWND pluginPort = nullptr;
    aFrame->GetPluginPort(&pluginPort);

    RefPtr<Accessible> accessible = new HTMLWin32ObjectOwnerAccessible(
        aContent, aContext->Document(), pluginPort);
    return accessible.forget();

#  elif MOZ_ACCESSIBILITY_ATK
    if (!AtkSocketAccessible::gCanEmbed) return nullptr;

    // Note this calls into the plugin, so unexpected things may happen and
    // aFrame may go away.
    nsCString plugId;
    nsresult rv = pluginInstance->GetValueFromPlugin(
        NPPVpluginNativeAccessibleAtkPlugId, &plugId);
    if (NS_SUCCEEDED(rv) && !plugId.IsEmpty()) {
      RefPtr<AtkSocketAccessible> socketAccessible =
          new AtkSocketAccessible(aContent, aContext->Document(), plugId);

      return socketAccessible.forget();
    }
#  endif
  }
#endif

  return nullptr;
}

void nsAccessibilityService::DeckPanelSwitched(PresShell* aPresShell,
                                               nsIContent* aDeckNode,
                                               nsIFrame* aPrevBoxFrame,
@@ -1306,11 +1196,6 @@ bool nsAccessibilityService::Init() {
  CrashReporter::AnnotateCrashReport(CrashReporter::Annotation::Accessibility,
                                     "Active"_ns);

#ifdef XP_WIN
  sPendingPlugins = new nsTArray<nsCOMPtr<nsIContent> >;
  sPluginTimers = new nsTArray<nsCOMPtr<nsITimer> >;
#endif

  // Now its safe to start platform accessibility.
  if (XRE_IsParentProcess()) PlatformInit();

@@ -1344,16 +1229,6 @@ void nsAccessibilityService::Shutdown() {

  SelectionManager::Shutdown();

#ifdef XP_WIN
  sPendingPlugins = nullptr;

  uint32_t timerCount = sPluginTimers->Length();
  for (uint32_t i = 0; i < timerCount; i++)
    sPluginTimers->ElementAt(i)->Cancel();

  sPluginTimers = nullptr;
#endif

  if (XRE_IsParentProcess()) PlatformShutdown();

  gApplicationAccessible->Shutdown();
@@ -1510,11 +1385,6 @@ nsAccessibilityService::CreateAccessibleByFrameType(nsIFrame* aFrame,
    case eOuterDocType:
      newAcc = new OuterDocAccessible(aContent, document);
      break;
    case ePluginType: {
      nsPluginFrame* pluginFrame = do_QueryFrame(aFrame);
      newAcc = CreatePluginAccessible(pluginFrame, aContent, aContext);
      break;
    }
    case eTextLeafType:
      newAcc = new TextLeafAccessibleWrap(aContent, document);
      break;
+0 −4
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@
class nsImageFrame;
class nsIArray;
class nsIPersistentProperties;
class nsPluginFrame;
class nsITreeView;

namespace mozilla {
@@ -116,9 +115,6 @@ class nsAccessibilityService final : public mozilla::a11y::DocManager,

  Accessible* GetRootDocumentAccessible(mozilla::PresShell* aPresShell,
                                        bool aCanCreate);
  already_AddRefed<Accessible> CreatePluginAccessible(nsPluginFrame* aFrame,
                                                      nsIContent* aContent,
                                                      Accessible* aContext);

  /**
   * Adds/remove ATK root accessible for gtk+ native window to/from children
+1 −67
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@
#include "nsIScriptObjectPrincipal.h"
#include "nsIPrincipal.h"
#include "nsIObserverService.h"
#include "nsIObjectFrame.h"
#include "BrowserChild.h"
#include "nsFrameLoader.h"
#include "nsHTMLDocument.h"
@@ -2210,36 +2209,6 @@ bool nsFocusManager::BlurImpl(BrowsingContext* aBrowsingContextToClear,
                             false);
    }

    // if an object/plug-in/remote browser is being blurred, move the system
    // focus to the parent window, otherwise events will still get fired at the
    // plugin. But don't do this if we are blurring due to the window being
    // lowered, otherwise, the parent window can get raised again.
    if (GetActiveBrowsingContext()) {
      nsIFrame* contentFrame = element->GetPrimaryFrame();
      nsIObjectFrame* objectFrame = do_QueryFrame(contentFrame);
      if (aAdjustWidget && objectFrame && !sTestMode) {
        if (XRE_IsContentProcess()) {
          // set focus to the top level window via the chrome process.
          nsCOMPtr<nsIBrowserChild> browserChild = docShell->GetBrowserChild();
          if (browserChild) {
            static_cast<BrowserChild*>(browserChild.get())
                ->SendDispatchFocusToTopLevelWindow();
          }
        } else {
          // note that the presshell's widget is being retrieved here, not the
          // one for the object frame.
          if (nsViewManager* vm = presShell->GetViewManager()) {
            nsCOMPtr<nsIWidget> widget;
            vm->GetRootWidget(getter_AddRefs(widget));
            if (widget) {
              // set focus to the top level window but don't raise it.
              widget->SetFocus(nsIWidget::Raise::No, CallerType::System);
            }
          }
        }
      }
    }

    bool windowBeingLowered = !aBrowsingContextToClear &&
                              !aAncestorBrowsingContextToFocus &&
                              aIsLeavingDocument && aAdjustWidget;
@@ -2458,18 +2427,7 @@ void nsFocusManager::Focus(

  SetFocusedWindowInternal(aWindow);

  // Update the system focus by focusing the root widget.  But avoid this
  // if 1) aAdjustWidget is false or 2) aElement is a plugin that has its
  // own widget and is either already focused or is about to be focused.
  nsCOMPtr<nsIWidget> objectFrameWidget;
  if (aElement) {
    nsIFrame* contentFrame = aElement->GetPrimaryFrame();
    nsIObjectFrame* objectFrame = do_QueryFrame(contentFrame);
    if (objectFrame) {
      objectFrameWidget = objectFrame->GetWidget();
    }
  }
  if (aAdjustWidget && !objectFrameWidget && !sTestMode) {
  if (aAdjustWidget && !sTestMode) {
    if (nsViewManager* vm = presShell->GetViewManager()) {
      nsCOMPtr<nsIWidget> widget;
      vm->GetRootWidget(getter_AddRefs(widget));
@@ -2532,13 +2490,6 @@ void nsFocusManager::Focus(
      // that we might no longer be in the same document, due to the events we
      // fired above when aIsNewDocument.
      if (presShell->GetDocument() == aElement->GetComposedDoc()) {
        if (aAdjustWidget && objectFrameWidget && !sTestMode) {
          objectFrameWidget->SetFocus(nsIWidget::Raise::No,
                                      aFlags & FLAG_NONSYSTEMCALLER
                                          ? CallerType::NonSystem
                                          : CallerType::System);
        }

        // if the object being focused is a remote browser, activate remote
        // content
        ActivateRemoteFrameIfNeeded(*aElement, aActionId);
@@ -2572,23 +2523,6 @@ void nsFocusManager::Focus(
      }
    }
  } else {
    // If the window focus event (fired above when aIsNewDocument) caused
    // the plugin not to be focusable, update the system focus by focusing
    // the root widget.
    if (aAdjustWidget && objectFrameWidget &&
        GetFocusedBrowsingContext() == aWindow->GetBrowsingContext() &&
        mFocusedElement == nullptr && !sTestMode) {
      if (nsViewManager* vm = presShell->GetViewManager()) {
        nsCOMPtr<nsIWidget> widget;
        vm->GetRootWidget(getter_AddRefs(widget));
        if (widget) {
          widget->SetFocus(nsIWidget::Raise::No, aFlags & FLAG_NONSYSTEMCALLER
                                                     ? CallerType::NonSystem
                                                     : CallerType::System);
        }
      }
    }

    if (!mFocusedElement) {
      // When there is no focused element, IMEStateManager needs to adjust IME
      // enabled state with the document.
+0 −18
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@
interface nsIChannel;
interface nsIRequest;
interface nsIFrame;
interface nsIObjectFrame;
interface nsIPluginTag;
interface nsIURI;

@@ -102,23 +101,6 @@ interface nsIObjectLoadingContent : nsISupports
   */
  [notxpcom,nostdcall] readonly attribute nsNPAPIPluginInstancePtr pluginInstance;

  /**
   * Tells the content about an associated object frame.
   * This can be called multiple times for different frames.
   *
   * This is noscript because this is an internal method that will go away, and
   * because nsIObjectFrame is unscriptable.
   */
  [noscript] void hasNewFrame(in nsIObjectFrame aFrame);

  /**
   * If this object is in going to be printed, this method
   * returns the nsIObjectFrame object which should be used when
   * printing the plugin. The returned nsIFrame is in the original document,
   * not in the static clone.
   */
  [noscript] nsIFrame getPrintFrame();

  /*
   * Notifications from pluginhost that our instance crashed or was destroyed.
   */
Loading