| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/web/public/web_state/context_menu_params.h" | 5 #import "ios/web/public/web_state/context_menu_params.h" |
| 6 | 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 |
| 7 #if !defined(__has_feature) || !__has_feature(objc_arc) | 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 8 #error "This file requires ARC support." | 12 #error "This file requires ARC support." |
| 9 #endif | 13 #endif |
| 10 | 14 |
| 11 namespace web { | 15 namespace web { |
| 12 | 16 |
| 13 ContextMenuParams::ContextMenuParams() | 17 ContextMenuParams::ContextMenuParams() |
| 14 : referrer_policy(ReferrerPolicyDefault), location(CGPointZero) {} | 18 : referrer_policy(ReferrerPolicyDefault), location(CGPointZero) {} |
| 15 | 19 |
| 16 ContextMenuParams::ContextMenuParams(const ContextMenuParams& other) = default; | 20 ContextMenuParams::ContextMenuParams(const ContextMenuParams& other) = default; |
| 17 | 21 |
| 18 ContextMenuParams::~ContextMenuParams() {} | 22 ContextMenuParams::~ContextMenuParams() {} |
| 19 | 23 |
| 24 ContextMenuParams::ContextMenuParams(NSDictionary* element) |
| 25 : ContextMenuParams() { |
| 26 NSString* title = nil; |
| 27 NSString* href = element[@"href"]; |
| 28 if (href) { |
| 29 link_url = GURL(base::SysNSStringToUTF8(href)); |
| 30 if (link_url.SchemeIs(url::kJavaScriptScheme)) { |
| 31 title = @"JavaScript"; |
| 32 } else { |
| 33 base::string16 URLText = url_formatter::FormatUrl(link_url); |
| 34 title = base::SysUTF16ToNSString(URLText); |
| 35 } |
| 36 } |
| 37 NSString* src = element[@"src"]; |
| 38 if (src) { |
| 39 src_url = GURL(base::SysNSStringToUTF8(src)); |
| 40 if (!title) |
| 41 title = [src copy]; |
| 42 if ([title hasPrefix:base::SysUTF8ToNSString(url::kDataScheme)]) |
| 43 title = nil; |
| 44 } |
| 45 NSString* titleAttribute = element[@"title"]; |
| 46 if (titleAttribute) |
| 47 title = titleAttribute; |
| 48 if (title) { |
| 49 menu_title.reset([title copy]); |
| 50 } |
| 51 NSString* referrerPolicy = element[@"referrerPolicy"]; |
| 52 if (referrerPolicy) { |
| 53 referrer_policy = |
| 54 web::ReferrerPolicyFromString(base::SysNSStringToUTF8(referrerPolicy)); |
| 55 } |
| 56 NSString* innerText = element[@"innerText"]; |
| 57 if ([innerText length] > 0) { |
| 58 link_text.reset([innerText copy]); |
| 59 } |
| 60 } |
| 61 |
| 20 } // namespace web | 62 } // namespace web |
| OLD | NEW |