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