diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-01 01:33:03 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-01 01:33:03 +0000 |
commit | fada28b55b676a75333a6fe9efa22bb97df0248d (patch) | |
tree | 5304a40d7677afd0f834df1ccd6145e02f99ab80 | |
parent | 4f4e00cbc1071345fd54589c4e2f4fbf9a951257 (diff) | |
download | chromium_src-fada28b55b676a75333a6fe9efa22bb97df0248d.zip chromium_src-fada28b55b676a75333a6fe9efa22bb97df0248d.tar.gz chromium_src-fada28b55b676a75333a6fe9efa22bb97df0248d.tar.bz2 |
Implement DocuementHasImages
Requires new plumbing to get custom android_webview
layer IPC messages a flowing.
BUG=
Review URL: https://chromiumcodereview.appspot.com/10890024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154564 0039d316-1c4b-4281-b951-d872f2087c98
18 files changed, 433 insertions, 43 deletions
diff --git a/android_webview/android_webview.gyp b/android_webview/android_webview.gyp index ec9fdbe..3322ed7 100644 --- a/android_webview/android_webview.gyp +++ b/android_webview/android_webview.gyp @@ -22,6 +22,12 @@ '<(DEPTH)/skia/config', ], 'sources': [ + 'common/android_webview_message_generator.cc', + 'common/android_webview_message_generator.h', + 'common/render_view_messages.cc', + 'common/render_view_messages.h', + 'browser/renderer_host/aw_render_view_host_ext.cc', + 'browser/renderer_host/aw_render_view_host_ext.h', 'browser/renderer_host/aw_resource_dispatcher_host_delegate.cc', 'browser/renderer_host/aw_resource_dispatcher_host_delegate.h', 'lib/aw_browser_dependency_factory_impl.cc', @@ -32,6 +38,8 @@ 'lib/main/aw_main_delegate.h', 'lib/main/webview_entry_point.cc', 'lib/main/webview_stubs.cc', + 'renderer/aw_render_view_ext.cc', + 'renderer/aw_render_view_ext.h', ], }, { diff --git a/android_webview/browser/renderer_host/aw_render_view_host_ext.cc b/android_webview/browser/renderer_host/aw_render_view_host_ext.cc new file mode 100644 index 0000000..63ac993 --- /dev/null +++ b/android_webview/browser/renderer_host/aw_render_view_host_ext.cc @@ -0,0 +1,69 @@ +// Copyright (c) 2012 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. + +#include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" + +#include "android_webview/common/render_view_messages.h" +#include "base/android/scoped_java_ref.h" +#include "base/callback.h" +#include "base/logging.h" +#include "content/public/browser/user_metrics.h" +#include "content/public/browser/web_contents.h" + +namespace android_webview { + +AwRenderViewHostExt::AwRenderViewHostExt(content::WebContents* contents) + : content::WebContentsObserver(contents) { +} + +AwRenderViewHostExt::~AwRenderViewHostExt() {} + +void AwRenderViewHostExt::DocumentHasImages(DocumentHasImagesResult result) { + DCHECK(CalledOnValidThread()); + if (!web_contents()->GetRenderViewHost()) { + result.Run(false); + return; + } + static int next_id = 1; + int this_id = next_id++; + pending_document_has_images_requests_[this_id] = result; + Send(new AwViewMsg_DocumentHasImages(web_contents()->GetRoutingID(), + this_id)); +} + +void AwRenderViewHostExt::RenderViewGone(base::TerminationStatus status) { + DCHECK(CalledOnValidThread()); + for (std::map<int, DocumentHasImagesResult>::iterator pending_req = + pending_document_has_images_requests_.begin(); + pending_req != pending_document_has_images_requests_.end(); + ++pending_req) { + pending_req->second.Run(false); + } +} + +bool AwRenderViewHostExt::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(AwRenderViewHostExt, message) + IPC_MESSAGE_HANDLER(AwViewHostMsg_DocumentHasImagesResponse, + OnDocumentHasImagesResponse) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + + return handled ? true : WebContentsObserver::OnMessageReceived(message); +} + +void AwRenderViewHostExt::OnDocumentHasImagesResponse(int msg_id, + bool has_images) { + DCHECK(CalledOnValidThread()); + std::map<int, DocumentHasImagesResult>::iterator pending_req = + pending_document_has_images_requests_.find(msg_id); + if (pending_req == pending_document_has_images_requests_.end()) { + DLOG(WARNING) << "unexpected DocumentHasImages Response: " << msg_id; + } else { + pending_req->second.Run(has_images); + pending_document_has_images_requests_.erase(pending_req); + } +} + +} // namespace android_webview diff --git a/android_webview/browser/renderer_host/aw_render_view_host_ext.h b/android_webview/browser/renderer_host/aw_render_view_host_ext.h new file mode 100644 index 0000000..f5bade2 --- /dev/null +++ b/android_webview/browser/renderer_host/aw_render_view_host_ext.h @@ -0,0 +1,42 @@ +// Copyright (c) 2012 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. + +#ifndef ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_ +#define ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_ + +#include "content/public/browser/web_contents_observer.h" + +#include "base/threading/non_thread_safe.h" + +namespace android_webview { + +// Provides RenderViewHost wrapper functionality for sending WebView-specific +// IPC messages to the renderer and from there to WebKit. +class AwRenderViewHostExt : public content::WebContentsObserver, + public base::NonThreadSafe { + public: + // To send receive messages to a RenderView we take the WebContents instance, + // as it internally handles RenderViewHost instances changing underneath us. + AwRenderViewHostExt(content::WebContents* contents); + virtual ~AwRenderViewHostExt(); + + // |result| will be invoked with the outcome of the request. + typedef base::Callback<void(bool)> DocumentHasImagesResult; + void DocumentHasImages(DocumentHasImagesResult result); + + private: + // content::WebContentsObserver implementation. + virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + void OnDocumentHasImagesResponse(int msg_id, bool has_images); + + std::map<int, DocumentHasImagesResult> pending_document_has_images_requests_; + + DISALLOW_COPY_AND_ASSIGN(AwRenderViewHostExt); +}; + +} // namespace android_webview + +#endif // ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_ diff --git a/android_webview/common/android_webview_message_generator.cc b/android_webview/common/android_webview_message_generator.cc new file mode 100644 index 0000000..d8b0080 --- /dev/null +++ b/android_webview/common/android_webview_message_generator.cc @@ -0,0 +1,34 @@ +// Copyright (c) 2010 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. + +// Get basic type definitions. +#define IPC_MESSAGE_IMPL +#include "android_webview/common/android_webview_message_generator.h" + +// Generate constructors. +#include "ipc/struct_constructor_macros.h" +#include "android_webview/common/android_webview_message_generator.h" + +// Generate destructors. +#include "ipc/struct_destructor_macros.h" +#include "android_webview/common/android_webview_message_generator.h" + +// Generate param traits write methods. +#include "ipc/param_traits_write_macros.h" +namespace IPC { +#include "android_webview/common/android_webview_message_generator.h" +} // namespace IPC + +// Generate param traits read methods. +#include "ipc/param_traits_read_macros.h" +namespace IPC { +#include "android_webview/common/android_webview_message_generator.h" +} // namespace IPC + +// Generate param traits log methods. +#include "ipc/param_traits_log_macros.h" +namespace IPC { +#include "android_webview/common/android_webview_message_generator.h" +} // namespace IPC + diff --git a/android_webview/common/android_webview_message_generator.h b/android_webview/common/android_webview_message_generator.h new file mode 100644 index 0000000..40d2d0a --- /dev/null +++ b/android_webview/common/android_webview_message_generator.h @@ -0,0 +1,8 @@ +// Copyright (c) 2012 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. + +// Multiply-included file, hence no include guard. + +#include "android_webview/common/render_view_messages.h" + diff --git a/android_webview/common/render_view_messages.cc b/android_webview/common/render_view_messages.cc new file mode 100644 index 0000000..a954e2a --- /dev/null +++ b/android_webview/common/render_view_messages.cc @@ -0,0 +1,11 @@ +// Copyright (c) 2012 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. + +#include "android_webview/common/render_view_messages.h" + +namespace IPC { + +// TODO - add enums and custom IPC traits here when needed. + +} // namespace IPC diff --git a/android_webview/common/render_view_messages.h b/android_webview/common/render_view_messages.h new file mode 100644 index 0000000..52bea1b --- /dev/null +++ b/android_webview/common/render_view_messages.h @@ -0,0 +1,43 @@ +// Copyright (c) 2012 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. + +// Multiply-included file, no traditional include guard. +#include "ipc/ipc_channel_handle.h" +#include "ipc/ipc_message_macros.h" +#include "ipc/ipc_platform_file.h" + +// Singly-included section for enums and custom IPC traits. +#ifndef ANDROID_WEBVIEW_COMMON_RENDER_VIEW_MESSAGES_H_ +#define ANDROID_WEBVIEW_COMMON_RENDER_VIEW_MESSAGES_H_ + + +namespace IPC { + +// TODO - add enums and custom IPC traits here when needed. + +} // namespace IPC + +#endif // ANDROID_WEBVIEW_COMMON_RENDER_VIEW_MESSAGES_H_ + +#define IPC_MESSAGE_START AndroidWebViewMsgStart + +//----------------------------------------------------------------------------- +// RenderView messages +// These are messages sent from the browser to the renderer process. + +// Request for the renderer to determine if the document contains any image +// elements. The id should be passed in the response message so the response +// can be associated with the request. +IPC_MESSAGE_ROUTED1(AwViewMsg_DocumentHasImages, + int /* id */) + +//----------------------------------------------------------------------------- +// RenderView messages +// These are messages sent from the renderer to the browser process. + +// Response to AwViewMsg_DocumentHasImages request. +IPC_MESSAGE_ROUTED2(AwViewHostMsg_DocumentHasImagesResponse, + int, /* id */ + bool /* has_images */) + diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index a5003ad..7addd03 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -5,7 +5,9 @@ package org.chromium.android_webview; import android.view.ViewGroup; +import android.os.Message; +import org.chromium.base.CalledByNative; import org.chromium.base.JNINamespace; import org.chromium.content.browser.ContentViewCore; import org.chromium.content.common.CleanupReference; @@ -78,12 +80,6 @@ public class AwContents { mCleanupReference.cleanupNow(); } - private native int nativeInit(AwWebContentsDelegate webViewWebContentsDelegate, - boolean privateBrowsing); - private static native void nativeDestroy(int nativeAwContents); - - private native int nativeGetWebContents(int nativeAwContents); - /** * @return load progress of the WebContents */ @@ -91,4 +87,34 @@ public class AwContents { // WebContentsDelegateAndroid conveniently caches the most recent notified value for us. return mContentsClient.getWebContentsDelegate().getMostRecentProgress(); } + + //-------------------------------------------------------------------------------------------- + // WebView[Provider] method implementations (where not provided by ContentViewCore) + //-------------------------------------------------------------------------------------------- + + public void documentHasImages(Message message) { + nativeDocumentHasImages(mNativeAwContents, message); + } + + //-------------------------------------------------------------------------------------------- + // Methods called from native via JNI + //-------------------------------------------------------------------------------------------- + + @CalledByNative + private static void onDocumentHasImagesResponse(boolean result, Message message) { + message.arg1 = result ? 1 : 0; + message.sendToTarget(); + } + + //-------------------------------------------------------------------------------------------- + // Native methods + //-------------------------------------------------------------------------------------------- + + private native int nativeInit(AwWebContentsDelegate webViewWebContentsDelegate, + boolean privateBrowsing); + private static native void nativeDestroy(int nativeAwContents); + + private native int nativeGetWebContents(int nativeAwContents); + + private native void nativeDocumentHasImages(int nativeAwContents, Message message); } diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java index f052070..ab907cc 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java @@ -4,62 +4,78 @@ package org.chromium.android_webview.test; -import android.content.Context; import android.os.Handler; import android.os.Looper; +import android.os.Message; +import android.test.UiThreadTest; import android.test.suitebuilder.annotation.SmallTest; -import android.widget.GridLayout; import org.chromium.android_webview.AwContents; -import org.chromium.android_webview.AwContentsClient; import org.chromium.base.test.Feature; -import org.chromium.content.browser.ContentViewCore; +import org.chromium.content.browser.test.CallbackHelper; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; /** * AwContents tests. */ public class AwContentsTest extends AndroidWebViewTestBase { - private AwContentsClient mContentsClient = new NullContentsClient(); - - private AwContents createContents(Context context) { - GridLayout viewGroup = new GridLayout(context); - - // TODO: Required ContentViewCore changes are not upstreamed yet. - // ContentViewCore contentViewCore = new ContentViewCore( - // context, ContentViewCore.PERSONALITY_VIEW); - ContentViewCore contentViewCore = new ContentViewCore( - context, viewGroup, null, 0, ContentViewCore.PERSONALITY_VIEW); - AwContents awContents = new AwContents(viewGroup, null, contentViewCore, - mContentsClient, false, false); - return awContents; - } + private TestAwContentsClient mContentsClient = new TestAwContentsClient(); @SmallTest @Feature({"Android-WebView"}) + @UiThreadTest public void testCreateDestroy() throws Throwable { - final Throwable[] error = new Throwable[1]; - final Semaphore s = new Semaphore(0); - final Context context = getActivity(); + // NOTE this test runs on UI thread, so we cannot call any async methods. + createAwTestContainerView(false, mContentsClient).getAwContents().destroy(); + } - Runnable r = new Runnable() { + private int callDocumentHasImagesSync(final AwContents awContents) + throws Throwable, InterruptedException { + // Set up a container to hold the result object and a semaphore to + // make the test wait for the result. + final AtomicInteger val = new AtomicInteger(); + final Semaphore s = new Semaphore(0); + final Message msg = Message.obtain(new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(Message msg) { + val.set(msg.arg1); + s.release(); + } + }); + runTestOnUiThread(new Runnable() { @Override public void run() { - try { - createContents(context).destroy(); - } catch (Throwable t) { - error[0] = t; - } finally { - s.release(); - } + awContents.documentHasImages(msg); } - }; - new Handler(Looper.getMainLooper()).post(r); - assertTrue(s.tryAcquire(10000, TimeUnit.MILLISECONDS)); - if (error[0] != null) { - throw error[0]; - } + }); + assertTrue(s.tryAcquire(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)); + int result = val.get(); + return result; + } + + @SmallTest + @Feature({"Android-WebView"}) + public void testDocumentHasImages() throws Throwable { + AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient); + AwContents awContents = testView.getAwContents(); + + final CallbackHelper loadHelper = mContentsClient.getOnPageFinishedHelper(); + + final String mime = "text/html"; + final String emptyDoc = "<head/><body/>"; + final String imageDoc = "<head/><body><img/><img/></body>"; + + // Make sure a document that does not have images returns 0 + loadDataSync(awContents.getContentViewCore(), loadHelper, emptyDoc, mime, false); + int result = callDocumentHasImagesSync(awContents); + assertEquals(0, result); + + // Make sure a document that does have images returns 1 + loadDataSync(awContents.getContentViewCore(), loadHelper, imageDoc, mime, false); + result = callDocumentHasImagesSync(awContents); + assertEquals(1, result); } -} +}
\ No newline at end of file diff --git a/android_webview/lib/aw_content_browser_client.cc b/android_webview/lib/aw_content_browser_client.cc index bc34974..aeaedf2 100644 --- a/android_webview/lib/aw_content_browser_client.cc +++ b/android_webview/lib/aw_content_browser_client.cc @@ -16,6 +16,7 @@ AwContentBrowserClient::~AwContentBrowserClient() { } void AwContentBrowserClient::ResourceDispatcherHostCreated() { + ChromeContentBrowserClient::ResourceDispatcherHostCreated(); AwResourceDispatcherHostDelegate::ResourceDispatcherHostCreated(); } diff --git a/android_webview/lib/main/aw_main_delegate.cc b/android_webview/lib/main/aw_main_delegate.cc index 611cf15..cd819ac 100644 --- a/android_webview/lib/main/aw_main_delegate.cc +++ b/android_webview/lib/main/aw_main_delegate.cc @@ -6,6 +6,7 @@ #include "android_webview/lib/aw_browser_dependency_factory_impl.h" #include "android_webview/lib/aw_content_browser_client.h" +#include "android_webview/renderer/aw_render_view_ext.h" #include "base/lazy_instance.h" #include "base/logging.h" #include "chrome/common/chrome_paths.h" @@ -15,9 +16,22 @@ namespace android_webview { +namespace { + +// TODO(joth): Remove chrome/ dependency; move into android_webview/renderer +class AwContentRendererClient : public chrome::ChromeContentRendererClient { + public: + virtual void RenderViewCreated(content::RenderView* render_view) { + chrome::ChromeContentRendererClient::RenderViewCreated(render_view); + AwRenderViewExt::RenderViewCreated(render_view); + } +}; + +} + base::LazyInstance<AwContentBrowserClient> g_webview_content_browser_client = LAZY_INSTANCE_INITIALIZER; -base::LazyInstance<chrome::ChromeContentRendererClient> +base::LazyInstance<AwContentRendererClient> g_webview_content_renderer_client = LAZY_INSTANCE_INITIALIZER; AwMainDelegate::AwMainDelegate() { diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc index f5eeebe..362a603 100644 --- a/android_webview/native/aw_contents.cc +++ b/android_webview/native/aw_contents.cc @@ -4,11 +4,14 @@ #include "android_webview/native/aw_contents.h" +#include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" #include "android_webview/native/aw_browser_dependency_factory.h" #include "android_webview/native/aw_contents_container.h" #include "android_webview/native/aw_web_contents_delegate.h" #include "base/android/jni_android.h" #include "base/android/jni_string.h" +#include "base/bind.h" +#include "base/callback.h" #include "base/supports_user_data.h" #include "content/public/browser/android/content_view_core.h" #include "content/public/browser/web_contents.h" @@ -16,6 +19,8 @@ using base::android::AttachCurrentThread; using base::android::ConvertUTF16ToJavaString; +using base::android::ScopedJavaGlobalRef; +using base::android::ScopedJavaLocalRef; using content::ContentViewCore; using content::WebContents; @@ -64,6 +69,7 @@ AwContents::AwContents(JNIEnv* env, dependency_factory->GetJavaScriptDialogCreator()); web_contents->SetUserData(kAwContentsUserDataKey, new AwContentsUserData(this)); + render_view_host_ext_.reset(new AwRenderViewHostExt(web_contents)); } AwContents::~AwContents() { @@ -80,6 +86,24 @@ void AwContents::Destroy(JNIEnv* env, jobject obj) { delete this; } +namespace { +// |message| is passed as base::Owned, so it will automatically be deleted +// when the callback goes out of scope. +void DocumentHasImagesCallback(ScopedJavaGlobalRef<jobject>* message, + bool has_images) { + Java_AwContents_onDocumentHasImagesResponse(AttachCurrentThread(), + has_images, + message->obj()); +} +} // namespace + +void AwContents::DocumentHasImages(JNIEnv* env, jobject obj, jobject message) { + render_view_host_ext_->DocumentHasImages( + base::Bind(&DocumentHasImagesCallback, + base::Owned(new ScopedJavaGlobalRef<jobject>( + ScopedJavaLocalRef<jobject>(env, message))))); +} + static jint Init(JNIEnv* env, jobject obj, jobject web_contents_delegate, diff --git a/android_webview/native/aw_contents.h b/android_webview/native/aw_contents.h index b282585..1c310ab 100644 --- a/android_webview/native/aw_contents.h +++ b/android_webview/native/aw_contents.h @@ -19,6 +19,7 @@ class WebContents; namespace android_webview { class AwContentsContainer; +class AwRenderViewHostExt; class AwWebContentsDelegate; // Native side of java-class of same name. @@ -39,11 +40,13 @@ class AwContents { // Methods called from Java. jint GetWebContents(JNIEnv* env, jobject obj); void Destroy(JNIEnv* env, jobject obj); + void DocumentHasImages(JNIEnv* env, jobject obj, jobject message); private: JavaObjectWeakGlobalRef java_ref_; scoped_ptr<AwContentsContainer> contents_container_; scoped_ptr<AwWebContentsDelegate> web_contents_delegate_; + scoped_ptr<AwRenderViewHostExt> render_view_host_ext_; DISALLOW_COPY_AND_ASSIGN(AwContents); }; diff --git a/android_webview/renderer/DEPS b/android_webview/renderer/DEPS new file mode 100644 index 0000000..d72bd7c --- /dev/null +++ b/android_webview/renderer/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+third_party/WebKit/Source/WebKit/chromium", +] diff --git a/android_webview/renderer/aw_render_view_ext.cc b/android_webview/renderer/aw_render_view_ext.cc new file mode 100644 index 0000000..ae0035d --- /dev/null +++ b/android_webview/renderer/aw_render_view_ext.cc @@ -0,0 +1,51 @@ +// Copyright (c) 2012 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. + +#include "android_webview/renderer/aw_render_view_ext.h" + +#include "android_webview/common/render_view_messages.h" +#include "content/public/renderer/render_view.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" + +namespace android_webview { + +AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view) + : content::RenderViewObserver(render_view) { +} + +AwRenderViewExt::~AwRenderViewExt() {} + +// static +void AwRenderViewExt::RenderViewCreated(content::RenderView* render_view) { + new AwRenderViewExt(render_view); // |render_view| takes ownership. +} + +bool AwRenderViewExt::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(AwRenderViewExt, message) + IPC_MESSAGE_HANDLER(AwViewMsg_DocumentHasImages, OnDocumentHasImagesRequest) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void AwRenderViewExt::OnDocumentHasImagesRequest(int id) { + bool hasImages = false; + if (render_view()) { + WebKit::WebView* webview = render_view()->GetWebView(); + if (webview) { + WebKit::WebVector<WebKit::WebElement> images; + webview->mainFrame()->document().images(images); + hasImages = !images.isEmpty(); + } + } + Send(new AwViewHostMsg_DocumentHasImagesResponse(routing_id(), id, + hasImages)); +} + +} // namespace android_webview diff --git a/android_webview/renderer/aw_render_view_ext.h b/android_webview/renderer/aw_render_view_ext.h new file mode 100644 index 0000000..fa58872 --- /dev/null +++ b/android_webview/renderer/aw_render_view_ext.h @@ -0,0 +1,35 @@ +// Copyright (c) 2012 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. + +#ifndef ANDROID_WEBVIEW_RENDERER_AW_RENDER_VIEW_EXT_H_ +#define ANDROID_WEBVIEW_RENDERER_AW_RENDER_VIEW_EXT_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "content/public/renderer/render_view_observer.h" + +namespace android_webview { + +// Render process side of AwRenderViewHostExt, this provides cross-process +// implementation of miscellaneous WebView functions that we need to poke +// WebKit directly to implement (and that aren't needed in the chrome app). +class AwRenderViewExt : public content::RenderViewObserver { + public: + static void RenderViewCreated(content::RenderView* render_view); + + private: + AwRenderViewExt(content::RenderView* render_view); + virtual ~AwRenderViewExt(); + + // RenderView::Observer: + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + void OnDocumentHasImagesRequest(int id); + + DISALLOW_COPY_AND_ASSIGN(AwRenderViewExt); +}; + +} // namespace android_webview + +#endif // ANDROID_WEBVIEW_RENDERER_AW_RENDER_VIEW_EXT_H_ diff --git a/base/android/jni_generator/jni_generator.py b/base/android/jni_generator/jni_generator.py index 26506c2..e62e3bb 100755 --- a/base/android/jni_generator/jni_generator.py +++ b/base/android/jni_generator/jni_generator.py @@ -137,6 +137,7 @@ def JavaParamToJni(param): 'Landroid/view/KeyEvent', 'Landroid/graphics/Rect', 'Landroid/graphics/RectF', + 'Landroid/os/Message', 'Landroid/view/View', 'Landroid/graphics/Matrix', 'Landroid/graphics/Point', diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h index 07db6ef..0d92f67 100644 --- a/ipc/ipc_message_utils.h +++ b/ipc/ipc_message_utils.h @@ -104,6 +104,7 @@ enum IPCMessageStart { ChromotingMsgStart, OldBrowserPluginMsgStart, BrowserPluginMsgStart, + AndroidWebViewMsgStart, LastIPCMsgStart // Must come last. }; |