Bug 1236991 - part 1: make default tooltiptextprovider xpcom-accessible, r?enndeakin draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 11 Apr 2016 14:17:07 +0100
changeset 349463 e127eb9b74fa7aebdb8f555fd10e3d3e4a6f257c
parent 349462 b26c9c90617b0a2f366afee79223b64b203625b1
child 349464 aedc58244082168f281155b60b13f613d23dbbd2
push id15095
push usergijskruitbosch@gmail.com
push dateMon, 11 Apr 2016 16:49:08 +0000
reviewersenndeakin
bugs1236991
milestone48.0a1
Bug 1236991 - part 1: make default tooltiptextprovider xpcom-accessible, r?enndeakin MozReview-Commit-ID: ATkzp7lCkdv
embedding/browser/build/nsWebBrowserModule.cpp
embedding/browser/nsCTooltipTextProvider.h
embedding/browser/nsDocShellTreeOwner.cpp
embedding/browser/nsDocShellTreeOwner.h
--- a/embedding/browser/build/nsWebBrowserModule.cpp
+++ b/embedding/browser/build/nsWebBrowserModule.cpp
@@ -5,41 +5,47 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ModuleUtils.h"
 #include "nsIServiceManager.h"
 #include "nsXPIDLString.h"
 
 #include "nsEmbedCID.h"
 
+#include "nsCTooltipTextProvider.h"
+#include "nsDocShellTreeOwner.h"
 #include "nsWebBrowser.h"
 #include "nsCommandHandler.h"
 #include "nsWebBrowserContentPolicy.h"
 
 // Factory Constructors
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebBrowser)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebBrowserContentPolicy)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCommandHandler)
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsDefaultTooltipTextProvider)
 
 NS_DEFINE_NAMED_CID(NS_WEBBROWSER_CID);
 NS_DEFINE_NAMED_CID(NS_COMMANDHANDLER_CID);
 NS_DEFINE_NAMED_CID(NS_WEBBROWSERCONTENTPOLICY_CID);
+NS_DEFINE_NAMED_CID(NS_DEFAULTTOOLTIPTEXTPROVIDER_CID);
 
 static const mozilla::Module::CIDEntry kWebBrowserCIDs[] = {
   { &kNS_WEBBROWSER_CID, false, nullptr, nsWebBrowserConstructor },
   { &kNS_COMMANDHANDLER_CID, false, nullptr, nsCommandHandlerConstructor },
   { &kNS_WEBBROWSERCONTENTPOLICY_CID, false, nullptr, nsWebBrowserContentPolicyConstructor },
+  { &kNS_DEFAULTTOOLTIPTEXTPROVIDER_CID, false, nullptr, nsDefaultTooltipTextProviderConstructor },
   { nullptr }
 };
 
 static const mozilla::Module::ContractIDEntry kWebBrowserContracts[] = {
   { NS_WEBBROWSER_CONTRACTID, &kNS_WEBBROWSER_CID },
   { NS_COMMANDHANDLER_CONTRACTID, &kNS_COMMANDHANDLER_CID },
   { NS_WEBBROWSERCONTENTPOLICY_CONTRACTID, &kNS_WEBBROWSERCONTENTPOLICY_CID },
+  { NS_DEFAULTTOOLTIPTEXTPROVIDER_CONTRACTID, &kNS_DEFAULTTOOLTIPTEXTPROVIDER_CID },
   { nullptr }
 };
 
 static const mozilla::Module::CategoryEntry kWebBrowserCategories[] = {
   { "content-policy", NS_WEBBROWSERCONTENTPOLICY_CONTRACTID, NS_WEBBROWSERCONTENTPOLICY_CONTRACTID },
   { nullptr }
 };
 
--- a/embedding/browser/nsCTooltipTextProvider.h
+++ b/embedding/browser/nsCTooltipTextProvider.h
@@ -7,9 +7,12 @@
 #ifndef NSCTOOLTIPTEXTPROVIDER_H
 #define NSCTOOLTIPTEXTPROVIDER_H
 
 #include "nsITooltipTextProvider.h"
 
 #define NS_TOOLTIPTEXTPROVIDER_CONTRACTID \
   "@mozilla.org/embedcomp/tooltiptextprovider;1"
 
+#define NS_DEFAULTTOOLTIPTEXTPROVIDER_CONTRACTID \
+  "@mozilla.org/embedcomp/default-tooltiptextprovider;1"
+
 #endif
--- a/embedding/browser/nsDocShellTreeOwner.cpp
+++ b/embedding/browser/nsDocShellTreeOwner.cpp
@@ -10,17 +10,16 @@
 
 // Helper Classes
 #include "nsStyleCoord.h"
 #include "nsSize.h"
 #include "nsHTMLReflowState.h"
 #include "nsIServiceManager.h"
 #include "nsComponentManagerUtils.h"
 #include "nsXPIDLString.h"
-#include "nsIAtom.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsISimpleEnumerator.h"
 #include "mozilla/LookAndFeel.h"
 
 // Interfaces needed to be included
 #include "nsPresContext.h"
 #include "nsIContextMenuListener.h"
@@ -1059,33 +1058,19 @@ nsDocShellTreeOwner::GetOwnerRequestor()
   if (mWebBrowserChromeWeak) {
     req = do_QueryReferent(mWebBrowserChromeWeak);
   } else if (mOwnerRequestor) {
     req = mOwnerRequestor;
   }
   return req.forget();
 }
 
-class DefaultTooltipTextProvider final : public nsITooltipTextProvider
-{
-public:
-  DefaultTooltipTextProvider();
-
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSITOOLTIPTEXTPROVIDER
+NS_IMPL_ISUPPORTS(nsDefaultTooltipTextProvider, nsITooltipTextProvider)
 
-protected:
-  ~DefaultTooltipTextProvider() {}
-
-  nsCOMPtr<nsIAtom> mTag_dialogHeader;
-};
-
-NS_IMPL_ISUPPORTS(DefaultTooltipTextProvider, nsITooltipTextProvider)
-
-DefaultTooltipTextProvider::DefaultTooltipTextProvider()
+nsDefaultTooltipTextProvider::nsDefaultTooltipTextProvider()
 {
   // There are certain element types which we don't want to use
   // as tool tip text.
   mTag_dialogHeader = NS_Atomize("dialogheader");
 }
 
 // A helper routine that determines whether we're still interested in SVG
 // titles. We need to stop at the SVG root element that has a document node
@@ -1097,17 +1082,17 @@ UseSVGTitle(nsIDOMElement* aCurrElement)
   if (!element || !element->IsSVGElement() || !element->GetParentNode()) {
     return false;
   }
 
   return element->GetParentNode()->NodeType() != nsIDOMNode::DOCUMENT_NODE;
 }
 
 NS_IMETHODIMP
-DefaultTooltipTextProvider::GetNodeText(nsIDOMNode* aNode, char16_t** aText,
+nsDefaultTooltipTextProvider::GetNodeText(nsIDOMNode* aNode, char16_t** aText,
                                         bool* aResult)
 {
   NS_ENSURE_ARG_POINTER(aNode);
   NS_ENSURE_ARG_POINTER(aText);
 
   nsString outText;
 
   nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
@@ -1265,17 +1250,17 @@ ChromeTooltipListener::ChromeTooltipList
   , mTooltipListenerInstalled(false)
   , mMouseClientX(0)
   , mMouseClientY(0)
   , mShowingTooltip(false)
   , mTooltipShownOnce(false)
 {
   mTooltipTextProvider = do_GetService(NS_TOOLTIPTEXTPROVIDER_CONTRACTID);
   if (!mTooltipTextProvider) {
-    mTooltipTextProvider = new DefaultTooltipTextProvider();
+    mTooltipTextProvider = do_GetService(NS_DEFAULTTOOLTIPTEXTPROVIDER_CONTRACTID);
   }
 }
 
 ChromeTooltipListener::~ChromeTooltipListener()
 {
 }
 
 // Hook up things to the chrome like context menus and tooltips, if the chrome
--- a/embedding/browser/nsDocShellTreeOwner.h
+++ b/embedding/browser/nsDocShellTreeOwner.h
@@ -8,16 +8,17 @@
 #define nsDocShellTreeOwner_h__
 
 // Helper Classes
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 
 // Interfaces Needed
+#include "nsIAtom.h"
 #include "nsIBaseWindow.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIWebBrowserChrome.h"
 #include "nsIDOMEventListener.h"
 #include "nsIEmbeddingSiteWindow.h"
 #include "nsIWebProgressListener.h"
@@ -40,16 +41,21 @@ class EventTarget;
 class nsWebBrowser;
 class ChromeTooltipListener;
 class ChromeContextMenuListener;
 
 // {6D10C180-6888-11d4-952B-0020183BF181}
 #define NS_ICDOCSHELLTREEOWNER_IID \
   { 0x6d10c180, 0x6888, 0x11d4, { 0x95, 0x2b, 0x0, 0x20, 0x18, 0x3b, 0xf1, 0x81 } }
 
+// {a9f7806d-3fa1-4598-9df2-92e51c031c0d}
+#define NS_DEFAULTTOOLTIPTEXTPROVIDER_CID \
+  { 0xa9f7806d, 0x3fa1, 0x4598, { 0x9d, 0xf2, 0x92, 0xe5, 0x1c, 0x03, 0x1c, 0x0d } }
+
+
 // This is a fake 'hidden' interface that nsDocShellTreeOwner implements.
 // Classes such as nsCommandHandler can QI for this interface to be sure that
 // they're dealing with a valid nsDocShellTreeOwner and not some other object
 // that implements nsIDocShellTreeOwner.
 class nsICDocShellTreeOwner : public nsISupports
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICDOCSHELLTREEOWNER_IID)
@@ -205,16 +211,31 @@ private:
   // firing. This is a strong reference, because the tooltip content can be
   // destroyed while we're waiting for the tooltip to pup up, and we need to
   // detect that. It's set only when the tooltip timer is created and launched.
   // The timer must either fire or be cancelled (or possibly released?), and we
   // release this reference in each of those cases. So we don't leak.
   nsCOMPtr<nsIDOMNode> mPossibleTooltipNode;
 };
 
+
+class nsDefaultTooltipTextProvider final : public nsITooltipTextProvider
+{
+public:
+  nsDefaultTooltipTextProvider();
+
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSITOOLTIPTEXTPROVIDER
+
+protected:
+  ~nsDefaultTooltipTextProvider() {}
+
+  nsCOMPtr<nsIAtom> mTag_dialogHeader;
+};
+
 // The class that listens to the chrome events and tells the embedding chrome to
 // show context menus, as appropriate. Handles registering itself with the DOM
 // with AddChromeListeners() and removing itself with RemoveChromeListeners().
 class ChromeContextMenuListener : public nsIDOMEventListener
 {
 protected:
   virtual ~ChromeContextMenuListener();