mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 594261 - Factor out geolocation prompt into something that can be reused. r=olli,gavin a=stuart
--HG-- extra : rebase_source : cd9b27a7c81f3eb61b79642e327ce086306a2535
This commit is contained in:
parent
dbf9d787ed
commit
e83bfbad33
@ -29,5 +29,5 @@ category command-line-validator b-browser @mozilla.org/browser/clh;1 application
|
||||
component {eab9012e-5f74-4cbc-b2b5-a590235513cc} nsBrowserGlue.js
|
||||
contract @mozilla.org/browser/browserglue;1 {eab9012e-5f74-4cbc-b2b5-a590235513cc}
|
||||
category app-startup nsBrowserGlue service,@mozilla.org/browser/browserglue;1
|
||||
component {C6E8C44D-9F39-4AF7-BCC0-76E38A8310F5} nsBrowserGlue.js
|
||||
contract @mozilla.org/geolocation/prompt;1 {C6E8C44D-9F39-4AF7-BCC0-76E38A8310F5}
|
||||
component {d8903bf6-68d5-4e97-bcd1-e4d3012f721a} nsBrowserGlue.js
|
||||
contract @mozilla.org/content-permission/prompt;1 {d8903bf6-68d5-4e97-bcd1-e4d3012f721a}
|
||||
|
@ -1323,15 +1323,20 @@ BrowserGlue.prototype = {
|
||||
_xpcom_factory: BrowserGlueServiceFactory,
|
||||
}
|
||||
|
||||
function GeolocationPrompt() {}
|
||||
function ContentPermissionPrompt() {}
|
||||
|
||||
GeolocationPrompt.prototype = {
|
||||
classID: Components.ID("{C6E8C44D-9F39-4AF7-BCC0-76E38A8310F5}"),
|
||||
ContentPermissionPrompt.prototype = {
|
||||
classID: Components.ID("{d8903bf6-68d5-4e97-bcd1-e4d3012f721a}"),
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIGeolocationPrompt]),
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt]),
|
||||
|
||||
prompt: function GP_prompt(request) {
|
||||
var requestingURI = request.requestingURI;
|
||||
prompt: function CPP_prompt(request) {
|
||||
|
||||
if (request.type != "geolocation") {
|
||||
return;
|
||||
}
|
||||
|
||||
var requestingURI = request.uri;
|
||||
|
||||
// Ignore requests from non-nsIStandardURLs
|
||||
if (!(requestingURI instanceof Ci.nsIStandardURL))
|
||||
@ -1382,7 +1387,7 @@ GeolocationPrompt.prototype = {
|
||||
// Different message/options if it is a local file
|
||||
if (requestingURI.schemeIs("file")) {
|
||||
message = browserBundle.formatStringFromName("geolocation.fileWantsToKnow",
|
||||
[request.requestingURI.path], 1);
|
||||
[requestingURI.path], 1);
|
||||
} else {
|
||||
message = browserBundle.formatStringFromName("geolocation.siteWantsToKnow",
|
||||
[requestingURI.host], 1);
|
||||
@ -1412,7 +1417,7 @@ GeolocationPrompt.prototype = {
|
||||
}
|
||||
}
|
||||
|
||||
var requestingWindow = request.requestingWindow.top;
|
||||
var requestingWindow = request.window.top;
|
||||
var chromeWin = getChromeWindow(requestingWindow).wrappedJSObject;
|
||||
var browser = chromeWin.gBrowser.getBrowserForDocument(requestingWindow.document);
|
||||
|
||||
@ -1421,5 +1426,5 @@ GeolocationPrompt.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
var components = [BrowserGlue, GeolocationPrompt];
|
||||
var components = [BrowserGlue, ContentPermissionPrompt];
|
||||
var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|
||||
|
@ -58,6 +58,7 @@ SDK_XPIDLSRCS = \
|
||||
XPIDLSRCS = \
|
||||
nsIAnimationFrameListener.idl \
|
||||
nsIBrowserDOMWindow.idl \
|
||||
nsIContentPermissionPrompt.idl \
|
||||
nsIContentPrefService.idl \
|
||||
nsIContentURIGrouper.idl \
|
||||
nsIDOMClientInformation.idl \
|
||||
|
@ -11,14 +11,14 @@
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Geolocation.
|
||||
* The Original Code is Mozilla DOM.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@meer.net> (Original Author)
|
||||
* Doug Turner <dougt@dougt.org> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@ -34,28 +34,43 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIURI;
|
||||
interface nsIDOMWindow;
|
||||
interface nsIDOMElement;
|
||||
interface nsIDOMGeoPosition;
|
||||
interface nsIGeolocationPrompt;
|
||||
|
||||
/**
|
||||
* Interface allows access to a geolocation and is passed to
|
||||
* the nsIGeolocationPrompt so that the application can approve
|
||||
* or deny the request.
|
||||
* Interface allows access to a content to request
|
||||
* permission to perform a privileged operation such as
|
||||
* geolocation.
|
||||
*/
|
||||
[scriptable, function, uuid(F2AEFDE1-8E38-48B3-BBB8-BD6C4AE1AC8A)]
|
||||
interface nsIGeolocationRequest : nsISupports {
|
||||
[scriptable, function, uuid(E79C7063-DBAB-45E3-8A98-D0142E1ABC9A)]
|
||||
interface nsIContentPermissionRequest : nsISupports {
|
||||
|
||||
readonly attribute nsIURI requestingURI;
|
||||
readonly attribute nsIDOMWindow requestingWindow;
|
||||
/**
|
||||
* The type of the permission request, such as
|
||||
* "geolocation".
|
||||
*/
|
||||
readonly attribute ACString type;
|
||||
|
||||
readonly attribute nsIDOMElement requestingElement;
|
||||
/**
|
||||
* The uri of the permission request.
|
||||
*/
|
||||
readonly attribute nsIURI uri;
|
||||
|
||||
/**
|
||||
* The window or element that the permission request was
|
||||
* originated in. Typically the element will be non-null
|
||||
* in when using out of process content. window or
|
||||
* element can be null but not both.
|
||||
*/
|
||||
readonly attribute nsIDOMWindow window;
|
||||
readonly attribute nsIDOMElement element;
|
||||
|
||||
/**
|
||||
* allow or cancel the request
|
||||
*/
|
||||
|
||||
void cancel();
|
||||
void allow();
|
||||
@ -65,18 +80,15 @@ interface nsIGeolocationRequest : nsISupports {
|
||||
* Interface provides a way for the application to handle
|
||||
* the UI prompts associated with geo position.
|
||||
*/
|
||||
[scriptable, function, uuid(2300C895-1BEE-4297-912C-A57082F3E936)]
|
||||
interface nsIGeolocationPrompt : nsISupports {
|
||||
[scriptable, function, uuid(F72DE90D-E954-4E69-9A61-917303029301)]
|
||||
interface nsIContentPermissionPrompt : nsISupports {
|
||||
/**
|
||||
* Called when a request has been made to access geolocation data
|
||||
* Called when a request has been made to access
|
||||
* privileged content apis
|
||||
*/
|
||||
void prompt(in nsIGeolocationRequest request);
|
||||
void prompt(in nsIContentPermissionRequest request);
|
||||
};
|
||||
|
||||
%{C++
|
||||
/*
|
||||
This must be implemented by embedders. It must support
|
||||
nsIGeolocationPrompt.
|
||||
*/
|
||||
#define NS_GEOLOCATION_PROMPT_CONTRACTID "@mozilla.org/geolocation/prompt;1"
|
||||
#define NS_CONTENT_PERMISSION_PROMPT_CONTRACTID "@mozilla.org/content-permission/prompt;1"
|
||||
%}
|
@ -56,7 +56,6 @@ XPIDLSRCS = \
|
||||
nsIDOMGeoPositionErrorCallback.idl \
|
||||
nsIDOMGeoPositionOptions.idl \
|
||||
nsIDOMNavigatorGeolocation.idl \
|
||||
nsIGeolocationPrompt.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
@ -108,10 +108,10 @@ public:
|
||||
}
|
||||
|
||||
NS_IMETHOD Run() {
|
||||
nsCOMPtr<nsIGeolocationPrompt> prompt = do_GetService(NS_GEOLOCATION_PROMPT_CONTRACTID);
|
||||
NS_ASSERTION(prompt, "null geolocation prompt");
|
||||
if (prompt)
|
||||
nsCOMPtr<nsIContentPermissionPrompt> prompt = do_GetService(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID);
|
||||
if (prompt) {
|
||||
prompt->Prompt(mRequest);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -147,7 +147,9 @@ public:
|
||||
// a bit funky. if locator is passed, that means this
|
||||
// event should remove the request from it. If we ever
|
||||
// have to do more, then we can change this around.
|
||||
RequestSendLocationEvent(nsIDOMGeoPosition* aPosition, nsGeolocationRequest* aRequest, nsGeolocation* aLocator = nsnull)
|
||||
RequestSendLocationEvent(nsIDOMGeoPosition* aPosition,
|
||||
nsGeolocationRequest* aRequest,
|
||||
nsGeolocation* aLocator = nsnull)
|
||||
: mPosition(aPosition),
|
||||
mRequest(aRequest),
|
||||
mLocator(aLocator)
|
||||
@ -267,8 +269,8 @@ nsGeolocationRequest::Init()
|
||||
}
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGeolocationRequest)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGeolocationRequest)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIGeolocationRequest)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContentPermissionRequest)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIContentPermissionRequest)
|
||||
NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
@ -305,7 +307,7 @@ nsGeolocationRequest::Notify(nsITimer* aTimer)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeolocationRequest::GetRequestingURI(nsIURI * *aRequestingURI)
|
||||
nsGeolocationRequest::GetUri(nsIURI * *aRequestingURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aRequestingURI);
|
||||
|
||||
@ -316,7 +318,14 @@ nsGeolocationRequest::GetRequestingURI(nsIURI * *aRequestingURI)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeolocationRequest::GetRequestingWindow(nsIDOMWindow * *aRequestingWindow)
|
||||
nsGeolocationRequest::GetType(nsACString & aType)
|
||||
{
|
||||
aType = "geolocation";
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeolocationRequest::GetWindow(nsIDOMWindow * *aRequestingWindow)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aRequestingWindow);
|
||||
|
||||
@ -327,7 +336,7 @@ nsGeolocationRequest::GetRequestingWindow(nsIDOMWindow * *aRequestingWindow)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeolocationRequest::GetRequestingElement(nsIDOMElement * *aRequestingElement)
|
||||
nsGeolocationRequest::GetElement(nsIDOMElement * *aRequestingElement)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aRequestingElement);
|
||||
*aRequestingElement = nsnull;
|
||||
@ -864,10 +873,10 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGeolocation)
|
||||
PRUint32 i;
|
||||
for (i = 0; i < tmp->mPendingCallbacks.Length(); ++i)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mPendingCallbacks[i], nsIGeolocationRequest)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mPendingCallbacks[i], nsIContentPermissionRequest)
|
||||
|
||||
for (i = 0; i < tmp->mWatchingCallbacks.Length(); ++i)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mWatchingCallbacks[i], nsIGeolocationRequest)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mWatchingCallbacks[i], nsIContentPermissionRequest)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
nsGeolocation::nsGeolocation()
|
||||
@ -1150,19 +1159,26 @@ nsGeolocationRequestProxy::Init(mozilla::dom::GeolocationRequestParent* parent)
|
||||
NS_ASSERTION(parent, "null parent");
|
||||
mParent = parent;
|
||||
|
||||
nsCOMPtr<nsIGeolocationPrompt> prompt = do_GetService(NS_GEOLOCATION_PROMPT_CONTRACTID);
|
||||
NS_ASSERTION(prompt, "null geolocation prompt. geolocation will not work without one.");
|
||||
if (!prompt)
|
||||
nsCOMPtr<nsIContentPermissionPrompt> prompt = do_GetService(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID);
|
||||
if (!prompt) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
(void) prompt->Prompt(this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsGeolocationRequestProxy, nsIGeolocationRequest);
|
||||
NS_IMPL_ISUPPORTS1(nsGeolocationRequestProxy, nsIContentPermissionRequest);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeolocationRequestProxy::GetRequestingWindow(nsIDOMWindow * *aRequestingWindow)
|
||||
nsGeolocationRequestProxy::GetType(nsACString & aType)
|
||||
{
|
||||
aType = "geolocation";
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeolocationRequestProxy::GetWindow(nsIDOMWindow * *aRequestingWindow)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aRequestingWindow);
|
||||
*aRequestingWindow = nsnull;
|
||||
@ -1170,7 +1186,7 @@ nsGeolocationRequestProxy::GetRequestingWindow(nsIDOMWindow * *aRequestingWindow
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeolocationRequestProxy::GetRequestingURI(nsIURI * *aRequestingURI)
|
||||
nsGeolocationRequestProxy::GetUri(nsIURI * *aRequestingURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aRequestingURI);
|
||||
NS_ASSERTION(mParent, "No parent for request");
|
||||
@ -1180,7 +1196,7 @@ nsGeolocationRequestProxy::GetRequestingURI(nsIURI * *aRequestingURI)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeolocationRequestProxy::GetRequestingElement(nsIDOMElement * *aRequestingElement)
|
||||
nsGeolocationRequestProxy::GetElement(nsIDOMElement * *aRequestingElement)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aRequestingElement);
|
||||
NS_ASSERTION(mParent && mParent->mElement.get(), "No parent for request");
|
||||
|
@ -65,13 +65,13 @@
|
||||
#include "nsPIDOMWindow.h"
|
||||
|
||||
#include "nsIGeolocationProvider.h"
|
||||
#include "nsIGeolocationPrompt.h"
|
||||
#include "nsIContentPermissionPrompt.h"
|
||||
|
||||
class nsGeolocationService;
|
||||
class nsGeolocation;
|
||||
|
||||
class nsGeolocationRequest
|
||||
: public nsIGeolocationRequest
|
||||
: public nsIContentPermissionRequest
|
||||
, public nsITimerCallback
|
||||
#ifdef MOZ_IPC
|
||||
, public mozilla::dom::PGeolocationRequestChild
|
||||
@ -79,10 +79,10 @@ class nsGeolocationRequest
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_NSIGEOLOCATIONREQUEST
|
||||
NS_DECL_NSICONTENTPERMISSIONREQUEST
|
||||
NS_DECL_NSITIMERCALLBACK
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsGeolocationRequest, nsIGeolocationRequest)
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsGeolocationRequest, nsIContentPermissionRequest)
|
||||
|
||||
nsGeolocationRequest(nsGeolocation* locator,
|
||||
nsIDOMGeoPositionCallback* callback,
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include "base/basictypes.h"
|
||||
|
||||
#include "nsIGeolocationProvider.h"
|
||||
#include "nsIGeolocationPrompt.h"
|
||||
#include "nsIContentPermissionPrompt.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIDOMElement.h"
|
||||
|
||||
@ -69,7 +69,7 @@ class GeolocationRequestParent : public PGeolocationRequestParent
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
class nsGeolocationRequestProxy : public nsIGeolocationRequest
|
||||
class nsGeolocationRequestProxy : public nsIContentPermissionRequest
|
||||
{
|
||||
public:
|
||||
nsGeolocationRequestProxy();
|
||||
@ -78,7 +78,7 @@ class nsGeolocationRequestProxy : public nsIGeolocationRequest
|
||||
nsresult Init(mozilla::dom::GeolocationRequestParent* parent);
|
||||
|
||||
NS_DECL_ISUPPORTS;
|
||||
NS_DECL_NSIGEOLOCATIONREQUEST;
|
||||
NS_DECL_NSICONTENTPERMISSIONREQUEST;
|
||||
|
||||
private:
|
||||
// Non-owning pointer to the GeolocationRequestParent object which owns this proxy.
|
||||
|
Loading…
Reference in New Issue
Block a user