| 1 | /* |
| 2 | * Copyright (C) 2018 Apple, Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 15 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 16 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 17 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 18 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 20 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #include "config.h" |
| 28 | #include "EditableImageReference.h" |
| 29 | |
| 30 | #include "Chrome.h" |
| 31 | #include "ChromeClient.h" |
| 32 | |
| 33 | namespace WebCore { |
| 34 | |
| 35 | EditableImageReference::EditableImageReference(Document& document) |
| 36 | : m_document(makeWeakPtr(document)) |
| 37 | , m_embeddedViewID(GraphicsLayer::nextEmbeddedViewID()) |
| 38 | { |
| 39 | if (auto* page = document.page()) |
| 40 | page->chrome().client().didCreateEditableImage(m_embeddedViewID); |
| 41 | } |
| 42 | |
| 43 | EditableImageReference::~EditableImageReference() |
| 44 | { |
| 45 | if (!m_document) |
| 46 | return; |
| 47 | if (auto* page = m_document->page()) |
| 48 | page->chrome().client().didDestroyEditableImage(m_embeddedViewID); |
| 49 | } |
| 50 | |
| 51 | void EditableImageReference::associateWithAttachment(const String& attachmentID) |
| 52 | { |
| 53 | if (!m_document) |
| 54 | return; |
| 55 | if (auto* page = m_document->page()) |
| 56 | page->chrome().client().associateEditableImageWithAttachment(m_embeddedViewID, attachmentID); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | } // namespace WebCore |
| 61 | |