| // 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/common/url_constants.h" |
| #include "content/public/renderer/render_view.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.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" |
| |
| namespace android_webview { |
| |
| AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view) |
| : content::RenderViewObserver(render_view) { |
| render_view->GetWebView()->setPermissionClient(this); |
| } |
| |
| 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)); |
| } |
| |
| bool AwRenderViewExt::allowImage(WebKit::WebFrame* frame, |
| bool enabled_per_settings, |
| const WebKit::WebURL& image_url) { |
| // Implementing setBlockNetworkImages, so allow local scheme images to be |
| // loaded. |
| if (enabled_per_settings) |
| return true; |
| |
| // For compatibility, only blacklist network schemes instead of whitelisting. |
| const GURL url(image_url); |
| return !(url.SchemeIs(chrome::kHttpScheme) || |
| url.SchemeIs(chrome::kHttpsScheme) || |
| url.SchemeIs(chrome::kFtpScheme)); |
| } |
| |
| } // namespace android_webview |