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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ios/web/web_state/context_menu_params_utils.mm
diff --git a/ios/web/web_state/context_menu_params_utils.mm b/ios/web/web_state/context_menu_params_utils.mm
new file mode 100644
index 0000000000000000000000000000000000000000..3acabb5e6517b4aeda8740c3f07f88ba8d76583b
--- /dev/null
+++ b/ios/web/web_state/context_menu_params_utils.mm
@@ -0,0 +1,56 @@
+// Copyright 2017 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.
+
+#import "ios/web/web_state/context_menu_params_utils.h"
+
+#include "base/strings/sys_string_conversions.h"
+#include "components/url_formatter/url_formatter.h"
+#include "ios/web/public/referrer_util.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+namespace web {
+ContextMenuParams ContextMenuParamsFromElementDictionary(
+ NSDictionary* element) {
+ ContextMenuParams params;
+ NSString* title = nil;
+ NSString* href = element[@"href"];
+ if (href) {
+ params.link_url = GURL(base::SysNSStringToUTF8(href));
+ if (params.link_url.SchemeIs(url::kJavaScriptScheme)) {
+ title = @"JavaScript";
+ } else {
+ base::string16 URLText = url_formatter::FormatUrl(params.link_url);
+ title = base::SysUTF16ToNSString(URLText);
+ }
+ }
+ NSString* src = element[@"src"];
+ if (src) {
+ params.src_url = GURL(base::SysNSStringToUTF8(src));
+ if (!title)
+ title = [src copy];
+ if ([title hasPrefix:base::SysUTF8ToNSString(url::kDataScheme)])
+ title = nil;
+ }
+ NSString* titleAttribute = element[@"title"];
+ if (titleAttribute)
+ title = titleAttribute;
+ if (title) {
+ params.menu_title.reset([title copy]);
+ }
+ NSString* referrerPolicy = element[@"referrerPolicy"];
+ if (referrerPolicy) {
+ params.referrer_policy =
+ web::ReferrerPolicyFromString(base::SysNSStringToUTF8(referrerPolicy));
+ }
+ NSString* innerText = element[@"innerText"];
+ if ([innerText length] > 0) {
+ params.link_text.reset([innerText copy]);
+ }
+ return params;
+}
+
+} // namespace web
« 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