blob: 6e45ec865ceeae45b407ec3e3224d09083b7c784 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/encoding_menu_controller_delegate.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/character_encoding.h"
#include "chrome/browser/encoding_menu_controller.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
EncodingMenuControllerDelegate::EncodingMenuControllerDelegate(Browser* browser)
: browser_(browser) {
}
bool EncodingMenuControllerDelegate::IsItemChecked(int id) const {
if (!browser_)
return false;
Profile *profile = browser_->profile();
if (!profile)
return false;
TabContents* current_tab = browser_->GetSelectedTabContents();
if (!current_tab) {
return false;
}
const std::wstring encoding = current_tab->encoding();
EncodingMenuController controller;
return controller.IsItemChecked(profile, encoding, id);
}
bool EncodingMenuControllerDelegate::SupportsCommand(int id) const {
return browser_->command_updater()->SupportsCommand(id);
}
bool EncodingMenuControllerDelegate::IsCommandEnabled(int id) const {
return browser_->command_updater()->IsCommandEnabled(id);
}
bool EncodingMenuControllerDelegate::GetContextualLabel(
int id,
std::wstring* out) const {
return false;
}
void EncodingMenuControllerDelegate::ExecuteCommand(int id) {
browser_->ExecuteCommand(id);
}
void EncodingMenuControllerDelegate::BuildEncodingMenu(
Profile* profile, views::Menu* encoding_menu) {
typedef EncodingMenuController::EncodingMenuItemList EncodingMenuItemList;
EncodingMenuItemList menuItems;
EncodingMenuController controller;
controller.GetEncodingMenuItems(profile, &menuItems);
for (EncodingMenuItemList::iterator it = menuItems.begin();
it != menuItems.end();
++it) {
views::Menu::MenuItemType type = views::Menu::RADIO;
int id = it->first;
std::wstring &localized_title = it->second;
if (id == 0) {
encoding_menu->AppendSeparator();
} else {
if (id == IDC_ENCODING_AUTO_DETECT) {
type = views::Menu::CHECKBOX;
}
encoding_menu->AppendMenuItem(id, localized_title, type);
}
}
}
|