Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | #include "nsAutoPtr.h" // for nsRefPtr, getter_AddRefs, etc |
michael@0 | 8 | #include "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc |
michael@0 | 9 | #include "nsCRT.h" // for nsCRT |
michael@0 | 10 | #include "nsComposerCommands.h" // for nsSetDocumentOptionsCommand, etc |
michael@0 | 11 | #include "nsDebug.h" // for NS_ENSURE_ARG_POINTER, etc |
michael@0 | 12 | #include "nsError.h" // for NS_ERROR_INVALID_ARG, etc |
michael@0 | 13 | #include "nsICommandParams.h" // for nsICommandParams |
michael@0 | 14 | #include "nsIDOMDocument.h" // for nsIDOMDocument |
michael@0 | 15 | #include "nsIDocShell.h" // for nsIDocShell |
michael@0 | 16 | #include "nsIDocument.h" // for nsIDocument |
michael@0 | 17 | #include "nsIEditingSession.h" // for nsIEditingSession, etc |
michael@0 | 18 | #include "nsIEditor.h" // for nsIEditor |
michael@0 | 19 | #include "nsIHTMLEditor.h" // for nsIHTMLEditor |
michael@0 | 20 | #include "nsIHTMLInlineTableEditor.h" // for nsIHTMLInlineTableEditor |
michael@0 | 21 | #include "nsIHTMLObjectResizer.h" // for nsIHTMLObjectResizer |
michael@0 | 22 | #include "nsIPlaintextEditor.h" // for nsIPlaintextEditor, etc |
michael@0 | 23 | #include "nsIPresShell.h" // for nsIPresShell |
michael@0 | 24 | #include "nsISelectionController.h" // for nsISelectionController |
michael@0 | 25 | #include "nsISupportsImpl.h" // for nsPresContext::Release |
michael@0 | 26 | #include "nsISupportsUtils.h" // for NS_IF_ADDREF |
michael@0 | 27 | #include "nsIURI.h" // for nsIURI |
michael@0 | 28 | #include "nsPresContext.h" // for nsPresContext |
michael@0 | 29 | #include "nscore.h" // for NS_IMETHODIMP, nsresult, etc |
michael@0 | 30 | |
michael@0 | 31 | class nsISupports; |
michael@0 | 32 | |
michael@0 | 33 | //defines |
michael@0 | 34 | #define STATE_ENABLED "state_enabled" |
michael@0 | 35 | #define STATE_ALL "state_all" |
michael@0 | 36 | #define STATE_ATTRIBUTE "state_attribute" |
michael@0 | 37 | #define STATE_DATA "state_data" |
michael@0 | 38 | |
michael@0 | 39 | static |
michael@0 | 40 | nsresult |
michael@0 | 41 | GetPresContextFromEditor(nsIEditor *aEditor, nsPresContext **aResult) |
michael@0 | 42 | { |
michael@0 | 43 | NS_ENSURE_ARG_POINTER(aResult); |
michael@0 | 44 | *aResult = nullptr; |
michael@0 | 45 | NS_ENSURE_ARG_POINTER(aEditor); |
michael@0 | 46 | |
michael@0 | 47 | nsCOMPtr<nsISelectionController> selCon; |
michael@0 | 48 | nsresult rv = aEditor->GetSelectionController(getter_AddRefs(selCon)); |
michael@0 | 49 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 50 | NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE); |
michael@0 | 51 | |
michael@0 | 52 | nsCOMPtr<nsIPresShell> presShell = do_QueryInterface(selCon); |
michael@0 | 53 | NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); |
michael@0 | 54 | |
michael@0 | 55 | NS_IF_ADDREF(*aResult = presShell->GetPresContext()); |
michael@0 | 56 | return NS_OK; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | NS_IMETHODIMP |
michael@0 | 60 | nsSetDocumentOptionsCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 61 | nsISupports *refCon, |
michael@0 | 62 | bool *outCmdEnabled) |
michael@0 | 63 | { |
michael@0 | 64 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 65 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); |
michael@0 | 66 | if (editor) |
michael@0 | 67 | return editor->GetIsSelectionEditable(outCmdEnabled); |
michael@0 | 68 | |
michael@0 | 69 | *outCmdEnabled = false; |
michael@0 | 70 | return NS_OK; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | NS_IMETHODIMP |
michael@0 | 74 | nsSetDocumentOptionsCommand::DoCommand(const char *aCommandName, |
michael@0 | 75 | nsISupports *refCon) |
michael@0 | 76 | { |
michael@0 | 77 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | NS_IMETHODIMP |
michael@0 | 81 | nsSetDocumentOptionsCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 82 | nsICommandParams *aParams, |
michael@0 | 83 | nsISupports *refCon) |
michael@0 | 84 | { |
michael@0 | 85 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 86 | |
michael@0 | 87 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); |
michael@0 | 88 | NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG); |
michael@0 | 89 | |
michael@0 | 90 | nsRefPtr<nsPresContext> presContext; |
michael@0 | 91 | nsresult rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext)); |
michael@0 | 92 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 93 | NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); |
michael@0 | 94 | |
michael@0 | 95 | int32_t animationMode; |
michael@0 | 96 | rv = aParams->GetLongValue("imageAnimation", &animationMode); |
michael@0 | 97 | if (NS_SUCCEEDED(rv)) |
michael@0 | 98 | { |
michael@0 | 99 | // for possible values of animation mode, see: |
michael@0 | 100 | // http://lxr.mozilla.org/seamonkey/source/image/public/imgIContainer.idl |
michael@0 | 101 | presContext->SetImageAnimationMode(animationMode); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | bool allowPlugins; |
michael@0 | 105 | rv = aParams->GetBooleanValue("plugins", &allowPlugins); |
michael@0 | 106 | if (NS_SUCCEEDED(rv)) |
michael@0 | 107 | { |
michael@0 | 108 | nsCOMPtr<nsIDocShell> docShell(presContext->GetDocShell()); |
michael@0 | 109 | NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); |
michael@0 | 110 | |
michael@0 | 111 | rv = docShell->SetAllowPlugins(allowPlugins); |
michael@0 | 112 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | return NS_OK; |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | NS_IMETHODIMP |
michael@0 | 119 | nsSetDocumentOptionsCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 120 | nsICommandParams *aParams, |
michael@0 | 121 | nsISupports *refCon) |
michael@0 | 122 | { |
michael@0 | 123 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 124 | NS_ENSURE_ARG_POINTER(refCon); |
michael@0 | 125 | |
michael@0 | 126 | // The base editor owns most state info |
michael@0 | 127 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); |
michael@0 | 128 | NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG); |
michael@0 | 129 | |
michael@0 | 130 | // Always get the enabled state |
michael@0 | 131 | bool outCmdEnabled = false; |
michael@0 | 132 | IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); |
michael@0 | 133 | nsresult rv = aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled); |
michael@0 | 134 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 135 | |
michael@0 | 136 | // get pres context |
michael@0 | 137 | nsRefPtr<nsPresContext> presContext; |
michael@0 | 138 | rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext)); |
michael@0 | 139 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 140 | NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); |
michael@0 | 141 | |
michael@0 | 142 | int32_t animationMode; |
michael@0 | 143 | rv = aParams->GetLongValue("imageAnimation", &animationMode); |
michael@0 | 144 | if (NS_SUCCEEDED(rv)) |
michael@0 | 145 | { |
michael@0 | 146 | // for possible values of animation mode, see |
michael@0 | 147 | // http://lxr.mozilla.org/seamonkey/source/image/public/imgIContainer.idl |
michael@0 | 148 | rv = aParams->SetLongValue("imageAnimation", |
michael@0 | 149 | presContext->ImageAnimationMode()); |
michael@0 | 150 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | bool allowPlugins = false; |
michael@0 | 154 | rv = aParams->GetBooleanValue("plugins", &allowPlugins); |
michael@0 | 155 | if (NS_SUCCEEDED(rv)) |
michael@0 | 156 | { |
michael@0 | 157 | nsCOMPtr<nsIDocShell> docShell(presContext->GetDocShell()); |
michael@0 | 158 | NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); |
michael@0 | 159 | |
michael@0 | 160 | allowPlugins = docShell->PluginsAllowedInCurrentDoc(); |
michael@0 | 161 | |
michael@0 | 162 | rv = aParams->SetBooleanValue("plugins", allowPlugins); |
michael@0 | 163 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | return NS_OK; |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | |
michael@0 | 170 | /** |
michael@0 | 171 | * Commands for document state that may be changed via doCommandParams |
michael@0 | 172 | * As of 11/11/02, this is just "cmd_setDocumentModified" |
michael@0 | 173 | * Note that you can use the same command class, nsSetDocumentStateCommand, |
michael@0 | 174 | * for more than one of this type of command |
michael@0 | 175 | * We check the input command param for different behavior |
michael@0 | 176 | */ |
michael@0 | 177 | |
michael@0 | 178 | NS_IMETHODIMP |
michael@0 | 179 | nsSetDocumentStateCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 180 | nsISupports *refCon, |
michael@0 | 181 | bool *outCmdEnabled) |
michael@0 | 182 | { |
michael@0 | 183 | // These commands are always enabled |
michael@0 | 184 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 185 | *outCmdEnabled = true; |
michael@0 | 186 | return NS_OK; |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | NS_IMETHODIMP |
michael@0 | 190 | nsSetDocumentStateCommand::DoCommand(const char *aCommandName, |
michael@0 | 191 | nsISupports *refCon) |
michael@0 | 192 | { |
michael@0 | 193 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | NS_IMETHODIMP |
michael@0 | 197 | nsSetDocumentStateCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 198 | nsICommandParams *aParams, |
michael@0 | 199 | nsISupports *refCon) |
michael@0 | 200 | { |
michael@0 | 201 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); |
michael@0 | 202 | NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG); |
michael@0 | 203 | |
michael@0 | 204 | if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified")) |
michael@0 | 205 | { |
michael@0 | 206 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 207 | |
michael@0 | 208 | bool modified; |
michael@0 | 209 | nsresult rv = aParams->GetBooleanValue(STATE_ATTRIBUTE, &modified); |
michael@0 | 210 | |
michael@0 | 211 | // Should we fail if this param wasn't set? |
michael@0 | 212 | // I'm not sure we should be that strict |
michael@0 | 213 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 214 | |
michael@0 | 215 | if (modified) |
michael@0 | 216 | return editor->IncrementModificationCount(1); |
michael@0 | 217 | |
michael@0 | 218 | return editor->ResetModificationCount(); |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentReadOnly")) |
michael@0 | 222 | { |
michael@0 | 223 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 224 | bool isReadOnly; |
michael@0 | 225 | nsresult rvRO = aParams->GetBooleanValue(STATE_ATTRIBUTE, &isReadOnly); |
michael@0 | 226 | NS_ENSURE_SUCCESS(rvRO, rvRO); |
michael@0 | 227 | |
michael@0 | 228 | uint32_t flags; |
michael@0 | 229 | editor->GetFlags(&flags); |
michael@0 | 230 | if (isReadOnly) |
michael@0 | 231 | flags |= nsIPlaintextEditor::eEditorReadonlyMask; |
michael@0 | 232 | else |
michael@0 | 233 | flags &= ~(nsIPlaintextEditor::eEditorReadonlyMask); |
michael@0 | 234 | |
michael@0 | 235 | return editor->SetFlags(flags); |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS")) |
michael@0 | 239 | { |
michael@0 | 240 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 241 | nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon); |
michael@0 | 242 | NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG); |
michael@0 | 243 | |
michael@0 | 244 | bool desireCSS; |
michael@0 | 245 | nsresult rvCSS = aParams->GetBooleanValue(STATE_ATTRIBUTE, &desireCSS); |
michael@0 | 246 | NS_ENSURE_SUCCESS(rvCSS, rvCSS); |
michael@0 | 247 | |
michael@0 | 248 | return htmleditor->SetIsCSSEnabled(desireCSS); |
michael@0 | 249 | } |
michael@0 | 250 | |
michael@0 | 251 | if (!nsCRT::strcmp(aCommandName, "cmd_insertBrOnReturn")) |
michael@0 | 252 | { |
michael@0 | 253 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 254 | nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon); |
michael@0 | 255 | NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG); |
michael@0 | 256 | |
michael@0 | 257 | bool insertBrOnReturn; |
michael@0 | 258 | nsresult rvBR = aParams->GetBooleanValue(STATE_ATTRIBUTE, |
michael@0 | 259 | &insertBrOnReturn); |
michael@0 | 260 | NS_ENSURE_SUCCESS(rvBR, rvBR); |
michael@0 | 261 | |
michael@0 | 262 | return htmleditor->SetReturnInParagraphCreatesNewParagraph(!insertBrOnReturn); |
michael@0 | 263 | } |
michael@0 | 264 | |
michael@0 | 265 | if (!nsCRT::strcmp(aCommandName, "cmd_enableObjectResizing")) |
michael@0 | 266 | { |
michael@0 | 267 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 268 | nsCOMPtr<nsIHTMLObjectResizer> resizer = do_QueryInterface(refCon); |
michael@0 | 269 | NS_ENSURE_TRUE(resizer, NS_ERROR_INVALID_ARG); |
michael@0 | 270 | |
michael@0 | 271 | bool enabled; |
michael@0 | 272 | nsresult rvOR = aParams->GetBooleanValue(STATE_ATTRIBUTE, &enabled); |
michael@0 | 273 | NS_ENSURE_SUCCESS(rvOR, rvOR); |
michael@0 | 274 | |
michael@0 | 275 | return resizer->SetObjectResizingEnabled(enabled); |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | if (!nsCRT::strcmp(aCommandName, "cmd_enableInlineTableEditing")) |
michael@0 | 279 | { |
michael@0 | 280 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 281 | nsCOMPtr<nsIHTMLInlineTableEditor> editor = do_QueryInterface(refCon); |
michael@0 | 282 | NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG); |
michael@0 | 283 | |
michael@0 | 284 | bool enabled; |
michael@0 | 285 | nsresult rvOR = aParams->GetBooleanValue(STATE_ATTRIBUTE, &enabled); |
michael@0 | 286 | NS_ENSURE_SUCCESS(rvOR, rvOR); |
michael@0 | 287 | |
michael@0 | 288 | return editor->SetInlineTableEditingEnabled(enabled); |
michael@0 | 289 | } |
michael@0 | 290 | |
michael@0 | 291 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 292 | } |
michael@0 | 293 | |
michael@0 | 294 | NS_IMETHODIMP |
michael@0 | 295 | nsSetDocumentStateCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 296 | nsICommandParams *aParams, |
michael@0 | 297 | nsISupports *refCon) |
michael@0 | 298 | { |
michael@0 | 299 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 300 | NS_ENSURE_ARG_POINTER(refCon); |
michael@0 | 301 | |
michael@0 | 302 | // The base editor owns most state info |
michael@0 | 303 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); |
michael@0 | 304 | NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG); |
michael@0 | 305 | |
michael@0 | 306 | // Always get the enabled state |
michael@0 | 307 | bool outCmdEnabled = false; |
michael@0 | 308 | IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); |
michael@0 | 309 | nsresult rv = aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled); |
michael@0 | 310 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 311 | |
michael@0 | 312 | if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified")) |
michael@0 | 313 | { |
michael@0 | 314 | bool modified; |
michael@0 | 315 | rv = editor->GetDocumentModified(&modified); |
michael@0 | 316 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 317 | |
michael@0 | 318 | return aParams->SetBooleanValue(STATE_ATTRIBUTE, modified); |
michael@0 | 319 | } |
michael@0 | 320 | |
michael@0 | 321 | if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentReadOnly")) |
michael@0 | 322 | { |
michael@0 | 323 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 324 | |
michael@0 | 325 | uint32_t flags; |
michael@0 | 326 | editor->GetFlags(&flags); |
michael@0 | 327 | bool isReadOnly = flags & nsIPlaintextEditor::eEditorReadonlyMask; |
michael@0 | 328 | return aParams->SetBooleanValue(STATE_ATTRIBUTE, isReadOnly); |
michael@0 | 329 | } |
michael@0 | 330 | |
michael@0 | 331 | if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS")) |
michael@0 | 332 | { |
michael@0 | 333 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 334 | nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon); |
michael@0 | 335 | NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG); |
michael@0 | 336 | |
michael@0 | 337 | bool isCSS; |
michael@0 | 338 | htmleditor->GetIsCSSEnabled(&isCSS); |
michael@0 | 339 | return aParams->SetBooleanValue(STATE_ALL, isCSS); |
michael@0 | 340 | } |
michael@0 | 341 | |
michael@0 | 342 | if (!nsCRT::strcmp(aCommandName, "cmd_insertBrOnReturn")) |
michael@0 | 343 | { |
michael@0 | 344 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 345 | nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon); |
michael@0 | 346 | NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG); |
michael@0 | 347 | |
michael@0 | 348 | bool createPOnReturn; |
michael@0 | 349 | htmleditor->GetReturnInParagraphCreatesNewParagraph(&createPOnReturn); |
michael@0 | 350 | return aParams->SetBooleanValue(STATE_ATTRIBUTE, !createPOnReturn); |
michael@0 | 351 | } |
michael@0 | 352 | |
michael@0 | 353 | if (!nsCRT::strcmp(aCommandName, "cmd_enableObjectResizing")) |
michael@0 | 354 | { |
michael@0 | 355 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 356 | nsCOMPtr<nsIHTMLObjectResizer> resizer = do_QueryInterface(refCon); |
michael@0 | 357 | NS_ENSURE_TRUE(resizer, NS_ERROR_INVALID_ARG); |
michael@0 | 358 | |
michael@0 | 359 | bool enabled; |
michael@0 | 360 | resizer->GetObjectResizingEnabled(&enabled); |
michael@0 | 361 | return aParams->SetBooleanValue(STATE_ATTRIBUTE, enabled); |
michael@0 | 362 | } |
michael@0 | 363 | |
michael@0 | 364 | if (!nsCRT::strcmp(aCommandName, "cmd_enableInlineTableEditing")) |
michael@0 | 365 | { |
michael@0 | 366 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 367 | nsCOMPtr<nsIHTMLInlineTableEditor> editor = do_QueryInterface(refCon); |
michael@0 | 368 | NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG); |
michael@0 | 369 | |
michael@0 | 370 | bool enabled; |
michael@0 | 371 | editor->GetInlineTableEditingEnabled(&enabled); |
michael@0 | 372 | return aParams->SetBooleanValue(STATE_ATTRIBUTE, enabled); |
michael@0 | 373 | } |
michael@0 | 374 | |
michael@0 | 375 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 376 | } |
michael@0 | 377 | |
michael@0 | 378 | /** |
michael@0 | 379 | * Commands just for state notification |
michael@0 | 380 | * As of 11/21/02, possible commands are: |
michael@0 | 381 | * "obs_documentCreated" |
michael@0 | 382 | * "obs_documentWillBeDestroyed" |
michael@0 | 383 | * "obs_documentLocationChanged" |
michael@0 | 384 | * Note that you can use the same command class, nsDocumentStateCommand |
michael@0 | 385 | * for these or future observer commands. |
michael@0 | 386 | * We check the input command param for different behavior |
michael@0 | 387 | * |
michael@0 | 388 | * How to use: |
michael@0 | 389 | * 1. Get the nsICommandManager for the current editor |
michael@0 | 390 | * 2. Implement an nsIObserve object, e.g: |
michael@0 | 391 | * |
michael@0 | 392 | * void Observe( |
michael@0 | 393 | * in nsISupports aSubject, // The nsICommandManager calling this Observer |
michael@0 | 394 | * in string aTopic, // command name, e.g.:"obs_documentCreated" |
michael@0 | 395 | * // or "obs_documentWillBeDestroyed" |
michael@0 | 396 | in wstring aData ); // ignored (set to "command_status_changed") |
michael@0 | 397 | * |
michael@0 | 398 | * 3. Add the observer by: |
michael@0 | 399 | * commandManager.addObserver(observeobject, obs_documentCreated); |
michael@0 | 400 | * 4. In the appropriate location in editorSession, editor, or commands code, |
michael@0 | 401 | * trigger the notification of this observer by something like: |
michael@0 | 402 | * |
michael@0 | 403 | * nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(mDocShell); |
michael@0 | 404 | * nsCOMPtr<nsPICommandUpdater> commandUpdater = do_QueryInterface(commandManager); |
michael@0 | 405 | * NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE); |
michael@0 | 406 | * commandUpdater->CommandStatusChanged(obs_documentCreated); |
michael@0 | 407 | * |
michael@0 | 408 | * 5. Use GetCommandStateParams() to obtain state information |
michael@0 | 409 | * e.g., any creation state codes when creating an editor are |
michael@0 | 410 | * supplied for "obs_documentCreated" command in the |
michael@0 | 411 | * "state_data" param's value |
michael@0 | 412 | * |
michael@0 | 413 | */ |
michael@0 | 414 | |
michael@0 | 415 | NS_IMETHODIMP |
michael@0 | 416 | nsDocumentStateCommand::IsCommandEnabled(const char* aCommandName, |
michael@0 | 417 | nsISupports *refCon, |
michael@0 | 418 | bool *outCmdEnabled) |
michael@0 | 419 | { |
michael@0 | 420 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 421 | // Always return false to discourage callers from using DoCommand() |
michael@0 | 422 | *outCmdEnabled = false; |
michael@0 | 423 | return NS_OK; |
michael@0 | 424 | } |
michael@0 | 425 | |
michael@0 | 426 | NS_IMETHODIMP |
michael@0 | 427 | nsDocumentStateCommand::DoCommand(const char *aCommandName, |
michael@0 | 428 | nsISupports *refCon) |
michael@0 | 429 | { |
michael@0 | 430 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 431 | } |
michael@0 | 432 | |
michael@0 | 433 | NS_IMETHODIMP |
michael@0 | 434 | nsDocumentStateCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 435 | nsICommandParams *aParams, |
michael@0 | 436 | nsISupports *refCon) |
michael@0 | 437 | { |
michael@0 | 438 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 439 | } |
michael@0 | 440 | |
michael@0 | 441 | NS_IMETHODIMP |
michael@0 | 442 | nsDocumentStateCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 443 | nsICommandParams *aParams, |
michael@0 | 444 | nsISupports *refCon) |
michael@0 | 445 | { |
michael@0 | 446 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 447 | NS_ENSURE_ARG_POINTER(aCommandName); |
michael@0 | 448 | nsresult rv; |
michael@0 | 449 | |
michael@0 | 450 | if (!nsCRT::strcmp(aCommandName, "obs_documentCreated")) |
michael@0 | 451 | { |
michael@0 | 452 | uint32_t editorStatus = nsIEditingSession::eEditorErrorUnknown; |
michael@0 | 453 | |
michael@0 | 454 | nsCOMPtr<nsIEditingSession> editingSession = do_QueryInterface(refCon); |
michael@0 | 455 | if (editingSession) |
michael@0 | 456 | { |
michael@0 | 457 | // refCon is initially set to nsIEditingSession until editor |
michael@0 | 458 | // is successfully created and source doc is loaded |
michael@0 | 459 | // Embedder gets error status if this fails |
michael@0 | 460 | // If called before startup is finished, |
michael@0 | 461 | // status = eEditorCreationInProgress |
michael@0 | 462 | rv = editingSession->GetEditorStatus(&editorStatus); |
michael@0 | 463 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 464 | } |
michael@0 | 465 | else |
michael@0 | 466 | { |
michael@0 | 467 | // If refCon is an editor, then everything started up OK! |
michael@0 | 468 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); |
michael@0 | 469 | if (editor) |
michael@0 | 470 | editorStatus = nsIEditingSession::eEditorOK; |
michael@0 | 471 | } |
michael@0 | 472 | |
michael@0 | 473 | // Note that if refCon is not-null, but is neither |
michael@0 | 474 | // an nsIEditingSession or nsIEditor, we return "eEditorErrorUnknown" |
michael@0 | 475 | aParams->SetLongValue(STATE_DATA, editorStatus); |
michael@0 | 476 | return NS_OK; |
michael@0 | 477 | } |
michael@0 | 478 | else if (!nsCRT::strcmp(aCommandName, "obs_documentLocationChanged")) |
michael@0 | 479 | { |
michael@0 | 480 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); |
michael@0 | 481 | if (editor) |
michael@0 | 482 | { |
michael@0 | 483 | nsCOMPtr<nsIDOMDocument> domDoc; |
michael@0 | 484 | editor->GetDocument(getter_AddRefs(domDoc)); |
michael@0 | 485 | nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc); |
michael@0 | 486 | NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); |
michael@0 | 487 | |
michael@0 | 488 | nsIURI *uri = doc->GetDocumentURI(); |
michael@0 | 489 | NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE); |
michael@0 | 490 | |
michael@0 | 491 | return aParams->SetISupportsValue(STATE_DATA, (nsISupports*)uri); |
michael@0 | 492 | } |
michael@0 | 493 | return NS_OK; |
michael@0 | 494 | } |
michael@0 | 495 | |
michael@0 | 496 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 497 | } |