OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ntp/android/context_menu_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/android/context_menu_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/android/tab_android.h" | |
13 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 12 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/android/context_menu_helper.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/common/context_menu_params.h" | 18 #include "content/public/common/context_menu_params.h" |
19 #include "content/public/common/page_transition_types.h" | 19 #include "content/public/common/page_transition_types.h" |
20 | 20 |
21 ContextMenuHandler::ContextMenuHandler() | 21 ContextMenuHandler::ContextMenuHandler() |
22 : weak_ptr_factory_(this) { | 22 : weak_ptr_factory_(this) { |
23 } | 23 } |
24 | 24 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 Value* value = NULL; | 99 Value* value = NULL; |
100 item_list_value->Get(1, &value); | 100 item_list_value->Get(1, &value); |
101 LOG(ERROR) << "Invalid context menu request: menu item " << i << | 101 LOG(ERROR) << "Invalid context menu request: menu item " << i << |
102 " expected string value for second parameter (got " << | 102 " expected string value for second parameter (got " << |
103 value->GetType() << ")."; | 103 value->GetType() << ")."; |
104 return; | 104 return; |
105 } | 105 } |
106 menu.custom_items.push_back(menu_item); | 106 menu.custom_items.push_back(menu_item); |
107 } | 107 } |
108 | 108 |
109 TabAndroid* tab = TabAndroid::FromWebContents(web_ui()->GetWebContents()); | 109 ContextMenuHelper* context_menu_helper = |
110 if (tab) { | 110 ContextMenuHelper::FromWebContents(web_ui()->GetWebContents()); |
111 tab->ShowCustomContextMenu( | 111 if (context_menu_helper) { |
| 112 context_menu_helper->ShowCustomContextMenu( |
112 menu, | 113 menu, |
113 base::Bind(&ContextMenuHandler::OnItemSelected, | 114 base::Bind(&ContextMenuHandler::OnItemSelected, |
114 weak_ptr_factory_.GetWeakPtr())); | 115 weak_ptr_factory_.GetWeakPtr())); |
115 } | 116 } |
116 } | 117 } |
117 | 118 |
118 void ContextMenuHandler::HandleOpenInNewTab(const ListValue* args) { | 119 void ContextMenuHandler::HandleOpenInNewTab(const ListValue* args) { |
119 OpenUrl(args, NEW_FOREGROUND_TAB); | 120 OpenUrl(args, NEW_FOREGROUND_TAB); |
120 } | 121 } |
121 | 122 |
122 void ContextMenuHandler::HandleOpenInIncognitoTab(const ListValue* args) { | 123 void ContextMenuHandler::HandleOpenInIncognitoTab(const ListValue* args) { |
123 OpenUrl(args, OFF_THE_RECORD); | 124 OpenUrl(args, OFF_THE_RECORD); |
124 } | 125 } |
125 | 126 |
126 void ContextMenuHandler::OpenUrl(const ListValue* args, | 127 void ContextMenuHandler::OpenUrl(const ListValue* args, |
127 WindowOpenDisposition disposition) { | 128 WindowOpenDisposition disposition) { |
128 string16 url = ExtractStringValue(args); | 129 string16 url = ExtractStringValue(args); |
129 if (!url.empty()) { | 130 if (!url.empty()) { |
130 web_ui()->GetWebContents()->OpenURL(content::OpenURLParams( | 131 web_ui()->GetWebContents()->OpenURL(content::OpenURLParams( |
131 GURL(url), content::Referrer(), disposition, | 132 GURL(url), content::Referrer(), disposition, |
132 content::PAGE_TRANSITION_AUTO_BOOKMARK, false)); | 133 content::PAGE_TRANSITION_AUTO_BOOKMARK, false)); |
133 } | 134 } |
134 } | 135 } |
OLD | NEW |