forked from mirrors/gecko-dev
Bug 1678629: Implement a mechanism to fire bookmark-keyword-changed event. r=mak
Differential Revision: https://phabricator.services.mozilla.com/D130439
This commit is contained in:
parent
1a83dbf1e0
commit
73d3679f2a
7 changed files with 106 additions and 0 deletions
|
|
@ -18,6 +18,8 @@ Each successful operation is noticed by observer for these events and passed to
|
|||
- ``“bookmark-removed”`` - ``data: PlacesBookmarkRemoved`` Fired whenever a bookmark (or a bookmark folder/separator) is removed.
|
||||
- ``“bookmark-moved”`` - ``data: PlacesBookmarkMoved`` Fired whenever a bookmark (or a bookmark folder/separator) is moved.
|
||||
- ``“bookmark-guid-changed”`` - ``data: PlacesBookmarkGuid`` Fired whenever a bookmark guid changes.
|
||||
- ``“bookmark-keyword-changed”`` - ``data: PlacesBookmarkKeyword`` Fired whenever a bookmark keyword changes.
|
||||
|
||||
- ``“bookmark-tags-changed”`` - ``data: PlacesBookmarkTags`` Fired whenever tags of bookmark changes.
|
||||
- ``“bookmark-time-changed”`` - ``data: PlacesBookmarkTime`` Fired whenever dateAdded or lastModified of a bookmark is explicitly changed through the Bookmarks API. This notification doesn't fire when a bookmark is created, or when a property of a bookmark (e.g. title) is changed, even if lastModified will be updated as a consequence of that change.
|
||||
- ``“bookmark-title-changed”`` - ``data: PlacesBookmarkTitle`` Fired whenever a bookmark title changes.
|
||||
|
|
|
|||
53
dom/base/PlacesBookmarkKeyword.h
Normal file
53
dom/base/PlacesBookmarkKeyword.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_PlacesBookmarkKeyword_h
|
||||
#define mozilla_dom_PlacesBookmarkKeyword_h
|
||||
|
||||
#include "mozilla/dom/PlacesBookmarkChanged.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class PlacesBookmarkKeyword final : public PlacesBookmarkChanged {
|
||||
public:
|
||||
explicit PlacesBookmarkKeyword()
|
||||
: PlacesBookmarkChanged(PlacesEventType::Bookmark_keyword_changed) {}
|
||||
|
||||
static already_AddRefed<PlacesBookmarkKeyword> Constructor(
|
||||
const GlobalObject& aGlobal, const PlacesBookmarkKeywordInit& aInitDict) {
|
||||
RefPtr<PlacesBookmarkKeyword> event = new PlacesBookmarkKeyword();
|
||||
event->mId = aInitDict.mId;
|
||||
event->mItemType = aInitDict.mItemType;
|
||||
event->mUrl = aInitDict.mUrl;
|
||||
event->mGuid = aInitDict.mGuid;
|
||||
event->mParentGuid = aInitDict.mParentGuid;
|
||||
event->mKeyword = aInitDict.mKeyword;
|
||||
event->mLastModified = aInitDict.mLastModified;
|
||||
event->mSource = aInitDict.mSource;
|
||||
event->mIsTagging = aInitDict.mIsTagging;
|
||||
return event.forget();
|
||||
}
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override {
|
||||
return PlacesBookmarkKeyword_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
const PlacesBookmarkKeyword* AsPlacesBookmarkKeyword() const override {
|
||||
return this;
|
||||
}
|
||||
|
||||
void GetKeyword(nsCString& aKeyword) const { aKeyword = mKeyword; }
|
||||
nsCString mKeyword;
|
||||
|
||||
private:
|
||||
~PlacesBookmarkKeyword() = default;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
||||
|
|
@ -47,6 +47,9 @@ class PlacesEvent : public nsWrapperCache {
|
|||
virtual const PlacesBookmarkGuid* AsPlacesBookmarkGuid() const {
|
||||
return nullptr;
|
||||
}
|
||||
virtual const PlacesBookmarkKeyword* AsPlacesBookmarkKeyword() const {
|
||||
return nullptr;
|
||||
}
|
||||
virtual const PlacesBookmarkTags* AsPlacesBookmarkTags() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -235,6 +235,7 @@ EXPORTS.mozilla.dom += [
|
|||
"PlacesBookmarkAddition.h",
|
||||
"PlacesBookmarkChanged.h",
|
||||
"PlacesBookmarkGuid.h",
|
||||
"PlacesBookmarkKeyword.h",
|
||||
"PlacesBookmarkMoved.h",
|
||||
"PlacesBookmarkRemoved.h",
|
||||
"PlacesBookmarkTags.h",
|
||||
|
|
|
|||
|
|
@ -24,6 +24,10 @@ enum PlacesEventType {
|
|||
* data: PlacesBookmarkGuid. Fired whenever a bookmark guid changes.
|
||||
*/
|
||||
"bookmark-guid-changed",
|
||||
/**
|
||||
* data: PlacesBookmarkKeyword. Fired whenever a bookmark keyword changes.
|
||||
*/
|
||||
"bookmark-keyword-changed",
|
||||
/**
|
||||
* data: PlacesBookmarkTags. Fired whenever tags of bookmark changes.
|
||||
*/
|
||||
|
|
@ -312,6 +316,29 @@ interface PlacesBookmarkGuid : PlacesBookmarkChanged {
|
|||
constructor(PlacesBookmarkGuidInit initDict);
|
||||
};
|
||||
|
||||
dictionary PlacesBookmarkKeywordInit {
|
||||
required long long id;
|
||||
required unsigned short itemType;
|
||||
DOMString? url = null;
|
||||
required ByteString guid;
|
||||
required ByteString parentGuid;
|
||||
required ByteString keyword;
|
||||
required long long lastModified;
|
||||
required unsigned short source;
|
||||
required boolean isTagging;
|
||||
};
|
||||
|
||||
[ChromeOnly, Exposed=Window]
|
||||
interface PlacesBookmarkKeyword : PlacesBookmarkChanged {
|
||||
constructor(PlacesBookmarkKeywordInit initDict);
|
||||
|
||||
/**
|
||||
* Keyword the bookmark has currently.
|
||||
*/
|
||||
[Constant,Cached]
|
||||
readonly attribute ByteString keyword;
|
||||
};
|
||||
|
||||
dictionary PlacesBookmarkTagsInit {
|
||||
required long long id;
|
||||
required unsigned short itemType;
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ async function notifyKeywordChange(url, keyword, source) {
|
|||
bookmark.id = ids.get(bookmark.guid);
|
||||
bookmark.parentId = ids.get(bookmark.parentGuid);
|
||||
}
|
||||
|
||||
let observers = PlacesUtils.bookmarks.getObservers();
|
||||
for (let bookmark of bookmarks) {
|
||||
notify(observers, "onItemChanged", [
|
||||
|
|
@ -101,6 +102,24 @@ async function notifyKeywordChange(url, keyword, source) {
|
|||
source,
|
||||
]);
|
||||
}
|
||||
|
||||
const notifications = bookmarks.map(
|
||||
bookmark =>
|
||||
new PlacesBookmarkKeyword({
|
||||
id: bookmark.id,
|
||||
itemType: bookmark.type,
|
||||
url,
|
||||
guid: bookmark.guid,
|
||||
parentGuid: bookmark.parentGuid,
|
||||
keyword,
|
||||
lastModified: bookmark.lastModified,
|
||||
source,
|
||||
isTagging: false,
|
||||
})
|
||||
);
|
||||
if (notifications.length) {
|
||||
PlacesObservers.notifyListeners(notifications);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -438,6 +438,7 @@ module.exports = {
|
|||
PlacesBookmark: false,
|
||||
PlacesBookmarkAddition: false,
|
||||
PlacesBookmarkGuid: false,
|
||||
PlacesBookmarkKeyword: false,
|
||||
PlacesBookmarkMoved: false,
|
||||
PlacesBookmarkRemoved: false,
|
||||
PlacesBookmarkTags: false,
|
||||
|
|
|
|||
Loading…
Reference in a new issue