blob: 2196ffedd4050d49cea844fc5fa553cbcb1985fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// 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/document_state.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/WebDataSource.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/WebSecurityOrigin.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));
}
void AwRenderViewExt::DidCommitProvisionalLoad(WebKit::WebFrame* frame,
bool is_new_navigation) {
content::DocumentState* document_state =
content::DocumentState::FromDataSource(frame->dataSource());
if (document_state->can_load_local_resources()) {
WebKit::WebSecurityOrigin origin = frame->document().securityOrigin();
origin.grantLoadLocalResources();
}
}
} // namespace android_webview
|