1 // Copyright (c) 2011 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 "chrome/browser/ui/webui/remoting_ui.h"
6
7 #include "base/memory/singleton.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
10 #include "chrome/common/url_constants.h"
11 #include "content/browser/browser_thread.h"
12 #include "content/browser/tab_contents/tab_contents.h"
13 #include "grit/theme_resources.h"
14 #include "ui/base/resource/resource_bundle.h"
15
16 namespace {
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //
20 // RemotingHTMLSource
21 //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 class RemotingUIHTMLSource : public ChromeURLDataManager::DataSource {
25 public:
RemotingUIHTMLSource()26 RemotingUIHTMLSource()
27 : DataSource(chrome::kChromeUIRemotingHost, MessageLoop::current()) {}
28
29 // Called when the network layer has requested a resource underneath
30 // the path we registered.
31 virtual void StartDataRequest(const std::string& path,
32 bool is_incognito,
33 int request_id);
GetMimeType(const std::string &) const34 virtual std::string GetMimeType(const std::string&) const {
35 return "pepper-application/x-chromoting";
36 }
37
38 private:
~RemotingUIHTMLSource()39 ~RemotingUIHTMLSource() {}
40
41 DISALLOW_COPY_AND_ASSIGN(RemotingUIHTMLSource);
42 };
43
StartDataRequest(const std::string & path,bool is_incognito,int request_id)44 void RemotingUIHTMLSource::StartDataRequest(const std::string& path,
45 bool is_incognito,
46 int request_id) {
47 // Dummy data. Not used, but we need to send something back in the response.
48 std::string full_html = "remoting";
49
50 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes());
51 html_bytes->data.resize(full_html.size());
52 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
53
54 SendResponse(request_id, html_bytes);
55 }
56
57 } // namespace
58
59 ///////////////////////////////////////////////////////////////////////////////
60 //
61 // RemotingUI
62 //
63 ///////////////////////////////////////////////////////////////////////////////
64
RemotingUI(TabContents * contents)65 RemotingUI::RemotingUI(TabContents* contents) : WebUI(contents) {
66 RemotingUIHTMLSource* html_source = new RemotingUIHTMLSource();
67
68 // Set up the chrome://remoting source.
69 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source);
70 }
71
72
73 // static
GetFaviconResourceBytes()74 RefCountedMemory* RemotingUI::GetFaviconResourceBytes() {
75 return ResourceBundle::GetSharedInstance().
76 // TODO(garykac): Have custom remoting icon created.
77 LoadDataResourceBytes(IDR_PLUGIN);
78 }
79
80 // static
RegisterUserPrefs(PrefService * prefs)81 void RemotingUI::RegisterUserPrefs(PrefService* prefs) {
82 // TODO(garykac): Add remoting prefs (if needed).
83 }
84