Commit 8b527b1d authored by smaslo@chromium.org's avatar smaslo@chromium.org

JavaScript that returns whether or not a page is an article

Has a JavaScript file that contains a function to tell whether or not a
page is an article and related functions to get a string of that JavaScript
so that it can be injected into the page.

BUG=383630

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

Cr-Commit-Position: refs/heads/master@{#289192}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289192 0039d316-1c4b-4281-b951-d872f2087c98
parent 7f1e19ef
...@@ -49,7 +49,14 @@ public final class DomDistillerUrlUtils { ...@@ -49,7 +49,14 @@ public final class DomDistillerUrlUtils {
return nativeIsUrlDistillable(url); return nativeIsUrlDistillable(url);
} }
// TODO(yfriedman): Change method so that it takes in a WebContents and a
// callback.
public static String getIsDistillableJs() {
return nativeGetIsDistillableJs();
}
private static native String nativeGetDistillerViewUrlFromUrl(String scheme, String url); private static native String nativeGetDistillerViewUrlFromUrl(String scheme, String url);
private static native String nativeGetIsDistillableJs();
private static native String nativeGetOriginalUrlFromDistillerUrl(String viewerUrl); private static native String nativeGetOriginalUrlFromDistillerUrl(String viewerUrl);
private static native boolean nativeIsDistilledPage(String url); private static native boolean nativeIsDistilledPage(String url);
private static native boolean nativeIsUrlDistillable(String url); private static native boolean nativeIsUrlDistillable(String url);
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function() {
var elems = document.querySelectorAll(
'meta[property="og:type"],meta[name=\\"og:type\\"]');
for (var i in elems) {
if (elems[i].content && elems[i].content.toUpperCase() == 'ARTICLE') {
return true;
}
}
var elems = document.querySelectorAll(
'*[itemtype="http://schema.org/Article"]');
for (var i in elems) {
if (elems[i].itemscope) {
return true;
}
}
return false;
})()
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
#include "base/guid.h" #include "base/guid.h"
#include "components/dom_distiller/core/url_constants.h" #include "components/dom_distiller/core/url_constants.h"
#include "grit/component_resources.h"
#include "net/base/url_util.h" #include "net/base/url_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace dom_distiller { namespace dom_distiller {
...@@ -51,6 +53,11 @@ bool IsDistilledPage(const GURL& url) { ...@@ -51,6 +53,11 @@ bool IsDistilledPage(const GURL& url) {
return url.is_valid() && url.scheme() == kDomDistillerScheme; return url.is_valid() && url.scheme() == kDomDistillerScheme;
} }
std::string GetIsDistillableJs() {
return ResourceBundle::GetSharedInstance()
.GetRawDataResource(IDR_IS_DISTILLABLE_JS).as_string();
}
} // namespace url_utils } // namespace url_utils
} // namespace dom_distiller } // namespace dom_distiller
...@@ -31,6 +31,10 @@ bool IsUrlDistillable(const GURL& url); ...@@ -31,6 +31,10 @@ bool IsUrlDistillable(const GURL& url);
// Returns whether the given |url| is for a distilled page. // Returns whether the given |url| is for a distilled page.
bool IsDistilledPage(const GURL& url); bool IsDistilledPage(const GURL& url);
// Returns a JavaScript snippet that returns whether or not a page should be
// used with DomDistillerService and can be executed in a live page.
std::string GetIsDistillableJs();
} // namespace url_utils } // namespace url_utils
} // namespace dom_distiller } // namespace dom_distiller
......
...@@ -63,6 +63,11 @@ jboolean IsUrlDistillable(JNIEnv* env, jclass clazz, jstring j_url) { ...@@ -63,6 +63,11 @@ jboolean IsUrlDistillable(JNIEnv* env, jclass clazz, jstring j_url) {
return dom_distiller::url_utils::IsUrlDistillable(url); return dom_distiller::url_utils::IsUrlDistillable(url);
} }
jstring GetIsDistillableJs(JNIEnv* env, jclass clazz) {
return base::android::ConvertUTF8ToJavaString(
env, dom_distiller::url_utils::GetIsDistillableJs()).Release();
}
bool RegisterUrlUtils(JNIEnv* env) { return RegisterNativesImpl(env); } bool RegisterUrlUtils(JNIEnv* env) { return RegisterNativesImpl(env); }
} // namespace android } // namespace android
......
...@@ -7,4 +7,5 @@ ...@@ -7,4 +7,5 @@
<include name="IDR_DOM_DISTILLER_VIEWER_JS" file="../dom_distiller/content/resources/dom_distiller_viewer.js" type="BINDATA" /> <include name="IDR_DOM_DISTILLER_VIEWER_JS" file="../dom_distiller/content/resources/dom_distiller_viewer.js" type="BINDATA" />
<include name="IDR_DISTILLER_JS" file="../dom_distiller/core/javascript/domdistiller.js" flattenhtml="true" type="BINDATA" /> <include name="IDR_DISTILLER_JS" file="../dom_distiller/core/javascript/domdistiller.js" flattenhtml="true" type="BINDATA" />
<include name="IDR_DISTILLER_CSS" file="../dom_distiller/core/css/distilledpage.css" type="BINDATA" /> <include name="IDR_DISTILLER_CSS" file="../dom_distiller/core/css/distilledpage.css" type="BINDATA" />
<include name="IDR_IS_DISTILLABLE_JS" file="../dom_distiller/core/javascript/is_distillable_trigger.js" type="BINDATA" />
</grit-part> </grit-part>
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