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.
4
5 #include "content/renderer/renderer_webapplicationcachehost_impl.h"
6
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/public/web/WebFrame.h"
11 #include "third_party/WebKit/public/web/WebView.h"
12
13 using appcache::AppCacheBackend;
14 using blink::WebApplicationCacheHostClient;
15 using blink::WebConsoleMessage;
16
17 namespace content {
18
RendererWebApplicationCacheHostImpl(RenderViewImpl * render_view,WebApplicationCacheHostClient * client,AppCacheBackend * backend)19 RendererWebApplicationCacheHostImpl::RendererWebApplicationCacheHostImpl(
20 RenderViewImpl* render_view,
21 WebApplicationCacheHostClient* client,
22 AppCacheBackend* backend)
23 : WebApplicationCacheHostImpl(client, backend),
24 routing_id_(render_view->routing_id()) {
25 }
26
OnLogMessage(appcache::AppCacheLogLevel log_level,const std::string & message)27 void RendererWebApplicationCacheHostImpl::OnLogMessage(
28 appcache::AppCacheLogLevel log_level, const std::string& message) {
29 if (RenderThreadImpl::current()->layout_test_mode())
30 return;
31
32 RenderViewImpl* render_view = GetRenderView();
33 if (!render_view || !render_view->webview() ||
34 !render_view->webview()->mainFrame())
35 return;
36
37 blink::WebFrame* frame = render_view->webview()->mainFrame();
38 frame->addMessageToConsole(WebConsoleMessage(
39 static_cast<WebConsoleMessage::Level>(log_level),
40 blink::WebString::fromUTF8(message.c_str())));
41 }
42
OnContentBlocked(const GURL & manifest_url)43 void RendererWebApplicationCacheHostImpl::OnContentBlocked(
44 const GURL& manifest_url) {
45 RenderThreadImpl::current()->Send(new ViewHostMsg_AppCacheAccessed(
46 routing_id_, manifest_url, true));
47 }
48
OnCacheSelected(const appcache::AppCacheInfo & info)49 void RendererWebApplicationCacheHostImpl::OnCacheSelected(
50 const appcache::AppCacheInfo& info) {
51 if (!info.manifest_url.is_empty()) {
52 RenderThreadImpl::current()->Send(new ViewHostMsg_AppCacheAccessed(
53 routing_id_, info.manifest_url, false));
54 }
55 WebApplicationCacheHostImpl::OnCacheSelected(info);
56 }
57
GetRenderView()58 RenderViewImpl* RendererWebApplicationCacheHostImpl::GetRenderView() {
59 return RenderViewImpl::FromRoutingID(routing_id_);
60 }
61
62 } // namespace content
63