Index: third_party/WebKit/Source/web/WebLocalFrameImpl.cpp |
diff --git a/third_party/WebKit/Source/web/WebLocalFrameImpl.cpp b/third_party/WebKit/Source/web/WebLocalFrameImpl.cpp |
index 074ddd83efbbd192e16f1e4075ad0b34eecd2604..96611ab88526a332c51a3c055130978457c1bc4e 100644 |
--- a/third_party/WebKit/Source/web/WebLocalFrameImpl.cpp |
+++ b/third_party/WebKit/Source/web/WebLocalFrameImpl.cpp |
@@ -1350,6 +1350,42 @@ bool WebLocalFrameImpl::selectionStartHasSpellingMarkerFor(int from, int length) |
return frame()->spellChecker().selectionStartHasSpellingMarkerFor(from, length); |
} |
+void WebLocalFrameImpl::copyImageAt(const WebPoint& posInViewport) |
+{ |
+ if (!frame()) |
dcheng
2016/05/24 07:18:08
Can this actually happen in practice?
brettw
2016/05/25 19:10:20
No idea, I just copied some other code in this fil
|
+ return; |
+ |
+ HitTestResult result = hitTestResultForVisualViewportPos(posInViewport); |
+ if (!isHTMLCanvasElement(result.innerNodeOrImageMapImage()) && result.absoluteImageURL().isEmpty()) { |
+ // There isn't actually an image at these coordinates. Might be because |
+ // the window scrolled while the context menu was open or because the page |
+ // changed itself between when we thought there was an image here and when |
+ // we actually tried to retreive the image. |
+ // |
+ // FIXME: implement a cache of the most recent HitTestResult to avoid having |
+ // to do two hit tests. |
+ return; |
+ } |
+ |
+ frame()->editor().copyImage(result); |
+} |
+ |
+void WebLocalFrameImpl::saveImageAt(const WebPoint& posInViewport) |
+{ |
+ if (!frame() || !m_client) |
dcheng
2016/05/24 07:18:08
Ditto: can this actually happen? //content is call
|
+ return; |
+ |
+ Node* node = hitTestResultForVisualViewportPos(posInViewport).innerNodeOrImageMapImage(); |
+ if (!node || !(isHTMLCanvasElement(*node) || isHTMLImageElement(*node))) |
+ return; |
+ |
+ String url = toElement(*node).imageSourceURL(); |
+ if (!KURL(KURL(), url).protocolIsData()) |
+ return; |
+ |
+ m_client->saveImageFromDataURL(url); |
+} |
+ |
WebString WebLocalFrameImpl::layerTreeAsText(bool showDebugInfo) const |
{ |
if (!frame()) |
@@ -1769,6 +1805,15 @@ void WebLocalFrameImpl::loadJavaScriptURL(const KURL& url) |
frame()->loader().replaceDocumentWhileExecutingJavaScriptURL(scriptResult, ownerDocument); |
} |
+HitTestResult WebLocalFrameImpl::hitTestResultForVisualViewportPos(const IntPoint& posInViewport) |
+{ |
+ IntPoint rootFramePoint(frame()->host()->visualViewport().viewportToRootFrame(posInViewport)); |
+ IntPoint docPoint(frame()->view()->rootFrameToContents(rootFramePoint)); |
+ HitTestResult result = frame()->eventHandler().hitTestResultAtPoint(docPoint, HitTestRequest::ReadOnly | HitTestRequest::Active); |
+ result.setToShadowHostIfInUserAgentShadowRoot(); |
+ return result; |
+} |
+ |
static void ensureFrameLoaderHasCommitted(FrameLoader& frameLoader) |
{ |
// Internally, Blink uses CommittedMultipleRealLoads to track whether the |