<rdar://problem/8613727> and https://bugs.webkit.org/show_bug.cgi?id=49836
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Nov 2010 23:41:02 +0000 (23:41 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Nov 2010 23:41:02 +0000 (23:41 +0000)
Add WebKit2 API relevant to customization of context menus

Reviewed by Darin Adler.

WebCore:

* WebCore.exp.in:

WebKit2:

Most of this is just exposing already-existing concepts in API.

* Shared/API/c/WKURLRequest.cpp:
(WKURLRequestCreateWithWKURL):
* Shared/API/c/WKURLRequest.h:

* Shared/WebURLRequest.cpp:
(WebKit::WebURLRequest::create):
* Shared/WebURLRequest.h:

* WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp:
(WKBundleHitTestResultCopyAbsoluteImageURL):
(WKBundleHitTestResultCopyAbsoluteMediaURL):
(WKBundleHitTestResultGetImageRect):
(WKBundleHitTestResultGetIsSelected):
* WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h:

* WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
(WKBundlePageHasLocalDataForURL):
(WKBundlePageCanHandleRequest):
* WebProcess/InjectedBundle/API/c/WKBundlePage.h:

* WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
(WebKit::InjectedBundleHitTestResult::absoluteImageURL):
(WebKit::InjectedBundleHitTestResult::absoluteMediaURL):
(WebKit::InjectedBundleHitTestResult::imageRect):
(WebKit::InjectedBundleHitTestResult::isSelected):
* WebProcess/InjectedBundle/InjectedBundleHitTestResult.h:

* WebProcess/WebPage/WebContextMenu.cpp:
(WebKit::WebContextMenu::show):

* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::hasLocalDataForURL):
(WebKit::WebPage::canHandleRequest):
* WebProcess/WebPage/qt/WebPageQt.cpp:
(WebKit::WebPage::hasLocalDataForURL): Stubbed for now.
(WebKit::WebPage::canHandleRequest): Ditto.
* WebProcess/WebPage/win/WebPageWin.cpp:
(WebKit::WebPage::hasLocalDataForURL): Ditto.
(WebKit::WebPage::canHandleRequest): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@72446 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
WebCore/ChangeLog
WebCore/WebCore.exp.in
WebKit2/ChangeLog
WebKit2/Shared/API/c/WKURLRequest.cpp
WebKit2/Shared/API/c/WKURLRequest.h
WebKit2/Shared/WebURLRequest.cpp
WebKit2/Shared/WebURLRequest.h
WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp
WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h
WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp
WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h
WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp
WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h
WebKit2/WebProcess/WebPage/WebContextMenu.cpp
WebKit2/WebProcess/WebPage/WebPage.h
WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
WebKit2/WebProcess/WebPage/qt/WebPageQt.cpp
WebKit2/WebProcess/WebPage/win/WebPageWin.cpp

index 15d4c2c..9c7a55c 100644 (file)
@@ -1,3 +1,12 @@
+2010-11-19  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Darin Adler.
+
+        <rdar://problem/8613727> and https://bugs.webkit.org/show_bug.cgi?id=49836
+        Add WebKit2 API relevant to customization of context menus
+
+        * WebCore.exp.in:
+
 2010-11-19  Michael Saboff  <msaboff@apple.com>
 
         Reviewed by Sam Weinig.
index e418ede..3246e0a 100644 (file)
@@ -1362,6 +1362,7 @@ __ZN7WebCore16ScriptController29cleanupScriptObjectsForPluginEPv
 __ZN7WebCore17HTMLPlugInElement11getNPObjectEv
 __ZNK7WebCore12RenderObject4viewEv
 __ZNK7WebCore14SecurityOrigin9canAccessEPKS0_
+__ZNK7WebCore4KURL10protocolIsEPKc
 __ZNK7WebCore4KURL7hasPathEv
 __ZNK7WebCore4KURL9prettyURLEv
 #endif
index d68cea5..06b956e 100644 (file)
@@ -1,3 +1,53 @@
+2010-11-19  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Darin Adler.
+
+        <rdar://problem/8613727> and https://bugs.webkit.org/show_bug.cgi?id=49836
+        Add WebKit2 API relevant to customization of context menus
+
+        Most of this is just exposing already-existing concepts in API.
+
+        * Shared/API/c/WKURLRequest.cpp:
+        (WKURLRequestCreateWithWKURL):
+        * Shared/API/c/WKURLRequest.h:
+
+        * Shared/WebURLRequest.cpp:
+        (WebKit::WebURLRequest::create):
+        * Shared/WebURLRequest.h:
+
+        * WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp:
+        (WKBundleHitTestResultCopyAbsoluteImageURL):
+        (WKBundleHitTestResultCopyAbsoluteMediaURL):
+        (WKBundleHitTestResultGetImageRect):
+        (WKBundleHitTestResultGetIsSelected):
+        * WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h:
+
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
+        (WKBundlePageHasLocalDataForURL):
+        (WKBundlePageCanHandleRequest):
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.h:
+
+        * WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
+        (WebKit::InjectedBundleHitTestResult::absoluteImageURL):
+        (WebKit::InjectedBundleHitTestResult::absoluteMediaURL):
+        (WebKit::InjectedBundleHitTestResult::imageRect):
+        (WebKit::InjectedBundleHitTestResult::isSelected):
+        * WebProcess/InjectedBundle/InjectedBundleHitTestResult.h:
+
+        * WebProcess/WebPage/WebContextMenu.cpp:
+        (WebKit::WebContextMenu::show):
+
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::hasLocalDataForURL):
+        (WebKit::WebPage::canHandleRequest):
+        * WebProcess/WebPage/qt/WebPageQt.cpp:
+        (WebKit::WebPage::hasLocalDataForURL): Stubbed for now.
+        (WebKit::WebPage::canHandleRequest): Ditto.
+        * WebProcess/WebPage/win/WebPageWin.cpp:
+        (WebKit::WebPage::hasLocalDataForURL): Ditto.
+        (WebKit::WebPage::canHandleRequest): Ditto.
+
 2010-11-19  Darin Adler  <darin@apple.com>
 
         Reviewed by Sam Weinig.
index 060627b..27d45b1 100644 (file)
@@ -34,3 +34,8 @@ WKTypeID WKURLRequestGetTypeID()
 {
     return toAPI(WebURLRequest::APIType);
 }
+
+WKURLRequestRef WKURLRequestCreateWithWKURL(WKURLRef url)
+{
+    return toAPI(WebURLRequest::create(toImpl(url)->string()).leakRef());
+}
index cb9d003..d78968d 100644 (file)
@@ -34,6 +34,8 @@ extern "C" {
 
 WK_EXPORT WKTypeID WKURLRequestGetTypeID();
 
+WK_EXPORT WKURLRequestRef WKURLRequestCreateWithWKURL(WKURLRef);
+
 #ifdef __cplusplus
 }
 #endif
index c0e3433..1e255c2 100644 (file)
@@ -13,6 +13,11 @@ using namespace WebCore;
 
 namespace WebKit {
 
+PassRefPtr<WebURLRequest> WebURLRequest::create(const KURL& url)
+{
+    return adoptRef(new WebURLRequest(ResourceRequest(url)));
+}
+
 WebURLRequest::WebURLRequest(const ResourceRequest& request)
     : m_request(request)
 {
index b21bca1..6cb5ba8 100644 (file)
@@ -44,6 +44,8 @@ class WebURLRequest : public APIObject {
 public:
     static const Type APIType = TypeURLRequest;
 
+    static PassRefPtr<WebURLRequest> create(const WebCore::KURL&);
+
     static PassRefPtr<WebURLRequest> create(const WebCore::ResourceRequest& request)
     {
         return adoptRef(new WebURLRequest(request));
index 78544e5..ca55fa9 100644 (file)
@@ -53,7 +53,28 @@ WKBundleFrameRef WKBundleHitTestResultGetTargetFrame(WKBundleHitTestResultRef hi
     return toAPI(toImpl(hitTestResultRef)->targetFrame());
 }
 
+WKURLRef WKBundleHitTestResultCopyAbsoluteImageURL(WKBundleHitTestResultRef hitTestResultRef)
+{
+    return toCopiedURLAPI(toImpl(hitTestResultRef)->absoluteImageURL());
+}
+
 WKURLRef WKBundleHitTestResultCopyAbsoluteLinkURL(WKBundleHitTestResultRef hitTestResultRef)
 {
     return toCopiedURLAPI(toImpl(hitTestResultRef)->absoluteLinkURL());
 }
+
+WKURLRef WKBundleHitTestResultCopyAbsoluteMediaURL(WKBundleHitTestResultRef hitTestResultRef)
+{
+    return toCopiedURLAPI(toImpl(hitTestResultRef)->absoluteMediaURL());
+}
+
+WKRect WKBundleHitTestResultGetImageRect(WKBundleHitTestResultRef hitTestResultRef)
+{
+    return toAPI(toImpl(hitTestResultRef)->imageRect());
+}
+
+bool WKBundleHitTestResultGetIsSelected(WKBundleHitTestResultRef hitTestResultRef)
+{
+    return toImpl(hitTestResultRef)->isSelected();
+
+}
index 88da5f5..f22da68 100644 (file)
@@ -27,6 +27,7 @@
 #define WKBundleHitTestResult_h
 
 #include <WebKit2/WKBase.h>
+#include <WebKit2/WKGeometry.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -35,9 +36,16 @@ extern "C" {
 WK_EXPORT WKTypeID WKBundleHitTestResultGetTypeID();
 
 WK_EXPORT WKBundleNodeHandleRef WKBundleHitTestResultGetNodeHandle(WKBundleHitTestResultRef hitTestResult);
+
 WK_EXPORT WKBundleFrameRef WKBundleHitTestResultGetFrame(WKBundleHitTestResultRef hitTestResult);
 WK_EXPORT WKBundleFrameRef WKBundleHitTestResultGetTargetFrame(WKBundleHitTestResultRef hitTestResult);
+
+WK_EXPORT WKURLRef WKBundleHitTestResultCopyAbsoluteImageURL(WKBundleHitTestResultRef hitTestResult);
 WK_EXPORT WKURLRef WKBundleHitTestResultCopyAbsoluteLinkURL(WKBundleHitTestResultRef hitTestResult);
+WK_EXPORT WKURLRef WKBundleHitTestResultCopyAbsoluteMediaURL(WKBundleHitTestResultRef hitTestResult);
+
+WK_EXPORT WKRect WKBundleHitTestResultGetImageRect(WKBundleHitTestResultRef hitTestResult);
+WK_EXPORT bool WKBundleHitTestResultGetIsSelected(WKBundleHitTestResultRef hitTestResult);
 
 #ifdef __cplusplus
 }
index 13fb09f..cd8f158 100644 (file)
 #include "WKBundlePagePrivate.h"
 
 #include "InjectedBundleBackForwardList.h"
+#include "WebPage.h"
+#include "WebURL.h"
+#include "WebURLRequest.h"
 #include "WKAPICast.h"
 #include "WKBundleAPICast.h"
-#include "WebPage.h"
+
+#include <WebCore/KURL.h>
 
 using namespace WebKit;
 
@@ -142,3 +146,13 @@ void WKBundlePageUninstallPageOverlay(WKBundlePageRef pageRef, WKBundlePageOverl
 {
     toImpl(pageRef)->uninstallPageOverlay(toImpl(pageOverlayRef));
 }
+
+bool WKBundlePageHasLocalDataForURL(WKBundlePageRef pageRef, WKURLRef urlRef)
+{
+    return toImpl(pageRef)->hasLocalDataForURL(WebCore::KURL(WebCore::KURL(), toImpl(urlRef)->string()));
+}
+
+bool WKBundlePageCanHandleRequest(WKURLRequestRef requestRef)
+{
+    return WebPage::canHandleRequest(toImpl(requestRef)->resourceRequest());
+}
index aa58930..d507df2 100644 (file)
@@ -206,6 +206,9 @@ WK_EXPORT WKBundleBackForwardListRef WKBundlePageGetBackForwardList(WKBundlePage
 WK_EXPORT void WKBundlePageInstallPageOverlay(WKBundlePageRef page, WKBundlePageOverlayRef pageOverlay);
 WK_EXPORT void WKBundlePageUninstallPageOverlay(WKBundlePageRef page, WKBundlePageOverlayRef pageOverlay);
 
+WK_EXPORT bool WKBundlePageHasLocalDataForURL(WKBundlePageRef page, WKURLRef url);
+WK_EXPORT bool WKBundlePageCanHandleRequest(WKURLRequestRef request);
+
 #ifdef __cplusplus
 }
 #endif
index 98629cd..d60fff9 100644 (file)
@@ -74,9 +74,29 @@ WebFrame* InjectedBundleHitTestResult::targetFrame() const
     return static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame();
 }
 
+String InjectedBundleHitTestResult::absoluteImageURL() const
+{
+    return m_hitTestResult.absoluteImageURL().string();
+}
+
 String InjectedBundleHitTestResult::absoluteLinkURL() const
 {
     return m_hitTestResult.absoluteLinkURL().string();
 }
 
+String InjectedBundleHitTestResult::absoluteMediaURL() const
+{
+    return m_hitTestResult.absoluteMediaURL().string();
+}
+
+WebCore::IntRect InjectedBundleHitTestResult::imageRect() const
+{
+    return m_hitTestResult.imageRect();
+}
+
+bool InjectedBundleHitTestResult::isSelected() const
+{
+    return m_hitTestResult.isSelected();
+}
+
 } // WebKit
index eac9e78..8b82ce7 100644 (file)
@@ -48,7 +48,14 @@ public:
     PassRefPtr<InjectedBundleNodeHandle> nodeHandle() const; 
     WebFrame* frame() const;
     WebFrame* targetFrame() const;
+
+    String absoluteImageURL() const;
     String absoluteLinkURL() const;
+    String absoluteMediaURL() const;
+    
+    WebCore::IntRect imageRect() const;
+    
+    bool isSelected() const;
 
 private:
     explicit InjectedBundleHitTestResult(const WebCore::HitTestResult& hitTestResult)
index 6ce928e..8418905 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "WebContextMenu.h"
 
+#include "InjectedBundleHitTestResult.h"
 #include "InjectedBundleUserMessageCoders.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebPage.h"
@@ -64,7 +65,8 @@ void WebContextMenu::show()
     Vector<WebContextMenuItemData> proposedMenu = kitItems(coreItems, menu);
     Vector<WebContextMenuItemData> newMenu;
     RefPtr<APIObject> userData;
-    if (m_page->injectedBundleContextMenuClient().getCustomMenuFromDefaultItems(m_page, 0, proposedMenu, newMenu, userData))
+    RefPtr<InjectedBundleHitTestResult> hitTestResult = InjectedBundleHitTestResult::create(menu->hitTestResult());
+    if (m_page->injectedBundleContextMenuClient().getCustomMenuFromDefaultItems(m_page, hitTestResult.get(), proposedMenu, newMenu, userData))
         proposedMenu = newMenu;
 
     // Notify the UIProcess.
index fb05ebf..2ec1d42 100644 (file)
@@ -203,6 +203,10 @@ public:
 #endif
 
     WebContextMenu* contextMenu();
+    
+    bool hasLocalDataForURL(const WebCore::KURL&);
+    
+    static bool canHandleRequest(const WebCore::ResourceRequest&);
 
     class SandboxExtensionTracker {
     public:
index 90c088b..2460266 100644 (file)
@@ -29,6 +29,8 @@
 #include "WebEvent.h"
 #include "WebPageProxyMessages.h"
 #include "WebProcess.h"
+#include <WebCore/ArchiveResource.h>
+#include <WebCore/DocumentLoader.h>
 #include <WebCore/FocusController.h>
 #include <WebCore/Frame.h>
 #include <WebCore/KeyboardEvent.h>
@@ -191,4 +193,31 @@ bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboard
     return true;
 }
 
+bool WebPage::hasLocalDataForURL(const WebCore::KURL& url)
+{
+    if (url.isLocalFile())
+        return true;
+    
+    FrameLoader* frameLoader = m_page->mainFrame()->loader();
+    DocumentLoader* documentLoader = frameLoader ? frameLoader->documentLoader() : 0;
+    if (documentLoader && documentLoader->subresource(url))
+        return true;
+
+    NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
+    [request setValue:(NSString*)userAgent() forHTTPHeaderField:@"User-Agent"];
+    NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:request];
+    [request release];
+    
+    return cachedResponse;
+}
+
+bool WebPage::canHandleRequest(const WebCore::ResourceRequest& request)
+{
+    if ([NSURLConnection canHandleRequest:request.nsURLRequest()])
+        return YES;
+
+    // FIXME: Return true if this scheme is any one WebKit2 knows how to handle.
+    return request.url().protocolIs("applewebdata");
+}
+
 } // namespace WebKit
index 4d3bbe5..2562583 100644 (file)
@@ -259,4 +259,16 @@ bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboard
     return true;
 }
 
+bool WebPage::hasLocalDataForURL(const WebCore::KURL&)
+{
+    // FIXME: Implement
+    return false;
+}
+
+bool WebPage::canHandleRequest(const WebCore::ResourceRequest&)
+{
+    // FIXME: Implement
+    return true;
+}
+
 } // namespace WebKit
index 526474a..d0c9935 100644 (file)
@@ -229,4 +229,16 @@ bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboard
     return true;
 }
 
+bool WebPage::hasLocalDataForURL(const WebCore::KURL&)
+{
+    // FIXME <rdar://problem/8608754>: Implement
+    return false;
+}
+
+bool WebPage::canHandleRequest(const WebCore::ResourceRequest&)
+{
+    // FIXME <rdar://problem/8608754>: Implement
+    return true;
+}
+
 } // namespace WebKit