Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: chrome/browser/ui/webui/sessions_ui.cc

Issue 7452012: Add content-security-policy to chrome://sessions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/sessions.html ('k') | chrome/test/functional/special_tabs.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/sessions_ui.h" 5 #include "chrome/browser/ui/webui/sessions_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sync/engine/syncapi.h" 10 #include "chrome/browser/sync/engine/syncapi.h"
11 #include "chrome/browser/sync/glue/session_model_associator.h" 11 #include "chrome/browser/sync/glue/session_model_associator.h"
12 #include "chrome/browser/sync/profile_sync_service.h" 12 #include "chrome/browser/sync/profile_sync_service.h"
13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
14 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
14 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 15 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
15 #include "chrome/common/chrome_version_info.h" 16 #include "chrome/common/chrome_version_info.h"
16 #include "chrome/common/jstemplate_builder.h" 17 #include "chrome/common/jstemplate_builder.h"
17 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
18 #include "content/browser/webui/web_ui.h" 19 #include "content/browser/webui/web_ui.h"
19 #include "grit/browser_resources.h" 20 #include "grit/browser_resources.h"
20 #include "grit/chromium_strings.h" 21 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
22 #include "grit/theme_resources.h" 23 #include "grit/theme_resources.h"
23 #include "grit/theme_resources_standard.h" 24 #include "grit/theme_resources_standard.h"
24 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
26 27
27 28
28 namespace { 29 namespace {
29 30
30 /////////////////////////////////////////////////////////////////////////////// 31 ChromeWebUIDataSource* CreateSessionsUIHTMLSource() {
31 // 32 ChromeWebUIDataSource* source =
32 // SessionsUIHTMLSource 33 new ChromeWebUIDataSource(chrome::kChromeUISessionsHost);
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 34
36 class SessionsUIHTMLSource : public ChromeURLDataManager::DataSource { 35 source->AddLocalizedString("sessionsTitle", IDS_SESSIONS_TITLE);
37 public: 36 source->AddLocalizedString("sessionsCountFormat",
38 SessionsUIHTMLSource() 37 IDS_SESSIONS_SESSION_COUNT_BANNER_FORMAT);
39 : DataSource(chrome::kChromeUISessionsHost, MessageLoop::current()) {} 38 source->AddLocalizedString("noSessionsMessage",
39 IDS_SESSIONS_NO_SESSIONS_MESSAGE);
40 source->AddLocalizedString("magicCountFormat",
41 IDS_SESSIONS_MAGIC_LIST_BANNER_FORMAT);
42 source->AddLocalizedString("noMagicMessage",
43 IDS_SESSIONS_NO_MAGIC_MESSAGE);
40 44
41 // Called when the network layer has requested a resource underneath 45 source->set_json_path("strings.js");
42 // the path we registered. 46 source->add_resource_path("sessions.js", IDR_SESSIONS_JS);
43 virtual void StartDataRequest(const std::string& path, 47 source->set_default_resource(IDR_SESSIONS_HTML);
44 bool is_incognito, 48 return source;
45 int request_id);
46 virtual std::string GetMimeType(const std::string&) const {
47 return "text/html";
48 }
49
50 private:
51 ~SessionsUIHTMLSource() {}
52
53 DISALLOW_COPY_AND_ASSIGN(SessionsUIHTMLSource);
54 };
55
56 void SessionsUIHTMLSource::StartDataRequest(const std::string& path,
57 bool is_incognito,
58 int request_id) {
59 DictionaryValue localized_strings;
60 localized_strings.SetString("sessionsTitle",
61 l10n_util::GetStringUTF16(IDS_SESSIONS_TITLE));
62 localized_strings.SetString("sessionsCountFormat",
63 l10n_util::GetStringUTF16(IDS_SESSIONS_SESSION_COUNT_BANNER_FORMAT));
64 localized_strings.SetString("noSessionsMessage",
65 l10n_util::GetStringUTF16(IDS_SESSIONS_NO_SESSIONS_MESSAGE));
66
67 localized_strings.SetString("magicCountFormat",
68 l10n_util::GetStringUTF16(IDS_SESSIONS_MAGIC_LIST_BANNER_FORMAT));
69 localized_strings.SetString("noMagicMessage",
70 l10n_util::GetStringUTF16(IDS_SESSIONS_NO_MAGIC_MESSAGE));
71
72 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings);
73
74 static const base::StringPiece sessions_html(
75 ResourceBundle::GetSharedInstance().
76 GetRawDataResource(IDR_SESSIONS_HTML));
77 std::string full_html =
78 jstemplate_builder::GetI18nTemplateHtml(sessions_html,
79 &localized_strings);
80 jstemplate_builder::AppendJsTemplateSourceHtml(&full_html);
81
82 SendResponse(request_id, base::RefCountedString::TakeString(&full_html));
83 } 49 }
84 50
85 //////////////////////////////////////////////////////////////////////////////// 51 ////////////////////////////////////////////////////////////////////////////////
86 // 52 //
87 // SessionsDOMHandler 53 // SessionsDOMHandler
88 // 54 //
89 //////////////////////////////////////////////////////////////////////////////// 55 ////////////////////////////////////////////////////////////////////////////////
90 56
91 // The handler for Javascript messages for the chrome://sessions/ page. 57 // The handler for Javascript messages for the chrome://sessions/ page.
92 class SessionsDOMHandler : public WebUIMessageHandler { 58 class SessionsDOMHandler : public WebUIMessageHandler {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 242
277 /////////////////////////////////////////////////////////////////////////////// 243 ///////////////////////////////////////////////////////////////////////////////
278 // 244 //
279 // SessionsUI 245 // SessionsUI
280 // 246 //
281 /////////////////////////////////////////////////////////////////////////////// 247 ///////////////////////////////////////////////////////////////////////////////
282 248
283 SessionsUI::SessionsUI(TabContents* contents) : ChromeWebUI(contents) { 249 SessionsUI::SessionsUI(TabContents* contents) : ChromeWebUI(contents) {
284 AddMessageHandler((new SessionsDOMHandler())->Attach(this)); 250 AddMessageHandler((new SessionsDOMHandler())->Attach(this));
285 251
286 SessionsUIHTMLSource* html_source = new SessionsUIHTMLSource();
287
288 // Set up the chrome://sessions/ source. 252 // Set up the chrome://sessions/ source.
289 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); 253 contents->profile()->GetChromeURLDataManager()->AddDataSource(
254 CreateSessionsUIHTMLSource());
290 } 255 }
291 256
292 // static 257 // static
293 RefCountedMemory* SessionsUI::GetFaviconResourceBytes() { 258 RefCountedMemory* SessionsUI::GetFaviconResourceBytes() {
294 return ResourceBundle::GetSharedInstance(). 259 return ResourceBundle::GetSharedInstance().
295 LoadDataResourceBytes(IDR_HISTORY_FAVICON); 260 LoadDataResourceBytes(IDR_HISTORY_FAVICON);
296 } 261 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/sessions.html ('k') | chrome/test/functional/special_tabs.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698