Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: chrome_frame/utils.cc

Issue 7167002: Convert RenderViewContextMenu to MenuItemView. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Remove unused utility function. Created 9 years, 6 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
« chrome/common/automation_messages.h ('K') | « chrome_frame/utils.h ('k') | no next file » | 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_frame/utils.h" 5 #include "chrome_frame/utils.h"
6 6
7 #include <atlsafe.h> 7 #include <atlsafe.h>
8 #include <atlsecurity.h> 8 #include <atlsecurity.h>
9 #include <htiframe.h> 9 #include <htiframe.h>
10 #include <mshtml.h> 10 #include <mshtml.h>
11 #include <shlobj.h> 11 #include <shlobj.h>
12 12
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/file_version_info.h" 14 #include "base/file_version_info.h"
15 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
19 #include "base/string_tokenizer.h" 19 #include "base/string_tokenizer.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/stringprintf.h" 21 #include "base/stringprintf.h"
22 #include "base/threading/thread_local.h" 22 #include "base/threading/thread_local.h"
23 #include "base/utf_string_conversions.h" 23 #include "base/utf_string_conversions.h"
24 #include "base/win/registry.h" 24 #include "base/win/registry.h"
25 #include "base/win/scoped_bstr.h" 25 #include "base/win/scoped_bstr.h"
26 #include "base/win/scoped_comptr.h" 26 #include "base/win/scoped_comptr.h"
27 #include "base/win/scoped_variant.h" 27 #include "base/win/scoped_variant.h"
28 #include "chrome/common/automation_messages.h"
28 #include "chrome/common/chrome_paths_internal.h" 29 #include "chrome/common/chrome_paths_internal.h"
29 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
30 #include "chrome/installer/util/chrome_frame_distribution.h" 31 #include "chrome/installer/util/chrome_frame_distribution.h"
31 #include "chrome_frame/extra_system_apis.h" 32 #include "chrome_frame/extra_system_apis.h"
32 #include "chrome_frame/html_utils.h" 33 #include "chrome_frame/html_utils.h"
33 #include "chrome_frame/navigation_constraints.h" 34 #include "chrome_frame/navigation_constraints.h"
34 #include "chrome_frame/policy_settings.h" 35 #include "chrome_frame/policy_settings.h"
35 #include "chrome_frame/simple_resource_loader.h" 36 #include "chrome_frame/simple_resource_loader.h"
36 #include "googleurl/src/gurl.h" 37 #include "googleurl/src/gurl.h"
37 #include "googleurl/src/url_canon.h" 38 #include "googleurl/src/url_canon.h"
38 #include "grit/chromium_strings.h" 39 #include "grit/chromium_strings.h"
39 #include "net/base/escape.h" 40 #include "net/base/escape.h"
40 #include "net/http/http_util.h" 41 #include "net/http/http_util.h"
42 #include "ui/base/models/menu_model.h"
41 43
42 #include "chrome_tab.h" // NOLINT 44 #include "chrome_tab.h" // NOLINT
43 45
44 using base::win::RegKey; 46 using base::win::RegKey;
45 47
46 // Note that these values are all lower case and are compared to 48 // Note that these values are all lower case and are compared to
47 // lower-case-transformed values. 49 // lower-case-transformed values.
48 const wchar_t kMetaTag[] = L"meta"; 50 const wchar_t kMetaTag[] = L"meta";
49 const wchar_t kHttpEquivAttribName[] = L"http-equiv"; 51 const wchar_t kHttpEquivAttribName[] = L"http-equiv";
50 const wchar_t kContentAttribName[] = L"content"; 52 const wchar_t kContentAttribName[] = L"content";
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 HMODULE GetModuleFromAddress(void* address) { 582 HMODULE GetModuleFromAddress(void* address) {
581 MEMORY_BASIC_INFORMATION info = {0}; 583 MEMORY_BASIC_INFORMATION info = {0};
582 ::VirtualQuery(address, &info, sizeof(info)); 584 ::VirtualQuery(address, &info, sizeof(info));
583 return reinterpret_cast<HMODULE>(info.AllocationBase); 585 return reinterpret_cast<HMODULE>(info.AllocationBase);
584 } 586 }
585 587
586 namespace { 588 namespace {
587 589
588 const int kMaxSubmenuDepth = 10; 590 const int kMaxSubmenuDepth = 10;
589 591
590 // Copies original_menu and returns the copy. The caller is responsible for 592 // Builds a Windows menu from the menu model sent from Chrome. The
591 // closing the returned HMENU. This does not currently copy over bitmaps 593 // caller is responsible for closing the returned HMENU. This does
592 // (e.g. hbmpChecked, hbmpUnchecked or hbmpItem), so checkmarks, radio buttons, 594 // not currently handle bitmaps (e.g. hbmpChecked, hbmpUnchecked or
593 // and custom icons won't work. 595 // hbmpItem), so checkmarks, radio buttons, and custom icons won't work.
594 // It also copies over submenus up to a maximum depth of kMaxSubMenuDepth. 596 // It also copies over submenus up to a maximum depth of kMaxSubMenuDepth.
595 // 597 HMENU BuildContextMenuImpl(const ContextMenuModel* menu_model, int depth) {
596 // TODO(robertshield): Add support for the bitmap fields if need be.
597 HMENU UtilCloneContextMenuImpl(HMENU original_menu, int depth) {
598 DCHECK(IsMenu(original_menu));
599
600 if (depth >= kMaxSubmenuDepth) 598 if (depth >= kMaxSubmenuDepth)
601 return NULL; 599 return NULL;
602 600
603 HMENU new_menu = CreatePopupMenu(); 601 HMENU menu = CreatePopupMenu();
604 int item_count = GetMenuItemCount(original_menu); 602 for (size_t i = 0; i < menu_model->items.size(); i++) {
605 if (item_count <= 0) { 603 const ContextMenuModel::Item& item = menu_model->items[i];
606 NOTREACHED();
607 } else {
608 for (int i = 0; i < item_count; i++) {
609 MENUITEMINFO item_info = { 0 };
610 item_info.cbSize = sizeof(MENUITEMINFO);
611 item_info.fMask = MIIM_ID | MIIM_STRING | MIIM_FTYPE |
612 MIIM_STATE | MIIM_DATA | MIIM_SUBMENU |
613 MIIM_CHECKMARKS | MIIM_BITMAP;
614 604
615 // Call GetMenuItemInfo a first time to obtain the buffer size for 605 MENUITEMINFO item_info = { 0 };
616 // the label. 606 item_info.cbSize = sizeof(MENUITEMINFO);
617 if (GetMenuItemInfo(original_menu, i, TRUE, &item_info)) { 607 switch (item.type)
ananta 2011/06/17 19:03:38 The curly brace indicating the switch statement sc
rhashimoto 2011/06/17 23:34:36 Done.
618 item_info.cch++; // Increment this as per MSDN 608 {
619 std::vector<wchar_t> buffer(item_info.cch, 0); 609 case ui::MenuModel::TYPE_BUTTON_ITEM:
ananta 2011/06/17 19:03:38 Just replace this with a default case and print ou
ananta 2011/06/17 19:03:38 The alignment for the case labels is wrong. Please
rhashimoto 2011/06/17 23:34:36 Done.
rhashimoto 2011/06/17 23:34:36 Done.
620 item_info.dwTypeData = &buffer[0]; 610 NOTREACHED();
611 break;
612 case ui::MenuModel::TYPE_COMMAND:
613 case ui::MenuModel::TYPE_CHECK:
614 item_info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
615 item_info.fType = MFT_STRING;
616 item_info.wID = item.item_id;
617 item_info.dwTypeData = const_cast<LPWSTR>(item.label.c_str());
618 break;
619 case ui::MenuModel::TYPE_RADIO:
620 item_info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
621 item_info.fType = MFT_STRING | MFT_RADIOCHECK;
622 item_info.wID = item.item_id;
623 item_info.dwTypeData = const_cast<LPWSTR>(item.label.c_str());
624 break;
625 case ui::MenuModel::TYPE_SEPARATOR:
626 item_info.fMask = MIIM_FTYPE;
627 item_info.fType = MFT_SEPARATOR;
628 break;
629 case ui::MenuModel::TYPE_SUBMENU:
630 item_info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_SUBMENU;
631 item_info.fType = MFT_STRING;
632 item_info.wID = item.item_id;
633 item_info.dwTypeData = const_cast<LPWSTR>(item.label.c_str());
634 item_info.hSubMenu = BuildContextMenuImpl(item.submenu, depth + 1);
635 break;
636 }
621 637
622 // Call GetMenuItemInfo a second time with dwTypeData set to a buffer 638 item_info.fMask |= MIIM_STATE;
623 // of a correct size to get the label. 639 item_info.fState =
624 GetMenuItemInfo(original_menu, i, TRUE, &item_info); 640 (item.checked ? MFS_CHECKED : MFS_UNCHECKED) |
641 (item.enabled ? MFS_ENABLED : (MFS_DISABLED | MFS_GRAYED));
625 642
626 // Clone any submenus. Within reason. 643 InsertMenuItem(menu, i, TRUE, &item_info);
627 if (item_info.hSubMenu) { 644 }
628 HMENU new_submenu = UtilCloneContextMenuImpl(item_info.hSubMenu,
629 depth + 1);
630 item_info.hSubMenu = new_submenu;
631 }
632 645
633 // Now insert the item into the new menu. 646 return menu;
634 InsertMenuItem(new_menu, i, TRUE, &item_info);
635 }
636 }
637 }
638 return new_menu;
639 } 647 }
640 648
641 } // namespace 649 } // namespace
642 650
643 HMENU UtilCloneContextMenu(HMENU original_menu) { 651 HMENU BuildContextMenu(const ContextMenuModel& menu_model) {
644 return UtilCloneContextMenuImpl(original_menu, 0); 652 return BuildContextMenuImpl(&menu_model, 0);
645 } 653 }
646 654
647 std::string ResolveURL(const std::string& document, 655 std::string ResolveURL(const std::string& document,
648 const std::string& relative) { 656 const std::string& relative) {
649 if (document.empty()) { 657 if (document.empty()) {
650 return GURL(relative).spec(); 658 return GURL(relative).spec();
651 } else { 659 } else {
652 return GURL(document).Resolve(relative).spec(); 660 return GURL(document).Resolve(relative).spec();
653 } 661 }
654 } 662 }
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 ret = InternetSetOption(NULL, connection_options[option_index], 1672 ret = InternetSetOption(NULL, connection_options[option_index],
1665 &connections, connection_value_size); 1673 &connections, connection_value_size);
1666 if (!ret) { 1674 if (!ret) {
1667 return false; 1675 return false;
1668 } 1676 }
1669 } 1677 }
1670 wininet_connection_count_updated = true; 1678 wininet_connection_count_updated = true;
1671 return true; 1679 return true;
1672 } 1680 }
1673 1681
OLDNEW
« chrome/common/automation_messages.h ('K') | « chrome_frame/utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698