Home | History | Annotate | Download | only in UIProcess
      1 /*
      2  * Copyright (C) 2010 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  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     23  * THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #include "config.h"
     27 #include "WebPageContextMenuClient.h"
     28 
     29 #include "Logging.h"
     30 #include "MutableArray.h"
     31 #include "WebContextMenuItem.h"
     32 #include "WKAPICast.h"
     33 #include "WKSharedAPICast.h"
     34 
     35 namespace WebKit {
     36 
     37 bool WebPageContextMenuClient::getContextMenuFromProposedMenu(WebPageProxy* page, const Vector<WebContextMenuItemData>& proposedMenuVector, Vector<WebContextMenuItemData>& customMenu, APIObject* userData)
     38 {
     39     if (!m_client.getContextMenuFromProposedMenu)
     40         return false;
     41 
     42     unsigned size = proposedMenuVector.size();
     43     RefPtr<MutableArray> proposedMenu = MutableArray::create();
     44     proposedMenu->reserveCapacity(size);
     45     for (unsigned i = 0; i < size; ++i)
     46         proposedMenu->append(WebContextMenuItem::create(proposedMenuVector[i]).get());
     47 
     48     WKArrayRef newMenu = 0;
     49     m_client.getContextMenuFromProposedMenu(toAPI(page), toAPI(proposedMenu.get()), &newMenu, toAPI(userData), m_client.clientInfo);
     50     RefPtr<ImmutableArray> array = adoptRef(toImpl(newMenu));
     51 
     52     customMenu.clear();
     53 
     54     size_t newSize = array ? array->size() : 0;
     55     for (size_t i = 0; i < newSize; ++i) {
     56         WebContextMenuItem* item = array->at<WebContextMenuItem>(i);
     57         if (!item) {
     58             LOG(ContextMenu, "New menu entry at index %i is not a WebContextMenuItem", (int)i);
     59             continue;
     60         }
     61 
     62         customMenu.append(*item->data());
     63     }
     64 
     65     return true;
     66 }
     67 
     68 void WebPageContextMenuClient::customContextMenuItemSelected(WebPageProxy* page, const WebContextMenuItemData& itemData)
     69 {
     70     if (!m_client.customContextMenuItemSelected)
     71         return;
     72 
     73     RefPtr<WebContextMenuItem> item = WebContextMenuItem::create(itemData);
     74     m_client.customContextMenuItemSelected(toAPI(page), toAPI(item.get()), m_client.clientInfo);
     75 }
     76 
     77 } // namespace WebKit
     78