e614359ba8de2ce7895d2fa96b237ede8753dc70
[platform/framework/web/crosswalk.git] / src / components / dom_distiller / content / dom_distiller_viewer_source.cc
1 // Copyright 2014 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 "components/dom_distiller/content/dom_distiller_viewer_source.h"
6
7 #include <string>
8
9 #include "base/memory/ref_counted_memory.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "content/public/browser/render_frame_host.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "net/url_request/url_request.h"
14 #include "url/gurl.h"
15
16 namespace dom_distiller {
17
18 DomDistillerViewerSource::DomDistillerViewerSource(const std::string& scheme)
19     : scheme_(scheme) {}
20
21 DomDistillerViewerSource::~DomDistillerViewerSource() {}
22
23 std::string DomDistillerViewerSource::GetSource() const { return scheme_; }
24
25 void DomDistillerViewerSource::StartDataRequest(
26     const std::string& path,
27     int render_process_id,
28     int render_frame_id,
29     const content::URLDataSource::GotDataCallback& callback) {
30   content::RenderFrameHost* render_frame_host =
31       content::RenderFrameHost::FromID(render_process_id, render_frame_id);
32   DCHECK(render_frame_host);
33   content::RenderViewHost* render_view_host =
34       render_frame_host->GetRenderViewHost();
35   DCHECK(render_view_host);
36   CHECK_EQ(0, render_view_host->GetEnabledBindings());
37
38   std::string page_template = "Aloha!";
39   callback.Run(base::RefCountedString::TakeString(&page_template));
40 };
41
42 std::string DomDistillerViewerSource::GetMimeType(const std::string& path)
43     const {
44   return "text/plain";
45 }
46
47 bool DomDistillerViewerSource::ShouldServiceRequest(
48     const net::URLRequest* request) const {
49   return request->url().SchemeIs(scheme_.c_str());
50 }
51
52 }  // namespace dom_distiller