Closed Bug 621915 Opened 9 years ago Closed 6 years ago

implement capture picker for camera input


(Toolkit :: XUL Widgets, defect)

Not set





(Reporter: blassey, Unassigned)


(Blocks 2 open bugs)


(Keywords: dev-doc-needed)


(1 file)

Attached patch WIPSplinter Review
this works for taking stills. Probably need some design love though
Attachment #500211 - Flags: feedback?(mark.finkle)
Blocks: 451674
Comment on attachment 500211 [details] [diff] [review]

>diff --git a/browser/ b/browser/

>+if test "$OS_ARCH" = "Linux"; then
>\ No newline at end of file

Fix the newline

Can't comment too much on the C++ impl. The printf's should probably be changed to something more debug/release friendly

>+++ b/toolkit/components/capturepicker/content/capturepicker.js
>@@ -0,0 +1,76 @@
>+var retvals;

>+var Cc = Components.classes;
>+var Ci = Components.interfaces;
>+var Cu = Components.utils;

>+var cp_deck;
>+var cp_video;
>+var cp_image;

>+function capturepickerLoad() {

Add some line breaks to clean this up

>+  if (window.arguments) {
>+    var o = window.arguments[0];
>+    retvals = o.retvals;
>+    document.title = o.title;
>+  }

Remove the blank line

>+function takePhoto() {
>+  let tmpDir = Cc[";1"].getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
>+  let file = tmpDir.clone();
>+  file.append("image.png");
>+  file.createUnique(file.NORMAL_FILE_TYPE, 0600);
>+  var io = Cc[";1"]
>+    .getService(Ci.nsIIOService);
>+  var source = io.newURI("moz-device:camera?type=image/png", "UTF8", null);
>+  var persist = Cc[";1"]
>+    .createInstance(Ci.nsIWebBrowserPersist);

You are mixing "let" and "var" a lot. "var" for globals and "let" for locals is a good rule. Also, the line wrapping is a bit loose ("io" lines could be all on one)

>+  var progressListener = {
>+  onProgressChange: function() {
>+      /* Ignore progress callback */
>+    },
>+  onStateChange: function(aProgress, aRequest, aStateFlag, aStatus) {
>+    if (aStateFlag & STATE_STOP) {
>+      cp_deck.selectedIndex = 1;
>+      cp_image.src = fileURL.spec;
>+    }
>+    }
>+  }

Indent the body of progressListener

>+function onOK() {
>+  retvals.buttonStatus = nsIFilePicker.returnOK;

Ci.nsIFilePicker (unless I missed something)

>+function onCancel()
>+  // Close the window.
>+  retvals.buttonStatus = nsIFilePicker.returnCancel;

Ci.nsIFilePicker (unless I missed something)

>diff --git a/toolkit/components/capturepicker/content/capturepicker.xul b/toolkit/components/capturepicker/content/capturepicker.xul

>+<dialog id="main-window"
>+	xmlns=""
>+	xmlns:html=""
>+	onload="capturepickerLoad();"
>+	width="320" height="320"
>+	persist="screenX screenY">

Align indent on the "id" attribute

>+      <vbox flex="10">
>+	<html:video id="capturepicker_video"  src="moz-device:camera?type=video/x-raw-yuv" width="320" height="240" autoplay="true"/>
>+	<button oncommand="takePhoto()" label="&takePhoto.label;"/>
>+      </vbox>

needs to be indented. <vbox> is a container

>+      <vbox flex="10">
>+	<hbox flex="0">


>diff --git a/toolkit/components/capturepicker/ b/toolkit/components/capturepicker/

>+* content/global/capturepicker.xul                     (content/capturepicker.xul)
>+* content/global/capturepicker.js                      (content/capturepicker.js)

Do we need to preprocess these files? (the '*' means preprocess)

>diff --git a/toolkit/components/capturepicker/src/nsCapturePicker.js b/toolkit/components/capturepicker/src/nsCapturePicker.js

>+ * The Initial Developer of the Original Code is
>+ * Netscape Communications Corporation.
>+ * Portions created by the Initial Developer are Copyright (C) 2010
>+ * the Initial Developer. All Rights Reserved.

Is this boilerplate really old?


You could use shorter const names here. They are almost as long as the real strings! Replace the "CONTRACTID" with "CID" and maybe drop the "SERV"

>+const nsIAppShellService    = Ci.nsIAppShellService;
>+const nsILocalFile          = Ci.nsILocalFile;
>+const nsIFileURL            = Ci.nsIFileURL;
>+const nsISupports           = Ci.nsISupports;
>+const nsIFactory            = Ci.nsIFactory;
>+const nsICapturePicker      = Ci.nsICapturePicker;
>+const nsIInterfaceRequestor = Ci.nsIInterfaceRequestor;
>+const nsIDOMWindow          = Ci.nsIDOMWindow;
>+const nsIStringBundleService= Ci.nsIStringBundleService;
>+const nsIWebNavigation      = Ci.nsIWebNavigation;
>+const nsIDocShellTreeItem   = Ci.nsIDocShellTreeItem;
>+const nsIBaseWindow         = Ci.nsIBaseWindow;

Remove all of this. Just add the darn "Ci." to the places where this is needed.

>+  QueryInterface: function(iid) {
>+    if (iid.equals(nsICapturePicker) ||
>+        iid.equals(nsISupports))
>+      return this;
>+    throw Components.results.NS_ERROR_NO_INTERFACE;
>+  },

Use XPCOMUtils:

QueryInterface: XPCOMUtils.generateQI([Ci.nsICapturePicker]),

>+  show: function() {
>+  },

The code in this method that tries to get the parentWin is almost scary. I assume it came from somewhere else?

>+  init: function (parent, title, mode) {
>+    this.mParentWindow = parent;
>+    this.mTitle = title;

No need to hold mode?

>+  modeMayBeAvailable: function(mode) {
>+    return true; mode == nsICapturePicker.MODE_STILL;

Which is it? "true" or "mode == Ci.nsICapturePicker.MODE_STILL"  ?

>+  /* readonly attribute nsILocalFile file; */
>+  set file(a) { throw "readonly property"; },

Just don't supply the setter

>+  get file()  {
>+    var utils = this.mParentWindow.QueryInterface(Ci.nsIInterfaceRequestor).
>+                                     getInterface(Ci.nsIDOMWindowUtils);
>+    return utils.wrapDOMFile(this.mFile);

wrapDOMFile exists somewhere?

>diff --git a/toolkit/locales/ b/toolkit/locales/

>   locale/@AB_CD@/global/            (%chrome/global/
>   locale/@AB_CD@/global/filepicker.dtd                  (%chrome/global/filepicker.dtd)
>+  locale/@AB_CD@/global/capturepicker.dtd                  (%chrome/global/capturepicker.dtd)
>   locale/@AB_CD@/global/           (%chrome/global/

Fix spacing and maybe add after filepicker.dtd / .properties ?

If I were writing the JS parts i would use a more Object based approach instead of the global funcs and data style used here (and probably prevalent in the older file picker code)

I assume this won't work from e10s since the component will try to load in the child process.

Overall approach looks good to proceed.
Attachment #500211 - Flags: feedback?(mark.finkle) → feedback+
Depends on: 690501
Whiteboard: [secr:imelven]
No longer blocks: 451674
Blocks: camera
Blocks: 741393
:imelven - does this need reassignment since sec realignment?
Whiteboard: [secr:imelven] → [sec-assigned:imelven]
(In reply to Curtis Koenig [:curtisk] from comment #2)
> :imelven - does this need reassignment since sec realignment?

yes, but it looks like this bug isn't currently active ?
Flags: sec-review?(imelven)
I think this may have ended up being the getUserMedia work instead ?

sending to mgoodwin as it's mobile but don't think there's anything to do here..
Flags: sec-review?(imelven) → sec-review?(mgoodwin)
Blocks: 785073
I've spoken to blassey about this; he says:

"I think getUserMedia's impl has made that irrelevant".
No longer blocks: 785073
Whiteboard: [sec-assigned:imelven]
See comment 5
Closed: 7 years ago
Resolution: --- → INVALID
getUserMedia and HTML media capture have a very different set of use cases, and implementing one doesn't obsolete the other.

As of now, getUserMedia doesn't have the necessary APIs to take high quality pictures, it also forces the developer to build his own API for taking pictures instead of being able to rely on the device's camera application when there is one (frequent on mobile devices).

Please reconsider closing this.
Ah, apologies; I though this was the secreview bug. Un-closing
Resolution: INVALID → ---
The secreview bug!?
(In reply to Tobie Langel from comment #9)
> The secreview bug!?

Yeah; the security review for this feature (there doesn't seem to be a separate bug for this). Security reviews for bugs that seem dormant aren't necessarily the best use of time, which is why I was closing it out.
Isn't this bug related to the old and ugly capture button that was in Fennec XUL? I doubt this is needed for bug 741393. Bug 741393 could simply make the intent fired when the <input type='file'> is activated different and only use the capture handlers.

IMO, we should close this bug and work on bug 741393 instead.
This is now implemented via getUserMedia
Closed: 7 years ago6 years ago
Resolution: --- → WONTFIX
Flags: sec-review?(mgoodwin) → sec-review-
You need to log in before you can comment on or make changes to this bug.