Bug 636512 - Make document.getSelection() return the same as window.getSelection(). r=bzbarsky
authorVishnu S <onlinevishnu@gmail.com>
Thu, 07 Jul 2011 14:17:13 -0400
changeset 72465 764fbee6b335
parent 72464 61224f22f178
child 72466 c688b177aa30
push id441
push userbzbarsky@mozilla.com
push dateThu, 07 Jul 2011 18:17:52 +0000
treeherdermozilla-inbound@4836dc515ac2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs636512
milestone8.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 636512 - Make document.getSelection() return the same as window.getSelection(). r=bzbarsky
content/html/document/src/nsHTMLDocument.cpp
dom/interfaces/html/nsIDOMHTMLDocument.idl
toolkit/components/console/hudservice/tests/browser/Makefile.in
toolkit/components/console/hudservice/tests/browser/browser_webconsole_bug_595934_message_categories.js
toolkit/components/console/hudservice/tests/browser/test-bug-595934-getselection.html
toolkit/components/console/hudservice/tests/browser/test-bug-595934-getselection.js
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -2165,45 +2165,28 @@ nsHTMLDocument::GetEmbeds(nsIDOMHTMLColl
 
   *aEmbeds = mEmbeds;
   NS_ADDREF(*aEmbeds);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsHTMLDocument::GetSelection(nsAString& aReturn)
+nsHTMLDocument::GetSelection(nsISelection** aReturn)
 {
-  aReturn.Truncate();
-
-  nsCOMPtr<nsIJSContextStack> stack = do_GetService("@mozilla.org/js/xpc/ContextStack;1");
-  JSContext* ccx = nsnull;
-  if (stack && NS_SUCCEEDED(stack->Peek(&ccx)) && ccx) {
-    JS_ReportWarning(ccx, "Deprecated method document.getSelection() called.  Please use window.getSelection() instead.");
-  }
-
   nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(GetScopeObject());
   nsCOMPtr<nsPIDOMWindow> pwin = do_QueryInterface(window);
   NS_ENSURE_TRUE(pwin, NS_OK);
   NS_ASSERTION(pwin->IsInnerWindow(), "Should have inner window here!");
   NS_ENSURE_TRUE(pwin->GetOuterWindow() &&
                  pwin->GetOuterWindow()->GetCurrentInnerWindow() == pwin,
                  NS_OK);
 
-  nsCOMPtr<nsISelection> selection;
-  nsresult rv = window->GetSelection(getter_AddRefs(selection));
-  NS_ENSURE_TRUE(selection && NS_SUCCEEDED(rv), rv);
-
-  nsXPIDLString str;
-
-  rv = selection->ToString(getter_Copies(str));
-
-  aReturn.Assign(str);
-
-  return rv;
+  return window->GetSelection(aReturn);
+  
 }
 
 NS_IMETHODIMP
 nsHTMLDocument::CaptureEvents(PRInt32 aEventFlags)
 {
   ReportUseOfDeprecatedMethod(this, "UseOfCaptureEventsWarning");
   return NS_OK;
 }
--- a/dom/interfaces/html/nsIDOMHTMLDocument.idl
+++ b/dom/interfaces/html/nsIDOMHTMLDocument.idl
@@ -44,18 +44,19 @@
 %}
 
 /**
  * The nsIDOMHTMLDocument interface is the interface to a [X]HTML
  * document object.
  *
  * @see <http://www.whatwg.org/html/>
  */
+interface nsISelection;
 
-[scriptable, uuid(3c0ca40f-72c5-4d15-935e-ccaff7953f2c)]
+[scriptable, uuid(3ab3e856-361d-435a-8a4d-b462799945cd)]
 interface nsIDOMHTMLDocument : nsIDOMDocument
 {
   readonly attribute DOMString            URL;
            attribute DOMString            domain;
            attribute DOMString            cookie;
   // returns "BackCompat" if we're in quirks mode,
   // or "CSS1Compat" if we're in strict mode
   readonly attribute DOMString            compatMode;
@@ -127,17 +128,17 @@ interface nsIDOMHTMLDocument : nsIDOMDoc
 
   readonly attribute nsIDOMHTMLCollection anchors;
   readonly attribute nsIDOMHTMLCollection applets;
 
   void                      clear();
 
 
   // DOM Range
-  DOMString                 getSelection();
+  nsISelection                getSelection();
 
 
   // Mozilla extensions
   /**
    * @deprecated These are old Netscape 4 methods. Do not use,
    *             the implementation is no-op.
    */
   void                      captureEvents(in long eventFlags);
--- a/toolkit/components/console/hudservice/tests/browser/Makefile.in
+++ b/toolkit/components/console/hudservice/tests/browser/Makefile.in
@@ -185,18 +185,16 @@ include $(topsrcdir)/config/rules.mk
 	test-bug-595934-css-parser.html \
 	test-bug-595934-css-parser.css \
 	test-bug-595934-canvas-css.html \
 	test-bug-595934-canvas-css.js \
 	test-bug-595934-malformedxml-external.html \
 	test-bug-595934-malformedxml-external.xml \
 	test-bug-595934-empty-getelementbyid.html \
 	test-bug-595934-empty-getelementbyid.js \
-	test-bug-595934-getselection.html \
-	test-bug-595934-getselection.js \
 	test-bug-595934-image.html \
 	test-bug-595934-image.jpg \
 	test-bug-597136-external-script-errors.html \
 	test-bug-597136-external-script-errors.js \
 	test-bug-613013-console-api-iframe.html \
 	test-bug-597756-reopen-closed-tab.html \
 	test-bug-600183-charset.html \
 	test-bug-600183-charset.html^headers^ \
--- a/toolkit/components/console/hudservice/tests/browser/browser_webconsole_bug_595934_message_categories.js
+++ b/toolkit/components/console/hudservice/tests/browser/browser_webconsole_bug_595934_message_categories.js
@@ -84,21 +84,16 @@ const TESTS = [
     category: "DOM",
     matchString: "getElementById",
   },
   { // #14
     file: "test-bug-595934-canvas-css.html",
     category: "CSS Parser",
     matchString: "foobarCanvasCssParser",
   },
-  { // #15
-    file: "test-bug-595934-getselection.html",
-    category: "content javascript",
-    matchString: "getSelection",
-  },
   { // #16
     file: "test-bug-595934-image.html",
     category: "Image",
     matchString: "corrupt",
   },
 ];
 
 let pos = -1;
deleted file mode 100644
--- a/toolkit/components/console/hudservice/tests/browser/test-bug-595934-getselection.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <title>Web Console test for bug 595934 - category: content javascript.
-    (getSelection())</title>
-<!-- Any copyright is dedicated to the Public Domain.
-     http://creativecommons.org/publicdomain/zero/1.0/ -->
-    <script type="text/javascript"
-            src="test-bug-595934-getselection.js"></script>
-  </head>
-  <body>
-    <p>Web Console test for bug 595934 - category "content javascript"
-       (getSelection()).</p>
-  </body>
-</html>
-
deleted file mode 100644
--- a/toolkit/components/console/hudservice/tests/browser/test-bug-595934-getselection.js
+++ /dev/null
@@ -1,9 +0,0 @@
-/*
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
-
-window.addEventListener("load", function() {
-  document.getSelection();
-}, false);
-