1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/renderer_webapplicationcachehost_impl.h"
7 #include "content/common/view_messages.h"
8 #include "content/renderer/render_thread_impl.h"
9 #include "content/renderer/render_view_impl.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
13 using appcache::AppCacheBackend
;
14 using WebKit::WebApplicationCacheHostClient
;
15 using WebKit::WebConsoleMessage
;
19 static bool g_disable_logging
= false;
21 RendererWebApplicationCacheHostImpl::RendererWebApplicationCacheHostImpl(
22 RenderViewImpl
* render_view
,
23 WebApplicationCacheHostClient
* client
,
24 AppCacheBackend
* backend
)
25 : WebApplicationCacheHostImpl(client
, backend
),
26 routing_id_(render_view
->routing_id()) {
29 void RendererWebApplicationCacheHostImpl::OnLogMessage(
30 appcache::LogLevel log_level
, const std::string
& message
) {
31 if (g_disable_logging
)
34 RenderViewImpl
* render_view
= GetRenderView();
35 if (!render_view
|| !render_view
->webview() ||
36 !render_view
->webview()->mainFrame())
39 WebKit::WebFrame
* frame
= render_view
->webview()->mainFrame();
40 frame
->addMessageToConsole(WebConsoleMessage(
41 static_cast<WebConsoleMessage::Level
>(log_level
),
42 WebKit::WebString::fromUTF8(message
.c_str())));
45 void RendererWebApplicationCacheHostImpl::OnContentBlocked(
46 const GURL
& manifest_url
) {
47 RenderThreadImpl::current()->Send(new ViewHostMsg_AppCacheAccessed(
48 routing_id_
, manifest_url
, true));
51 void RendererWebApplicationCacheHostImpl::OnCacheSelected(
52 const appcache::AppCacheInfo
& info
) {
53 if (!info
.manifest_url
.is_empty()) {
54 RenderThreadImpl::current()->Send(new ViewHostMsg_AppCacheAccessed(
55 routing_id_
, info
.manifest_url
, false));
57 WebApplicationCacheHostImpl::OnCacheSelected(info
);
60 RenderViewImpl
* RendererWebApplicationCacheHostImpl::GetRenderView() {
61 return static_cast<RenderViewImpl
*>
62 (RenderThreadImpl::current()->ResolveRoute(routing_id_
));
66 void RendererWebApplicationCacheHostImpl::DisableLoggingForTesting() {
67 g_disable_logging
= true;
70 } // namespace content