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

Side by Side Diff: ios/web/web_state/context_menu_params_utils.mm

Issue 2640433002: Clean the new CRWContextMenuController (Closed)
Patch Set: feedback Created 3 years, 11 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
OLDNEW
(Empty)
1 // Copyright 2017 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 #import "ios/web/web_state/context_menu_params_utils.h"
6
7 #include "base/strings/sys_string_conversions.h"
8 #include "components/url_formatter/url_formatter.h"
9 #include "ios/web/public/referrer_util.h"
10
11 #if !defined(__has_feature) || !__has_feature(objc_arc)
12 #error "This file requires ARC support."
13 #endif
14
15 namespace web {
16 ContextMenuParams ContextMenuParamsFromElementDictionary(
17 NSDictionary* element) {
18 ContextMenuParams params;
19 NSString* title = nil;
20 NSString* href = element[@"href"];
21 if (href) {
22 params.link_url = GURL(base::SysNSStringToUTF8(href));
23 if (params.link_url.SchemeIs(url::kJavaScriptScheme)) {
24 title = @"JavaScript";
25 } else {
26 base::string16 URLText = url_formatter::FormatUrl(params.link_url);
27 title = base::SysUTF16ToNSString(URLText);
28 }
29 }
30 NSString* src = element[@"src"];
31 if (src) {
32 params.src_url = GURL(base::SysNSStringToUTF8(src));
33 if (!title)
34 title = [src copy];
35 if ([title hasPrefix:base::SysUTF8ToNSString(url::kDataScheme)])
36 title = nil;
37 }
38 NSString* titleAttribute = element[@"title"];
39 if (titleAttribute)
40 title = titleAttribute;
41 if (title) {
42 params.menu_title.reset([title copy]);
43 }
44 NSString* referrerPolicy = element[@"referrerPolicy"];
45 if (referrerPolicy) {
46 params.referrer_policy =
47 web::ReferrerPolicyFromString(base::SysNSStringToUTF8(referrerPolicy));
48 }
49 NSString* innerText = element[@"innerText"];
50 if ([innerText length] > 0) {
51 params.link_text.reset([innerText copy]);
52 }
53 return params;
54 }
55
56 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/web_state/context_menu_params_utils.h ('k') | ios/web/web_state/context_menu_params_utils_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698