29 #include <nsAutoPtr.h>
30 #include <nsIDOMElement.h>
31 #include <nsIDocument.h>
32 #include <nsIDOMDocument.h>
33 #include <nsIDOMEvent.h>
34 #include <nsIDOMEventTarget.h>
35 #include <nsIDOMWindow.h>
37 #include <nsServiceManagerUtils.h>
38 #include <nsStringGlue.h>
46 static PRLogModuleInfo* gRemoteCommandsLog = nsnull;
50 #define LOG(args) PR_LOG(gRemoteCommandsLog, PR_LOG_WARN, args)
56 "classinfo:classDescription",
57 "classinfo:contractID",
59 "classinfo:implementationLanguage",
64 "site:getNumCommands",
65 "site:getCommandType",
67 "site:getCommandText",
68 "site:getCommandToolTipText",
69 "site:getCommandEnabled",
70 "site:getCommandFlag",
71 "site:getCommandVisible",
72 "site:getCommandValue",
73 "site:getCommandShortcutModifiers",
74 "site:getCommandShortcutKey",
75 "site:getCommandShortcutKeycode",
76 "site:getCommandShortcutLocal",
102 mRemotePlayer(aRemotePlayer)
105 if (!gRemoteCommandsLog) {
106 gRemoteCommandsLog = PR_NewLogModule(
"sbRemoteCommands");
108 LOG((
"sbRemoteCommands::sbRemoteCommands()"));
114 LOG((
"sbRemoteCommands::~sbRemoteCommands()"));
127 NS_ENSURE_ARG_POINTER(aRemotePlayer);
129 *aRemotePlayer = nsnull;
147 sbRemoteCommands::SetCommandData( PRUint32 aNumCommands,
148 const PRUnichar **aTypeArray,
149 const PRUnichar **aIDArray,
150 const PRUnichar **aNameArray,
151 const PRUnichar **aTooltipArray )
153 LOG((
"sbRemoteCommands::SetCommandData(%d)", aNumCommands ));
156 NS_ENSURE_ARG_POINTER(aTypeArray);
157 NS_ENSURE_ARG_POINTER(aIDArray);
158 NS_ENSURE_ARG_POINTER(aNameArray);
159 NS_ENSURE_ARG_POINTER(aTooltipArray);
161 for ( PRUint32 index = 0; index < aNumCommands; index++ ) {
163 NS_ASSERTION( aTypeArray[index],
"ERROR - null array element" );
164 NS_ASSERTION( aIDArray[index],
"ERROR - null array element" );
165 NS_ASSERTION( aNameArray[index],
"ERROR - null array element" );
166 NS_ASSERTION( aTooltipArray[index],
"ERROR - null array element" );
169 command.
type = aTypeArray[index];
170 command.
id = aIDArray[index];
171 command.
name = aNameArray[index];
172 command.
tooltip = aTooltipArray[index];
173 if ( !
mCommands.AppendElement(command) ) {
175 return NS_ERROR_OUT_OF_MEMORY;
183 sbRemoteCommands::AddCommand(
const nsAString &aType,
184 const nsAString &aID,
185 const nsAString &
aName,
186 const nsAString &aTooltip )
188 LOG((
"sbRemoteCommands::AddCommand(%s)",
189 NS_LossyConvertUTF16toASCII(aID).
get() ));
191 command.
type = aType;
197 return NS_ERROR_OUT_OF_MEMORY;
203 sbRemoteCommands::RemoveCommand(
const nsAString &aID )
205 LOG((
"sbRemoteCommands::RemoveCommand()"));
207 for ( PRUint32 index = 0; index <
num; index++ ) {
208 LOG((
"sbRemoteCommands::RemoveCommand(%d:%s)",
210 NS_LossyConvertUTF16toASCII(
mCommands.ElementAt(index).id).
get()));
211 if (
mCommands.ElementAt(index).id == aID ) {
227 owner->OnCommandsChanged();
233 LOG((
"sbRemoteCommands::SetOwner()"));
235 mWeakOwner = do_GetWeakReference( aOwner, &rv );
242 LOG((
"sbRemoteCommands::GetOwner()"));
244 nsCOMPtr<sbIRemotePlayer> strong = do_QueryReferent(
mWeakOwner, &rv );
245 NS_IF_ADDREF( *aOwner = strong );
259 return NS_ERROR_NOT_IMPLEMENTED;
266 return NS_ERROR_NOT_IMPLEMENTED;
270 sbRemoteCommands::NotifyListeners(
const nsAString &aTriggerFunction,
273 return NS_ERROR_NOT_IMPLEMENTED;
279 return NS_ERROR_NOT_IMPLEMENTED;
285 return NS_ERROR_NOT_IMPLEMENTED;
291 LOG((
"sbRemoteCommands::SetContext()"));
297 sbRemoteCommands::GetVisible(
const nsAString &
aHost, PRBool *_retval)
299 NS_ENSURE_ARG_POINTER(_retval);
305 sbRemoteCommands::GetNumCommands(
const nsAString &aSubMenu,
306 const nsAString &
aHost,
309 NS_ENSURE_ARG_POINTER(_retval);
315 sbRemoteCommands::GetCommandType(
const nsAString &aSubMenu,
317 const nsAString &aHost,
320 if ( aIndex >= 0 && aIndex < (PRInt32)
mCommands.Length() ) {
321 _retval =
mCommands.ElementAt(aIndex).type;
324 return NS_ERROR_INVALID_ARG;
328 sbRemoteCommands::GetCommandId(
const nsAString &aSubMenu,
330 const nsAString &aHost,
333 if ( aIndex >= 0 && aIndex < (PRInt32)
mCommands.Length() ) {
334 _retval =
mCommands.ElementAt(aIndex).id;
337 return NS_ERROR_INVALID_ARG;
342 sbRemoteCommands::GetId(nsAString & _retval NS_OUTPARAM)
344 return NS_ERROR_NOT_IMPLEMENTED;
349 sbRemoteCommands::GetTargetFlags(PRUint16 *_retval)
351 return NS_ERROR_NOT_IMPLEMENTED;
355 sbRemoteCommands::SetTargetFlags(PRUint16 targetFlags)
357 return NS_ERROR_NOT_IMPLEMENTED;
364 return NS_ERROR_NOT_IMPLEMENTED;
370 return NS_ERROR_NOT_IMPLEMENTED;
374 sbRemoteCommands::GetCommandText(
const nsAString &aSubMenu,
376 const nsAString &aHost,
379 if ( aIndex >= 0 && aIndex < (PRInt32)
mCommands.Length() ) {
380 _retval =
mCommands.ElementAt(aIndex).name;
383 return NS_ERROR_INVALID_ARG;
387 sbRemoteCommands::GetCommandFlex(
const nsAString &aSubMenu,
389 const nsAString &aHost,
392 NS_ENSURE_ARG_POINTER(_retval);
393 if ( aIndex >= 0 && aIndex < (PRInt32)
mCommands.Length() ) {
394 nsAutoString cmdType =
mCommands.ElementAt(aIndex).type;
395 if ( cmdType == NS_LITERAL_STRING(
"separator") )
401 return NS_ERROR_INVALID_ARG;
405 sbRemoteCommands::GetCommandToolTipText(
const nsAString &aSubMenu,
407 const nsAString & aHost,
410 if ( aIndex >= 0 && aIndex < (PRInt32)
mCommands.Length() ) {
411 _retval =
mCommands.ElementAt(aIndex).tooltip;
414 return NS_ERROR_INVALID_ARG;
418 sbRemoteCommands::GetCommandEnabled(
const nsAString &aSubMenu,
420 const nsAString &aHost,
423 NS_ENSURE_ARG_POINTER(_retval);
429 sbRemoteCommands::GetCommandVisible(
const nsAString &aSubMenu,
431 const nsAString &aHost,
434 NS_ENSURE_ARG_POINTER(_retval);
442 NS_ENSURE_ARG_POINTER(_retval);
444 return NS_ERROR_NOT_IMPLEMENTED;
448 sbRemoteCommands::GetCommandFlag(
const nsAString &aSubMenu,
450 const nsAString &aHost,
453 NS_ENSURE_ARG_POINTER(_retval);
459 sbRemoteCommands::GetCommandValue(
const nsAString &aSubMenu,
461 const nsAString &aHost,
464 _retval = EmptyString();
469 sbRemoteCommands::GetCommandShortcutModifiers(
const nsAString &aSubMenu,
471 const nsAString &aHost,
474 _retval = EmptyString();
479 sbRemoteCommands::GetCommandShortcutKey(
const nsAString &aSubMenu,
481 const nsAString &aHost,
484 _retval = EmptyString();
489 sbRemoteCommands::GetCommandShortcutKeycode(
const nsAString &aSubMenu,
491 const nsAString &aHost,
494 _retval = EmptyString();
499 sbRemoteCommands::GetCommandShortcutLocal(
const nsAString &aSubMenu,
501 const nsAString &aHost,
504 NS_ENSURE_ARG_POINTER(_retval);
510 sbRemoteCommands::GetCommandChoiceItem(
const nsAString &aChoiceMenu,
511 const nsAString &aHost,
514 _retval = EmptyString();
520 sbRemoteCommands::GetCommandSubObject(
const nsAString &aSubMenu,
522 const nsAString &aHost,
525 NS_ENSURE_ARG_POINTER(_retval);
533 NS_ENSURE_ARG_POINTER(_retval);
535 return NS_ERROR_NOT_IMPLEMENTED;
539 sbRemoteCommands::InstantiateCustomCommand(
const nsAString &aSubMenu,
541 const nsAString &aHost,
542 const nsAString &aID,
544 nsIDOMNode **_retval)
546 NS_ENSURE_ARG_POINTER(_retval);
548 return NS_ERROR_NOT_IMPLEMENTED;
552 sbRemoteCommands::RefreshCustomCommand(
const nsAString &aSubMenu,
554 const nsAString &aHost,
555 const nsAString &aID,
556 nsIDOMNode *aCustomCommandElement)
558 return NS_ERROR_NOT_IMPLEMENTED;
563 sbRemoteCommands::OnCommand(
const nsAString &aSubMenu,
564 const PRInt32 aIndex,
565 const nsAString &aHost,
566 const nsAString &aID,
569 LOG((
"sbRemoteCommands::OnCommand(%s, %d, %s, %s, %s)",
570 NS_LossyConvertUTF16toASCII(aSubMenu).
get(), aIndex,
571 NS_LossyConvertUTF16toASCII(aHost).
get(),
572 NS_LossyConvertUTF16toASCII(aID).
get(),
573 NS_LossyConvertUTF16toASCII(aValue).
get()));
576 nsCOMPtr<sbIRemotePlayer>
owner( do_QueryReferent(
mWeakOwner, &rv ) );
577 NS_ENSURE_SUCCESS( rv, rv );
578 return owner->FireEventToContent( NS_LITERAL_STRING(
"Events"), aID );
582 sbRemoteCommands::InitCommands(
const nsAString &aHost )
588 sbRemoteCommands::ShutdownCommands( )
597 NS_ENSURE_ARG_POINTER(_retval);
598 LOG((
"sbRemoteCommands::Duplicate()"));
601 NS_ENSURE_TRUE( copy, NS_ERROR_OUT_OF_MEMORY );
603 nsresult rv = copy->Init();
604 NS_ENSURE_SUCCESS( rv, rv );
607 for ( PRUint32 index = 0; index <
num; index++ ) {
609 rv = copy->AddCommand( command.
type,
614 NS_ENSURE_SUCCESS( rv, rv );
616 nsCOMPtr<sbIRemotePlayer>
owner( do_QueryReferent(
mWeakOwner, &rv ) );
617 NS_ENSURE_SUCCESS( rv, rv );
618 rv = copy->SetOwner(
owner);
619 NS_ENSURE_SUCCESS( rv, rv );
620 nsCOMPtr<sbIPlaylistCommands> plCommands(
622 NS_ENSURE_SUCCESS( rv, rv );
623 NS_ADDREF( *_retval = plCommands );
#define SB_IMPL_SECURITYCHECKEDCOMP_INIT(_class)
The interface for receiving notices when a Command Object is added to or removed from another Command...
readonly attribute sbIRemotePlayer remotePlayer
This interface is a composition of many of our other interfaces with the goal of exposing a more web-...
A callback interface used to receive callbacks from an sbIPlaylistCommandsBuilder object relating to ...
sbRemoteCommands(sbRemotePlayer *aRemotePlayer)
nsISecurityCheckedComponent
_collectFormDataForFrame aDocument
An interface to specify playlist commands from remote web pages.
static const char * sPublicWProperties[]
A marker interface for objects that aggregate the security mixin.
NS_IMPL_ISUPPORTS5(sbRemoteCommands, nsIClassInfo, nsISecurityCheckedComponent, sbIPlaylistCommands, sbIRemoteCommands, sbISecurityAggregator) NS_IMPL_CI_INTERFACE_GETTER4(sbRemoteCommands
virtual ~sbRemoteCommands()
An interface that represents the set of command buttons and context menu items available on a display...
nsRefPtr< sbRemotePlayer > mRemotePlayer
The interface for giving context to a playlistcommands object.
#define SB_IMPL_CLASSINFO_INTERFACES_ONLY(_class)
attribute sbIRemotePlayer owner
static const char * sPublicMethods[]
nsCOMPtr< nsIWeakReference > mWeakOwner
static const char * sPublicRProperties[]
nsTArray< sbCommand > mCommands
nsCOMPtr< sbIPlaylistCommandsContext > mContext