Implementation of brand-color

Add APIs
- WebFrame::brandColor() to get the brand color.
- WebFrameClinet::didChangeBrandColor to notify the brand color change.

BUG=383941

Intent to implement and ship link
https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/nzRY-h_-_ig

Review URL: https://codereview.chromium.org/329943004

git-svn-id: svn://svn.chromium.org/blink/trunk@176142 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b5248cc7
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "core/css/StyleSheetContents.h" #include "core/css/StyleSheetContents.h"
#include "core/css/StyleSheetList.h" #include "core/css/StyleSheetList.h"
#include "core/css/invalidation/StyleInvalidator.h" #include "core/css/invalidation/StyleInvalidator.h"
#include "core/css/parser/CSSPropertyParser.h"
#include "core/css/resolver/FontBuilder.h" #include "core/css/resolver/FontBuilder.h"
#include "core/css/resolver/StyleResolver.h" #include "core/css/resolver/StyleResolver.h"
#include "core/css/resolver/StyleResolverStats.h" #include "core/css/resolver/StyleResolverStats.h"
...@@ -4737,6 +4738,19 @@ Vector<IconURL> Document::iconURLs(int iconTypesMask) ...@@ -4737,6 +4738,19 @@ Vector<IconURL> Document::iconURLs(int iconTypesMask)
return iconURLs; return iconURLs;
} }
Color Document::brandColor() const
{
if (!RuntimeEnabledFeatures::brandColorEnabled())
return Color();
for (HTMLMetaElement* metaElement = head() ? Traversal<HTMLMetaElement>::firstChild(*head()) : 0; metaElement; metaElement = Traversal<HTMLMetaElement>::nextSibling(*metaElement)) {
RGBA32 rgb;
if (equalIgnoringCase(metaElement->name(), "brand-color") && CSSPropertyParser::fastParseColor(rgb, metaElement->content().string().stripWhiteSpace(), true))
return Color(rgb);
}
return Color();
}
HTMLLinkElement* Document::linkManifest() const HTMLLinkElement* Document::linkManifest() const
{ {
HTMLHeadElement* head = this->head(); HTMLHeadElement* head = this->head();
......
...@@ -857,6 +857,8 @@ public: ...@@ -857,6 +857,8 @@ public:
Vector<IconURL> iconURLs(int iconTypesMask); Vector<IconURL> iconURLs(int iconTypesMask);
Color brandColor() const;
// Returns the HTMLLinkElement currently in use for the Web Manifest. // Returns the HTMLLinkElement currently in use for the Web Manifest.
// Returns null if there is no such element. // Returns null if there is no such element.
HTMLLinkElement* linkManifest() const; HTMLLinkElement* linkManifest() const;
......
...@@ -24,8 +24,11 @@ ...@@ -24,8 +24,11 @@
#include "core/html/HTMLMetaElement.h" #include "core/html/HTMLMetaElement.h"
#include "HTMLNames.h" #include "HTMLNames.h"
#include "RuntimeEnabledFeatures.h"
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h" #include "core/frame/Settings.h"
#include "core/loader/FrameLoaderClient.h"
namespace WebCore { namespace WebCore {
...@@ -468,6 +471,8 @@ void HTMLMetaElement::process() ...@@ -468,6 +471,8 @@ void HTMLMetaElement::process()
processViewportContentAttribute("width=device-width", ViewportDescription::HandheldFriendlyMeta); processViewportContentAttribute("width=device-width", ViewportDescription::HandheldFriendlyMeta);
else if (equalIgnoringCase(nameValue, "mobileoptimized")) else if (equalIgnoringCase(nameValue, "mobileoptimized"))
processViewportContentAttribute("width=device-width, initial-scale=1", ViewportDescription::MobileOptimizedMeta); processViewportContentAttribute("width=device-width, initial-scale=1", ViewportDescription::MobileOptimizedMeta);
else if (RuntimeEnabledFeatures::brandColorEnabled() && equalIgnoringCase(nameValue, "brand-color") && document().frame())
document().frame()->loader().client()->dispatchDidChangeBrandColor();
} }
// Get the document to process the tag, but only if we're actually part of DOM // Get the document to process the tag, but only if we're actually part of DOM
......
...@@ -202,6 +202,7 @@ public: ...@@ -202,6 +202,7 @@ public:
virtual void dispatchDidFinishDocumentLoad() OVERRIDE { } virtual void dispatchDidFinishDocumentLoad() OVERRIDE { }
virtual void dispatchDidFinishLoad() OVERRIDE { } virtual void dispatchDidFinishLoad() OVERRIDE { }
virtual void dispatchDidFirstVisuallyNonEmptyLayout() OVERRIDE { } virtual void dispatchDidFirstVisuallyNonEmptyLayout() OVERRIDE { }
virtual void dispatchDidChangeBrandColor() OVERRIDE { };
virtual NavigationPolicy decidePolicyForNavigation(const ResourceRequest&, DocumentLoader*, NavigationPolicy) OVERRIDE; virtual NavigationPolicy decidePolicyForNavigation(const ResourceRequest&, DocumentLoader*, NavigationPolicy) OVERRIDE;
......
...@@ -109,6 +109,7 @@ namespace WebCore { ...@@ -109,6 +109,7 @@ namespace WebCore {
virtual void dispatchDidFinishDocumentLoad() = 0; virtual void dispatchDidFinishDocumentLoad() = 0;
virtual void dispatchDidFinishLoad() = 0; virtual void dispatchDidFinishLoad() = 0;
virtual void dispatchDidFirstVisuallyNonEmptyLayout() = 0; virtual void dispatchDidFirstVisuallyNonEmptyLayout() = 0;
virtual void dispatchDidChangeBrandColor() = 0;
virtual NavigationPolicy decidePolicyForNavigation(const ResourceRequest&, DocumentLoader*, NavigationPolicy) = 0; virtual NavigationPolicy decidePolicyForNavigation(const ResourceRequest&, DocumentLoader*, NavigationPolicy) = 0;
......
...@@ -28,6 +28,7 @@ PrefixedVideoFullscreen status=test ...@@ -28,6 +28,7 @@ PrefixedVideoFullscreen status=test
// The changes enabled behind this flag are very likely to break lots of content. // The changes enabled behind this flag are very likely to break lots of content.
// ** DO NOT use this flag unless you know what you are doing. ** // ** DO NOT use this flag unless you know what you are doing. **
BleedingEdgeFastPaths BleedingEdgeFastPaths
BrandColor status=experimental
ClientHintsDpr status=experimental ClientHintsDpr status=experimental
Crypto status=experimental Crypto status=experimental
......
...@@ -450,6 +450,12 @@ void FrameLoaderClientImpl::dispatchDidFirstVisuallyNonEmptyLayout() ...@@ -450,6 +450,12 @@ void FrameLoaderClientImpl::dispatchDidFirstVisuallyNonEmptyLayout()
m_webFrame->client()->didFirstVisuallyNonEmptyLayout(m_webFrame); m_webFrame->client()->didFirstVisuallyNonEmptyLayout(m_webFrame);
} }
void FrameLoaderClientImpl::dispatchDidChangeBrandColor()
{
if (m_webFrame->client())
m_webFrame->client()->didChangeBrandColor(m_webFrame);
}
NavigationPolicy FrameLoaderClientImpl::decidePolicyForNavigation(const ResourceRequest& request, DocumentLoader* loader, NavigationPolicy policy) NavigationPolicy FrameLoaderClientImpl::decidePolicyForNavigation(const ResourceRequest& request, DocumentLoader* loader, NavigationPolicy policy)
{ {
if (!m_webFrame->client()) if (!m_webFrame->client())
......
...@@ -94,6 +94,7 @@ public: ...@@ -94,6 +94,7 @@ public:
virtual void dispatchDidFinishDocumentLoad() OVERRIDE; virtual void dispatchDidFinishDocumentLoad() OVERRIDE;
virtual void dispatchDidFinishLoad() OVERRIDE; virtual void dispatchDidFinishLoad() OVERRIDE;
virtual void dispatchDidFirstVisuallyNonEmptyLayout() OVERRIDE; virtual void dispatchDidFirstVisuallyNonEmptyLayout() OVERRIDE;
virtual void dispatchDidChangeBrandColor() OVERRIDE;
virtual WebCore::NavigationPolicy decidePolicyForNavigation(const WebCore::ResourceRequest&, WebCore::DocumentLoader*, WebCore::NavigationPolicy) OVERRIDE; virtual WebCore::NavigationPolicy decidePolicyForNavigation(const WebCore::ResourceRequest&, WebCore::DocumentLoader*, WebCore::NavigationPolicy) OVERRIDE;
virtual void dispatchWillRequestResource(WebCore::FetchRequest*) OVERRIDE; virtual void dispatchWillRequestResource(WebCore::FetchRequest*) OVERRIDE;
virtual void dispatchWillSendSubmitEvent(WebCore::HTMLFormElement*) OVERRIDE; virtual void dispatchWillSendSubmitEvent(WebCore::HTMLFormElement*) OVERRIDE;
......
...@@ -98,6 +98,11 @@ WebString WebDocument::referrer() const ...@@ -98,6 +98,11 @@ WebString WebDocument::referrer() const
return constUnwrap<Document>()->referrer(); return constUnwrap<Document>()->referrer();
} }
WebColor WebDocument::brandColor() const
{
return constUnwrap<Document>()->brandColor().rgb();
}
WebURL WebDocument::openSearchDescriptionURL() const WebURL WebDocument::openSearchDescriptionURL() const
{ {
return const_cast<Document*>(constUnwrap<Document>())->openSearchDescriptionURL(); return const_cast<Document*>(constUnwrap<Document>())->openSearchDescriptionURL();
......
...@@ -5544,4 +5544,43 @@ TEST_F(WebFrameTest, NodeImageTestCSS3DTransform) ...@@ -5544,4 +5544,43 @@ TEST_F(WebFrameTest, NodeImageTestCSS3DTransform)
EXPECT_EQ(0, memcmp(bitmap.getPixels(), dragBitmap.getPixels(), bitmap.getSize())); EXPECT_EQ(0, memcmp(bitmap.getPixels(), dragBitmap.getPixels(), bitmap.getSize()));
} }
class BrandColorTestWebFrameClient : public FrameTestHelpers::TestWebFrameClient {
public:
BrandColorTestWebFrameClient()
: m_didNotify(false)
, m_brandColor(0)
{
}
bool didNotify() const
{
return m_didNotify;
}
WebColor brandColor() const
{
return m_brandColor;
}
private:
virtual void didChangeBrandColor(WebLocalFrame* webLocalFrame)
{
m_didNotify = true;
m_brandColor = webLocalFrame->document().brandColor();
}
bool m_didNotify;
WebColor m_brandColor;
};
TEST_F(WebFrameTest, BrandColor)
{
registerMockedHttpURLLoad("brand_color_test.html");
FrameTestHelpers::WebViewHelper webViewHelper;
BrandColorTestWebFrameClient client;
webViewHelper.initializeAndLoad(m_baseURL + "brand_color_test.html", false, &client);
EXPECT_TRUE(client.didNotify());
EXPECT_EQ(0xff0000ff, client.brandColor());
}
} // namespace } // namespace
<html>
<head>
<title>Original Title</title>
<meta name="brand-color" content=" blue ">
<head>
<body>
</body>
</html>
...@@ -82,6 +82,7 @@ public: ...@@ -82,6 +82,7 @@ public:
BLINK_EXPORT WebString encoding() const; BLINK_EXPORT WebString encoding() const;
BLINK_EXPORT WebString contentLanguage() const; BLINK_EXPORT WebString contentLanguage() const;
BLINK_EXPORT WebString referrer() const; BLINK_EXPORT WebString referrer() const;
BLINK_EXPORT WebColor brandColor() const;
// The url of the OpenSearch Desription Document (if any). // The url of the OpenSearch Desription Document (if any).
BLINK_EXPORT WebURL openSearchDescriptionURL() const; BLINK_EXPORT WebURL openSearchDescriptionURL() const;
......
...@@ -266,6 +266,9 @@ public: ...@@ -266,6 +266,9 @@ public:
// The frame's manifest has changed. // The frame's manifest has changed.
virtual void didChangeManifest(WebLocalFrame*) { } virtual void didChangeManifest(WebLocalFrame*) { }
// The frame's brand color has changed.
virtual void didChangeBrandColor(WebLocalFrame*) { }
// Misc ---------------------------------------------------------------- // Misc ----------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment