RESOLVED FIXED 117667
Expose a getMediaType method in WebKit
https://bugs.webkit.org/show_bug.cgi?id=117667
Summary Expose a getMediaType method in WebKit
Ruth Fong
Reported 2013-06-14 18:05:51 PDT
Provide hooks in WebKit to detect whether a media element is a <video> element.
Attachments
Patch (5.74 KB, patch)
2013-06-14 18:24 PDT, Ruth Fong
no flags
Patch (6.87 KB, patch)
2013-06-17 13:24 PDT, Ruth Fong
no flags
Patch (7.57 KB, patch)
2013-06-17 15:11 PDT, Ruth Fong
no flags
Patch (7.07 KB, patch)
2013-06-17 15:14 PDT, Ruth Fong
no flags
Patch (15.40 KB, patch)
2013-06-17 16:47 PDT, Ruth Fong
no flags
Patch (15.38 KB, patch)
2013-06-17 16:56 PDT, Ruth Fong
no flags
Patch (17.02 KB, patch)
2013-06-17 17:21 PDT, Ruth Fong
no flags
Patch (16.99 KB, patch)
2013-06-18 12:39 PDT, Ruth Fong
no flags
Patch (17.00 KB, patch)
2013-06-18 12:47 PDT, Ruth Fong
beidson: review+
eflews.bot: commit-queue-
Radar WebKit Bug Importer
Comment 1 2013-06-14 18:08:29 PDT
Ruth Fong
Comment 2 2013-06-14 18:24:23 PDT
Brady Eidson
Comment 3 2013-06-17 11:28:00 PDT
Comment on attachment 204752 [details] Patch Style seems fine here, but I'm not convinced this API is the way to go. Asking a WKBundleHitTestResult if the media is video for a non-media element is kind of weird. Of course it's not video - It's a div, or a img! The client would have to first determine that the hit test result represents a media element by getting the media src URL (which is kind of a weird way to determine that...) and then use this API. The new API should probably be a general purpose "what kind of media element is this?" call. To start with it could return: kWKMediaTypeAudio kWKMediaTypeVideo kWKMediaTypeNone This removes some burden on the client and is also expandable in the future when we add <smell>, <taste>, or <touch>.
Ruth Fong
Comment 4 2013-06-17 13:24:32 PDT
Brady Eidson
Comment 5 2013-06-17 14:35:29 PDT
Comment on attachment 204851 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=204851&action=review Great first swipe. My feedback should be pretty straightforward to address. How did you test this? I have a *vague* concern that we're getting at the wrong Node from the hit test result, but am not sure. > Source/WebCore/ChangeLog:4 > + Expose the mediaIsVideo method in WebKit > + https://bugs.webkit.org/show_bug.cgi?id=117667 s/in WebKit/to WebKit/ > Source/WebCore/ChangeLog:8 > + No new tests added. Generally isn't necessary with patches that obviously have no behavior change in WebCore, especially when they don't even touch actual source files in WebCore. > Source/WebKit2/ChangeLog:4 > + Expose the mediaIsVideo method in WebKit > + https://bugs.webkit.org/show_bug.cgi?id=117667 The WK2 API being exposed is no longer mediaIsVideo. > Source/WebKit2/ChangeLog:10 > + * WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp: > + (WKBundleHitTestResultGetMediaType): Added to return what type, if any, > + a media element is. The WK* functions that implement the API are generally meant to be as thin and simple as possible. Usually they just call directly to their impl class. So this function should just call through... > Source/WebKit2/ChangeLog:16 > + * WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp: > + (WebKit::InjectedBundleHitTestResult::mediaIsVideo): Added to hook into WebCore > + method HitTestResult::mediaIsVideo(). ...to this function, which should be InjectedBundleHitTestResult::getMediaType Also please adjust the descriptions as necessary. > Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:106 > +bool InjectedBundleHitTestResult::mediaIsVideo() const As mentioned above, this should be renamed and most the work moved here. > Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp:85 > +WKBundleHitTestResultMediaType WKBundleHitTestResultGetMediaType(WKBundleHitTestResultRef hitTestResultRef) As mentioned above, this should just be a thin layer that calls directly to InjectedBundleHitTest > Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp:92 > + WebCore::Node* node = toImpl(hitTestResultRef)->coreHitTestResult().innerNonSharedNode(); > + if (node->nodeType() != Node::ELEMENT_NODE) > + return kWKBundleHitTestResultMediaTypeNone; > + > + if (!((Element*)node)->isMediaElement()) > + return kWKBundleHitTestResultMediaTypeNone; After we banged this out, I recalled there's a convenience method in WebCore for casting Node->Element See "toElement()" in WebCore/Element.h. Use that instead. :) > Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp:97 > + if (toImpl(hitTestResultRef)->mediaIsVideo()) > + return kWKBundleHitTestResultMediaTypeVideo; > + > + return kWKBundleHitTestResultMediaTypeAudio; This is fine. An alternate way to write it would be: return toImpl(hitTestResultRef)->mediaIsVideo() ? kWKBundleHitTestResultMediaTypeVideo : kWKBundleHitTestResultMediaTypeAudio;
Ruth Fong
Comment 6 2013-06-17 15:11:55 PDT
Ruth Fong
Comment 7 2013-06-17 15:14:14 PDT
Brady Eidson
Comment 8 2013-06-17 15:53:50 PDT
Comment on attachment 204860 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=204860&action=review > Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:111 > + if (node->nodeType() != Node::ELEMENT_NODE) > + return kWKBundleHitTestResultMediaTypeNone; This should probably be if (node->isElementNode()) instead. Sorry for not catching that earlier. > Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h:32 > #include <WebCore/HitTestResult.h> > +#include <WebKit2/WKBundleHitTestResult.h> > #include <wtf/Forward.h> Seeing this in the flesh set off a red flag - We shouldn't be directly including API headers in implementation files when we can avoid it. I've suggested to Ruth on IRC a path forward with an API set of enums, an impl set of enums, and API casting.
Ruth Fong
Comment 9 2013-06-17 16:47:58 PDT
EFL EWS Bot
Comment 10 2013-06-17 16:56:03 PDT
Ruth Fong
Comment 11 2013-06-17 16:56:34 PDT
EFL EWS Bot
Comment 12 2013-06-17 17:01:34 PDT
Ruth Fong
Comment 13 2013-06-17 17:21:12 PDT
EFL EWS Bot
Comment 14 2013-06-17 17:29:05 PDT
Brady Eidson
Comment 15 2013-06-18 11:45:34 PDT
Comment on attachment 204869 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=204869&action=review > Source/WebKit2/UIProcess/API/C/WKAPICast.h:176 > + > + return kWKBundleHitTestResultMediaTypeNone; ASSERT_NOT_REACHED() here also, right? > Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h:32 > +#include <WebKit2/InjectedBundleHitTestResultMediaType.h> > +#include <WebKit2/WKBundleHitTestResult.h> These headers are local to the WK2 project, so it should just be #include "InjectedBundleHitTestResultMediaType.h" under the APIObject include. And the WKBundleHitTestResult.h include isn't needed at all - that's what we're avoiding with all these casts and such! > Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp:84 > + return toImpl(hitTestResultRef)->getMediaType(); This needs to be: return toAPI(toImpl(hitTestResultRef)->getMediaType()) to perform the InjectedBundle* -> WKBundle* cast
Ruth Fong
Comment 16 2013-06-18 12:33:51 PDT
Comment on attachment 204869 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=204869&action=review >> Source/WebKit2/UIProcess/API/C/WKAPICast.h:176 >> + return kWKBundleHitTestResultMediaTypeNone; > > ASSERT_NOT_REACHED() here also, right? None of the other toAPI methods include the ASSERT_NOT_REACHED() (not sure why) >> Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h:32 >> +#include <WebKit2/WKBundleHitTestResult.h> > > These headers are local to the WK2 project, so it should just be #include "InjectedBundleHitTestResultMediaType.h" under the APIObject include. > > And the WKBundleHitTestResult.h include isn't needed at all - that's what we're avoiding with all these casts and such! Got it. >> Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp:84 >> + return toImpl(hitTestResultRef)->getMediaType(); > > This needs to be: > return toAPI(toImpl(hitTestResultRef)->getMediaType()) to perform the InjectedBundle* -> WKBundle* cast Got it (it seemed to work without the cast...)
Ruth Fong
Comment 17 2013-06-18 12:39:09 PDT
Ruth Fong
Comment 18 2013-06-18 12:47:31 PDT
EFL EWS Bot
Comment 19 2013-06-18 13:06:39 PDT
Beth Dakin
Comment 20 2013-06-18 14:40:35 PDT
Brady Eidson
Comment 21 2013-06-18 14:43:05 PDT
(In reply to comment #19) > (From update of attachment 204934 [details]) > Attachment 204934 [details] did not pass efl-wk2-ews (efl-wk2): > Output: http://webkit-queues.appspot.com/results/948047 This build failure is bizarre. It's in WebKitTestRunner and TestWebKitAPI with regards to WKAPICast.h. In those failures, WKAPICast.h includes other WK2 internal headers. For the other ~6 it includes, they are found without issue. For the newly added header, it is not found. There's no build system file we can find that includes those other headers. It doesn't seem like we missed a build system. Our only theory is that EFL copies all the Shared/ headers (and therefore gets those other ones) but doesn't copy the InjectedBundle/ headers. If that's what's going on, that's a failure with the EFL build system, as this new header is in the right place.
Darin Adler
Comment 22 2013-06-18 17:41:31 PDT
Comment on attachment 204934 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=204934&action=review > Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h:56 > + BundleHitTestResultMediaType getMediaType() const; WebKit coding style says this should be named mediaType(), not getMediaType(). > Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h:55 > +WK_EXPORT WKBundleHitTestResultMediaType WKBundleHitTestResultGetMediaType(WKBundleHitTestResultRef hitTestResult); Here it is fine to use the name WKBundleHitTestResultGetMediaType.
Csaba Osztrogonác
Comment 23 2013-06-18 17:42:37 PDT
(In reply to comment #20) > Committed Ruth's patch: http://trac.webkit.org/changeset/151699 It broke the !ENABLE(VIDEO) platforms because of a missing ifdef guard: /home/webkitbuildbot/slaves/armQt5Release-buildonly/buildslave/qt5-linux-armv7-release/build/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp: In member function 'WebKit::BundleHitTestResultMediaType WebKit::InjectedBundleHitTestResult::getMediaType() const': /home/webkitbuildbot/slaves/armQt5Release-buildonly/buildslave/qt5-linux-armv7-release/build/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:113:27: error: 'class WebCore::Element' has no member named 'isMediaElement' Could you check and fix it, please?
Csaba Osztrogonác
Comment 24 2013-06-18 17:43:38 PDT
(In reply to comment #20) > Committed Ruth's patch: http://trac.webkit.org/changeset/151699 The patch landed, so can we close the bug?
Ruth Fong
Comment 25 2013-06-18 18:02:36 PDT
Closed this bug. Bug 117765 is now tracking the revisions to this patch: namely the renaming of the getMediaType functions and fixing the patch for !ENABLE(VIDEO) platforms.
Note You need to log in before you can comment on or make changes to this bug.